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);
}
}
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);
}
}
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);
}
}
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;
}
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;
}
Aggregations