use of org.apache.syncope.client.lib.SyncopeClient in project testcases by coheigea.
the class SyncopeDeployer method deployUserData.
@SuppressWarnings("unchecked")
public void deployUserData() {
WebClient client = WebClient.create(address);
client = client.type("application/xml");
String authorizationHeader = "Basic " + Base64Utility.encode(("admin" + ":" + "password").getBytes());
client.header("Authorization", authorizationHeader);
client.accept("application/xml");
// Create the groups first
client = client.path("groups");
PagedResult<GroupTO> existingGroups = (PagedResult<GroupTO>) client.get(PagedResult.class);
GroupTO bossGroup = findOrCreateGroup("boss", existingGroups, client);
GroupTO employeeGroup = findOrCreateGroup("employee", existingGroups, client);
// Now create the users
client = client.replacePath("users");
PagedResult<UserTO> existingUsers = (PagedResult<UserTO>) client.get(PagedResult.class);
if (!doesUserAlreadyExist("alice", existingUsers.getResult())) {
UserTO user = new UserTO();
user.setUsername("alice");
user.setPassword("security");
user.setRealm("/");
MembershipTO membership = new MembershipTO();
membership.setGroupKey(employeeGroup.getKey());
// membership.setGroupName(employeeGroup.getName());
user.getMemberships().add(membership);
membership = new MembershipTO();
// membership.setGroupName(bossGroup.getName());
membership.setGroupKey(bossGroup.getKey());
user.getMemberships().add(membership);
client.post(user, ProvisioningResult.class);
}
if (!doesUserAlreadyExist("bob", existingUsers.getResult())) {
UserTO user = new UserTO();
user.setUsername("bob");
user.setPassword("security");
user.setRealm("/");
MembershipTO membership = new MembershipTO();
membership.setGroupKey(employeeGroup.getKey());
// membership.setGroupName(employeeGroup.getName());
user.getMemberships().add(membership);
client.post(user, ProvisioningResult.class);
}
client.close();
// Check via the client API that the users were created correctly
SyncopeClientFactoryBean clientFactory = new SyncopeClientFactoryBean().setAddress(address);
SyncopeClient syncopeClient = clientFactory.create("admin", "password");
UserService userService = syncopeClient.getService(UserService.class);
int count = userService.search(new AnyQuery.Builder().build()).getTotalCount();
Assert.assertEquals(2, count);
}
use of org.apache.syncope.client.lib.SyncopeClient in project syncope by apache.
the class SyncopeServices method testUsernameAndPassword.
public static void testUsernameAndPassword(final String username, final String password) {
final Properties properties = new Properties();
try (InputStream is = Files.newInputStream(Paths.get(InstallConfigFileTemplate.configurationFilePath()))) {
properties.load(is);
} catch (final IOException e) {
LOG.error("Error opening properties file", e);
}
final SyncopeClient syncopeClient = new SyncopeClientFactoryBean().setAddress(properties.getProperty("syncope.rest.services")).create(username, password);
syncopeClient.getService(SyncopeService.class).platform();
}
use of org.apache.syncope.client.lib.SyncopeClient in project syncope by apache.
the class SyncopeServices method get.
public static <T> T get(final Class<T> clazz) {
final Properties properties = new Properties();
try (InputStream is = Files.newInputStream(Paths.get(InstallConfigFileTemplate.configurationFilePath()))) {
properties.load(is);
} catch (final IOException e) {
LOG.error("Error opening properties file", e);
}
String syncopeAdminPassword = JasyptUtils.get().decrypt(properties.getProperty("syncope.admin.password"));
SYNCOPE_ADDRESS = properties.getProperty("syncope.rest.services");
String useGZIPCompression = properties.getProperty("useGZIPCompression");
SyncopeClient syncopeClient = new SyncopeClientFactoryBean().setAddress(SYNCOPE_ADDRESS).setUseCompression(BooleanUtils.toBoolean(useGZIPCompression)).create(properties.getProperty("syncope.admin.user"), syncopeAdminPassword);
LOG.debug("Creating service for {}", clazz.getName());
return syncopeClient.getService(clazz);
}
use of org.apache.syncope.client.lib.SyncopeClient in project syncope by apache.
the class UserSelfITCase method passwordResetWithoutSecurityQuestion.
@Test
public void passwordResetWithoutSecurityQuestion() {
// 0. disable security question for password reset
configurationService.set(attrTO("passwordReset.securityQuestion", "false"));
// 1. create an user with security question and answer
UserTO user = UserITCase.getUniqueSampleTO("pwdResetNoSecurityQuestion@syncope.apache.org");
createUser(user);
// 2. verify that new user is able to authenticate
SyncopeClient authClient = clientFactory.create(user.getUsername(), "password123");
UserTO read = authClient.self().getRight();
assertNotNull(read);
// 3. request password reset (as anonymous) with no security answer
SyncopeClient anonClient = clientFactory.create();
anonClient.getService(UserSelfService.class).requestPasswordReset(user.getUsername(), null);
// 4. get token (normally sent via e-mail, now reading as admin)
String token = userService.read(read.getKey()).getToken();
assertNotNull(token);
// 5. confirm password reset
try {
anonClient.getService(UserSelfService.class).confirmPasswordReset("WRONG TOKEN", "newPassword");
fail("This should not happen");
} catch (SyncopeClientException e) {
assertEquals(ClientExceptionType.NotFound, e.getType());
assertTrue(e.getMessage().contains("WRONG TOKEN"));
}
anonClient.getService(UserSelfService.class).confirmPasswordReset(token, "newPassword123");
// 6. verify that password was reset and token removed
authClient = clientFactory.create(user.getUsername(), "newPassword123");
read = authClient.self().getRight();
assertNotNull(read);
assertNull(read.getToken());
// 7. re-enable security question for password reset
configurationService.set(attrTO("passwordReset.securityQuestion", "true"));
}
use of org.apache.syncope.client.lib.SyncopeClient in project syncope by apache.
the class UserSelfITCase method mustChangePassword.
@Test
public void mustChangePassword() {
// PRE: reset vivaldi's password
UserPatch userPatch = new UserPatch();
userPatch.setKey("b3cbc78d-32e6-4bd4-92e0-bbe07566a2ee");
userPatch.setPassword(new PasswordPatch.Builder().value("password321").build());
userService.update(userPatch);
// 0. access as vivaldi -> succeed
SyncopeClient vivaldiClient = clientFactory.create("vivaldi", "password321");
Pair<Map<String, Set<String>>, UserTO> self = vivaldiClient.self();
assertFalse(self.getRight().isMustChangePassword());
// 1. update user vivaldi (3) requirig password update
userPatch = new UserPatch();
userPatch.setKey("b3cbc78d-32e6-4bd4-92e0-bbe07566a2ee");
userPatch.setMustChangePassword(new BooleanReplacePatchItem.Builder().value(true).build());
UserTO vivaldi = updateUser(userPatch).getEntity();
assertTrue(vivaldi.isMustChangePassword());
// 2. attempt to access -> fail
try {
vivaldiClient.getService(ResourceService.class).list();
fail("This should not happen");
} catch (ForbiddenException e) {
assertNotNull(e);
assertEquals("Please change your password first", e.getMessage());
}
// 3. change password
vivaldiClient.getService(UserSelfService.class).changePassword("password123");
// 4. verify it worked
self = clientFactory.create("vivaldi", "password123").self();
assertFalse(self.getRight().isMustChangePassword());
}
Aggregations