Search in sources :

Example 86 with Parameter

use of org.wso2.carbon.apimgt.api.doc.model.Parameter in project charon by wso2.

the class MeResourceManager method create.

@Override
public SCIMResponse create(String scimObjectString, UserManager userManager, String attributes, String excludeAttributes) {
    JSONEncoder encoder = null;
    try {
        // obtain the json encoder
        encoder = getEncoder();
        // obtain the json decoder
        JSONDecoder decoder = getDecoder();
        // obtain the schema corresponding to user
        // unless configured returns core-user schema or else returns extended user schema)
        SCIMResourceTypeSchema schema = SCIMResourceSchemaManager.getInstance().getUserResourceSchema();
        // get the URIs of required attributes which must be given a value
        Map<String, Boolean> requiredAttributes = ResourceManagerUtil.getOnlyRequiredAttributesURIs((SCIMResourceTypeSchema) CopyUtil.deepCopy(schema), attributes, excludeAttributes);
        // decode the SCIM User object, encoded in the submitted payload.
        User user = (User) decoder.decodeResource(scimObjectString, schema, new User());
        // validate the created user.
        ServerSideValidator.validateCreatedSCIMObject(user, schema);
        User createdUser;
        if (userManager != null) {
            /*handover the SCIM User object to the user usermanager provided by the SP.
            need to send back the newly created user in the response payload*/
            createdUser = userManager.createMe(user, requiredAttributes);
        } else {
            String error = "Provided user manager handler is null.";
            // throw internal server error.
            throw new InternalErrorException(error);
        }
        // encode the newly created SCIM user object and add id attribute to Location header.
        String encodedUser;
        Map<String, String> responseHeaders = new HashMap<String, String>();
        if (createdUser != null) {
            // create a deep copy of the user object since we are going to change it.
            User copiedUser = (User) CopyUtil.deepCopy(createdUser);
            // need to remove password before returning
            ServerSideValidator.validateReturnedAttributes(copiedUser, attributes, excludeAttributes);
            encodedUser = encoder.encodeSCIMObject(copiedUser);
            // add location header
            responseHeaders.put(SCIMConstants.LOCATION_HEADER, getResourceEndpointURL(SCIMConstants.USER_ENDPOINT) + "/" + createdUser.getId());
            responseHeaders.put(SCIMConstants.CONTENT_TYPE_HEADER, SCIMConstants.APPLICATION_JSON);
        } else {
            String error = "Newly created User resource is null.";
            throw new InternalErrorException(error);
        }
        // put the uri of the User object in the response header parameter.
        return new SCIMResponse(ResponseCodeConstants.CODE_CREATED, encodedUser, responseHeaders);
    } catch (CharonException e) {
        return encodeSCIMException(e);
    } catch (BadRequestException e) {
        return encodeSCIMException(e);
    } catch (ConflictException e) {
        return encodeSCIMException(e);
    } catch (InternalErrorException e) {
        return encodeSCIMException(e);
    } catch (NotFoundException e) {
        return encodeSCIMException(e);
    }
}
Also used : User(org.wso2.charon3.core.objects.User) HashMap(java.util.HashMap) ConflictException(org.wso2.charon3.core.exceptions.ConflictException) NotFoundException(org.wso2.charon3.core.exceptions.NotFoundException) InternalErrorException(org.wso2.charon3.core.exceptions.InternalErrorException) JSONDecoder(org.wso2.charon3.core.encoder.JSONDecoder) BadRequestException(org.wso2.charon3.core.exceptions.BadRequestException) JSONEncoder(org.wso2.charon3.core.encoder.JSONEncoder) SCIMResourceTypeSchema(org.wso2.charon3.core.schema.SCIMResourceTypeSchema) CharonException(org.wso2.charon3.core.exceptions.CharonException) SCIMResponse(org.wso2.charon3.core.protocol.SCIMResponse)

Example 87 with Parameter

use of org.wso2.carbon.apimgt.api.doc.model.Parameter in project charon by wso2.

the class UserResourceManager method create.

/*
     * Returns SCIMResponse based on the sucess or failure of the create user operation
     *
     * @param scimObjectString -raw string containing user info
     * @return usermanager - usermanager instance defined by the external implementor of charon
     */
public SCIMResponse create(String scimObjectString, UserManager userManager, String attributes, String excludeAttributes) {
    JSONEncoder encoder = null;
    try {
        // obtain the json encoder
        encoder = getEncoder();
        // obtain the json decoder
        JSONDecoder decoder = getDecoder();
        // obtain the schema corresponding to user
        // unless configured returns core-user schema or else returns extended user schema)
        SCIMResourceTypeSchema schema = SCIMResourceSchemaManager.getInstance().getUserResourceSchema();
        // decode the SCIM User object, encoded in the submitted payload.
        User user = (User) decoder.decodeResource(scimObjectString, schema, new User());
        // validate the created user.
        ServerSideValidator.validateCreatedSCIMObject(user, schema);
        // get the URIs of required attributes which must be given a value
        Map<String, Boolean> requiredAttributes = ResourceManagerUtil.getOnlyRequiredAttributesURIs((SCIMResourceTypeSchema) CopyUtil.deepCopy(schema), attributes, excludeAttributes);
        User createdUser;
        if (userManager != null) {
            /*handover the SCIM User object to the user usermanager provided by the SP.
            need to send back the newly created user in the response payload*/
            createdUser = userManager.createUser(user, requiredAttributes);
        } else {
            String error = "Provided user manager handler is null.";
            // throw internal server error.
            throw new InternalErrorException(error);
        }
        // encode the newly created SCIM user object and add id attribute to Location header.
        String encodedUser;
        Map<String, String> responseHeaders = new HashMap<String, String>();
        if (createdUser != null) {
            // create a deep copy of the user object since we are going to change it.
            User copiedUser = (User) CopyUtil.deepCopy(createdUser);
            // need to remove password before returning
            ServerSideValidator.validateReturnedAttributes(copiedUser, attributes, excludeAttributes);
            encodedUser = encoder.encodeSCIMObject(copiedUser);
            // add location header
            responseHeaders.put(SCIMConstants.LOCATION_HEADER, getResourceEndpointURL(SCIMConstants.USER_ENDPOINT) + "/" + createdUser.getId());
            responseHeaders.put(SCIMConstants.CONTENT_TYPE_HEADER, SCIMConstants.APPLICATION_JSON);
        } else {
            String error = "Newly created User resource is null.";
            throw new InternalErrorException(error);
        }
        // put the uri of the User object in the response header parameter.
        return new SCIMResponse(ResponseCodeConstants.CODE_CREATED, encodedUser, responseHeaders);
    } catch (CharonException e) {
        // because inside API code throws CharonException.
        if (e.getStatus() == -1) {
            e.setStatus(ResponseCodeConstants.CODE_INTERNAL_ERROR);
        }
        return AbstractResourceManager.encodeSCIMException(e);
    } catch (BadRequestException e) {
        return AbstractResourceManager.encodeSCIMException(e);
    } catch (ConflictException e) {
        return AbstractResourceManager.encodeSCIMException(e);
    } catch (InternalErrorException e) {
        return AbstractResourceManager.encodeSCIMException(e);
    } catch (NotFoundException e) {
        return AbstractResourceManager.encodeSCIMException(e);
    }
}
Also used : User(org.wso2.charon3.core.objects.User) HashMap(java.util.HashMap) ConflictException(org.wso2.charon3.core.exceptions.ConflictException) NotFoundException(org.wso2.charon3.core.exceptions.NotFoundException) InternalErrorException(org.wso2.charon3.core.exceptions.InternalErrorException) JSONDecoder(org.wso2.charon3.core.encoder.JSONDecoder) BadRequestException(org.wso2.charon3.core.exceptions.BadRequestException) JSONEncoder(org.wso2.charon3.core.encoder.JSONEncoder) SCIMResourceTypeSchema(org.wso2.charon3.core.schema.SCIMResourceTypeSchema) CharonException(org.wso2.charon3.core.exceptions.CharonException) SCIMResponse(org.wso2.charon3.core.protocol.SCIMResponse)

Example 88 with Parameter

use of org.wso2.carbon.apimgt.api.doc.model.Parameter in project charon by wso2.

the class UserResourceManager method updateWithPATCH.

/**
 * Update the user resource by sequence of operations.
 *
 * @param existingId
 * @param scimObjectString
 * @param userManager
 * @param attributes
 * @param excludeAttributes
 * @return
 */
public SCIMResponse updateWithPATCH(String existingId, String scimObjectString, UserManager userManager, String attributes, String excludeAttributes) {
    try {
        if (userManager == null) {
            String error = "Provided user manager handler is null.";
            throw new InternalErrorException(error);
        }
        // obtain the json decoder.
        JSONDecoder decoder = getDecoder();
        // decode the SCIM User object, encoded in the submitted payload.
        List<PatchOperation> opList = decoder.decodeRequest(scimObjectString);
        SCIMResourceTypeSchema schema = SCIMResourceSchemaManager.getInstance().getUserResourceSchema();
        // get the user from the user core
        User oldUser = userManager.getUser(existingId, ResourceManagerUtil.getAllAttributeURIs(schema));
        if (oldUser == null) {
            throw new NotFoundException("No user with the id : " + existingId + " in the user store.");
        }
        // make a copy of the original user
        User copyOfOldUser = (User) CopyUtil.deepCopy(oldUser);
        // make another copy of original user.
        // this will be used to restore to the original condition if failure occurs.
        User originalUser = (User) CopyUtil.deepCopy(copyOfOldUser);
        User newUser = null;
        for (PatchOperation operation : opList) {
            if (operation.getOperation().equals(SCIMConstants.OperationalConstants.ADD)) {
                if (newUser == null) {
                    newUser = (User) PatchOperationUtil.doPatchAdd(operation, getDecoder(), oldUser, copyOfOldUser, schema);
                    copyOfOldUser = (User) CopyUtil.deepCopy(newUser);
                } else {
                    newUser = (User) PatchOperationUtil.doPatchAdd(operation, getDecoder(), newUser, copyOfOldUser, schema);
                    copyOfOldUser = (User) CopyUtil.deepCopy(newUser);
                }
            } else if (operation.getOperation().equals(SCIMConstants.OperationalConstants.REMOVE)) {
                if (newUser == null) {
                    newUser = (User) PatchOperationUtil.doPatchRemove(operation, oldUser, copyOfOldUser, schema);
                    copyOfOldUser = (User) CopyUtil.deepCopy(newUser);
                } else {
                    newUser = (User) PatchOperationUtil.doPatchRemove(operation, newUser, copyOfOldUser, schema);
                    copyOfOldUser = (User) CopyUtil.deepCopy(newUser);
                }
            } else if (operation.getOperation().equals(SCIMConstants.OperationalConstants.REPLACE)) {
                if (newUser == null) {
                    newUser = (User) PatchOperationUtil.doPatchReplace(operation, getDecoder(), oldUser, copyOfOldUser, schema);
                    copyOfOldUser = (User) CopyUtil.deepCopy(newUser);
                } else {
                    newUser = (User) PatchOperationUtil.doPatchReplace(operation, getDecoder(), newUser, copyOfOldUser, schema);
                    copyOfOldUser = (User) CopyUtil.deepCopy(newUser);
                }
            } else {
                throw new BadRequestException("Unknown operation.", ResponseCodeConstants.INVALID_SYNTAX);
            }
        }
        // get the URIs of required attributes which must be given a value
        Map<String, Boolean> requiredAttributes = ResourceManagerUtil.getOnlyRequiredAttributesURIs((SCIMResourceTypeSchema) CopyUtil.deepCopy(schema), attributes, excludeAttributes);
        User validatedUser = (User) ServerSideValidator.validateUpdatedSCIMObject(originalUser, newUser, schema);
        newUser = userManager.updateUser(validatedUser, requiredAttributes);
        // encode the newly created SCIM user object and add id attribute to Location header.
        String encodedUser;
        Map<String, String> httpHeaders = new HashMap<String, String>();
        if (newUser != null) {
            // create a deep copy of the user object since we are going to change it.
            User copiedUser = (User) CopyUtil.deepCopy(newUser);
            // need to remove password before returning
            ServerSideValidator.validateReturnedAttributes(copiedUser, attributes, excludeAttributes);
            encodedUser = getEncoder().encodeSCIMObject(copiedUser);
            // add location header
            httpHeaders.put(SCIMConstants.LOCATION_HEADER, getResourceEndpointURL(SCIMConstants.USER_ENDPOINT) + "/" + newUser.getId());
            httpHeaders.put(SCIMConstants.CONTENT_TYPE_HEADER, SCIMConstants.APPLICATION_JSON);
        } else {
            String error = "Updated User resource is null.";
            throw new CharonException(error);
        }
        // put the URI of the User object in the response header parameter.
        return new SCIMResponse(ResponseCodeConstants.CODE_OK, encodedUser, httpHeaders);
    } catch (NotFoundException e) {
        return AbstractResourceManager.encodeSCIMException(e);
    } catch (BadRequestException e) {
        return AbstractResourceManager.encodeSCIMException(e);
    } catch (NotImplementedException e) {
        return AbstractResourceManager.encodeSCIMException(e);
    } catch (CharonException e) {
        return AbstractResourceManager.encodeSCIMException(e);
    } catch (InternalErrorException e) {
        return AbstractResourceManager.encodeSCIMException(e);
    } catch (RuntimeException e) {
        CharonException e1 = new CharonException("Error in performing the patch operation on user resource.", e);
        return AbstractResourceManager.encodeSCIMException(e1);
    }
}
Also used : User(org.wso2.charon3.core.objects.User) HashMap(java.util.HashMap) NotImplementedException(org.wso2.charon3.core.exceptions.NotImplementedException) NotFoundException(org.wso2.charon3.core.exceptions.NotFoundException) InternalErrorException(org.wso2.charon3.core.exceptions.InternalErrorException) JSONDecoder(org.wso2.charon3.core.encoder.JSONDecoder) PatchOperation(org.wso2.charon3.core.utils.codeutils.PatchOperation) BadRequestException(org.wso2.charon3.core.exceptions.BadRequestException) SCIMResourceTypeSchema(org.wso2.charon3.core.schema.SCIMResourceTypeSchema) CharonException(org.wso2.charon3.core.exceptions.CharonException) SCIMResponse(org.wso2.charon3.core.protocol.SCIMResponse)

Example 89 with Parameter

use of org.wso2.carbon.apimgt.api.doc.model.Parameter in project carbon-business-process by wso2.

the class BPELBindingContextImpl method deactivateMyRoleEndpoint.

public void deactivateMyRoleEndpoint(QName processID, Endpoint endpoint) {
    if (log.isDebugEnabled()) {
        log.debug("Deactivating my role endpoint for process: " + processID + " service: " + endpoint.serviceName + " and port: " + endpoint.portName);
    }
    Integer tenantId = bpelServer.getMultiTenantProcessStore().getTenantId(processID);
    BPELProcessProxy processProxy = getBPELProcessProxy(tenantId.toString(), endpoint.serviceName, endpoint.portName);
    if (processProxy != null) {
        ProcessConfigurationImpl processConf = (ProcessConfigurationImpl) processProxy.getProcessConfiguration();
        if (processConf.isUndeploying()) {
            AxisService service = processProxy.getAxisService();
            Parameter param = service.getParameter(CarbonConstants.PRESERVE_SERVICE_HISTORY_PARAM);
            param.setValue("false");
        }
        removeBPELProcessProxyAndAxisService(tenantId.toString(), endpoint.serviceName, endpoint.portName);
        updateServiceList(((ProcessConfigurationImpl) processProxy.getProcessConfiguration()).getTenantId(), endpoint, STATE.REMOVE);
        serviceEprMap.remove(processProxy);
    }
// else this method also get called for the retired processes where there could be an
// active version of the same process type. Since there is only one service for a
// particular process type, processProxy will be null for all the endpoints except for 1.
}
Also used : AxisService(org.apache.axis2.description.AxisService) Parameter(org.apache.axis2.description.Parameter) ProcessConfigurationImpl(org.wso2.carbon.bpel.core.ode.integration.store.ProcessConfigurationImpl)

Example 90 with Parameter

use of org.wso2.carbon.apimgt.api.doc.model.Parameter in project carbon-business-process by wso2.

the class AttachmentMgtDAOConnectionFactoryImpl method init.

@Override
public void init() {
    if (transactionManager == null) {
        log.debug("Transaction-Manager is not initialized before initializing entityManager. So internal " + "transaction-manager in entity manager will be used.");
    }
    JPAVendorAdapter vendorAdapter = getJPAVendorAdapter();
    // Here we pass a "null" valued transaction manager,
    // as we enforce the entity-manager-factory to use its local transactions. In future,
    // if required to use external JTA transactions, a transaction reference should be passed
    // as the input parameter.
    this.entityManagerFactory = Persistence.createEntityManagerFactory("Attachment-Mgt-PU", vendorAdapter.getJpaPropertyMap(null));
}
Also used : JPAVendorAdapter(org.wso2.carbon.attachment.mgt.core.dao.impl.jpa.JPAVendorAdapter)

Aggregations

HashMap (java.util.HashMap)35 ArrayList (java.util.ArrayList)32 Parameter (org.apache.axis2.description.Parameter)14 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)14 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)13 JSONDecoder (org.wso2.charon3.core.encoder.JSONDecoder)11 BadRequestException (org.wso2.charon3.core.exceptions.BadRequestException)11 CharonException (org.wso2.charon3.core.exceptions.CharonException)11 InternalErrorException (org.wso2.charon3.core.exceptions.InternalErrorException)11 NotFoundException (org.wso2.charon3.core.exceptions.NotFoundException)11 SCIMResponse (org.wso2.charon3.core.protocol.SCIMResponse)11 SCIMResourceTypeSchema (org.wso2.charon3.core.schema.SCIMResourceTypeSchema)11 List (java.util.List)10 Map (java.util.Map)10 ConstantExpressionExecutor (org.wso2.siddhi.core.executor.ConstantExpressionExecutor)9 IOException (java.io.IOException)8 PreparedStatement (java.sql.PreparedStatement)8 ResultSet (java.sql.ResultSet)8 Test (org.testng.annotations.Test)8 BInvokableSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol)8