Search in sources :

Example 1 with ProfileException

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

the class ProfileServiceImpl method addProfileAttachment.

@Override
public ProfileAttachment addProfileAttachment(final String profileId, final String attachmentName, final InputStream file) throws ProfileException {
    String storeName = "/" + profileId + "/" + FilenameUtils.removeExtension(attachmentName);
    try {
        ObjectId currentId = checkIfAttachmentExist(storeName);
        String mimeType = getAttachmentContentType(attachmentName);
        FileInfo fileInfo;
        if (currentId != null) {
            // Update !!!
            fileInfo = profileRepository.updateFile(currentId, file, storeName, mimeType, true);
        } else {
            fileInfo = profileRepository.saveFile(file, storeName, mimeType);
        }
        return fileInfoToProfileAttachment(fileInfo);
    } catch (MongoDataException | FileExistsException | FileNotFoundException e) {
        throw new ProfileException("Unable to attach file to profile '" + profileId + "'", e);
    }
}
Also used : FileInfo(org.craftercms.commons.mongo.FileInfo) ObjectId(org.bson.types.ObjectId) FileNotFoundException(java.io.FileNotFoundException) MongoDataException(org.craftercms.commons.mongo.MongoDataException) NoSuchProfileException(org.craftercms.profile.exceptions.NoSuchProfileException) I10nProfileException(org.craftercms.profile.api.exceptions.I10nProfileException) ProfileException(org.craftercms.profile.api.exceptions.ProfileException) FileExistsException(org.apache.commons.io.FileExistsException)

Example 2 with ProfileException

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

the class TenantServiceImpl method verifyNewProfiles.

@Override
public Tenant verifyNewProfiles(String tenantName, final boolean verify) throws ProfileException {
    Tenant tenant = updateTenant(tenantName, new UpdateCallback() {

        @Override
        public void doWithTenant(TenantUpdater tenantUpdater) throws ProfileException {
            tenantUpdater.setVerifyNewProfiles(verify);
        }
    });
    logger.debug(LOG_KEY_VERIFY_NEW_PROFILES_FLAG_SET, tenantName, verify);
    return tenant;
}
Also used : Tenant(org.craftercms.profile.api.Tenant) TenantUpdater(org.craftercms.profile.utils.db.TenantUpdater) I10nProfileException(org.craftercms.profile.api.exceptions.I10nProfileException) ProfileException(org.craftercms.profile.api.exceptions.ProfileException)

Example 3 with ProfileException

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

the class TenantServiceImpl method addRoles.

@Override
public Tenant addRoles(String tenantName, final Collection<String> roles) throws ProfileException {
    Tenant tenant = updateTenant(tenantName, new UpdateCallback() {

        @Override
        public void doWithTenant(TenantUpdater tenantUpdater) throws ProfileException {
            tenantUpdater.addAvailableRoles(roles);
        }
    });
    logger.debug(LOG_KEY_ROLES_ADDED, roles, tenantName);
    return tenant;
}
Also used : Tenant(org.craftercms.profile.api.Tenant) TenantUpdater(org.craftercms.profile.utils.db.TenantUpdater) I10nProfileException(org.craftercms.profile.api.exceptions.I10nProfileException) ProfileException(org.craftercms.profile.api.exceptions.ProfileException)

Example 4 with ProfileException

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

the class TenantServiceImpl method updateTenant.

@Override
public Tenant updateTenant(final Tenant tenant) throws ProfileException {
    final String tenantName = tenant.getName();
    Tenant updatedTenant = updateTenant(tenant.getName(), new UpdateCallback() {

        @Override
        public void doWithTenant(TenantUpdater tenantUpdater) throws ProfileException {
            Tenant originalTenant = tenantUpdater.getTenant();
            Collection<String> originalRoles = originalTenant.getAvailableRoles();
            Collection<String> newRoles = tenant.getAvailableRoles();
            Collection<AttributeDefinition> originalDefinitions = originalTenant.getAttributeDefinitions();
            Collection<AttributeDefinition> newDefinitions = tenant.getAttributeDefinitions();
            Collection<String> removedRoles = CollectionUtils.subtract(originalRoles, newRoles);
            Collection<AttributeDefinition> removedDefinitions = CollectionUtils.subtract(originalDefinitions, newDefinitions);
            for (String removedRole : removedRoles) {
                removeRoleFromProfiles(tenantName, removedRole);
            }
            for (AttributeDefinition removedDefinition : removedDefinitions) {
                removeAttributeFromProfiles(tenantName, removedDefinition.getName());
            }
            tenantUpdater.setVerifyNewProfiles(tenant.isVerifyNewProfiles());
            tenantUpdater.setSsoEnabled(tenant.isSsoEnabled());
            tenantUpdater.setAvailableRoles(tenant.getAvailableRoles());
            tenantUpdater.setAttributeDefinitions(tenant.getAttributeDefinitions());
        }
    });
    for (AttributeDefinition definition : updatedTenant.getAttributeDefinitions()) {
        addDefaultValue(tenantName, definition.getName(), definition.getDefaultValue());
    }
    return updatedTenant;
}
Also used : Tenant(org.craftercms.profile.api.Tenant) TenantUpdater(org.craftercms.profile.utils.db.TenantUpdater) Collection(java.util.Collection) AttributeDefinition(org.craftercms.profile.api.AttributeDefinition) I10nProfileException(org.craftercms.profile.api.exceptions.I10nProfileException) ProfileException(org.craftercms.profile.api.exceptions.ProfileException)

Example 5 with ProfileException

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

the class TenantServiceImpl method removeRoles.

@Override
public Tenant removeRoles(final String tenantName, final Collection<String> roles) throws ProfileException {
    Tenant tenant = updateTenant(tenantName, new UpdateCallback() {

        @Override
        public void doWithTenant(TenantUpdater tenantUpdater) throws ProfileException {
            for (String role : roles) {
                removeRoleFromProfiles(tenantName, role);
            }
            tenantUpdater.removeAvailableRoles(roles);
        }
    });
    logger.debug(LOG_KEY_ROLES_REMOVED, roles, tenantName);
    return tenant;
}
Also used : Tenant(org.craftercms.profile.api.Tenant) TenantUpdater(org.craftercms.profile.utils.db.TenantUpdater) I10nProfileException(org.craftercms.profile.api.exceptions.I10nProfileException) ProfileException(org.craftercms.profile.api.exceptions.ProfileException)

Aggregations

ProfileException (org.craftercms.profile.api.exceptions.ProfileException)22 Tenant (org.craftercms.profile.api.Tenant)8 I10nProfileException (org.craftercms.profile.api.exceptions.I10nProfileException)8 TenantUpdater (org.craftercms.profile.utils.db.TenantUpdater)7 PersistentLogin (org.craftercms.profile.api.PersistentLogin)5 Profile (org.craftercms.profile.api.Profile)4 RememberMeException (org.craftercms.security.exception.rememberme.RememberMeException)4 ProfileRestServiceException (org.craftercms.profile.exceptions.ProfileRestServiceException)3 AuthenticationSystemException (org.craftercms.security.exception.AuthenticationSystemException)3 RememberMeAuthenticationException (org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationException)3 AttributeDefinition (org.craftercms.profile.api.AttributeDefinition)2 Ticket (org.craftercms.profile.api.Ticket)2 NoSuchProfileException (org.craftercms.profile.exceptions.NoSuchProfileException)2 DisabledUserException (org.craftercms.security.exception.DisabledUserException)2 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1 Collection (java.util.Collection)1 FileExistsException (org.apache.commons.io.FileExistsException)1 ObjectId (org.bson.types.ObjectId)1