Search in sources :

Example 21 with ResourceType

use of org.wso2.carbon.identity.configuration.mgt.core.model.ResourceType in project carbon-identity-framework by wso2.

the class ConfigurationManagerImpl method getResourceType.

/**
 * {@inheritDoc}
 */
public ResourceType getResourceType(String resourceTypeName) throws ConfigurationManagementException {
    validateResourceTypeRetrieveRequest(resourceTypeName);
    ResourceType resourceType = getConfigurationDAO().getResourceTypeByName(resourceTypeName);
    if (resourceType == null || resourceType.getId() == null) {
        if (log.isDebugEnabled()) {
            log.debug("Resource Type: " + resourceTypeName + " does not exist.");
        }
        throw handleClientException(ERROR_CODE_RESOURCE_TYPE_DOES_NOT_EXISTS, resourceTypeName);
    }
    if (log.isDebugEnabled()) {
        log.debug("Resource type: " + resourceType.getName() + " retrieved successfully.");
    }
    return resourceType;
}
Also used : ResourceType(org.wso2.carbon.identity.configuration.mgt.core.model.ResourceType)

Example 22 with ResourceType

use of org.wso2.carbon.identity.configuration.mgt.core.model.ResourceType in project carbon-identity-framework by wso2.

the class ConfigurationManagerImpl method replaceResourceType.

/**
 * {@inheritDoc}
 */
public ResourceType replaceResourceType(ResourceTypeAdd resourceTypeAdd) throws ConfigurationManagementException {
    validateResourceTypeReplaceRequest(resourceTypeAdd);
    String resourceTypeID;
    resourceTypeID = generateResourceTypeId(resourceTypeAdd.getName());
    ResourceType resourceType = generateResourceTypeFromRequest(resourceTypeAdd, resourceTypeID);
    getConfigurationDAO().replaceResourceType(resourceType);
    if (log.isDebugEnabled()) {
        log.debug("Resource type: " + resourceType.getName() + " successfully replaced with the id: " + resourceType.getId());
    }
    return new ResourceType(resourceType.getName(), resourceType.getId(), resourceType.getDescription());
}
Also used : ResourceType(org.wso2.carbon.identity.configuration.mgt.core.model.ResourceType)

Example 23 with ResourceType

use of org.wso2.carbon.identity.configuration.mgt.core.model.ResourceType in project carbon-identity-framework by wso2.

the class ConfigurationManagerImpl method getResource.

/**
 * {@inheritDoc}
 */
public Resource getResource(String resourceTypeName, String resourceName) throws ConfigurationManagementException {
    validateResourceRetrieveRequest(resourceTypeName, resourceName);
    ResourceType resourceType = getResourceType(resourceTypeName);
    Resource resource = this.getConfigurationDAO().getResourceByName(getTenantId(), resourceType.getId(), resourceName);
    if (resource == null) {
        if (log.isDebugEnabled()) {
            log.debug("No resource found for the resourceName: " + resourceName);
        }
        throw handleClientException(ErrorMessages.ERROR_CODE_RESOURCE_DOES_NOT_EXISTS, resourceName, null);
    }
    return resource;
}
Also used : Resource(org.wso2.carbon.identity.configuration.mgt.core.model.Resource) ResourceType(org.wso2.carbon.identity.configuration.mgt.core.model.ResourceType)

Example 24 with ResourceType

use of org.wso2.carbon.identity.configuration.mgt.core.model.ResourceType in project carbon-identity-framework by wso2.

the class ConfigurationDAOImpl method addResourceType.

/**
 * {@inheritDoc}
 */
@Override
public void addResourceType(ResourceType resourceType) throws ConfigurationManagementException {
    JdbcTemplate jdbcTemplate = JdbcUtils.getNewTemplate();
    try {
        jdbcTemplate.executeInsert(SQLConstants.INSERT_RESOURCE_TYPE_SQL, preparedStatement -> {
            int initialParameterIndex = 1;
            preparedStatement.setString(initialParameterIndex, resourceType.getId());
            preparedStatement.setString(++initialParameterIndex, resourceType.getName());
            preparedStatement.setString(++initialParameterIndex, resourceType.getDescription());
        }, resourceType, false);
    } catch (DataAccessException e) {
        throw handleServerException(ERROR_CODE_ADD_RESOURCE_TYPE, resourceType.getName(), e);
    }
}
Also used : JdbcTemplate(org.wso2.carbon.database.utils.jdbc.JdbcTemplate) DataAccessException(org.wso2.carbon.database.utils.jdbc.exceptions.DataAccessException)

Example 25 with ResourceType

use of org.wso2.carbon.identity.configuration.mgt.core.model.ResourceType in project identity-inbound-provisioning-scim2 by wso2-extensions.

the class IdentityResourceTypeResourceManager method getResourceType.

/*
     * return RESOURCE_TYPE schema
     *
     * @return
     */
private SCIMResponse getResourceType() {
    JSONEncoder encoder = null;
    try {
        // obtain the json encoder
        encoder = getEncoder();
        // obtain the json decoder
        JSONDecoder decoder = getDecoder();
        // get the service provider config schema
        SCIMResourceTypeSchema schema;
        String scimUserObjectString;
        if (isCustomSchemaEnabled()) {
            schema = SCIMResourceSchemaManager.getInstance().getResourceTypeResourceSchema();
            scimUserObjectString = encoder.buildUserResourceTypeJsonBody();
        } else {
            schema = SCIMResourceSchemaManager.getInstance().getResourceTypeResourceSchemaWithoutMultiValuedSchemaExtensions();
            scimUserObjectString = buildUserResourceTypeJsonBody();
        }
        // create a string in json format for group resource type with relevant values
        String scimGroupObjectString = encoder.buildGroupResourceTypeJsonBody();
        // build the user abstract scim object
        AbstractSCIMObject userResourceTypeObject = (AbstractSCIMObject) decoder.decodeResource(scimUserObjectString, schema, new AbstractSCIMObject());
        // add meta data
        userResourceTypeObject = ServerSideValidator.validateResourceTypeSCIMObject(userResourceTypeObject);
        // build the group abstract scim object
        AbstractSCIMObject groupResourceTypeObject = (AbstractSCIMObject) decoder.decodeResource(scimGroupObjectString, schema, new AbstractSCIMObject());
        // add meta data
        groupResourceTypeObject = ServerSideValidator.validateResourceTypeSCIMObject(groupResourceTypeObject);
        // build the root abstract scim object
        AbstractSCIMObject resourceTypeObject = buildCombinedResourceType(userResourceTypeObject, groupResourceTypeObject);
        // encode the newly created SCIM Resource Type object.
        String encodedObject;
        Map<String, String> responseHeaders = new HashMap<String, String>();
        if (resourceTypeObject != null) {
            // create a deep copy of the resource type object since we are going to change it.
            AbstractSCIMObject copiedObject = (AbstractSCIMObject) CopyUtil.deepCopy(resourceTypeObject);
            encodedObject = encoder.encodeSCIMObject(copiedObject);
            // add location header
            responseHeaders.put(SCIMConstants.LOCATION_HEADER, getResourceEndpointURL(SCIMConstants.RESOURCE_TYPE_ENDPOINT));
            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 resource type object in the response header parameter.
        return new SCIMResponse(ResponseCodeConstants.CODE_OK, encodedObject, responseHeaders);
    } catch (CharonException | BadRequestException | InternalErrorException | NotFoundException e) {
        return encodeSCIMException(e);
    } catch (JSONException e) {
        if (log.isDebugEnabled()) {
            log.debug("Error while building resourceType api response: ", e);
        }
        return null;
    }
}
Also used : AbstractSCIMObject(org.wso2.charon3.core.objects.AbstractSCIMObject) HashMap(java.util.HashMap) NotFoundException(org.wso2.charon3.core.exceptions.NotFoundException) JSONException(org.json.JSONException) 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)

Aggregations

ResourceType (org.wso2.carbon.identity.configuration.mgt.core.model.ResourceType)36 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)27 Test (org.testng.annotations.Test)27 Resource (org.wso2.carbon.identity.configuration.mgt.core.model.Resource)22 Attribute (org.wso2.carbon.identity.configuration.mgt.core.model.Attribute)9 InputStream (java.io.InputStream)7 ResourceFile (org.wso2.carbon.identity.configuration.mgt.core.model.ResourceFile)7 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)6 QName (javax.xml.namespace.QName)6 XMLStreamException (javax.xml.stream.XMLStreamException)6 OMAttribute (org.apache.axiom.om.OMAttribute)6 OMElement (org.apache.axiom.om.OMElement)6 Resources (org.wso2.carbon.identity.configuration.mgt.core.model.Resources)6 Resource (org.wso2.carbon.registry.core.Resource)6 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)6 File (java.io.File)5 APIProductResource (org.wso2.carbon.apimgt.api.model.APIProductResource)4 Mediation (org.wso2.carbon.apimgt.api.model.Mediation)4 JdbcTemplate (org.wso2.carbon.database.utils.jdbc.JdbcTemplate)4