Search in sources :

Example 26 with RandomValueStringGenerator

use of org.springframework.security.oauth2.common.util.RandomValueStringGenerator in project uaa by cloudfoundry.

the class JdbcScimGroupMembershipManagerTests method setUp.

@BeforeEach
void setUp() {
    generator = new RandomValueStringGenerator();
    otherIdentityZone = MultitenancyFixture.identityZone("otherIdentityZone-" + generator.generate(), "otherIdentityZone-" + generator.generate());
    uaaIdentityZone = IdentityZone.getUaa();
    JdbcPagingListFactory pagingListFactory = new JdbcPagingListFactory(jdbcTemplate, limitSqlAdapter);
    JdbcScimUserProvisioning jdbcScimUserProvisioning = new JdbcScimUserProvisioning(jdbcTemplate, pagingListFactory, passwordEncoder);
    jdbcScimGroupProvisioning = new JdbcScimGroupProvisioning(jdbcTemplate, pagingListFactory);
    jdbcScimGroupMembershipManager = new JdbcScimGroupMembershipManager(jdbcTemplate, new TimeServiceImpl(), jdbcScimUserProvisioning, null);
    jdbcScimGroupMembershipManager.setScimGroupProvisioning(jdbcScimGroupProvisioning);
    IdentityZoneHolder.get().getConfig().getUserConfig().setDefaultGroups(Collections.singletonList("uaa.user"));
    jdbcScimGroupProvisioning.createOrGet(new ScimGroup(null, "uaa.user", IdentityZoneHolder.get().getId()), IdentityZoneHolder.get().getId());
    addUsersAndGroups(jdbcTemplate, otherIdentityZone.getId(), otherIdentityZone.getId() + "-");
    addUsersAndGroups(jdbcTemplate, uaaIdentityZone.getId(), "");
    validateCount(0, jdbcTemplate, IdentityZoneHolder.get().getId());
}
Also used : TimeServiceImpl(org.cloudfoundry.identity.uaa.util.TimeServiceImpl) JdbcPagingListFactory(org.cloudfoundry.identity.uaa.resources.jdbc.JdbcPagingListFactory) RandomValueStringGenerator(org.springframework.security.oauth2.common.util.RandomValueStringGenerator) ScimGroup(org.cloudfoundry.identity.uaa.scim.ScimGroup) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 27 with RandomValueStringGenerator

use of org.springframework.security.oauth2.common.util.RandomValueStringGenerator in project uaa by cloudfoundry.

the class JdbcScimGroupProvisioningTests method initJdbcScimGroupProvisioningTests.

@BeforeEach
void initJdbcScimGroupProvisioningTests() {
    generator = new RandomValueStringGenerator();
    SecureRandom random = new SecureRandom();
    random.setSeed(System.nanoTime());
    generator.setRandom(random);
    zoneId = generator.generate();
    IdentityZone zone = new IdentityZone();
    zone.setId(zoneId);
    IdentityZoneHolder.set(zone);
    IdentityZoneHolder.get().getConfig().getUserConfig().setDefaultGroups(new ArrayList<>());
    validateGroupCountInZone(0, zoneId);
    dao = spy(new JdbcScimGroupProvisioning(jdbcTemplate, new JdbcPagingListFactory(jdbcTemplate, limitSqlAdapter)));
    users = mock(ScimUserProvisioning.class);
    memberships = new JdbcScimGroupMembershipManager(jdbcTemplate, new TimeServiceImpl(), users, null);
    memberships.setScimGroupProvisioning(dao);
    dao.setJdbcScimGroupMembershipManager(memberships);
    JdbcScimGroupExternalMembershipManager jdbcScimGroupExternalMembershipManager = new JdbcScimGroupExternalMembershipManager(jdbcTemplate);
    jdbcScimGroupExternalMembershipManager.setScimGroupProvisioning(dao);
    dao.setJdbcScimGroupExternalMembershipManager(jdbcScimGroupExternalMembershipManager);
    g1Id = "g1";
    g2Id = "g2";
    g3Id = "g3";
    group1Description = "u" + generator.generate();
    g1 = addGroup(g1Id, group1Description, zoneId);
    group2Description = "u" + generator.generate();
    g2 = addGroup(g2Id, group2Description, zoneId);
    group3Description = "op" + generator.generate();
    g3 = addGroup(g3Id, group3Description, zoneId);
    validateGroupCountInZone(3, zoneId);
}
Also used : IdentityZone(org.cloudfoundry.identity.uaa.zone.IdentityZone) TimeServiceImpl(org.cloudfoundry.identity.uaa.util.TimeServiceImpl) JdbcPagingListFactory(org.cloudfoundry.identity.uaa.resources.jdbc.JdbcPagingListFactory) SecureRandom(java.security.SecureRandom) RandomValueStringGenerator(org.springframework.security.oauth2.common.util.RandomValueStringGenerator) ScimUserProvisioning(org.cloudfoundry.identity.uaa.scim.ScimUserProvisioning) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 28 with RandomValueStringGenerator

use of org.springframework.security.oauth2.common.util.RandomValueStringGenerator in project uaa by cloudfoundry.

the class ScimUserBootstrapTests method externalInvitedUserGetsVerifiedSetToFalse.

@Test
void externalInvitedUserGetsVerifiedSetToFalse() {
    String origin = "testOrigin";
    addIdentityProvider(jdbcTemplate, origin);
    String email = "test@test.org";
    String firstName = "FirstName";
    String lastName = "LastName";
    String password = "testPassword";
    String externalId = null;
    String username = new RandomValueStringGenerator().generate().toLowerCase();
    UaaUser user = getUaaUser(new String[0], origin, email, firstName, lastName, password, externalId, "not-used-id", username);
    ScimUserBootstrap bootstrap = new ScimUserBootstrap(jdbcScimUserProvisioning, jdbcScimGroupProvisioning, jdbcScimGroupMembershipManager, Collections.singletonList(user), false, Collections.emptyList());
    bootstrap.afterPropertiesSet();
    ScimUser existingUser = jdbcScimUserProvisioning.retrieveAll(IdentityZone.getUaaZoneId()).stream().filter(u -> username.equals(u.getUserName())).findFirst().get();
    String userId = existingUser.getId();
    existingUser.setVerified(true);
    jdbcScimUserProvisioning.update(userId, existingUser, IdentityZone.getUaaZoneId());
    InvitedUserAuthenticatedEvent event = new InvitedUserAuthenticatedEvent(user);
    bootstrap.onApplicationEvent(event);
    ScimUser modifiedUser = jdbcScimUserProvisioning.retrieve(userId, IdentityZone.getUaaZoneId());
    assertFalse(modifiedUser.isVerified());
}
Also used : ScimUser(org.cloudfoundry.identity.uaa.scim.ScimUser) UaaUser(org.cloudfoundry.identity.uaa.user.UaaUser) RandomValueStringGenerator(org.springframework.security.oauth2.common.util.RandomValueStringGenerator) InvitedUserAuthenticatedEvent(org.cloudfoundry.identity.uaa.authentication.manager.InvitedUserAuthenticatedEvent) Test(org.junit.jupiter.api.Test)

Example 29 with RandomValueStringGenerator

use of org.springframework.security.oauth2.common.util.RandomValueStringGenerator in project uaa by cloudfoundry.

the class ScimUserBootstrapTests method addUsersWithSameUsername.

@Test
void addUsersWithSameUsername() {
    String origin = "testOrigin";
    addIdentityProvider(jdbcTemplate, origin);
    String email = "test@test.org";
    String firstName = "FirstName";
    String lastName = "LastName";
    String password = "testPassword";
    String externalId = null;
    String userId = new RandomValueStringGenerator().generate();
    String username = new RandomValueStringGenerator().generate();
    UaaUser user = getUaaUser(new String[0], origin, email, firstName, lastName, password, externalId, userId, username);
    ScimUserBootstrap bootstrap = new ScimUserBootstrap(jdbcScimUserProvisioning, jdbcScimGroupProvisioning, jdbcScimGroupMembershipManager, Collections.singletonList(user), false, Collections.emptyList());
    bootstrap.afterPropertiesSet();
    addIdentityProvider(jdbcTemplate, "newOrigin");
    bootstrap = new ScimUserBootstrap(jdbcScimUserProvisioning, jdbcScimGroupProvisioning, jdbcScimGroupMembershipManager, Arrays.asList(user, user.modifySource("newOrigin", "")), false, Collections.emptyList());
    bootstrap.afterPropertiesSet();
    assertEquals(2, jdbcScimUserProvisioning.retrieveAll(IdentityZone.getUaaZoneId()).size());
}
Also used : UaaUser(org.cloudfoundry.identity.uaa.user.UaaUser) RandomValueStringGenerator(org.springframework.security.oauth2.common.util.RandomValueStringGenerator) Test(org.junit.jupiter.api.Test)

Example 30 with RandomValueStringGenerator

use of org.springframework.security.oauth2.common.util.RandomValueStringGenerator in project uaa by cloudfoundry.

the class ScimUserBootstrapTests method concurrentAuthEventsRaceCondition.

@Test
void concurrentAuthEventsRaceCondition() throws Exception {
    int numthreads = 5;
    int numgroups = 100;
    String[] externalAuthorities = new String[] { "extTest1", "extTest2", "extTest3" };
    String[] userAuthorities = new String[] { "usrTest1", "usrTest2", "usrTest3" };
    String origin = "testOrigin";
    addIdentityProvider(jdbcTemplate, origin);
    String email = "test@test.org";
    String firstName = "FirstName";
    String lastName = "LastName";
    String password = "testPassword";
    String externalId = null;
    String userId = new RandomValueStringGenerator().generate();
    String username = new RandomValueStringGenerator().generate();
    UaaUser user = getUaaUser(userAuthorities, origin, email, firstName, lastName, password, externalId, userId, username);
    ScimUserBootstrap bootstrap = new ScimUserBootstrap(jdbcScimUserProvisioning, jdbcScimGroupProvisioning, jdbcScimGroupMembershipManager, Collections.singletonList(user), false, Collections.emptyList());
    bootstrap.afterPropertiesSet();
    List<ScimUser> scimUsers = jdbcScimUserProvisioning.query("userName eq \"" + username + "\" and origin eq \"" + origin + "\"", IdentityZone.getUaaZoneId());
    assertEquals(1, scimUsers.size());
    ScimUser scimUser = scimUsers.get(0);
    ScimGroupMember member = new ScimGroupMember<>(scimUser);
    user = getUaaUser(userAuthorities, origin, email, firstName, lastName, password, externalId, member.getMemberId(), username);
    for (int i = 0; i < numgroups; i++) {
        jdbcScimGroupProvisioning.create(new ScimGroup("group" + i, "group" + i, IdentityZone.getUaaZoneId()), IdentityZone.getUaaZoneId());
        String gid = jdbcScimGroupProvisioning.query("displayName eq \"group" + i + "\"", IdentityZone.getUaaZoneId()).get(0).getId();
        jdbcScimGroupMembershipManager.addMember(gid, member, IdentityZone.getUaaZoneId());
    }
    bootstrap.onApplicationEvent(new ExternalGroupAuthorizationEvent(user, true, getAuthorities(externalAuthorities), true));
    ExternalGroupAuthorizationEvent externalGroupAuthorizationEvent = new ExternalGroupAuthorizationEvent(user, false, getAuthorities(externalAuthorities), true);
    Thread[] threads = new Thread[numthreads];
    for (int i = 0; i < numthreads; i++) {
        threads[i] = new Thread(new AuthEventRunnable(externalGroupAuthorizationEvent, bootstrap));
        threads[i].start();
    }
    for (int i = 0; i < numthreads; i++) {
        threads[i].join();
    }
    if (AuthEventRunnable.failure != null) {
        throw AuthEventRunnable.failure;
    }
}
Also used : ScimUser(org.cloudfoundry.identity.uaa.scim.ScimUser) ExternalGroupAuthorizationEvent(org.cloudfoundry.identity.uaa.authentication.manager.ExternalGroupAuthorizationEvent) ScimGroupMember(org.cloudfoundry.identity.uaa.scim.ScimGroupMember) UaaUser(org.cloudfoundry.identity.uaa.user.UaaUser) RandomValueStringGenerator(org.springframework.security.oauth2.common.util.RandomValueStringGenerator) ScimGroup(org.cloudfoundry.identity.uaa.scim.ScimGroup) Test(org.junit.jupiter.api.Test)

Aggregations

RandomValueStringGenerator (org.springframework.security.oauth2.common.util.RandomValueStringGenerator)271 Test (org.junit.jupiter.api.Test)111 Matchers.containsString (org.hamcrest.Matchers.containsString)92 ScimUser (org.cloudfoundry.identity.uaa.scim.ScimUser)81 BaseClientDetails (org.springframework.security.oauth2.provider.client.BaseClientDetails)76 Test (org.junit.Test)52 BeforeEach (org.junit.jupiter.api.BeforeEach)45 IdentityZone (org.cloudfoundry.identity.uaa.zone.IdentityZone)40 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)36 RestTemplate (org.springframework.web.client.RestTemplate)34 IdentityProvider (org.cloudfoundry.identity.uaa.provider.IdentityProvider)30 SamlIdentityProviderDefinition (org.cloudfoundry.identity.uaa.provider.SamlIdentityProviderDefinition)29 MvcResult (org.springframework.test.web.servlet.MvcResult)26 SetServerNameRequestPostProcessor (org.cloudfoundry.identity.uaa.util.SetServerNameRequestPostProcessor)16 IdentityZoneConfiguration (org.cloudfoundry.identity.uaa.zone.IdentityZoneConfiguration)16 ClientDetails (org.springframework.security.oauth2.provider.ClientDetails)16 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)15 ScimGroup (org.cloudfoundry.identity.uaa.scim.ScimGroup)14 KeyWithCertTest (org.cloudfoundry.identity.uaa.util.KeyWithCertTest)14 Matchers.isEmptyOrNullString (org.hamcrest.Matchers.isEmptyOrNullString)14