Search in sources :

Example 1 with JndiLdapRealm

use of org.apache.shiro.realm.ldap.JndiLdapRealm in project zeppelin by apache.

the class SecurityRestApi method getUserList.

/**
   * 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();
}
Also used : IniRealm(org.apache.shiro.realm.text.IniRealm) JdbcRealm(org.apache.shiro.realm.jdbc.JdbcRealm) LdapRealm(org.apache.zeppelin.realm.LdapRealm) JndiLdapRealm(org.apache.shiro.realm.ldap.JndiLdapRealm) IniRealm(org.apache.shiro.realm.text.IniRealm) LdapRealm(org.apache.zeppelin.realm.LdapRealm) Realm(org.apache.shiro.realm.Realm) ActiveDirectoryGroupRealm(org.apache.zeppelin.realm.ActiveDirectoryGroupRealm) JdbcRealm(org.apache.shiro.realm.jdbc.JdbcRealm) JndiLdapRealm(org.apache.shiro.realm.ldap.JndiLdapRealm) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 2 with JndiLdapRealm

use of org.apache.shiro.realm.ldap.JndiLdapRealm in project airavata by apache.

the class LDAPUserStore method initializeLDAP.

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();
}
Also used : JndiLdapRealm(org.apache.shiro.realm.ldap.JndiLdapRealm) JndiLdapContextFactory(org.apache.shiro.realm.ldap.JndiLdapContextFactory)

Example 3 with JndiLdapRealm

use of org.apache.shiro.realm.ldap.JndiLdapRealm in project SSM by Intel-bigdata.

the class SecurityRestApi method getUserList.

/**
 * 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();
}
Also used : IniRealm(org.apache.shiro.realm.text.IniRealm) JdbcRealm(org.apache.shiro.realm.jdbc.JdbcRealm) LdapRealm(org.apache.zeppelin.realm.LdapRealm) JndiLdapRealm(org.apache.shiro.realm.ldap.JndiLdapRealm) IniRealm(org.apache.shiro.realm.text.IniRealm) LdapRealm(org.apache.zeppelin.realm.LdapRealm) Realm(org.apache.shiro.realm.Realm) ActiveDirectoryGroupRealm(org.apache.zeppelin.realm.ActiveDirectoryGroupRealm) JdbcRealm(org.apache.shiro.realm.jdbc.JdbcRealm) JndiLdapRealm(org.apache.shiro.realm.ldap.JndiLdapRealm) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 4 with JndiLdapRealm

use of org.apache.shiro.realm.ldap.JndiLdapRealm in project vertx-auth by vert-x3.

the class LDAPAuthProvider method createRealm.

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;
}
Also used : JndiLdapRealm(org.apache.shiro.realm.ldap.JndiLdapRealm) JndiLdapContextFactory(org.apache.shiro.realm.ldap.JndiLdapContextFactory)

Aggregations

JndiLdapRealm (org.apache.shiro.realm.ldap.JndiLdapRealm)4 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Realm (org.apache.shiro.realm.Realm)2 JdbcRealm (org.apache.shiro.realm.jdbc.JdbcRealm)2 JndiLdapContextFactory (org.apache.shiro.realm.ldap.JndiLdapContextFactory)2 IniRealm (org.apache.shiro.realm.text.IniRealm)2 ActiveDirectoryGroupRealm (org.apache.zeppelin.realm.ActiveDirectoryGroupRealm)2 LdapRealm (org.apache.zeppelin.realm.LdapRealm)2