use of org.gluu.oxtrust.model.scim2.annotations.Schema in project oxTrust by GluuFederation.
the class ResourceValidator method validateSchemasAttribute.
/**
* Inspects the {@link BaseScimResource#getSchemas() schemas} attribute of the resource passed in the constructor and
* checks the default schema <code>urn</code> associated to the resource type is present in the list. If some of the
* <code>urn</code>s part of the <code>Extension</code>s passed in the constructor are contained in the list, the validation is also
* successful.
* <p>This method should be called after a successful call to {@link #validateRequiredAttributes()}.</p>
* @throws SCIMException If there is no {@link BaseScimResource#getSchemas() schemas} in this resource or if some of
* the <code>urn</code>s there are not known.
*/
public void validateSchemasAttribute() throws SCIMException {
Set<String> schemaList = new HashSet<String>(resource.getSchemas());
if (schemaList.size() == 0)
throw new SCIMException(WRONG_SCHEMAS_ATTR);
Set<String> allSchemas = new HashSet<String>();
allSchemas.add(ScimResourceUtil.getDefaultSchemaUrn(resourceClass));
for (Extension ext : extensions) allSchemas.add(ext.getUrn());
schemaList.removeAll(allSchemas);
if (// means that some wrong extension urn is there
schemaList.size() > 0)
throw new SCIMException(WRONG_SCHEMAS_ATTR);
}
use of org.gluu.oxtrust.model.scim2.annotations.Schema in project oxTrust by GluuFederation.
the class GroupCoreLoadingStrategy method load.
@Override
public SchemaType load(AppConfiguration appConfiguration, SchemaType schemaType) throws Exception {
log.info(" load() ");
Meta meta = new Meta();
meta.setLocation(appConfiguration.getBaseEndpoint() + "/scim/v2/Schemas/" + schemaType.getId());
meta.setResourceType("Schema");
schemaType.setMeta(meta);
// Use serializer to walk the class structure
ObjectMapper mapper = new ObjectMapper();
mapper.disable(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS);
SimpleModule groupCoreLoadingStrategyModule = new SimpleModule("GroupCoreLoadingStrategyModule", new Version(1, 0, 0, ""));
SchemaTypeGroupSerializer serializer = new SchemaTypeGroupSerializer();
serializer.setSchemaType(schemaType);
groupCoreLoadingStrategyModule.addSerializer(Group.class, serializer);
mapper.registerModule(groupCoreLoadingStrategyModule);
mapper.writeValueAsString(createDummyGroup());
return serializer.getSchemaType();
}
use of org.gluu.oxtrust.model.scim2.annotations.Schema in project oxTrust by GluuFederation.
the class UserCoreLoadingStrategy method load.
@Override
public SchemaType load(AppConfiguration appConfiguration, SchemaType schemaType) throws Exception {
log.info(" load() ");
Meta meta = new Meta();
meta.setLocation(appConfiguration.getBaseEndpoint() + "/scim/v2/Schemas/" + schemaType.getId());
meta.setResourceType("Schema");
schemaType.setMeta(meta);
// Use serializer to walk the class structure
ObjectMapper mapper = new ObjectMapper();
mapper.disable(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS);
SimpleModule userCoreLoadingStrategyModule = new SimpleModule("UserCoreLoadingStrategyModule", new Version(1, 0, 0, ""));
SchemaTypeUserSerializer serializer = new SchemaTypeUserSerializer();
serializer.setSchemaType(schemaType);
userCoreLoadingStrategyModule.addSerializer(User.class, serializer);
mapper.registerModule(userCoreLoadingStrategyModule);
mapper.writeValueAsString(createDummyUser());
return serializer.getSchemaType();
}
use of org.gluu.oxtrust.model.scim2.annotations.Schema in project oxTrust by GluuFederation.
the class UserExtensionLoadingStrategy method load.
@Override
public SchemaType load(AppConfiguration appConfiguration, SchemaType schemaType) throws Exception {
log.info(" load() ");
Meta meta = new Meta();
meta.setLocation(appConfiguration.getBaseEndpoint() + "/scim/v2/Schemas/" + schemaType.getId());
meta.setResourceType("Schema");
schemaType.setMeta(meta);
// List<GluuAttribute> scimCustomAttributes = attributeService.getSCIMRelatedAttributesImpl(attributeService.getCustomAttributes());
List<GluuAttribute> scimCustomAttributes = attributeService.getSCIMRelatedAttributes();
List<AttributeHolder> attributeHolders = new ArrayList<AttributeHolder>();
for (GluuAttribute scimCustomAttribute : scimCustomAttributes) {
AttributeHolder attributeHolder = new AttributeHolder();
attributeHolder.setName(scimCustomAttribute.getName());
if (scimCustomAttribute.getDataType() != null) {
String typeStr = "";
GluuAttributeDataType attributeDataType = scimCustomAttribute.getDataType();
if (attributeDataType.equals(GluuAttributeDataType.STRING)) {
typeStr = "string";
} else if (attributeDataType.equals(GluuAttributeDataType.PHOTO)) {
typeStr = "reference";
attributeHolder.getReferenceTypes().add("external");
} else if (attributeDataType.equals(GluuAttributeDataType.DATE)) {
typeStr = "dateTime";
} else if (attributeDataType.equals(GluuAttributeDataType.NUMERIC)) {
typeStr = "decimal";
} else {
log.info(" NO MATCH: scimCustomAttribute.getDataType().getDisplayName() = " + scimCustomAttribute.getDataType().getDisplayName());
typeStr = "string";
}
attributeHolder.setType(typeStr);
}
attributeHolder.setDescription(scimCustomAttribute.getDescription());
attributeHolder.setRequired(scimCustomAttribute.isRequred());
if (scimCustomAttribute.getOxMultivaluedAttribute() != null) {
Boolean multiValued = Boolean.parseBoolean(scimCustomAttribute.getOxMultivaluedAttribute().getValue());
attributeHolder.setMultiValued(multiValued);
}
attributeHolders.add(attributeHolder);
}
UserExtensionSchema userExtensionSchema = (UserExtensionSchema) schemaType;
userExtensionSchema.setAttributeHolders(attributeHolders);
return userExtensionSchema;
}
use of org.gluu.oxtrust.model.scim2.annotations.Schema in project oxTrust by GluuFederation.
the class FilterUtil method stripScim2Schema.
public static String stripScim2Schema(String uri) {
for (SchemaType schemaType : SchemaTypeMapping.getSchemaInstances()) {
String schema = schemaType.getId() + ":";
if (uri.startsWith(schema)) {
int index = uri.indexOf(schema) + schema.length();
uri = uri.substring(index);
break;
}
}
return uri;
}
Aggregations