Search in sources :

Example 21 with UaaUser

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);
}
Also used : UaaUser(org.cloudfoundry.identity.uaa.user.UaaUser) IdentityProviderProvisioning(org.cloudfoundry.identity.uaa.provider.IdentityProviderProvisioning) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) ApplicationEvent(org.springframework.context.ApplicationEvent) MockHttpSession(org.springframework.mock.web.MockHttpSession) UaaUserDatabase(org.cloudfoundry.identity.uaa.user.UaaUserDatabase) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 22 with UaaUser

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;
}
Also used : UaaUser(org.cloudfoundry.identity.uaa.user.UaaUser)

Example 23 with UaaUser

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);
}
Also used : UaaUser(org.cloudfoundry.identity.uaa.user.UaaUser) Test(org.junit.jupiter.api.Test)

Example 24 with UaaUser

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());
}
Also used : UaaUser(org.cloudfoundry.identity.uaa.user.UaaUser) UaaUserPrototype(org.cloudfoundry.identity.uaa.user.UaaUserPrototype) Test(org.junit.jupiter.api.Test)

Example 25 with UaaUser

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);
    }
}
Also used : NewUserAuthenticatedEvent(org.cloudfoundry.identity.uaa.authentication.manager.NewUserAuthenticatedEvent) ExternalGroupAuthorizationEvent(org.cloudfoundry.identity.uaa.authentication.manager.ExternalGroupAuthorizationEvent) UaaUser(org.cloudfoundry.identity.uaa.user.UaaUser) GrantedAuthority(org.springframework.security.core.GrantedAuthority) InvitedUserAuthenticatedEvent(org.cloudfoundry.identity.uaa.authentication.manager.InvitedUserAuthenticatedEvent)

Aggregations

UaaUser (org.cloudfoundry.identity.uaa.user.UaaUser)148 Test (org.junit.jupiter.api.Test)73 UaaAuthentication (org.cloudfoundry.identity.uaa.authentication.UaaAuthentication)38 UaaPrincipal (org.cloudfoundry.identity.uaa.authentication.UaaPrincipal)29 UaaUserPrototype (org.cloudfoundry.identity.uaa.user.UaaUserPrototype)26 ScimUser (org.cloudfoundry.identity.uaa.scim.ScimUser)24 Test (org.junit.Test)23 HashMap (java.util.HashMap)22 Date (java.util.Date)20 UaaUserMatcher.aUaaUser (org.cloudfoundry.identity.uaa.user.UaaUserMatcher.aUaaUser)17 Authentication (org.springframework.security.core.Authentication)15 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)14 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)12 UaaUserDatabase (org.cloudfoundry.identity.uaa.user.UaaUserDatabase)11 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)11 BaseClientDetails (org.springframework.security.oauth2.provider.client.BaseClientDetails)11 ModelTestUtils.getResourceAsString (org.cloudfoundry.identity.uaa.test.ModelTestUtils.getResourceAsString)10 Mockito.anyString (org.mockito.Mockito.anyString)9 UsernameNotFoundException (org.springframework.security.core.userdetails.UsernameNotFoundException)8 ArrayList (java.util.ArrayList)7