Search in sources :

Example 1 with Profile

use of org.craftercms.profile.api.Profile in project profile by craftercms.

the class ProfileServiceImpl method updateAttributes.

@Override
public Profile updateAttributes(String profileId, final Map<String, Object> attributes, String... attributesToReturn) throws ProfileException {
    Profile profile = updateProfile(profileId, profileUpdater -> {
        String tenantName = profileUpdater.getProfile().getTenant();
        rejectAttributesIfActionNotAllowed(tenantName, attributes.keySet(), AttributeAction.WRITE_ATTRIBUTE);
        profileUpdater.addAttributes(attributes);
    }, attributesToReturn);
    if (logger.isDebugEnabled()) {
        logger.debug(LOG_KEY_PROFILE_ATTRIBS_UPDATED, attributes.keySet(), profileId);
    }
    return profile;
}
Also used : Profile(org.craftercms.profile.api.Profile)

Example 2 with Profile

use of org.craftercms.profile.api.Profile in project profile by craftercms.

the class ProfileServiceImpl method removeAttributes.

@Override
public Profile removeAttributes(String profileId, final Collection<String> attributeNames, String... attributesToReturn) throws ProfileException {
    Profile profile = updateProfile(profileId, profileUpdater -> {
        String tenantName = profileUpdater.getProfile().getTenant();
        rejectAttributesIfActionNotAllowed(tenantName, attributeNames, AttributeAction.REMOVE_ATTRIBUTE);
        profileUpdater.removeAttributes(attributeNames);
    }, attributesToReturn);
    logger.debug(LOG_KEY_PROFILE_ATTRIBS_REMOVED, attributeNames, profileId);
    return profile;
}
Also used : Profile(org.craftercms.profile.api.Profile)

Example 3 with Profile

use of org.craftercms.profile.api.Profile in project profile by craftercms.

the class ProfileServiceImpl method enableProfile.

@Override
public Profile enableProfile(String profileId, String... attributesToReturn) throws ProfileException {
    Profile profile = updateProfile(profileId, profileUpdater -> profileUpdater.setEnabled(true), attributesToReturn);
    logger.debug(LOG_KEY_PROFILE_ENABLED, profileId);
    return profile;
}
Also used : Profile(org.craftercms.profile.api.Profile)

Example 4 with Profile

use of org.craftercms.profile.api.Profile in project profile by craftercms.

the class ProfileServiceImpl method verifyProfile.

@Override
public Profile verifyProfile(String verificationTokenId, final String... attributesToReturn) throws ProfileException {
    VerificationToken token = verificationService.getToken(verificationTokenId);
    if (token == null) {
        throw new NoSuchVerificationTokenException(verificationTokenId);
    }
    Profile profile = updateProfile(token.getProfileId(), profileUpdater -> {
        profileUpdater.setEnabled(true);
        profileUpdater.setVerified(true);
    }, attributesToReturn);
    verificationService.deleteToken(verificationTokenId);
    logger.debug(LOG_KEY_PROFILE_VERIFIED, profile.getId());
    return profile;
}
Also used : NoSuchVerificationTokenException(org.craftercms.profile.exceptions.NoSuchVerificationTokenException) VerificationToken(org.craftercms.profile.api.VerificationToken) Profile(org.craftercms.profile.api.Profile)

Example 5 with Profile

use of org.craftercms.profile.api.Profile in project profile by craftercms.

the class ProfileServiceImpl method getProfilesByExistingAttribute.

@Override
public List<Profile> getProfilesByExistingAttribute(String tenantName, String attributeName, String sortBy, SortOrder sortOrder, String... attributesToReturn) throws ProfileException {
    checkIfManageProfilesIsAllowed(tenantName);
    try {
        List<Profile> profiles = IterableUtils.toList(profileRepository.findByTenantAndExistingAttribute(tenantName, attributeName, sortBy, sortOrder, attributesToReturn));
        filterNonReadableAttributes(profiles);
        return profiles;
    } catch (MongoDataException e) {
        throw new I10nProfileException(ERROR_KEY_GET_PROFILES_BY_EXISTING_ATTRIB_ERROR, e, attributeName, tenantName);
    }
}
Also used : I10nProfileException(org.craftercms.profile.api.exceptions.I10nProfileException) MongoDataException(org.craftercms.commons.mongo.MongoDataException) Profile(org.craftercms.profile.api.Profile)

Aggregations

Profile (org.craftercms.profile.api.Profile)111 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 Date (java.util.Date)11 Map (java.util.Map)11 ObjectId (org.bson.types.ObjectId)10 RequestContext (org.craftercms.commons.http.RequestContext)9 Authentication (org.craftercms.security.authentication.Authentication)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)6 HashMap (java.util.HashMap)4