本文整理汇总了Java中com.unboundid.ldap.sdk.SearchResultEntry.getAttributeValues方法的典型用法代码示例。如果您正苦于以下问题:Java SearchResultEntry.getAttributeValues方法的具体用法?Java SearchResultEntry.getAttributeValues怎么用?Java SearchResultEntry.getAttributeValues使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.unboundid.ldap.sdk.SearchResultEntry
的用法示例。
在下文中一共展示了SearchResultEntry.getAttributeValues方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getUserRoles
import com.unboundid.ldap.sdk.SearchResultEntry; //导入方法依赖的package包/类
@Override
public Set<String> getUserRoles(String username) throws Exception {
LOGGER.debug("getRoles("+username+")");
Objects.requireNonNull(username);
Set<String> roles = new HashSet<>();
String filter = "(uid=" + username + ")";
SearchRequest searchRequest = new SearchRequest(searchBase, SearchScope.SUB, filter);
SearchResult searchResult = connectionPool.search(searchRequest);
List<SearchResultEntry> searchResultEntries = searchResult.getSearchEntries();
if(searchResultEntries.isEmpty()) {
LOGGER.warn("No result found roles for user: " + username);
return new HashSet<String>();
} else if (searchResultEntries.size() > 1) {
LOGGER.error("Multiples users found and only one was expected for user: " + username);
return new HashSet<String>();
} else {
for(SearchResultEntry searchResultEntry : searchResultEntries) {
String[] groups = searchResultEntry.getAttributeValues("memberOf");
if(null != groups) {
for(String group : groups) {
for (RDN rdn : new DN(group).getRDNs()) {
if (rdn.hasAttribute("cn")) {
roles.addAll(Arrays.asList(rdn.getAttributeValues()));
break;
}
}
}
}
}
}
return roles;
}
示例2: getRoles
import com.unboundid.ldap.sdk.SearchResultEntry; //导入方法依赖的package包/类
private List<NamedRoleInfo> getRoles(SearchResultEntry entry) {
List<NamedRoleInfo> auths = new ArrayList<NamedRoleInfo>();
if (null != defaultRole) {
NamedRoleInfo defaultAuthority = new NamedRoleInfo();
defaultAuthority.setName(DEFAULT_ROLE_NAME);
defaultAuthority.setAuthorizations(defaultRole);
auths.add(defaultAuthority);
}
String[] attributes = entry.getAttributeValues(rolesAttribute);
if (null != attributes) {
for (String attr : attributes) {
List<NamedRoleInfo> auth = namedRoles.get(attr);
if (auth != null) {
auths.addAll(auth);
}
}
}
return auths;
}
示例3: getUser
import com.unboundid.ldap.sdk.SearchResultEntry; //导入方法依赖的package包/类
public User getUser(String username) {
User user = new User();
try {
List<SearchResultEntry> searchResultEntries = search(getLoginFilter(username));
if (!searchResultEntries.isEmpty()) {
SearchResultEntry searchResultEntry = searchResultEntries.get(0);
user.setUsername(username);
user.setGivenName(searchResultEntry.getAttributeValue(givenNameAttribute));
user.setSurName(searchResultEntry.getAttributeValue(surNameAttribute));
user.setEmail(searchResultEntry.getAttributeValue(mailAttribute));
List<String> groups = new ArrayList<>();
String[] groupAttributeValues = searchResultEntry.getAttributeValues(groupAttribute);
for (String groupAttributeValue : groupAttributeValues) {
DN groupDN = new DN(groupAttributeValue);
String groupName = groupDN.getRDN().getAttributeValues()[0];
groups.add(groupName);
}
user.setGroups(groups);
}
}
catch(Exception e) {
LOG.error(e.getMessage(), e);
}
return user;
}
示例4: fromLdap
import com.unboundid.ldap.sdk.SearchResultEntry; //导入方法依赖的package包/类
public static final AccountInfo fromLdap(SearchResultEntry entry) {
AccountInfo info = new AccountInfo();
info.setUsername(entry.getAttributeValue("uid"));
String[] emails = entry.getAttributeValues("mail");
info.setEmails(emails != null ? new HashSet<>(Arrays.asList(emails)) : Collections.emptySet());
info.setGivenName(entry.getAttributeValue("givenName"));
info.setFamilyName(entry.getAttributeValue("sn"));
info.setSubject(entry.getAttributeValue("employeeNumber"));
info.setName(entry.getAttributeValue("cn"));
info.setRole(Role.valueOf(entry.getAttributeValue("employeeType")));
return info;
}
示例5: getServerStatus
import com.unboundid.ldap.sdk.SearchResultEntry; //导入方法依赖的package包/类
private ServerStatus getServerStatus() throws Exception
{
SearchResult result =
findMonitorEntries("ds-general-monitor-entry");
if (result.getEntryCount() != 1)
{
throw new Exception(String.format(
"Expected one and only one general monitor entry; " +
"actual number was %d", result.getEntryCount()));
}
SearchResultEntry entry = result.getSearchEntries().get(0);
return new ServerStatus(
entry.getAttributeValues("unavailable-alert-type"),
entry.getAttributeValues("degraded-alert-type"));
}
示例6: getServletStatuses
import com.unboundid.ldap.sdk.SearchResultEntry; //导入方法依赖的package包/类
private List<ServletStatus> getServletStatuses() throws Exception
{
List<String> enabledServlets = new ArrayList<>();
List<ServletStatus> servletStatuses = new ArrayList<>();
if (!servletsToCheck.isEmpty())
{
SearchResult result =
findMonitorEntries("ds-http-servlet-config-monitor-entry",
"enabled-servlet-and-path");
if (result.getEntryCount() != 1)
{
throw new Exception(String.format(
"Expected one and only one HTTP servlet config monitor entry; " +
"actual number was %d", result.getEntryCount()));
}
SearchResultEntry entry = result.getSearchEntries().get(0);
for (String servletAndPath : entry.getAttributeValues("enabled-servlet-and-path"))
{
final String parsedServletName = parseServletName(servletAndPath);
if (parsedServletName != null)
{
enabledServlets.add(parsedServletName);
}
}
for (String servletToCheck : servletsToCheck)
{
if (enabledServlets.contains(servletToCheck))
{
servletStatuses.add(new ServletStatus(servletToCheck, true));
}
else
{
servletStatuses.add(new ServletStatus(servletToCheck, false));
}
}
}
return servletStatuses;
}
示例7: testInMemBind
import com.unboundid.ldap.sdk.SearchResultEntry; //导入方法依赖的package包/类
@Test
public void testInMemBind() throws Exception {
String user = "cn=test,dc=staticsecurity,dc=geomajas,dc=org";
LDAPConnection connection = new LDAPConnection("localhost", PORT);
BindResult auth = connection.bind(user, "cred");
System.out.println("auth " + auth);
System.out.println(" rc " + auth.getResultCode());
System.out.println(" cu " + auth.getResultCode().isConnectionUsable());
System.out.println(" dn " + auth.getMatchedDN());
System.out.println(" dm " + auth.getDiagnosticMessage());
SearchRequest request = new SearchRequest(user,
SearchScope.ONE, Filter.createEqualityFilter("objectclass", "person"),
"cn", "groupMembership", "givenName", "sn", "ou");
SearchResult search = connection.search(request);
System.out.println(search);
System.out.println("count " + search.getEntryCount());
System.out.println("count " + search.getSearchEntries());
for (SearchResultEntry se : search.getSearchEntries()) {
System.out.println("-- cn " + se.getAttributeValue("cn"));
System.out.println(" givenName " + se.getAttributeValue("givenName"));
System.out.println(" sn " + se.getAttributeValue("sn"));
System.out.println(" ou " + se.getAttributeValue("ou"));
System.out.println(" groupMembership ");
if (null != se.getAttributeValues("groupMembership")) {
for (String val : se.getAttributeValues("groupMembership")) {
System.out.println(" " + val);
}
}
}
}