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());
}
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);
}
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());
}
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());
}
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;
}
}
Aggregations