use of org.alfresco.rest.framework.core.exceptions.InvalidArgumentException in project alfresco-remote-api by Alfresco.
the class AuthenticationsImpl method deleteTicket.
@Override
public void deleteTicket(String me, Parameters parameters, WithResponse withResponse) {
if (!People.DEFAULT_USER.equals(me)) {
throw new InvalidArgumentException("Invalid parameter: " + me);
}
final String ticket = getTicket(parameters);
try {
final String ticketUser = ticketComponent.validateTicket(ticket);
final String currentUser = AuthenticationUtil.getFullyAuthenticatedUser();
// or the user is not fully authenticated
if (currentUser == null || !currentUser.equals(ticketUser)) {
throw new NotFoundException(NotFoundException.DEFAULT_MESSAGE_ID, new String[] { ticket });
} else {
// delete the ticket
authenticationService.invalidateTicket(ticket);
}
} catch (AuthenticationException e) {
throw new NotFoundException(NotFoundException.DEFAULT_MESSAGE_ID, new String[] { ticket });
}
}
use of org.alfresco.rest.framework.core.exceptions.InvalidArgumentException in project alfresco-remote-api by Alfresco.
the class AuthenticationsImpl method validateTicket.
@Override
public LoginTicketResponse validateTicket(String me, Parameters parameters, WithResponse withResponse) {
if (!People.DEFAULT_USER.equals(me)) {
throw new InvalidArgumentException("Invalid parameter: " + me);
}
final String ticket = getTicket(parameters);
try {
final String ticketUser = ticketComponent.validateTicket(ticket);
final String currentUser = AuthenticationUtil.getFullyAuthenticatedUser();
// or the user is not fully authenticated
if (currentUser == null || !currentUser.equals(ticketUser)) {
throw new NotFoundException(NotFoundException.DEFAULT_MESSAGE_ID, new String[] { ticket });
}
} catch (AuthenticationException e) {
throw new NotFoundException(NotFoundException.DEFAULT_MESSAGE_ID, new String[] { ticket });
}
LoginTicketResponse response = new LoginTicketResponse();
response.setId(ticket);
return response;
}
use of org.alfresco.rest.framework.core.exceptions.InvalidArgumentException in project alfresco-remote-api by Alfresco.
the class AuthenticationsImpl method getTicket.
protected String getTicket(Parameters parameters) {
// First check the alf_ticket in the URL
final String alfTicket = parameters.getParameter(PARAM_ALF_TICKET);
if (StringUtils.isNotEmpty(alfTicket)) {
return alfTicket;
}
// Check the Authorization header
final String authorization = parameters.getRequest().getHeader(AUTHORIZATION_HEADER);
if (StringUtils.isEmpty(authorization)) {
throw new InvalidArgumentException("Authorization header is required.");
}
final String[] authorizationParts = authorization.split(" ");
if (authorizationParts[0].equalsIgnoreCase("basic")) {
final String decodedAuthorisation = new String(Base64.decode(authorizationParts[1]));
Authorization authObj = new Authorization(decodedAuthorisation);
if (!authObj.isTicket()) {
throw new InvalidArgumentException("Ticket base authentication required.");
}
return authObj.getTicket();
} else if (authorizationParts[0].equalsIgnoreCase("bearer")) {
return getTicketFromRemoteUserMapperUserId(parameters);
}
throw new InvalidArgumentException("Authorization '" + authorizationParts[0] + "' not supported.");
}
use of org.alfresco.rest.framework.core.exceptions.InvalidArgumentException in project alfresco-remote-api by Alfresco.
the class CustomModelsImpl method updateCustomModel.
@Override
public CustomModel updateCustomModel(String modelName, CustomModel model, Parameters parameters) {
// Check the current user is authorised to update the custom model
validateCurrentUser();
// Check to see if the model exists
ModelDetails existingModelDetails = new ModelDetails(getCustomModelImpl(modelName));
CustomModel existingModel = existingModelDetails.getModel();
// the other properties should be untouched)
if (hasSelectProperty(parameters, SELECT_STATUS)) {
ModelStatus status = model.getStatus();
if (status == null) {
throw new InvalidArgumentException("cmm.rest_api.model_status_null");
}
try {
if (ModelStatus.ACTIVE.equals(status)) {
customModelService.activateCustomModel(modelName);
} else {
customModelService.deactivateCustomModel(modelName);
}
// update the model's status
existingModel.setStatus(status);
return existingModel;
} catch (CustomModelConstraintException mce) {
throw new ConstraintViolatedException(mce.getMessage());
} catch (Exception ex) {
throw new ApiException(ex.getMessage(), ex);
}
} else {
if (model.getName() != null && !(existingModel.getName().equals(model.getName()))) {
throw new InvalidArgumentException("cmm.rest_api.model_name_cannot_update");
}
existingModel.setNamespaceUri(model.getNamespaceUri());
final boolean isNamespacePrefixChanged = !(existingModel.getNamespacePrefix().equals(model.getNamespacePrefix()));
if (isNamespacePrefixChanged) {
// Change types' and aspects' parents as well as the property constraint's Ref namespace prefix
replacePrefix(existingModelDetails.getTypes(), existingModel.getNamespacePrefix(), model.getNamespacePrefix());
replacePrefix(existingModelDetails.getAspects(), existingModel.getNamespacePrefix(), model.getNamespacePrefix());
}
existingModel.setNamespacePrefix(model.getNamespacePrefix());
existingModel.setAuthor(model.getAuthor());
existingModel.setDescription(model.getDescription());
CustomModelDefinition modelDef = updateModel(existingModelDetails, "cmm.rest_api.model_update_failure");
return new CustomModel(modelDef);
}
}
use of org.alfresco.rest.framework.core.exceptions.InvalidArgumentException in project alfresco-remote-api by Alfresco.
the class CustomModelsImpl method getCustomType.
@Override
public CustomType getCustomType(String modelName, String typeName, Parameters parameters) {
if (typeName == null) {
throw new InvalidArgumentException(TYPE_NAME_NULL_ERR);
}
final CustomModelDefinition modelDef = getCustomModelImpl(modelName);
QName typeQname = QName.createQName(modelDef.getName().getNamespaceURI(), typeName);
TypeDefinition customTypeDef = customModelService.getCustomType(typeQname);
if (customTypeDef == null) {
throw new EntityNotFoundException(typeName);
}
// Check if inherited properties have been requested
boolean includeInheritedProps = hasSelectProperty(parameters, SELECT_ALL_PROPS);
return convertToCustomType(customTypeDef, includeInheritedProps);
}
Aggregations