Identity Connectors Schema hints

Almost every Identity Connector implements the SchemaOp operation - working with Schema might be sometime a bit cumbersome, but we can use the Connector Framework serialization feature to make it more convenient in some situations.

The Connector Framework uses serialization when the Connector Server is used (which is requirement for C# based connectors for example), in this case all the communication between the framework and Connector Server is serialized into binary or xml form. We can leverage the second...

Schema printing

 Assume the following code for building Schema with two attributes:

Set<attributeinfo> attributes = new HashSet<attributeinfo>();
attributes.add(AttributeInfoBuilder.build("ATT_1"));
attributes.add(AttributeInfoBuilder.build("ATT_2"));
SchemaBuilder schemaBuilder = new SchemaBuilder(YOURConnector.class);
schemaBuilder.defineObjectClass(ObjectClass.ACCOUNT_NAME, attributes);

System.out.println("schema: " + schemaBuilder.build()); 

 

Line 7 prints the following output:


  
    
      
        
        
          
        
        
      
    
  
  
  
    
      
        SyncApiOp
        
          __ACCOUNT__
        
      
      
        SearchApiOp
        
          __ACCOUNT__
        
      
      
        ScriptOnConnectorApiOp
        
          __ACCOUNT__
        
      
      
        TestApiOp
        
          __ACCOUNT__
        
      
      
        ValidateApiOp
        
          __ACCOUNT__
        
      
      
        UpdateApiOp
        
          __ACCOUNT__
        
      
      
        GetApiOp
        
          __ACCOUNT__
        
      
      
        CreateApiOp
        
          __ACCOUNT__
        
      
      
        DeleteApiOp
        
          __ACCOUNT__
        
      
      
        SchemaApiOp
        
          __ACCOUNT__
        
      
      
        AuthenticationApiOp
        
          __ACCOUNT__
        
      
    
  
  
    
  

Wondering where is the serialization? Look into Schema.toString() method source:

 public String toString() {
       return SerializerUtil.serializeXmlObject(this, false);
}

Everything is clear now - Connector Framework is using its serialization to print out the schema as xml. Note: You can use other supported Connector Framework object to be printed out like that, see AttributeInfo as an example.

Static Schema creation

Ok, we know how the serialized Schema looks like - what about the other way around - we have a schema in the xml and we want to create Schema object out of it, you can do:

Schema schema = (Schema)SerializerUtil.deserializeXmlObject(readXmlFromFile(), false);

You need to have the readXmlFromFile method which reads the xml as String from some file, the second parametr specifies if the <?xml> tag is included in the provided String.

Implementing the SchemaOp using the deserialization might be useful when your connector's schema doesn't change, you have a big number of attributes and you don't need to know all the attributes in your code (for example you just pass them to some resource specific client).

Unit Testing

This is probably the scenario which might be used the most often - you need to check your schema is correct. You can define your expected Schema in the xml, deserialize into Schema object and use equals method for actual Schema comparison, in other words:

Schema actualSchema = yourConnector.schema();
Schema expectedSchema = (Schema)SerializerUtil.deserializeXmlObject(readXmlFromFile(), false);
assertTrue(actualSchema.equals(expectedSchema));

Of course this technique doesn't make sense to use together with the previous one, cause you would just test that the Connector Framework works fine - and this is already covered by framework unit tests ;-)

The thing to remember is that you have an option to use the Connector Framework serialization to build the Schema in your connector as well as use the SchemaBuilder in your java code only. It is up to you what way you find more useful for your connector.

Comments:

Post a Comment:
Comments are closed for this entry.
About

Blog of the Identity Connectors team.

Search

Archives
« July 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
  
       
Today