Search in sources :

Example 11 with Profile

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);
    }
}
Also used : I10nProfileException(org.craftercms.profile.api.exceptions.I10nProfileException) MongoDataException(org.craftercms.commons.mongo.MongoDataException) Profile(org.craftercms.profile.api.Profile)

Example 12 with Profile

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;
}
Also used : Profile(org.craftercms.profile.api.Profile)

Example 13 with 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;
}
Also used : Profile(org.craftercms.profile.api.Profile)

Example 14 with 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);
}
Also used : ArgumentMatcher(org.mockito.ArgumentMatcher) Mockito.anyString(org.mockito.Mockito.anyString) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Profile(org.craftercms.profile.api.Profile) Test(org.junit.Test)

Example 15 with Profile

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;
}
Also used : Profile(org.craftercms.profile.api.Profile)

Aggregations

Profile (org.craftercms.profile.api.Profile)110 Test (org.junit.Test)54 ServerSetupTest (com.icegreen.greenmail.util.ServerSetupTest)19 MongoDataException (org.craftercms.commons.mongo.MongoDataException)15 I10nProfileException (org.craftercms.profile.api.exceptions.I10nProfileException)15 LinkedHashMap (java.util.LinkedHashMap)13 VerificationToken (org.craftercms.profile.api.VerificationToken)13 DefaultAuthentication (org.craftercms.security.authentication.impl.DefaultAuthentication)12 Authentication (org.craftercms.security.authentication.Authentication)11 Date (java.util.Date)10 Map (java.util.Map)10 ObjectId (org.bson.types.ObjectId)9 RequestContext (org.craftercms.commons.http.RequestContext)9 ArgumentMatcher (org.mockito.ArgumentMatcher)9 Mockito.anyString (org.mockito.Mockito.anyString)9 RequestSecurityProcessorChain (org.craftercms.security.processors.RequestSecurityProcessorChain)8 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)8 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)8 Tenant (org.craftercms.profile.api.Tenant)5 Ticket (org.craftercms.profile.api.Ticket)4