gluu
公開メンバ関数 | 非公開メンバ関数 | 非公開変数類 | 静的非公開変数類 | 全メンバ一覧
org.gluu.oxtrust.model.scim2.util.ResourceValidator クラス
org.gluu.oxtrust.model.scim2.util.ResourceValidator 連携図
Collaboration graph

公開メンバ関数

 ResourceValidator (BaseScimResource resource, List< Extension > extensions)
 
void validateRequiredAttributes () throws SCIMException
 
void validateValidableAttributes () throws SCIMException
 
void validateCanonicalizedAttributes () throws SCIMException
 
void validateSchemasAttribute () throws SCIMException
 
void validateExtendedAttributes () throws SCIMException
 

非公開メンバ関数

void validateDataTypeExtendedAttr (Extension extension, String attribute, Object value) throws SCIMException
 

非公開変数類

Logger log = LogManager.getLogger(getClass())
 
BaseScimResource resource
 
Class<? extends BaseScimResourceresourceClass
 
List< Extensionextensions
 

静的非公開変数類

static final String REQUIRED_ATTR_NOTFOUND ="Required attribute %s not found"
 
static final String WRONG_SCHEMAS_ATTR ="Wrong value of schemas attribute"
 
static final String UNKNOWN_EXTENSION ="Extension %s not recognized"
 
static final String ATTR_NOT_RECOGNIZED ="Attribute %s not part of schema %s"
 
static final String ERROR_PARSING_EXTENDED ="Error parsing extended attributes"
 
static final String ATTR_VALIDATION_FAILED ="Unexpected value for attribute %s"
 

詳解

This class provides static methods to validate whether a (SCIM) resource instance fulfills certain characteristics - regarded to formatting, mutability, uniqueness, etc. This allows to adhere more closely to SCIM spec

構築子と解体子

◆ ResourceValidator()

org.gluu.oxtrust.model.scim2.util.ResourceValidator.ResourceValidator ( BaseScimResource  resource,
List< Extension extensions 
)
inline

Construct a instance of this class

引数
resourceA SCIM resource object (the target of validation)
extensionsList of extensions associated to this resource
49  {
50  this.resource=resource;
51  resourceClass=resource.getClass();
53  }
List< Extension > extensions
Definition: ResourceValidator.java:42
Class<? extends BaseScimResource > resourceClass
Definition: ResourceValidator.java:41
BaseScimResource resource
Definition: ResourceValidator.java:40

関数詳解

◆ validateCanonicalizedAttributes()

void org.gluu.oxtrust.model.scim2.util.ResourceValidator.validateCanonicalizedAttributes ( ) throws SCIMException
inline

Inspects the resource passed in the constructor and for every attribute annotated with a non-empty collection of canonical values, it checks whether the attribute value matches any of the canonical values supplied.

This method should be called after a successful call to validateRequiredAttributes().

例外
SCIMExceptionWhen a validation does not pass (there is no match for any of the attributes inspected)
111  {
112 
113  Map<String, List<Method>> map=IntrospectUtil.canonicalCoreAttrs.get(resourceClass);
114 
115  for (String attributePath : map.keySet()) {
116 
117  Attribute attrAnnot=IntrospectUtil.getFieldAnnotation(attributePath, resourceClass, Attribute.class);
118  List<String> canonicalVals=Arrays.asList(attrAnnot.canonicalValues());
119  log.debug("Validating values of canonical attribute '{}'", attributePath);
120 
121  for (Object val : IntrospectUtil.getAttributeValues(resource, map.get(attributePath))) {
122  if (!canonicalVals.contains(val.toString())) {
123  log.error("Error validating canonical attribute '{}', wrong value supplied: '{}'", attributePath, val.toString());
124  throw new SCIMException(String.format(ATTR_VALIDATION_FAILED, attributePath));
125  }
126  }
127  }
128  }
Class<? extends BaseScimResource > resourceClass
Definition: ResourceValidator.java:41
Logger log
Definition: ResourceValidator.java:31
static final String ATTR_VALIDATION_FAILED
Definition: ResourceValidator.java:38
BaseScimResource resource
Definition: ResourceValidator.java:40

◆ validateDataTypeExtendedAttr()

void org.gluu.oxtrust.model.scim2.util.ResourceValidator.validateDataTypeExtendedAttr ( Extension  extension,
String  attribute,
Object  value 
) throws SCIMException
inlineprivate

Validates if an attribute part of an extension is consistent with an arbitrary value passed.

引数
extensionExtension where the attribute exists
attributeThe name of the attribute inside the extension
valueThe value to be checked (never null)
例外
SCIMExceptionWhen the value is inconsistent, or the attribute does not belong to the extension. As an example, consider an attribute whose type is "NUMERIC": if the value passed was "Hi", this is clearly an error.
165  {
166 
167  ExtensionField field=extension.getFields().get(attribute);
168  if (field==null)
169  throw new SCIMException(String.format(ATTR_NOT_RECOGNIZED, attribute, extension.getUrn()));
170  else{
171  log.debug("validateDataTypeExtendedAttr. Checking attribute '{}' for type '{}' with value '{}'", attribute, field.getType().toString(), value.toString());
172 
173  //look up if the field in this extension is consistent with the value passed
174  if (ExtensionField.valueOf(field, value)==null)
175  throw new SCIMException(String.format(ATTR_VALIDATION_FAILED, attribute));
176  }
177 
178  }
static final String ATTR_NOT_RECOGNIZED
Definition: ResourceValidator.java:36
Logger log
Definition: ResourceValidator.java:31
static final String ATTR_VALIDATION_FAILED
Definition: ResourceValidator.java:38

◆ validateExtendedAttributes()

void org.gluu.oxtrust.model.scim2.util.ResourceValidator.validateExtendedAttributes ( ) throws SCIMException
inline

Inspects the resource passed in the constructor and for every extended attribute (see BaseScimResource#getCustomAttributes(), the attribute's value is checked to see if it complies with the data type it is supposed to belong to. This information is obtained from the list of Extensions passed in the constructor (every ExtensionField has an associated type.

When an attribute is multi-valued, every single item inside the collection is validated.

例外
SCIMExceptionWhen any of the validations do not pass or an attribute seems not to be part of a known schema.
189  {
190 
191  //Note: throughout this method, we always ignore presence of nulls
192 
193  //Gets all extended attributes (see the @JsonAnySetter annotation in BaseScimResource)
194  Map<String, Object> extendedAttributes=resource.getCustomAttributes();
195 
196  //Iterate over every extension of the resource object (in practice it will be just one at most)
197  for (String schema : extendedAttributes.keySet()) {
198  //Validate if the schema referenced in the extended attributes is contained in the valid set of extension
199 
200  Extension extension=null;
201  for (Extension ext : extensions)
202  if (ext.getUrn().equals(schema)) {
203  extension = ext;
204  break;
205  }
206 
207  if (extension!=null) {
208  log.debug("validateExtendedAttributes. Revising attributes under schema {}", schema);
209 
210  try {
211  //Obtains a generic map consisting of all name/value(s) pairs associated to this schema
212  Map<String, Object> attrsMap = IntrospectUtil.strObjMap(extendedAttributes.get(schema));
213 
214  for (String attr : attrsMap.keySet()) {
215  Object value = attrsMap.get(attr);
216  if (value != null) {
217  /*
218  Gets the class associated to the value of current attribute. For extended attributes, we
219  should only see coming: String, Integer, Double, boolean, and Collection.
220  Different things will be rejected
221  */
222  Class cls = value.getClass();
223  boolean isCollection=IntrospectUtil.isCollection(cls);
224 
225  //If the attribute coming is unknown, NPE will be thrown and we are covered
226  log.debug("validateExtendedAttributes. Got value(s) for attribute '{}'", attr);
227  //Check if the multivalued custom attribute is consistent with the nature of the value itself
228  if (isCollection == extension.getFields().get(attr).isMultiValued()){
229  if (isCollection) {
230  for (Object elem : (Collection) value)
231  if (elem!=null)
232  validateDataTypeExtendedAttr(extension, attr, elem);
233  }
234  else
235  validateDataTypeExtendedAttr(extension, attr, value);
236  }
237  else
238  throw new SCIMException(ERROR_PARSING_EXTENDED);
239  }
240  }
241  }
242  catch (Exception e) {
243  log.error(e.getMessage(), e);
244  throw new SCIMException(ERROR_PARSING_EXTENDED);
245  }
246  }
247  else
248  throw new SCIMException(String.format(UNKNOWN_EXTENSION, schema));
249  }
250 
251  }
static final String UNKNOWN_EXTENSION
Definition: ResourceValidator.java:35
List< Extension > extensions
Definition: ResourceValidator.java:42
static final String ERROR_PARSING_EXTENDED
Definition: ResourceValidator.java:37
void validateDataTypeExtendedAttr(Extension extension, String attribute, Object value)
Definition: ResourceValidator.java:165
Logger log
Definition: ResourceValidator.java:31
Map< String, Object > getCustomAttributes()
Definition: BaseScimResource.java:106
BaseScimResource resource
Definition: ResourceValidator.java:40

◆ validateRequiredAttributes()

void org.gluu.oxtrust.model.scim2.util.ResourceValidator.validateRequiredAttributes ( ) throws SCIMException
inline

Inspects the resource passed in the constructor and determines if the attributes annotated as required in the Class of the resource were all provided (not null).

If an attribute was marked as "required" and is part of a multi-valued complex attribute, no validation takes place if the involved list is null or empty.

例外
SCIMExceptionWhen a validation does not pass (there is a missing value in a required attribute)
62  {
63 
64  Map<String, List<Method>> map=IntrospectUtil.requiredCoreAttrs.get(resourceClass);
65 
66  for (String attributePath : map.keySet()){
67  log.debug("Validating existence of required attribute '{}'", attributePath);
68 
69  for (Object val : IntrospectUtil.getAttributeValues(resource, map.get(attributePath)))
70  if (val == null) {
71  log.error("Error getting value of required attribute '{}'", attributePath);
72  throw new SCIMException(String.format(REQUIRED_ATTR_NOTFOUND, attributePath));
73  }
74  }
75 
76  }
Class<? extends BaseScimResource > resourceClass
Definition: ResourceValidator.java:41
Logger log
Definition: ResourceValidator.java:31
static final String REQUIRED_ATTR_NOTFOUND
Definition: ResourceValidator.java:33
BaseScimResource resource
Definition: ResourceValidator.java:40

◆ validateSchemasAttribute()

void org.gluu.oxtrust.model.scim2.util.ResourceValidator.validateSchemasAttribute ( ) throws SCIMException
inline

Inspects the schemas attribute of the resource passed in the constructor and checks the default schema urn associated to the resource type is present in the list. If some of the urns part of the Extensions passed in the constructor are contained in the list, the validation is also successful.

This method should be called after a successful call to validateRequiredAttributes().

例外
SCIMExceptionIf there is no schemas in this resource or if some of the urns there are not known.
139  {
140 
141  Set<String> schemaList = new HashSet<String>(resource.getSchemas());
142  if (schemaList.size()==0)
143  throw new SCIMException(WRONG_SCHEMAS_ATTR);
144 
145  Set<String> allSchemas=new HashSet<String>();
146  allSchemas.add(ScimResourceUtil.getDefaultSchemaUrn(resourceClass));
147  for (Extension ext : extensions)
148  allSchemas.add(ext.getUrn());
149 
150  schemaList.removeAll(allSchemas);
151 
152  if (schemaList.size()>0) //means that some wrong extension urn is there
153  throw new SCIMException(WRONG_SCHEMAS_ATTR);
154 
155  }
List< Extension > extensions
Definition: ResourceValidator.java:42
Class<? extends BaseScimResource > resourceClass
Definition: ResourceValidator.java:41
Set< String > getSchemas()
Definition: BaseScimResource.java:155
BaseScimResource resource
Definition: ResourceValidator.java:40
static final String WRONG_SCHEMAS_ATTR
Definition: ResourceValidator.java:34

◆ validateValidableAttributes()

void org.gluu.oxtrust.model.scim2.util.ResourceValidator.validateValidableAttributes ( ) throws SCIMException
inline

Inspects the resource passed in the constructor and applies validations for every attribute annotated with Validator. Validations are of different nature as seenhere.

例外
SCIMExceptionWhen a validation does not pass (the apply method returns false)
84  {
85 
86  Map<String, List<Method>> map=IntrospectUtil.validableCoreAttrs.get(resourceClass);
87 
88  for (String attributePath : map.keySet()) {
89 
90  Field f=IntrospectUtil.findFieldFromPath(resourceClass, attributePath);
91  Validations valToApply=f.getAnnotation(Validator.class).value();
92  log.debug("Validating value(s) of attribute '{}'", attributePath);
93 
94  for (Object val : IntrospectUtil.getAttributeValues(resource, map.get(attributePath))) {
95  if (val!=null && !Validations.apply(valToApply, val)) {
96  log.error("Error validating attribute '{}', wrong value supplied: '{}'", attributePath, val.toString());
97  throw new SCIMException(String.format(ATTR_VALIDATION_FAILED, attributePath));
98  }
99  }
100  }
101 
102  }
Class<? extends BaseScimResource > resourceClass
Definition: ResourceValidator.java:41
Logger log
Definition: ResourceValidator.java:31
static final String ATTR_VALIDATION_FAILED
Definition: ResourceValidator.java:38
BaseScimResource resource
Definition: ResourceValidator.java:40

メンバ詳解

◆ ATTR_NOT_RECOGNIZED

final String org.gluu.oxtrust.model.scim2.util.ResourceValidator.ATTR_NOT_RECOGNIZED ="Attribute %s not part of schema %s"
staticprivate

◆ ATTR_VALIDATION_FAILED

final String org.gluu.oxtrust.model.scim2.util.ResourceValidator.ATTR_VALIDATION_FAILED ="Unexpected value for attribute %s"
staticprivate

◆ ERROR_PARSING_EXTENDED

final String org.gluu.oxtrust.model.scim2.util.ResourceValidator.ERROR_PARSING_EXTENDED ="Error parsing extended attributes"
staticprivate

◆ extensions

List<Extension> org.gluu.oxtrust.model.scim2.util.ResourceValidator.extensions
private

◆ log

Logger org.gluu.oxtrust.model.scim2.util.ResourceValidator.log = LogManager.getLogger(getClass())
private

◆ REQUIRED_ATTR_NOTFOUND

final String org.gluu.oxtrust.model.scim2.util.ResourceValidator.REQUIRED_ATTR_NOTFOUND ="Required attribute %s not found"
staticprivate

◆ resource

BaseScimResource org.gluu.oxtrust.model.scim2.util.ResourceValidator.resource
private

◆ resourceClass

Class<? extends BaseScimResource> org.gluu.oxtrust.model.scim2.util.ResourceValidator.resourceClass
private

◆ UNKNOWN_EXTENSION

final String org.gluu.oxtrust.model.scim2.util.ResourceValidator.UNKNOWN_EXTENSION ="Extension %s not recognized"
staticprivate

◆ WRONG_SCHEMAS_ATTR

final String org.gluu.oxtrust.model.scim2.util.ResourceValidator.WRONG_SCHEMAS_ATTR ="Wrong value of schemas attribute"
staticprivate

このクラス詳解は次のファイルから抽出されました: