当前位置: 首页>>代码示例>>Java>>正文


Java JndiLdapRealm类代码示例

本文整理汇总了Java中org.apache.shiro.realm.ldap.JndiLdapRealm的典型用法代码示例。如果您正苦于以下问题:Java JndiLdapRealm类的具体用法?Java JndiLdapRealm怎么用?Java JndiLdapRealm使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


JndiLdapRealm类属于org.apache.shiro.realm.ldap包,在下文中一共展示了JndiLdapRealm类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getUserList

import org.apache.shiro.realm.ldap.JndiLdapRealm; //导入依赖的package包/类
/**
 * function to extract users from LDAP
 */
public List<String> getUserList(JndiLdapRealm r, String searchText) {
  List<String> userList = new ArrayList<>();
  String userDnTemplate = r.getUserDnTemplate();
  String userDn[] = userDnTemplate.split(",", 2);
  String userDnPrefix = userDn[0].split("=")[0];
  String userDnSuffix = userDn[1];
  JndiLdapContextFactory CF = (JndiLdapContextFactory) r.getContextFactory();
  try {
    LdapContext ctx = CF.getSystemLdapContext();
    SearchControls constraints = new SearchControls();
    constraints.setSearchScope(SearchControls.SUBTREE_SCOPE);
    String[] attrIDs = {userDnPrefix};
    constraints.setReturningAttributes(attrIDs);
    NamingEnumeration result = ctx.search(userDnSuffix, "(" + userDnPrefix + "=*" + searchText +
        "*)", constraints);
    while (result.hasMore()) {
      Attributes attrs = ((SearchResult) result.next()).getAttributes();
      if (attrs.get(userDnPrefix) != null) {
        String currentUser = attrs.get(userDnPrefix).toString();
        userList.add(currentUser.split(":")[1].trim());
      }
    }
  } catch (Exception e) {
    LOG.error("Error retrieving User list from Ldap Realm", e);
  }
  LOG.info("UserList: " + userList);
  return userList;
}
 
开发者ID:apache,项目名称:zeppelin,代码行数:32,代码来源:GetUserList.java

示例2: createRealm

import org.apache.shiro.realm.ldap.JndiLdapRealm; //导入依赖的package包/类
public static Realm createRealm(JsonObject config) {
  JndiLdapRealm ldapRealm = new JndiLdapRealm();
  JndiLdapContextFactory factory = new JndiLdapContextFactory();
  String userDNTemplate = config.getString(LDAP_USER_DN_TEMPLATE_FIELD);
  if (userDNTemplate != null) {
    ldapRealm.setUserDnTemplate(userDNTemplate);
  }
  String url = config.getString(LDAP_URL);
  if (url != null) {
    factory.setUrl(url);
  }
  String authenticationMechanism = config.getString(LDAP_AUTHENTICATION_MECHANISM);
  if (authenticationMechanism != null) {
    factory.setAuthenticationMechanism(authenticationMechanism);
  }
  String contextFactoryClassName = config.getString(LDAP_CONTEXT_FACTORY_CLASS_NAME);
  if (contextFactoryClassName != null) {
    factory.setContextFactoryClassName(contextFactoryClassName);
  }
  boolean poolingEnabled = config.getBoolean(LDAP_POOLING_ENABLED, false);
  factory.setPoolingEnabled(poolingEnabled);
  String referral = config.getString(LDAP_REFERRAL);
  if (referral != null) {
    factory.setReferral(referral);
  }
  String systemUsername = config.getString(LDAP_SYSTEM_USERNAME);
  if (systemUsername != null) {
    factory.setSystemUsername(systemUsername);
  }
  String systemPassword = config.getString(LDAP_SYSTEM_PASSWORD);
  if (systemPassword != null) {
    factory.setSystemPassword(systemPassword);
  }
  ldapRealm.setContextFactory(factory);
  ldapRealm.init();
  return ldapRealm;
}
 
开发者ID:vert-x3,项目名称:vertx-auth,代码行数:38,代码来源:LDAPAuthProvider.java

示例3: getUserList

import org.apache.shiro.realm.ldap.JndiLdapRealm; //导入依赖的package包/类
/**
 * Get userlist
 * Returns list of all user from available realms
 *
 * @return 200 response
 */
@GET
@Path("userlist/{searchText}")
public Response getUserList(@PathParam("searchText") final String searchText) {

  List<String> usersList = new ArrayList<>();
  List<String> rolesList = new ArrayList<>();
  try {
    GetUserList getUserListObj = new GetUserList();
    Collection realmsList = SecurityUtils.getRealmsList();
    if (realmsList != null) {
      for (Iterator<Realm> iterator = realmsList.iterator(); iterator.hasNext(); ) {
        Realm realm = iterator.next();
        String name = realm.getClass().getName();
        if (LOG.isDebugEnabled()) {
          LOG.debug("RealmClass.getName: " + name);
        }
        if (name.equals("org.apache.shiro.realm.text.IniRealm")) {
          usersList.addAll(getUserListObj.getUserList((IniRealm) realm));
          rolesList.addAll(getUserListObj.getRolesList((IniRealm) realm));
        } else if (name.equals("org.apache.zeppelin.realm.LdapGroupRealm")) {
          usersList.addAll(getUserListObj.getUserList((JndiLdapRealm) realm, searchText));
        } else if (name.equals("org.apache.zeppelin.realm.LdapRealm")) {
          usersList.addAll(getUserListObj.getUserList((LdapRealm) realm, searchText));
          rolesList.addAll(getUserListObj.getRolesList((LdapRealm) realm));
        } else if (name.equals("org.apache.zeppelin.realm.ActiveDirectoryGroupRealm")) {
          usersList.addAll(getUserListObj.getUserList((ActiveDirectoryGroupRealm) realm,
              searchText));
        } else if (name.equals("org.apache.shiro.realm.jdbc.JdbcRealm")) {
          usersList.addAll(getUserListObj.getUserList((JdbcRealm) realm));
        }
      }
    }
  } catch (Exception e) {
    LOG.error("Exception in retrieving Users from realms ", e);
  }
  List<String> autoSuggestUserList = new ArrayList<>();
  List<String> autoSuggestRoleList = new ArrayList<>();
  Collections.sort(usersList);
  Collections.sort(rolesList);
  Collections.sort(usersList, new Comparator<String>() {
    @Override
    public int compare(String o1, String o2) {
      if (o1.matches(searchText + "(.*)") && o2.matches(searchText + "(.*)")) {
        return 0;
      } else if (o1.matches(searchText + "(.*)")) {
        return -1;
      }
      return 0;
    }
  });
  int maxLength = 0;
  for (String user : usersList) {
    if (StringUtils.containsIgnoreCase(user, searchText)) {
      autoSuggestUserList.add(user);
      maxLength++;
    }
    if (maxLength == 5) {
      break;
    }
  }

  for (String role : rolesList) {
    if (StringUtils.containsIgnoreCase(role, searchText)) {
      autoSuggestRoleList.add(role);
    }
  }

  Map<String, List> returnListMap = new HashMap<>();
  returnListMap.put("users", autoSuggestUserList);
  returnListMap.put("roles", autoSuggestRoleList);


  return new JsonResponse<>(Response.Status.OK, "", returnListMap).build();
}
 
开发者ID:apache,项目名称:zeppelin,代码行数:81,代码来源:SecurityRestApi.java

示例4: initializeLDAP

import org.apache.shiro.realm.ldap.JndiLdapRealm; //导入依赖的package包/类
protected void initializeLDAP(String ldapUrl, String systemUser, String systemUserPassword, String userNameTemplate) {

        JndiLdapContextFactory jndiLdapContextFactory = new JndiLdapContextFactory();

        jndiLdapContextFactory.setUrl(ldapUrl);
        jndiLdapContextFactory.setSystemUsername(systemUser);
        jndiLdapContextFactory.setSystemPassword(systemUserPassword);

        ldapRealm = new JndiLdapRealm();

        ldapRealm.setContextFactory(jndiLdapContextFactory);
        ldapRealm.setUserDnTemplate(userNameTemplate);

        ldapRealm.init();

    }
 
开发者ID:apache,项目名称:airavata,代码行数:17,代码来源:LDAPUserStore.java


注:本文中的org.apache.shiro.realm.ldap.JndiLdapRealm类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。