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

静的公開メンバ関数

static BaseScimResource transferToResourceReplace (BaseScimResource replacementDataSource, BaseScimResource originalDataSource, List< Extension > extensions) throws InvalidAttributeValueException
 
static BaseScimResource transferToResourceAdd (BaseScimResource replacementDataSource, BaseScimResource originalDataSource, List< Extension > extensions) throws InvalidAttributeValueException
 
static BaseScimResource deleteFromResource (BaseScimResource origin, String path, List< Extension > extensions) throws InvalidAttributeValueException
 
static Schema getSchemaAnnotation (Class<? extends BaseScimResource > cls)
 
static String getDefaultSchemaUrn (Class<? extends BaseScimResource > cls)
 
static String stripDefaultSchema (Class<? extends BaseScimResource > cls, String attribute)
 
static String getType (Class<? extends BaseScimResource > cls)
 
static String adjustNotationInPath (String path, String defaultUrn, List< String > schemas)
 
static String [] splitPath (String path, List< String > urns)
 
static void adjustPrimarySubAttributes (BaseScimResource resource)
 

非公開メンバ関数

 ScimResourceUtil ()
 

静的非公開メンバ関数

static void attachExtensionInfo (Map< String, Object > source, Map< String, Object > destination, List< Extension > extensions, boolean replacing)
 
static void deleteCustomAttribute (Map< String, Object > source, String path, List< Extension > extensions)
 
static BaseScimResource transferToResource (BaseScimResource origin, final BaseScimResource destination, List< Extension > extensions, boolean replacing) throws InvalidAttributeValueException
 

静的非公開変数類

static Logger log = LogManager.getLogger(ScimResourceUtil.class)
 
static ObjectMapper mapper =new ObjectMapper()
 

詳解

This class contains methods to facilitate transformation, and manipulation of data inside SCIM resource objects, as well as some miscelaneous routines.

構築子と解体子

◆ ScimResourceUtil()

org.gluu.oxtrust.model.scim2.util.ScimResourceUtil.ScimResourceUtil ( )
inlineprivate
173 {}

関数詳解

◆ adjustNotationInPath()

static String org.gluu.oxtrust.model.scim2.util.ScimResourceUtil.adjustNotationInPath ( String  path,
String  defaultUrn,
List< String >  schemas 
)
inlinestatic
396  {
397 
398  for (String urn : schemas){
399  if (path.startsWith(urn + ":")) {
400  if (urn.equals(defaultUrn))
401  path = path.substring(urn.length()+1);
402  else
403  path = path.substring(0, urn.length()) + "." + path.substring(urn.length()+1);
404  }
405  }
406  return path;
407 
408  }

◆ adjustPrimarySubAttributes()

static void org.gluu.oxtrust.model.scim2.util.ScimResourceUtil.adjustPrimarySubAttributes ( BaseScimResource  resource)
inlinestatic

Takes a SCIM resource and "fixes" inconsistencies in "primary" subattribute: in a multivalued attribute setting, only one of the items in the collection can have "primary" : true. Thus, for every collection involved (e.g. addresses, emails... in org.gluu.oxtrust.model.scim2.user.UserResource), it switches all occurrences where "primary" is currently true to false, except for the first one found.

引数
resourceSCIM resource object
444  {
445 
446  String fragment=".primary";
447  Class<? extends BaseScimResource> cls=resource.getClass();
448 
449  //parents will contain the parent path (and associated getter list) where there are primary subattrs, e.g. emails,
450  //ims... if we are talking about users
451  List<String> parents=new ArrayList<String>();
452  for (String path : IntrospectUtil.allAttrs.get(cls))
453  if (path.endsWith(fragment))
454  parents.add(path.substring(0, path.length() - fragment.length()));
455 
456  List<Map<String,List<Method>>> niceList=Arrays.asList(IntrospectUtil.defaultCoreAttrs.get(cls),
457  IntrospectUtil.neverCoreAttrs.get(cls), IntrospectUtil.alwaysCoreAttrs.get(cls));
458 
459  log.info("adjustPrimarySubAttributes. Revising \"primary\":true uniqueness constraints");
460  for (String path : parents){
461  //Searh path in the maps
462  for (Map<String,List<Method>> niceMap : niceList) {
463  try {
464  if (niceMap.containsKey(path)) {
465  //Here we will get a singleton list that contains the multivalued complex objects (or an empty one at least)
466  List<Object> list = IntrospectUtil.getAttributeValues(resource, niceMap.get(path));
467  if (list.size()>0){
468  list=(List<Object>) list.get(0);
469 
470  if (list!=null && list.size()>1) { //Ensure is not empty or singleton
471  Class clz = list.get(0).getClass(); //All items are supposed to belong to the same class
472  //Find getter and setter of "primary" property
473  Method setter = IntrospectUtil.getSetter(fragment.substring(1), clz);
474  Method getter = IntrospectUtil.getGetter(fragment.substring(1), clz);
475  int trues = 0;
476 
477  for (Object item : list) {
478  Object primaryVal = getter.invoke(item);
479  trues += primaryVal != null && primaryVal.toString().equals("true") ? 1 : 0;
480  if (trues > 1) { //Revert to false
481  setter.invoke(item, false);
482  log.info("adjustPrimarySubAttributes. Setting primary = false for an item (a previous one was already primary = true)");
483  }
484  }
485  }
486  }
487  break; //skip the rest of nicemaps
488  }
489  }
490  catch (Exception e){
491  log.error(e.getMessage(), e);
492  }
493  }
494  }
495 
496  }
static Logger log
Definition: ScimResourceUtil.java:169

◆ attachExtensionInfo()

static void org.gluu.oxtrust.model.scim2.util.ScimResourceUtil.attachExtensionInfo ( Map< String, Object >  source,
Map< String, Object >  destination,
List< Extension extensions,
boolean  replacing 
)
inlinestaticprivate
175  {
176 
177  log.debug("attachExtensionInfo");
178 
179  for (Extension extension : extensions){
180  String urn=extension.getUrn();
181  Object extendedAttrsObj=source.get(urn);
182 
183  if (extendedAttrsObj!=null){
184 
185  Map<String, Object> extendedAttrs=IntrospectUtil.strObjMap(extendedAttrsObj);
186  Map<String, ExtensionField> fields=extension.getFields();
187 
188  Map<String, Object> destMap = destination.get(urn)==null ? new HashMap<String, Object>() : IntrospectUtil.strObjMap(destination.get(urn));
189 
190  for (String attr : fields.keySet()){
191  Object value=extendedAttrs.get(attr);
192 
193  if (value!=null) {
194 
195  if (IntrospectUtil.isCollection(value.getClass())) {
196  Collection col = (Collection) value;
197 
198  if (!replacing){
199  Object destValue=destMap.get(attr);
200  if (destValue != null) {
201 
202  if (!IntrospectUtil.isCollection(destValue.getClass()))
203  log.warn("Value {} was expected to be a collection", destValue);
204  else
205  col.addAll((Collection) destMap.get(attr));
206  }
207  }
208  value = col.size()==0 ? null : col;
209  }
210  destMap.put(attr, value);
211  }
212  }
213  destination.put(urn, destMap);
214  }
215  }
216 
217  }
static Logger log
Definition: ScimResourceUtil.java:169

◆ deleteCustomAttribute()

static void org.gluu.oxtrust.model.scim2.util.ScimResourceUtil.deleteCustomAttribute ( Map< String, Object >  source,
String  path,
List< Extension extensions 
)
inlinestaticprivate
219  {
220 
221  //All custom attributes are non-complex so we must search for the last dot
222  int i=path.lastIndexOf(".");
223  if (i==-1)
224  log.warn("Path not recognized {}", path);
225  else {
226  String key = path.substring(i+1);
227  path=path.substring(0,i);
228 
229  for (Extension ext : extensions)
230  if (ext.getUrn().equals(path)){
231  Map<String, Object> submap=IntrospectUtil.strObjMap(source.get(path));
232  submap.remove(key);
233  }
234 
235  }
236  }
static Logger log
Definition: ScimResourceUtil.java:169

◆ deleteFromResource()

static BaseScimResource org.gluu.oxtrust.model.scim2.util.ScimResourceUtil.deleteFromResource ( BaseScimResource  origin,
String  path,
List< Extension extensions 
) throws InvalidAttributeValueException
inlinestatic

Returns a SCIM resource with the same data found in origin object, except for the attribute referenced by path being removed from the output. In other words, this method nullifies an attribute.

引数
originThe resource having the the original data
pathAn attribute path (in dot notation). Examples could be: displayName, emails.type, addresses, meta.lastModified.
extensionsA list of Extensions associated to origin Object
戻り値
The resulting object: data in origin without the attribute referenced by path
例外
InvalidAttributeValueExceptionIf there is an attempt to remove an attribute annotated as required or read-only
323  {
324 
325  Field f=IntrospectUtil.findFieldFromPath(origin.getClass(), path);
326  if (f!=null){
327  Attribute attrAnnot = f.getAnnotation(Attribute.class);
328  if (attrAnnot != null && (attrAnnot.mutability().equals(READ_ONLY) || attrAnnot.isRequired()))
329  throw new InvalidAttributeValueException("Cannot remove read-only or required attribute " + path);
330  }
331 
332  Map<String, Object> map = mapper.convertValue(origin, new TypeReference<Map<String,Object>>(){});
333  traversalClass tclass=new traversalClass(origin.getClass());
334 
335  if (f==null) //Extensions stuff
336  deleteCustomAttribute(map, path, extensions);
337  else
338  tclass.traverseDelete(map, path);
339 
340  return mapper.convertValue(map, origin.getClass());
341 
342  }
static ObjectMapper mapper
Definition: ScimResourceUtil.java:171
static void deleteCustomAttribute(Map< String, Object > source, String path, List< Extension > extensions)
Definition: ScimResourceUtil.java:219

◆ getDefaultSchemaUrn()

static String org.gluu.oxtrust.model.scim2.util.ScimResourceUtil.getDefaultSchemaUrn ( Class<? extends BaseScimResource cls)
inlinestatic

Returns the urn associated to the default schema of the SCIM resource whose class is passed as parameter.

引数
clsA class representing a SCIM resource
戻り値
The urn (obtained by calling Schema#id() on the appropriate Schema annotation) or null if there is no such annotation in the class cls
359  {
360  Schema schema=getSchemaAnnotation(cls);
361  return schema==null ? null : schema.id();
362  }
static Schema getSchemaAnnotation(Class<? extends BaseScimResource > cls)
Definition: ScimResourceUtil.java:349

◆ getSchemaAnnotation()

static Schema org.gluu.oxtrust.model.scim2.util.ScimResourceUtil.getSchemaAnnotation ( Class<? extends BaseScimResource cls)
inlinestatic

Returns the Schema annotation found in the class passed as parameter.

引数
clsA class representing a SCIM resource
戻り値
The annotation found or null if there is no such
349  {
350  return cls.getAnnotation(Schema.class);
351  }

◆ getType()

static String org.gluu.oxtrust.model.scim2.util.ScimResourceUtil.getType ( Class<? extends BaseScimResource cls)
inlinestatic

Returns the (human-readable) type of a SCIM resource based on its class. In practice this will be something like "User" or "Group". The type is obtained by calling Schema#name() of the respective class annotation.

引数
clsA class that represents a SCIM resource type
戻り値
A string with the proper value, or null if there is no Schema annotation found
391  {
392  Schema annot=ScimResourceUtil.getSchemaAnnotation(cls);
393  return annot==null ? null : annot.name();
394  }
ScimResourceUtil()
Definition: ScimResourceUtil.java:173

◆ splitPath()

static String [] org.gluu.oxtrust.model.scim2.util.ScimResourceUtil.splitPath ( String  path,
List< String >  urns 
)
inlinestatic
410  {
411 
412  String prefix="";
413  for (String urn : urns)
414  if (path.startsWith(urn)){
415  prefix=urn;
416  break;
417  }
418 
419  if (prefix.length()>0) {
420 
421  List<String> pieces=new ArrayList<String>();
422  pieces.add(prefix);
423 
424  path=path.substring(prefix.length());
425 
426  if (path.length()>0) {
427  String subpath=path.substring(path.startsWith(".") ? 1 : 0);
428  pieces.addAll(Arrays.asList(subpath.split("\\.")));
429  }
430  return pieces.toArray(new String[]{});
431  }
432  else
433  return path.split("\\.");
434 
435  }

◆ stripDefaultSchema()

static String org.gluu.oxtrust.model.scim2.util.ScimResourceUtil.stripDefaultSchema ( Class<? extends BaseScimResource cls,
String  attribute 
)
inlinestatic

Removes from an attribute path the schema urn that might prefix such path. The urn to remove will correspond to the default schema urn of a SCIM resource type whose class is passed as parameter.

引数
clsA class that represents a SCIM resource type
attributeAn attribute path (potentially prefixed by a urn)
戻り値
The attribute with no prefix. As an example, attribute_name is returned if urn:attribute_name is the value of attribute parameter (as long as urn represent the default urn for this resource)
373  {
374 
375  String val=attribute;
376  String defaultSchema=getDefaultSchemaUrn(cls);
377  if (StringUtils.isNotEmpty(attribute) && StringUtils.isNotEmpty(defaultSchema)) {
378  if (attribute.startsWith(defaultSchema + ":"))
379  val = attribute.substring(defaultSchema.length() +1);
380  }
381  return val;
382 
383  }
static String getDefaultSchemaUrn(Class<? extends BaseScimResource > cls)
Definition: ScimResourceUtil.java:359

◆ transferToResource()

static BaseScimResource org.gluu.oxtrust.model.scim2.util.ScimResourceUtil.transferToResource ( BaseScimResource  origin,
final BaseScimResource  destination,
List< Extension extensions,
boolean  replacing 
) throws InvalidAttributeValueException
inlinestaticprivate
239  {
240 
241  log.debug("transferToResource. Processing {} operation", replacing ? "replace" : "add");
242 
243  Map<String, Object> fromMap = mapper.convertValue(origin, new TypeReference<Map<String,Object>>(){});
244  Map<String, Object> toMap = mapper.convertValue(destination, new TypeReference<Map<String,Object>>(){});
245 
246  log.debug("transferToResource. Recursive traversal of resource is taking place");
247  traversalClass tclass=new traversalClass(origin.getClass());
248  tclass.traverse("", fromMap, toMap, replacing);
249  attachExtensionInfo(fromMap, toMap, extensions, replacing);
250 
251  if (tclass.error==null)
252  return mapper.convertValue(toMap, origin.getClass());
253  else
254  throw new InvalidAttributeValueException(tclass.error);
255 
256  }
static ObjectMapper mapper
Definition: ScimResourceUtil.java:171
static Logger log
Definition: ScimResourceUtil.java:169
static void attachExtensionInfo(Map< String, Object > source, Map< String, Object > destination, List< Extension > extensions, boolean replacing)
Definition: ScimResourceUtil.java:175

◆ transferToResourceAdd()

static BaseScimResource org.gluu.oxtrust.model.scim2.util.ScimResourceUtil.transferToResourceAdd ( BaseScimResource  replacementDataSource,
BaseScimResource  originalDataSource,
List< Extension extensions 
) throws InvalidAttributeValueException
inlinestatic

This method applies the same copying rules of transferToResourceReplace except for the following:

  • When a multi-valued attribute is passed in replacementDataSource, the existing data in the originalDataSource object is retained, and the items in the former object are prepended to the existing collection.
引数
replacementDataSourceObject with the information to be incorporated. Only non-null attributes of this object end up being transfered to the result
originalDataSourceObject (SCIM resource) that provides the original data
extensionsA list of Extensions associated to parameter originalDataSource. This helps to manipulate the transference of custom attributes values.
戻り値
A new object that contains the result of data transference. Neither replacementDataSource nor originalDataSource are changed after a call to this method
例外
InvalidAttributeValueExceptionWhen recursive traversal of replacementDataSource fails or if the rule of immutable attribute was not fulfilled
307  {
308  return transferToResource(replacementDataSource, originalDataSource, extensions, false);
309  }
static BaseScimResource transferToResource(BaseScimResource origin, final BaseScimResource destination, List< Extension > extensions, boolean replacing)
Definition: ScimResourceUtil.java:238

◆ transferToResourceReplace()

static BaseScimResource org.gluu.oxtrust.model.scim2.util.ScimResourceUtil.transferToResourceReplace ( BaseScimResource  replacementDataSource,
BaseScimResource  originalDataSource,
List< Extension extensions 
) throws InvalidAttributeValueException
inlinestatic

Returns an object which is the result of incorporating the information found in the replacementDataSource parameter to the information existing in originalDataSource object by doing replacements. The transference of data follows these rules:

  • Ignores changes in readonly attributes
  • Ignores null values (for single-valued attributes) in replacementDataSource
  • Nullifies multi-valued attributes when empty array is passed in replacementDataSource
  • Immutable attributes must match in both input objects or else exception is thrown. However, if the value in originalDataSource is missing (null), the value coming from replacementDataSource is kept
  • When a multi-valued attribute is passed in replacementDataSource, no existing data in the originalDataSource is retained, that is, the replacement is not partial but thorough: it's not an item-by-item replacement
引数
replacementDataSourceObject with the information to be incorporated. Only non-null attributes of this o bject end up being transfered to the result
originalDataSourceObject (SCIM resource) that provides the original data
extensionsA list of Extensions associated to parameter originalDataSource. This helps to manipulate the transference of custom attributes values.
戻り値
A new object that contains the result of data transference. Neither replacementDataSource nor originalDataSource are changed after a call to this method
例外
InvalidAttributeValueExceptionWhen recursive traversal of replacementDataSource fails or if the rule of immutable attribute was not fulfilled
283  {
284  //This method is suitable for the replace operation via PUT, or for a PATCH with op="replace" and no "value selection" filter
285  return transferToResource(replacementDataSource, originalDataSource, extensions, true);
286  }
static BaseScimResource transferToResource(BaseScimResource origin, final BaseScimResource destination, List< Extension > extensions, boolean replacing)
Definition: ScimResourceUtil.java:238

メンバ詳解

◆ log

Logger org.gluu.oxtrust.model.scim2.util.ScimResourceUtil.log = LogManager.getLogger(ScimResourceUtil.class)
staticprivate

◆ mapper

ObjectMapper org.gluu.oxtrust.model.scim2.util.ScimResourceUtil.mapper =new ObjectMapper()
staticprivate

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