使用 UnboundID 的 @LDAPGetter 和 @LDAPSetter
有没有人有使用这两个注释的基本示例 UnboundID 的 SDK< /a> 将对象保留在 LDAP 目录中?我似乎找不到有关 @LDAPSetter
方法的参数类型或从 @LDAPGetter
方法返回的值的任何信息。
换句话说,如何填写 :
/**
* Called when creating a Java object from an LDAP entry.
*/
@LDAPSetter(attribute="roleOccupants")
void initMembers(<?> occupants) {
throw new UnsupportedOperationException();
}
/**
* Called when turning a Java object into an LDAP entry.
*/
@LDAPGetter(attribute="roleOccupants")
<?> storeMembers() {
throw new UnsupportedOperationException();
}
Does anyone have a basic example of using these two annotations from UnboundID's SDK to persist objects in an LDAP directory? I can't seem to find any info about the type of the argument to the @LDAPSetter
method or the value returned from the @LDAPGetter
method.
To put it another way, how do I fill in the <?>
s:
/**
* Called when creating a Java object from an LDAP entry.
*/
@LDAPSetter(attribute="roleOccupants")
void initMembers(<?> occupants) {
throw new UnsupportedOperationException();
}
/**
* Called when turning a Java object into an LDAP entry.
*/
@LDAPGetter(attribute="roleOccupants")
<?> storeMembers() {
throw new UnsupportedOperationException();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它实际上取决于
roleOccupants
属性的值。@LDAPGetter
和@LDAPSetter
注释的可选字段之一是encoderClass
,它允许您指定一个对象编码器,该编码器将用于在 LDAP 属性值和 Java 数据类型之间进行转换。如果您没有指定自定义编码器(大多数时候您不需要),那么它将使用DefaultObjectEncoder
类来执行工作,并且它支持以下数据类型:它还支持数组、列表和集合上述任何类型以及任何类型的枚举。请参阅 com.unboundid.ldap.sdk.persist.DefaultObjectEncoder 类,以获取支持的数据类型和 u 的任何约束的更完整描述。
因此,实际上,您选择的数据类型取决于以上哪种类型最适合存储在相应 LDAP 属性中的信息类型。在许多情况下,字符串可能是最合适的,但在其他情况下,您可能宁愿将其视为数字、DN、时间戳或类似的东西。如果没有任何默认类型是可接受的,那么您可以创建自己的自定义 ObjectEncoder 实例来执行您想要的任何转换。
It really depends on the value of the
roleOccupants
attribute. One of the optional fields of the@LDAPGetter
and@LDAPSetter
annotations isencoderClass
, which allows you to specify an object encoder that will be used to convert between LDAP attribute values and Java data types. If you don't specify a custom encoder (and most of the time you shouldn't need to), then it will use theDefaultObjectEncoder
class to perform the work, and it supports the following data types:It also supports arrays, lists, and sets of any of the above types, and any kind of enumeration. See the class-level documentation for the com.unboundid.ldap.sdk.persist.DefaultObjectEncoder class for a more complete description of the supported data types and any constraints with u.
So really, the data type that you choose depends on which of the above is most appropriate for the kind of information that is stored in the corresponding LDAP attribute. In many cases, String may be the most appropriate, but in others you may rather have it treated as a number or a DN or a timestamp or something like that. If none of the default types is acceptable, then you can create your own custom ObjectEncoder instance to perform whatever translation you want.
这是一个供其他想知道的人使用的示例。当您读取
organizationalRole
时,它会自动从 ldap 加载用户数据。UserRole
类:User
类:Here's an example of usage for anyone else that's wondering. It automatically loads user data from ldap when you read an
organizationalRole
.UserRole
class:User
class: