DefaultNameIdResolver implements NameIdResolver { @Override public String resolve( User user, String entityId, String format, String spQualifierName, boolean allowCreate, NameIdResolverSAMLContext nameIdResolverSAMLContext) { return getNameIdValue(user, entityId); }  @Override String resolve(
		User user, String entityId, String format, String spQualifierName,
		boolean allowCreate,
		NameIdResolverSAMLContext nameIdResolverSAMLContext); @Reference(unbind = "-") void setMetadataManager(MetadataManager metadataManager);  }
@Test public void testResolveEmailAddressNameId() throws Exception { when( _beanProperties.getObject( Mockito.any(User.class), Mockito.eq("emailAddress")) ).thenReturn( "test@liferay.com" ); when( _metadataManager.getNameIdAttribute(Mockito.eq(SP_ENTITY_ID)) ).thenReturn( "emailAddress" ); String nameId = _defaultNameIdResolver.resolve( _user, SP_ENTITY_ID, null, null, false, null); Assert.assertNotNull(nameId); Assert.assertEquals("test@liferay.com", nameId); }
@Test public void testResolveExpandoNameId() throws Exception { when( _expandoBridge.getAttribute(Mockito.eq("customerId")) ).thenReturn( "12345" ); when( _metadataManager.getNameIdAttribute(Mockito.eq(SP_ENTITY_ID)) ).thenReturn( "expando:customerId" ); String nameId = _defaultNameIdResolver.resolve( _user, SP_ENTITY_ID, null, null, false, null); Assert.assertNotNull(nameId); Assert.assertEquals("12345", nameId); }
@Test public void testResolveNameIdWithPolicy() throws Exception { when( _beanProperties.getObject( Mockito.any(User.class), Mockito.eq("screenName")) ).thenReturn( "test" ); when( _metadataManager.getNameIdAttribute(Mockito.eq(SP_ENTITY_ID)) ).thenReturn( "screenName" ); NameIDPolicy nameIDPolicy = OpenSamlUtil.buildNameIdPolicy(); nameIDPolicy.setFormat(NameID.ENTITY.toString()); nameIDPolicy.setSPNameQualifier("urn:liferay"); String nameId = _defaultNameIdResolver.resolve( _user, SP_ENTITY_ID, NameID.ENTITY.toString(), null, false, null); Assert.assertNotNull(nameId); Assert.assertEquals("test", nameId); }
@Test public void testResolveScreenNameNameId() throws Exception { when( _beanProperties.getObject( Mockito.any(User.class), Mockito.eq("screenName")) ).thenReturn( "test" ); when( _metadataManager.getNameIdAttribute(Mockito.eq(SP_ENTITY_ID)) ).thenReturn( "screenName" ); when( _metadataManager.getNameIdFormat(Mockito.eq(SP_ENTITY_ID)) ).thenReturn( NameID.ENTITY.toString() ); String nameId = _defaultNameIdResolver.resolve( _user, SP_ENTITY_ID, null, null, false, null); Assert.assertNotNull(nameId); Assert.assertEquals("test", nameId); }
@Test public void testResolveStaticNameId() throws Exception { when( _metadataManager.getNameIdAttribute(Mockito.eq(SP_ENTITY_ID)) ).thenReturn( "static:test@liferay.com" ); String nameId = _defaultNameIdResolver.resolve( _user, SP_ENTITY_ID, null, null, false, null); Assert.assertNotNull(nameId); Assert.assertEquals("test@liferay.com", nameId); }