Search in sources :

Example 11 with ProfileException

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

the class ProfileController method getAttachment.

@RequestMapping(value = URL_PROFILE_GET_ATTACHMENT, method = RequestMethod.GET)
@ApiOperation(value = "Gets the requested attachment of the given profile", notes = "If Attachment or profile does not exist will " + "throw error, content-type,content-legnth headers" + " are set")
public void getAttachment(@ApiParam("The profile's ID") @PathVariable(PATH_VAR_ID) String profileId, @ApiParam("Attachment Id to get") @PathVariable(PATH_VAR_ATTACHMENT) String attachmentId, HttpServletResponse response) throws ProfileException, IOException {
    Profile profile = profileService.getProfile(profileId);
    if (profile != null) {
        InputStream input = null;
        try {
            input = profileService.getProfileAttachment(attachmentId, profile.getId().toString());
            if (input != null) {
                ProfileAttachment attachment = profileService.getProfileAttachmentInformation(profile.getId().toString(), attachmentId);
                response.setContentType(attachment.getContentType());
                response.setContentLength((int) attachment.getFileSizeBytes());
                IOUtils.copy(input, response.getOutputStream());
            }
        } catch (ProfileException ex) {
            response.sendError(HttpServletResponse.SC_NOT_FOUND);
            response.setContentLength(0);
        } finally {
            if (input != null) {
                input.close();
            }
        }
    } else {
        throw new NoSuchProfileException.ById(profileId);
    }
}
Also used : ProfileAttachment(org.craftercms.profile.api.services.ProfileAttachment) InputStream(java.io.InputStream) NoSuchProfileException(org.craftercms.profile.exceptions.NoSuchProfileException) ProfileException(org.craftercms.profile.api.exceptions.ProfileException) Profile(org.craftercms.profile.api.Profile) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 12 with ProfileException

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

the class AuthenticationManagerImpl method invalidateAuthentication.

@Override
public void invalidateAuthentication(Authentication authentication) {
    try {
        authenticationCache.removeAuthentication(authentication.getTicket());
        authenticationService.invalidateTicket(authentication.getTicket());
        logger.debug("Ticket '{}' successfully invalidated");
    } catch (ProfileException e) {
        throw new AuthenticationSystemException("An unexpected error occurred while attempting to invalidate " + "ticket '" + authentication.getTicket() + "'", e);
    }
}
Also used : AuthenticationSystemException(org.craftercms.security.exception.AuthenticationSystemException) ProfileException(org.craftercms.profile.api.exceptions.ProfileException)

Example 13 with ProfileException

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

the class AuthenticationManagerImpl method authenticateUser.

@Override
public Authentication authenticateUser(Profile profile, boolean remembered) throws AuthenticationException {
    try {
        Ticket ticket = authenticationService.createTicket(profile.getId().toString());
        String ticketId = ticket.getId();
        DefaultAuthentication auth = new DefaultAuthentication(ticketId, profile, remembered);
        authenticationCache.putAuthentication(auth);
        logger.debug("Authentication successful for user '{}' (ticket ID = '{}')", ticket.getProfileId(), ticketId);
        return auth;
    } catch (ProfileRestServiceException e) {
        if (e.getErrorCode() == ErrorCode.DISABLED_PROFILE) {
            throw new DisabledUserException("User is disabled", e);
        } else {
            throw new AuthenticationSystemException("An unexpected error occurred while authenticating", e);
        }
    } catch (ProfileException e) {
        throw new AuthenticationSystemException("An unexpected error occurred while authenticating", e);
    }
}
Also used : Ticket(org.craftercms.profile.api.Ticket) ProfileRestServiceException(org.craftercms.profile.exceptions.ProfileRestServiceException) AuthenticationSystemException(org.craftercms.security.exception.AuthenticationSystemException) ProfileException(org.craftercms.profile.api.exceptions.ProfileException) DisabledUserException(org.craftercms.security.exception.DisabledUserException)

Example 14 with ProfileException

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

the class TenantServiceImpl method addAttributeDefinitions.

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

        @Override
        public void doWithTenant(TenantUpdater tenantUpdater) throws ProfileException {
            tenantUpdater.addAttributeDefinitions(attributeDefinitions);
        }
    });
    for (AttributeDefinition definition : tenant.getAttributeDefinitions()) {
        addDefaultValue(tenantName, definition.getName(), definition.getDefaultValue());
    }
    logger.debug(LOG_KEY_ATTRIBUTE_DEFINITIONS_ADDED, attributeDefinitions, tenantName);
    return tenant;
}
Also used : Tenant(org.craftercms.profile.api.Tenant) TenantUpdater(org.craftercms.profile.utils.db.TenantUpdater) AttributeDefinition(org.craftercms.profile.api.AttributeDefinition) I10nProfileException(org.craftercms.profile.api.exceptions.I10nProfileException) ProfileException(org.craftercms.profile.api.exceptions.ProfileException)

Example 15 with ProfileException

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

the class TenantServiceImpl method removeAttributeDefinitions.

@Override
public Tenant removeAttributeDefinitions(final String tenantName, final Collection<String> attributeNames) throws ProfileException {
    for (String attributeName : attributeNames) {
        removeAttributeFromProfiles(tenantName, attributeName);
    }
    Tenant tenant = updateTenant(tenantName, new UpdateCallback() {

        @Override
        public void doWithTenant(TenantUpdater tenantUpdater) throws ProfileException {
            tenantUpdater.removeAttributeDefinitions(attributeNames);
        }
    });
    logger.debug(LOG_KEY_ATTRIBUTE_DEFINITIONS_REMOVED, attributeNames, 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