Search in sources :

Example 1 with I10nProfileException

use of org.craftercms.profile.api.exceptions.I10nProfileException in project profile by craftercms.

the class AccessTokenServiceImpl method deleteToken.

@Override
public void deleteToken(String id) throws ProfileException {
    checkIfTokenActionIsAllowed(id, Action.DELETE_TOKEN);
    try {
        accessTokenRepository.removeByStringId(id);
    } catch (MongoDataException e) {
        throw new I10nProfileException(ERROR_KEY_DELETE_ACCESS_TOKEN_ERROR, e, id);
    }
    logger.debug(LOG_KEY_ACCESS_TOKEN_DELETED, id);
}
Also used : I10nProfileException(org.craftercms.profile.api.exceptions.I10nProfileException) MongoDataException(org.craftercms.commons.mongo.MongoDataException)

Example 2 with I10nProfileException

use of org.craftercms.profile.api.exceptions.I10nProfileException in project profile by craftercms.

the class ProfileServiceImpl method getProfileCountByQuery.

@Override
public long getProfileCountByQuery(String tenantName, String query) throws ProfileException {
    checkIfManageProfilesIsAllowed(tenantName);
    Tenant tenant = getTenant(tenantName);
    try {
        return profileRepository.count(getFinalQuery(tenant, query));
    } catch (MongoDataException e) {
        throw new I10nProfileException(ERROR_KEY_GET_PROFILE_COUNT_BY_QUERY_ERROR, e, tenant, query);
    }
}
Also used : Tenant(org.craftercms.profile.api.Tenant) I10nProfileException(org.craftercms.profile.api.exceptions.I10nProfileException) MongoDataException(org.craftercms.commons.mongo.MongoDataException)

Example 3 with I10nProfileException

use of org.craftercms.profile.api.exceptions.I10nProfileException 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)

Example 4 with I10nProfileException

use of org.craftercms.profile.api.exceptions.I10nProfileException in project profile by craftercms.

the class ProfileServiceImpl method getProfilesByQuery.

@Override
public List<Profile> getProfilesByQuery(String tenantName, String query, String sortBy, SortOrder sortOrder, Integer start, Integer count, String... attributesToReturn) throws ProfileException {
    checkIfManageProfilesIsAllowed(tenantName);
    Tenant tenant = getTenant(tenantName);
    try {
        List<Profile> profiles = IterableUtils.toList(profileRepository.findByQuery(getFinalQuery(tenant, query), sortBy, sortOrder, start, count, attributesToReturn));
        filterNonReadableAttributes(tenant, profiles);
        return profiles;
    } catch (MongoDataException e) {
        throw new I10nProfileException(ERROR_KEY_GET_PROFILES_BY_QUERY_ERROR, e, tenant, query);
    }
}
Also used : Tenant(org.craftercms.profile.api.Tenant) I10nProfileException(org.craftercms.profile.api.exceptions.I10nProfileException) MongoDataException(org.craftercms.commons.mongo.MongoDataException) Profile(org.craftercms.profile.api.Profile)

Example 5 with I10nProfileException

use of org.craftercms.profile.api.exceptions.I10nProfileException in project profile by craftercms.

the class ProfileServiceImpl method createProfile.

@Override
public Profile createProfile(String tenantName, String username, String password, String email, boolean enabled, Set<String> roles, Map<String, Object> attributes, String verificationUrl) throws ProfileException {
    checkIfManageProfilesIsAllowed(tenantName);
    if (!EmailUtils.validateEmail(email)) {
        throw new InvalidEmailAddressException(email);
    }
    try {
        Tenant tenant = getTenant(tenantName);
        Date now = new Date();
        Profile profile = new Profile();
        profile.setTenant(tenantName);
        profile.setUsername(username);
        profile.setPassword(CryptoUtils.hashPassword(password));
        profile.setEmail(email);
        profile.setCreatedOn(now);
        profile.setLastModified(now);
        profile.setVerified(false);
        boolean emailNewProfiles = tenant.isVerifyNewProfiles();
        if (!emailNewProfiles || StringUtils.isEmpty(verificationUrl)) {
            profile.setEnabled(enabled);
        }
        if (CollectionUtils.isNotEmpty(roles)) {
            profile.setRoles(roles);
        }
        for (AttributeDefinition definition : tenant.getAttributeDefinitions()) {
            if (definition.getDefaultValue() != null) {
                profile.setAttribute(definition.getName(), definition.getDefaultValue());
            }
        }
        if (MapUtils.isNotEmpty(attributes)) {
            rejectAttributesIfActionNotAllowed(tenant, attributes.keySet(), AttributeAction.WRITE_ATTRIBUTE);
            profile.getAttributes().putAll(attributes);
        }
        profileRepository.insert(profile);
        logger.debug(LOG_KEY_PROFILE_CREATED, profile);
        if (emailNewProfiles && StringUtils.isNotEmpty(verificationUrl)) {
            VerificationToken token = verificationService.createToken(profile);
            verificationService.sendEmail(token, profile, verificationUrl, newProfileEmailFromAddress, newProfileEmailSubject, newProfileEmailTemplateName);
        }
        return profile;
    } catch (DuplicateKeyException e) {
        throw new ProfileExistsException(tenantName, username);
    } catch (MongoDataException e) {
        throw new I10nProfileException(ERROR_KEY_CREATE_PROFILE_ERROR, e, username, tenantName);
    }
}
Also used : ProfileExistsException(org.craftercms.profile.exceptions.ProfileExistsException) Tenant(org.craftercms.profile.api.Tenant) InvalidEmailAddressException(org.craftercms.profile.exceptions.InvalidEmailAddressException) VerificationToken(org.craftercms.profile.api.VerificationToken) I10nProfileException(org.craftercms.profile.api.exceptions.I10nProfileException) AttributeDefinition(org.craftercms.profile.api.AttributeDefinition) MongoDataException(org.craftercms.commons.mongo.MongoDataException) Date(java.util.Date) Profile(org.craftercms.profile.api.Profile) DuplicateKeyException(org.craftercms.commons.mongo.DuplicateKeyException)

Aggregations

I10nProfileException (org.craftercms.profile.api.exceptions.I10nProfileException)31 MongoDataException (org.craftercms.commons.mongo.MongoDataException)26 Profile (org.craftercms.profile.api.Profile)15 Date (java.util.Date)7 Tenant (org.craftercms.profile.api.Tenant)5 Ticket (org.craftercms.profile.api.Ticket)4 URI (java.net.URI)3 URISyntaxException (java.net.URISyntaxException)3 DuplicateKeyException (org.craftercms.commons.mongo.DuplicateKeyException)3 PersistentLogin (org.craftercms.profile.api.PersistentLogin)3 DisabledProfileException (org.craftercms.profile.exceptions.DisabledProfileException)3 UpdateHelper (org.craftercms.commons.mongo.UpdateHelper)2 VerificationToken (org.craftercms.profile.api.VerificationToken)2 File (java.io.File)1 IOException (java.io.IOException)1 EmailException (org.craftercms.commons.mail.EmailException)1 AttributeDefinition (org.craftercms.profile.api.AttributeDefinition)1 AccessTokenExistsException (org.craftercms.profile.exceptions.AccessTokenExistsException)1 BadCredentialsException (org.craftercms.profile.exceptions.BadCredentialsException)1 InvalidEmailAddressException (org.craftercms.profile.exceptions.InvalidEmailAddressException)1