use of org.cloudfoundry.identity.uaa.user.UaaUser in project uaa by cloudfoundry.
the class AuthzAuthenticationManagerTests method setUp.
@BeforeEach
void setUp() {
user = new UaaUser(getPrototype());
providerProvisioning = mock(IdentityProviderProvisioning.class);
db = mock(UaaUserDatabase.class);
publisher = mock(ApplicationEventPublisher.class);
eventCaptor = ArgumentCaptor.forClass(ApplicationEvent.class);
doNothing().when(publisher).publishEvent(eventCaptor.capture());
AccountLoginPolicy mockAccountLoginPolicy = mock(AccountLoginPolicy.class);
when(mockAccountLoginPolicy.isAllowed(any(), any())).thenReturn(true);
mockHttpSession = new MockHttpSession();
mgr = new AuthzAuthenticationManager(db, encoder, providerProvisioning, mockHttpSession);
mgr.setApplicationEventPublisher(publisher);
mgr.setOrigin(OriginKeys.UAA);
mgr.setAccountLoginPolicy(mockAccountLoginPolicy);
}
use of org.cloudfoundry.identity.uaa.user.UaaUser in project uaa by cloudfoundry.
the class ExternalLoginAuthenticationManagerTest method addUserToDb.
private UaaUser addUserToDb(String userName, String userId, String origin, String email) {
UaaUser user = mock(UaaUser.class);
when(user.getUsername()).thenReturn(userName);
when(user.getId()).thenReturn(userId);
when(user.getOrigin()).thenReturn(origin);
when(user.getEmail()).thenReturn(email);
when(this.uaaUserDatabase.retrieveUserById(eq(userId))).thenReturn(user);
when(this.uaaUserDatabase.retrieveUserByName(eq(userName), eq(origin))).thenReturn(user);
return user;
}
use of org.cloudfoundry.identity.uaa.user.UaaUser in project uaa by cloudfoundry.
the class EntityDeletedEventTest method getAuditEvent_UaaUser.
@Test
void getAuditEvent_UaaUser() {
UaaUser mockUaaUser = mock(UaaUser.class);
when(mockUaaUser.getId()).thenReturn(randomId);
checkAuditEventData(mockUaaUser, UaaUser.class, randomId);
}
use of org.cloudfoundry.identity.uaa.user.UaaUser in project uaa by cloudfoundry.
the class SystemDeletableTest method uaaUserEventReceived.
@Test
void uaaUserEventReceived() {
UaaUser uaaUser = new UaaUser(new UaaUserPrototype().withUsername("username").withId("uaaUser-id").withZoneId("other-zone-id").withEmail("test@test.com"));
EntityDeletedEvent event = new EntityDeletedEvent<>(uaaUser, authentication, null);
deletable.onApplicationEvent(event);
verify(deletable, never()).deleteByIdentityZone(any());
verify(deletable, never()).deleteByOrigin(any(), any());
verify(deletable, never()).deleteByClient(any(), any());
verify(deletable, times(1)).deleteByUser("uaaUser-id", "other-zone-id");
verify(deletable, never()).deleteByMfaProvider(any(), any());
}
use of org.cloudfoundry.identity.uaa.user.UaaUser in project uaa by cloudfoundry.
the class ScimUserBootstrap method onApplicationEvent.
public void onApplicationEvent(AuthEvent event) {
UaaUser uaaUser = event.getUser();
if (event instanceof InvitedUserAuthenticatedEvent) {
ScimUser user = getScimUser(uaaUser);
// external users should default to not being verified
if (!OriginKeys.UAA.equals(uaaUser.getOrigin())) {
uaaUser.setVerified(false);
}
updateUser(user, uaaUser, false);
return;
}
if (event instanceof ExternalGroupAuthorizationEvent) {
ExternalGroupAuthorizationEvent exEvent = (ExternalGroupAuthorizationEvent) event;
// delete previous membership relation ships
String origin = exEvent.getUser().getOrigin();
if (!OriginKeys.UAA.equals(origin)) {
Set<ScimGroup> groupsWithMember = membershipManager.getGroupsWithExternalMember(exEvent.getUser().getId(), origin, IdentityZoneHolder.get().getId());
Map<String, ScimGroup> groupsMap = groupsWithMember.stream().collect(Collectors.toMap(ScimGroup::getDisplayName, Function.identity()));
Collection<? extends GrantedAuthority> externalAuthorities = new LinkedHashSet<>(exEvent.getExternalAuthorities());
for (GrantedAuthority authority : externalAuthorities) {
if (groupsMap.containsKey(authority.getAuthority())) {
groupsMap.remove(authority.getAuthority());
} else {
addToGroup(exEvent.getUser().getId(), authority.getAuthority(), origin, exEvent.isAddGroups());
}
}
for (ScimGroup group : groupsMap.values()) {
membershipManager.removeMemberById(group.getId(), exEvent.getUser().getId(), group.getZoneId());
}
}
// update the user itself
if (event.isUserModified()) {
// update the user itself
ScimUser user = getScimUser(uaaUser);
updateUser(user, uaaUser, false);
}
return;
}
if (event instanceof NewUserAuthenticatedEvent) {
addUser(uaaUser);
}
}
Aggregations