作为起点,我编写了一个简单的 servlet,通过针对 uid 的 LDAP 查询将 jpegPhoto(如果存在)的第一个值作为图像/png 返回。然后我编写了一个简单的转换类,根据 uid 返回相关的照片 URL:
import com.unboundid.asn1.ASN1OctetString;
import com.unboundid.scim.schema.AttributeDescriptor;
import com.unboundid.scim.sdk.SCIMAttributeValue;
import com.unboundid.util.ByteString;
public class PhotoTransform extends com.unboundid.scim.ldap.Transformation {
@Override
public String toLDAPFilterValue(String scimFilterValue) {
// TODO Auto-generated method stub
return null;
}
@Override
public ASN1OctetString toLDAPValue(AttributeDescriptor descriptor, SCIMAttributeValue value) {
// TODO Auto-generated method stub
return null;
}
@Override
public SCIMAttributeValue toSCIMValue(AttributeDescriptor descriptor, ByteString value) {
return SCIMAttributeValue.createStringValue("http://localhost:4567/photo/" + value.stringValue());
}
然后我引用了 SCIM resources.xml 中的类,将 uid 作为 LDAP 属性传递:
<attribute name="photos" schema="urn:scim:schemas:core:1.0"
readOnly="false" required="false">
<description>URL of photos of the User</description>
<simpleMultiValued childName="photo" dataType="string">
<canonicalValue name="photoUrl">
<subMapping name="value" ldapAttribute="uid"
transform="com.example.scim.PhotoTransform">
</subMapping>
</canonicalValue>
<canonicalValue name="thumbnail"/>
</simpleMultiValued>
</attribute>
和一个 SCIM 查询(针对参考实现)
curl 'http://localhost:8080/Users?filter=userName%20eq%20%22jsmith%22' -u bjensen:password
现在返回:
{
"totalResults" : 1,
"itemsPerPage" : 1,
"startIndex" : 1,
"schemas" : ["urn:scim:schemas:core:1.0", "urn:scim:schemas:extension:enterprise:1.0"],
"Resources" : [{
"name" : {
"formatted" : "Mr. John Smith",
"familyName" : "Smith",
"givenName" : "John"
},
"phoneNumbers" : [{
"value" : "tel:555-555-1256",
"type" : "work"
}
],
"userName" : "jsmith",
"emails" : [{
"value" : "jsmith@example.com",
"type" : "work"
}
],
"photos" : [{
"value" : "http://localhost:4567/photo/jsmith",
"type" : "photoUrl"
}
],
"id" : "fb4134dc-0a93-476a-964a-c29847f3bf79",
"meta" : {
"created" : "2015-09-09T00:17:12.768Z",
"lastModified" : "2015-09-09T00:17:12.768Z",
"location" : "http://localhost:8080/v1/Users/fb4134dc-0a93-476a-964a-c29847f3bf79",
"version" : "\"20150909001712.768Z\""
}
}]
}