Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class AuthLDAPService {
- /*
- *
- * Überprüft ob sich User einlochen kann oder abgelehnt wird
- *
- /*
- //Admin Name+Passwort
- final static String ADMIN_NAME = "sampleUser";
- final static String ADMIN_PASSWORD = "samplePassword";
- //Standardpfad im Active Directory
- final static String SEARCH_BASE = "ou=_fhwue,dc=fhwue,dc=de";
- static LdapContext ctx;
- static transactional = true
- public boolean CheckLDAPConnection(String user_name, String user_password) {
- //da auf den lokalen entwicklerrechnern kein LDAP verf¸gbar ist
- if (GrailsUtil.getEnvironment().equalsIgnoreCase("development")) {
- return true;
- }
- if (!user_name || !user_password) {
- return false;
- }
- try {
- //Mit dem LDAP Server verbinden
- LDAPConnect();
- //Pr¸fen, ob ¸bergebener User auf dem LDAP-Server angelegt ist
- List list = findUsersByAccountName(user_name);
- //Pr¸fung nur, wenn User nicht mehrfach angelegt ist
- if (list.size() == 1) {
- //Verbdinungs-Einstellungen f¸r den LDAP Zugriff mit ¸bergebenen Userdaten setzen
- Hashtable<String, String> env1 = new Hashtable<String, String>();
- env1.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
- env1.put(Context.SECURITY_AUTHENTICATION, "simple");
- env1.put(Context.SECURITY_PRINCIPAL, user_name);
- env1.put(Context.SECURITY_CREDENTIALS, user_password);
- env1.put(Context.PROVIDER_URL, "ldap://192.168.0.5:389");
- try {
- //Beim LDAP
- new InitialLdapContext(env1, null);
- //Erfolgreiche Verbindung
- return true;
- } catch (AuthenticationException e) {
- //Fehlgeschlagene Verbindung
- return false;
- }
- }
- ctx.close();
- } catch (Exception e1) {
- e1.printStackTrace();
- }
- return false;
- }
- }
Add Comment
Please, Sign In to add comment