繁体   English   中英

如何使用 WSO2 charon scim 库扩展用户模式

[英]How to extend user schema using WSO2 charon scim library

我正在使用 Charon 库创建一个 SCIM 服务器。 如何使用 WSO2 charon scim 库扩展用户模式?

您有两个选项可以使用 charon 库来扩展架构。

选项1:

在文件中定义属性定义并使用该文件构建模式。 编写该文件时,配置文件中的最终配置应该是扩展的定义。

在charon中使用的方法: https://github.com/wso2/charon/blob/27562f69ce5b23b4e85015daf5aa11c651a91a8c/modules/charon-core/src/main/java/org/wso2/charon3/core/config/SCIMUser.

示例 java 代码以使用此方法构建架构:

  String schemaFilePath = "<absolute path to the schema defined file>";
  SCIMUserSchemaExtensionBuilder.getInstance().buildUserSchemaExtension(schemaFilePath);
  AttributeSchema extensionSchema = SCIMUserSchemaExtensionBuilder.getInstance().getExtensionSchema();
  // print the attribute URIs in the built schema
  extensionSchema.getSubAttributeSchemas().stream().forEach(e->System.out.print(e.getURI() + "\n"));

参考: https://github.com/AnuradhaSK/schema-extension/blob/cea1fa636bea2bb1e599ac9c71c6c45eaa339199/src/main/java/ScimSchemas.java#L29-L35

文件格式: https://github.com/AnuradhaSK/schema-extension/blob/main/src/main/resources/custom-schema

选项 2:

在 charon 中使用 SCIMCustomSchemaExtensionBuilder。

  • 您必须首先定义扩展架构 URI。
  • 然后为您需要添加到扩展模式的每个属性创建 SCIMCustomAttribute 对象。 您必须为属性定义 scim 模式中提到的默认属性集
  • 最后创建另一个 SCIMCustomAttribute 来表示扩展模式
  • 将所有对象放入列表并调用buildUserCustomSchemaExtension中的 buildUserCustomSchemaExtension 方法

在charon中使用的方法: https://github.com/wso2/charon/blob/27562f69ce5b23b4e85015daf5aa11c651a91a8c/modules/charon-core/src/main/java/org/wso2/charon3/core/config/SCIM.CustomExtensionBuilder

样品 java 代码:

            SCIMCustomSchemaExtensionBuilder.getInstance().setURI("urn:scim:custom:extended:schemas");
            LOG.info("====Attributes of extended schema using custom attributes===");
            // Sub attribute of the schema.
            Map<String, String> subAttributeProperties = new HashMap<>();
            subAttributeProperties.put("attributeURI","urn:scim:custom:extended:schemas:vehicleNo");
            subAttributeProperties.put("attributeName","vehicleNo");
            subAttributeProperties.put("dataType","string");
            subAttributeProperties.put("multiValued","false");
            subAttributeProperties.put("description","User's vehicle number");
            subAttributeProperties.put("required","false");
            subAttributeProperties.put("caseExact","false");
            subAttributeProperties.put("mutability","readWrite");
            subAttributeProperties.put("returned","default");
            subAttributeProperties.put("uniqueness","none");
            subAttributeProperties.put("canonicalValues","[]");
            SCIMCustomAttribute scimCustomAttribute = new SCIMCustomAttribute();
            scimCustomAttribute.setProperties(subAttributeProperties);

            // Schema object.
            Map<String, String> schemaObjectProperties = new HashMap<>();
            schemaObjectProperties.put("attributeURI","urn:scim:custom:extended:schemas");
            schemaObjectProperties.put("attributeName","urn:scim:custom:extended:schemas");
            schemaObjectProperties.put("dataType","complex");
            schemaObjectProperties.put("multiValued","false");
            schemaObjectProperties.put("description","Extended custom schema");
            schemaObjectProperties.put("required","false");
            schemaObjectProperties.put("caseExact","false");
            schemaObjectProperties.put("mutability","readWrite");
            schemaObjectProperties.put("returned","default");
            schemaObjectProperties.put("uniqueness","none");
            schemaObjectProperties.put("subAttributes","vehicleNo");
            schemaObjectProperties.put("canonicalValues","[]");
            SCIMCustomAttribute schemaAttribute = new SCIMCustomAttribute();
            schemaAttribute.setProperties(schemaObjectProperties);

            List<SCIMCustomAttribute> attributeList = new ArrayList<>();
            attributeList.add(scimCustomAttribute);
            attributeList.add(schemaAttribute);
            AttributeSchema customExtendedSchema = SCIMCustomSchemaExtensionBuilder.getInstance().buildUserCustomSchemaExtension(attributeList);
            customExtendedSchema.getSubAttributeSchemas().stream().forEach(e->System.out.print(e.getURI() + "\n"));

参考: https://github.com/AnuradhaSK/schema-extension/blob/cea1fa636bea2bb1e599ac9c71c6c45eaa339199/src/main/java/ScimSchemas.java#L39-L78

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM