use of org.cloudfoundry.identity.uaa.user.UaaUser in project uaa by cloudfoundry.
the class LdapLoginAuthenticationManagerTests method testUserAuthenticated.
@Test
void testUserAuthenticated() {
UaaUser user = getUaaUser();
UaaUser userFromRequest = am.getUser(auth, null);
definition.setAutoAddGroups(true);
UaaUser result = am.userAuthenticated(auth, user, userFromRequest);
assertSame(dbUser, result);
verify(publisher, times(1)).publishEvent(ArgumentMatchers.any());
definition.setAutoAddGroups(false);
result = am.userAuthenticated(auth, userFromRequest, user);
assertSame(dbUser, result);
verify(publisher, times(2)).publishEvent(ArgumentMatchers.any());
}
use of org.cloudfoundry.identity.uaa.user.UaaUser in project uaa by cloudfoundry.
the class LdapLoginAuthenticationManagerTests method update_existingUser_if_attributes_different.
@Test
void update_existingUser_if_attributes_different() {
ExtendedLdapUserImpl authDetails = getAuthDetails(LDAP_EMAIL, "MarissaChanged", "BloggsChanged", "8675309");
when(auth.getPrincipal()).thenReturn(authDetails);
UaaUser user = getUaaUser();
UaaUser userFromRequest = am.getUser(auth, null);
am.userAuthenticated(auth, userFromRequest, user);
ArgumentCaptor<ExternalGroupAuthorizationEvent> captor = ArgumentCaptor.forClass(ExternalGroupAuthorizationEvent.class);
verify(publisher, times(1)).publishEvent(captor.capture());
assertEquals(LDAP_EMAIL, captor.getValue().getUser().getEmail());
assertEquals("MarissaChanged", captor.getValue().getUser().getGivenName());
assertEquals("BloggsChanged", captor.getValue().getUser().getFamilyName());
}
use of org.cloudfoundry.identity.uaa.user.UaaUser in project uaa by cloudfoundry.
the class LdapLoginAuthenticationManagerTests method testGetUserWithExtendedLdapInfo.
@Test
void testGetUserWithExtendedLdapInfo() {
UaaUser user = am.getUser(auth, null);
assertEquals(DN, user.getExternalId());
assertEquals(LDAP_EMAIL, user.getEmail());
assertEquals(origin, user.getOrigin());
assertFalse(user.isVerified());
}
use of org.cloudfoundry.identity.uaa.user.UaaUser in project uaa by cloudfoundry.
the class LdapLoginAuthenticationManagerTests method test_authentication_attributes.
void test_authentication_attributes(boolean storeUserInfo) {
UaaUser user = getUaaUser();
ExtendedLdapUserImpl authDetails = getAuthDetails(user.getEmail(), user.getGivenName(), user.getFamilyName(), user.getPhoneNumber(), new AttributeInfo(UAA_MANAGER, new String[] { KARI_THE_ANT_EATER, JOHN_THE_SLOTH }), new AttributeInfo(COST_CENTER, new String[] { DENVER_CO }));
Map<String, String[]> role1 = new HashMap<>();
role1.put("cn", new String[] { "ldap.role.1.a", "ldap.role.1.b", "ldap.role.1" });
Map<String, String[]> role2 = new HashMap<>();
role2.put("cn", new String[] { "ldap.role.2.a", "ldap.role.2.b", "ldap.role.2" });
authDetails.setAuthorities(Arrays.asList(new LdapAuthority("role1", "cn=role1,ou=test,ou=com", role1), new LdapAuthority("role2", "cn=role2,ou=test,ou=com", role2)));
definition.setExternalGroupsWhitelist(Collections.singletonList("*"));
when(auth.getPrincipal()).thenReturn(authDetails);
UaaUserDatabase db = mock(UaaUserDatabase.class);
when(db.retrieveUserByName(anyString(), eq(OriginKeys.LDAP))).thenReturn(user);
when(db.retrieveUserById(anyString())).thenReturn(user);
am.setOrigin(OriginKeys.LDAP);
am.setUserDatabase(db);
// set the config flag
definition.setStoreCustomAttributes(storeUserInfo);
UaaAuthentication authentication = (UaaAuthentication) am.authenticate(auth);
UserInfo info = new UserInfo().setUserAttributes(authentication.getUserAttributes()).setRoles(Arrays.asList("ldap.role.1.a", "ldap.role.1.b", "ldap.role.1", "ldap.role.2.a", "ldap.role.2.b", "ldap.role.2"));
if (storeUserInfo) {
verify(db, times(1)).storeUserInfo(anyString(), eq(info));
} else {
verify(db, never()).storeUserInfo(anyString(), eq(info));
}
assertEquals("Expected two user attributes", 2, authentication.getUserAttributes().size());
assertNotNull("Expected cost center attribute", authentication.getUserAttributes().get(COST_CENTERS));
assertEquals(DENVER_CO, authentication.getUserAttributes().getFirst(COST_CENTERS));
assertNotNull("Expected manager attribute", authentication.getUserAttributes().get(MANAGERS));
assertEquals("Expected 2 manager attribute values", 2, authentication.getUserAttributes().get(MANAGERS).size());
assertThat(authentication.getUserAttributes().get(MANAGERS), containsInAnyOrder(JOHN_THE_SLOTH, KARI_THE_ANT_EATER));
assertThat(authentication.getAuthenticationMethods(), containsInAnyOrder("ext", "pwd"));
}
use of org.cloudfoundry.identity.uaa.user.UaaUser in project uaa by cloudfoundry.
the class LoginAuthenticationManagerTests method testHappyDayWithAuthorities.
@Test
void testHappyDayWithAuthorities() {
UaaUser user = UaaUserTestFactory.getAdminUser("FOO", "foo", "fo@test.org", "Foo", "Bar");
Mockito.when(userDatabase.retrieveUserByName("foo", OriginKeys.LOGIN_SERVER)).thenReturn(user);
Authentication authentication = manager.authenticate(UaaAuthenticationTestFactory.getAuthenticationRequest("foo"));
assertEquals(user.getUsername(), ((UaaPrincipal) authentication.getPrincipal()).getName());
assertEquals(user.getAuthorities(), authentication.getAuthorities());
}
Aggregations