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