Search in sources :

Example 96 with InvalidArgumentException

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 });
    }
}
Also used : InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) AuthenticationException(org.alfresco.repo.security.authentication.AuthenticationException) NotFoundException(org.alfresco.rest.framework.core.exceptions.NotFoundException)

Example 97 with InvalidArgumentException

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;
}
Also used : LoginTicketResponse(org.alfresco.rest.api.model.LoginTicketResponse) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) AuthenticationException(org.alfresco.repo.security.authentication.AuthenticationException) NotFoundException(org.alfresco.rest.framework.core.exceptions.NotFoundException)

Example 98 with InvalidArgumentException

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.");
}
Also used : Authorization(org.alfresco.repo.security.authentication.Authorization) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)

Example 99 with InvalidArgumentException

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);
    }
}
Also used : CustomModelDefinition(org.alfresco.service.cmr.dictionary.CustomModelDefinition) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) ModelStatus(org.alfresco.rest.api.model.CustomModel.ModelStatus) ConstraintViolatedException(org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException) CustomModel(org.alfresco.rest.api.model.CustomModel) CustomModelConstraintException(org.alfresco.service.cmr.dictionary.CustomModelException.CustomModelConstraintException) PermissionDeniedException(org.alfresco.rest.framework.core.exceptions.PermissionDeniedException) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) ActiveModelConstraintException(org.alfresco.service.cmr.dictionary.CustomModelException.ActiveModelConstraintException) ModelDoesNotExistException(org.alfresco.service.cmr.dictionary.CustomModelException.ModelDoesNotExistException) CustomModelConstraintException(org.alfresco.service.cmr.dictionary.CustomModelException.CustomModelConstraintException) InvalidCustomModelException(org.alfresco.service.cmr.dictionary.CustomModelException.InvalidCustomModelException) ConstraintViolatedException(org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException) ApiException(org.alfresco.rest.framework.core.exceptions.ApiException) CustomModelException(org.alfresco.service.cmr.dictionary.CustomModelException) ModelExistsException(org.alfresco.service.cmr.dictionary.CustomModelException.ModelExistsException) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) ApiException(org.alfresco.rest.framework.core.exceptions.ApiException)

Example 100 with InvalidArgumentException

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);
}
Also used : CustomModelDefinition(org.alfresco.service.cmr.dictionary.CustomModelDefinition) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) QName(org.alfresco.service.namespace.QName) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) TypeDefinition(org.alfresco.service.cmr.dictionary.TypeDefinition) DataTypeDefinition(org.alfresco.service.cmr.dictionary.DataTypeDefinition)

Aggregations

InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)132 NodeRef (org.alfresco.service.cmr.repository.NodeRef)39 QName (org.alfresco.service.namespace.QName)37 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)31 ConstraintViolatedException (org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException)24 ArrayList (java.util.ArrayList)22 Test (org.junit.Test)20 PermissionDeniedException (org.alfresco.rest.framework.core.exceptions.PermissionDeniedException)17 Serializable (java.io.Serializable)12 SortColumn (org.alfresco.rest.framework.resource.parameters.SortColumn)12 SearchParameters (org.alfresco.service.cmr.search.SearchParameters)11 Paging (org.alfresco.rest.framework.resource.parameters.Paging)10 ApiException (org.alfresco.rest.framework.core.exceptions.ApiException)9 NotFoundException (org.alfresco.rest.framework.core.exceptions.NotFoundException)9 SiteInfo (org.alfresco.service.cmr.site.SiteInfo)9 Pair (org.alfresco.util.Pair)9 HashMap (java.util.HashMap)8 HashSet (java.util.HashSet)8 Params (org.alfresco.rest.framework.resource.parameters.Params)8 RelationshipResourceNotFoundException (org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException)7