use of org.craftercms.profile.api.Profile in project profile by craftercms.
the class ProfileServiceImpl method getProfile.
@Override
public Profile getProfile(String profileId, String... attributesToReturn) throws ProfileException {
try {
Profile profile = profileRepository.findById(profileId, attributesToReturn);
if (profile != null) {
checkIfManageProfilesIsAllowed(profile.getTenant());
filterNonReadableAttributes(profile);
}
return profile;
} catch (MongoDataException e) {
throw new I10nProfileException(ERROR_KEY_GET_PROFILE_ERROR, e, profileId);
}
}
use of org.craftercms.profile.api.Profile in project profile by craftercms.
the class ProfileServiceImpl method removeRoles.
@Override
public Profile removeRoles(String profileId, final Collection<String> roles, String... attributesToReturn) throws ProfileException {
Profile profile = updateProfile(profileId, profileUpdater -> profileUpdater.removeRoles(roles), attributesToReturn);
logger.debug(LOG_KEY_PROFILE_ROLES_REMOVED, roles, profileId);
return profile;
}
use of org.craftercms.profile.api.Profile in project profile by craftercms.
the class ProfileServiceImplTest method getTenant1Profile.
private Profile getTenant1Profile() {
Profile profile = new Profile();
profile.setId(PROFILE1_ID);
profile.setTenant(TENANT1_NAME);
profile.setUsername(USERNAME1);
profile.setPassword(CryptoUtils.hashPassword(PASSWORD1));
profile.setEmail(EMAIL1);
profile.setRoles(new HashSet<>(ROLES1));
profile.setVerified(true);
profile.setEnabled(true);
profile.setAttributes(getAttributes());
return profile;
}
use of org.craftercms.profile.api.Profile in project profile by craftercms.
the class ProfileServiceImplTest method testChangePassword.
@Test
public void testChangePassword() throws Exception {
Profile expected = getTenant1Profile();
expected.setAttributes(getAttributesWithoutPrivateAttribute());
Profile actual = profileService.changePassword(VERIFICATION_TOKEN_ID1, PASSWORD2);
assertEqualProfiles(expected, actual);
assertTrue(CryptoUtils.matchPassword(actual.getPassword(), PASSWORD2));
ArgumentMatcher<Object> setParamMatcher = new ArgumentMatcher<Object>() {
@Override
public boolean matches(Object argument) {
Map<String, Object> param = (Map<String, Object>) argument;
return param.size() == 2 && param.containsKey("password") && param.containsKey("lastModified");
}
};
verify(tenantPermissionEvaluator).isAllowed(TENANT1_NAME, TenantAction.MANAGE_PROFILES.toString());
verify(profileRepository).findById(PROFILE1_ID.toString(), new String[0]);
verify(profileRepository).update(eq(PROFILE1_ID.toString()), eq("{$set: #}"), eq(false), eq(false), argThat(setParamMatcher));
verify(verificationService).getToken(VERIFICATION_TOKEN_ID1);
verify(verificationService).deleteToken(VERIFICATION_TOKEN_ID1);
}
use of org.craftercms.profile.api.Profile in project profile by craftercms.
the class ProfileServiceImplTest method getTenant1ProfileNoLastName.
private Profile getTenant1ProfileNoLastName() {
Profile profile = getTenant1Profile();
profile.getAttributes().remove(ATTRIB_NAME_LAST_NAME);
return profile;
}
Aggregations