本文整理汇总了Java中javax.naming.directory.SearchResult.getAttributes方法的典型用法代码示例。如果您正苦于以下问题:Java SearchResult.getAttributes方法的具体用法?Java SearchResult.getAttributes怎么用?Java SearchResult.getAttributes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.naming.directory.SearchResult
的用法示例。
在下文中一共展示了SearchResult.getAttributes方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: decodeSearchResult
import javax.naming.directory.SearchResult; //导入方法依赖的package包/类
/**
* Converts a JNDI SearchResult into our LdapEntry object.
*/
private LdapEntry decodeSearchResult(
SearchResult sr,
String contextBase,
String[] attrNames)
throws LdapException
{
// print dn == distinguished name
String dn;
if (sr.getName() == null || sr.getName().length() == 0)
dn = contextBase;
else dn = sr.getName() + "," + contextBase;
Attributes attrraw = sr.getAttributes();
return decodeAttributes( dn, attrNames, attrraw);
}
示例2: LDAPResult
import javax.naming.directory.SearchResult; //导入方法依赖的package包/类
public LDAPResult(SearchResult sr, Name base) throws InvalidNameException
{
attributes = sr.getAttributes();
// getNameInNamespace, otherwise you get parsing problems
fullName = parse(sr.getNameInNamespace());
this.baseName = base;
}
示例3: mapToNode
import javax.naming.directory.SearchResult; //导入方法依赖的package包/类
private NodeDescription mapToNode(Map<String, String> attributeMapping, Map<String, String> attributeDefaults,
SearchResult result) throws NamingException
{
NodeDescription nodeDescription = new NodeDescription(result.getNameInNamespace());
Attributes ldapAttributes = result.getAttributes();
// Parse the timestamp
Attribute modifyTimestamp = ldapAttributes.get(this.modifyTimestampAttributeName);
if (modifyTimestamp != null)
{
try
{
nodeDescription.setLastModified(this.timestampFormat.parse(modifyTimestamp.get().toString()));
}
catch (ParseException e)
{
throw new AlfrescoRuntimeException("Failed to parse timestamp.", e);
}
}
// Apply the mapped attributes
PropertyMap properties = nodeDescription.getProperties();
for (String key : attributeMapping.keySet())
{
QName keyQName = QName.createQName(key, this.namespaceService);
// cater for null
String attributeName = attributeMapping.get(key);
if (attributeName != null)
{
Attribute attribute = ldapAttributes.get(attributeName);
String defaultAttribute = attributeDefaults.get(key);
if (attribute != null)
{
String value = (String) attribute.get(0);
if (value != null)
{
properties.put(keyQName, value);
}
}
else if (defaultAttribute != null)
{
properties.put(keyQName, defaultAttribute);
}
else
{
// Make sure that a 2nd sync, updates deleted ldap attributes(MNT-14026)
properties.put(keyQName, null);
}
}
else
{
String defaultValue = attributeDefaults.get(key);
if (defaultValue != null)
{
properties.put(keyQName, defaultValue);
}
}
}
return nodeDescription;
}
示例4: searchByLimit
import javax.naming.directory.SearchResult; //导入方法依赖的package包/类
private <T> List<T> searchByLimit(Properties properties, String baseDN,
String filter, ILdapResultMapper<T> mapper, boolean checkAttribute,
int searchLimit) throws NamingException {
List<T> list = new ArrayList<T>();
NamingEnumeration<SearchResult> namingEnum = null;
DirContext ctx = getDirContext(properties);
SearchControls ctls = new SearchControls();
String[] attrIds = mapper.getAttributes();
ctls.setReturningAttributes(attrIds);
ctls.setSearchScope(SearchControls.SUBTREE_SCOPE);
ctls.setCountLimit(searchLimit);
try {
namingEnum = ctx.search(baseDN, escapeLDAPSearchFilter(filter),
ctls);
int count = 0;
while (count++ < searchLimit && hasMoreEnum(namingEnum)) {
SearchResult res = namingEnum.next();
Attributes ldapAttributes = res.getAttributes();
String[] values = new String[attrIds.length];
for (int i = 0; i < values.length; i++) {
Attribute ldapAttr = ldapAttributes
.get(escapeLDAPSearchFilter(attrIds[i]));
if (checkAttribute && ldapAttr == null) {
NamingException e = new NamingException(
"Unknown LDAP attribute " + attrIds[i]);
throw e;
}
if (ldapAttr != null && ldapAttr.get() != null) {
values[i] = ldapAttr.get().toString();
}
}
T t = mapper.map(values);
if (t != null) {
list.add(t);
}
}
} finally {
if (namingEnum != null) {
try {
namingEnum.close();
} finally {
closeContext(ctx);
}
}
closeContext(ctx);
}
return list;
}
示例5: getRolesRecursive
import javax.naming.directory.SearchResult; //导入方法依赖的package包/类
/**
* Add roles to a user and search for other roles containing them themselves.
* We search recursively with a limited depth.
* By default the depth is 0, and we only use direct roles.
* The search needs to use the distinguished role names,
* but to return the role names.
*
* @param depth Recursion depth, starting at zero
* @param context The directory context we are searching
* @param recursiveMap The cumulative result map of role names and DNs.
* @param recursiveSet The cumulative result set of role names.
* @param groupName The role name to add to the list.
* @param groupDName The distinguished name of the role.
*
* @exception NamingException if a directory server error occurs
*/
private void getRolesRecursive(int depth, DirContext context, Map<String, String> recursiveMap, Set<String> recursiveSet,
String groupName, String groupDName) throws NamingException {
if (containerLog.isTraceEnabled())
containerLog.trace("Recursive search depth " + depth + " for group '" + groupDName + " (" + groupName + ")'");
// Adding the given group to the result set if not already found
if (!recursiveSet.contains(groupDName)) {
recursiveSet.add(groupDName);
recursiveMap.put(groupDName, groupName);
if (depth >= roleRecursionLimit) {
if (roleRecursionLimit > 0)
containerLog.warn("Terminating recursive role search because of recursion limit " +
roleRecursionLimit + ", results might be incomplete");
return;
}
// Prepare the parameters for searching groups
String filter = roleFormat.format(new String[] { groupDName });
SearchControls controls = new SearchControls();
controls.setSearchScope(roleSubtree ? SearchControls.SUBTREE_SCOPE : SearchControls.ONELEVEL_SCOPE);
controls.setReturningAttributes(new String[] { roleName });
if (containerLog.isTraceEnabled()) {
containerLog.trace("Recursive search in role base '" + roleBase + "' for attribute '" + roleName + "'" +
" with filter expression '" + filter + "'");
}
// Searching groups that assign the given group
NamingEnumeration results = context.search(roleBase, filter, controls);
if (results != null) {
// Iterate over the resulting groups
try {
while (results.hasMore()) {
SearchResult result = (SearchResult) results.next();
Attributes attrs = result.getAttributes();
if (attrs == null)
continue;
String dname = getDistinguishedName(context, roleBase, result);
String name = getAttributeValue(roleName, attrs);
if (name != null && dname != null) {
getRolesRecursive(depth+1, context, recursiveMap, recursiveSet, name, dname);
}
}
} catch (PartialResultException ex) {
if (!adCompat)
throw ex;
}
}
}
}