@Override protected DirContextOperations doAuthentication( UsernamePasswordAuthenticationToken authentication) { try { return getAuthenticator().authenticate(authentication); } catch (PasswordPolicyException ppe) { // The only reason a ppolicy exception can occur during a bind is that the // account is locked. throw new LockedException(this.messages.getMessage( ppe.getStatus().getErrorCode(), ppe.getStatus().getDefaultMessage())); } catch (UsernameNotFoundException notFound) { if (this.hideUserNotFoundExceptions) { throw new BadCredentialsException(this.messages.getMessage( "LdapAuthenticationProvider.badCredentials", "Bad credentials")); } else { throw notFound; } } catch (NamingException ldapAccessFailure) { throw new InternalAuthenticationServiceException( ldapAccessFailure.getMessage(), ldapAccessFailure); } }
public void getAllGroups(LdapTemplate ldapTemplate , String groupBaseDnPattern) { try { groupInfo =new ArrayList<>(); LdapQuery query = query().base(groupBaseDnPattern); groupInfo = ldapTemplate.list(query.base()); } catch(NamingException e) { log.error("Unable to Groups from LDAP " + e.getMessage()); throw new RuntimeException(e); } }
public void remove(Entity entity) throws SecurityException { String internalId = getInternalId(entity, false); if (internalId == null) { // not found return; } ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader()); ldapTemplate.unbind(getRelativeDN(internalId)); } catch (NameNotFoundException e) { // ignore } catch (NamingException e) { throw new SecurityException(SecurityException.UNEXPECTED.create(getClass().getName(), "remove", e.getMessage()), e); } finally { Thread.currentThread().setContextClassLoader(currentClassLoader); } }
public void getEntities(Filter filter, EntitySearchResultHandler handler) throws SecurityException { Validate.notNull(handler, "EntitySearchResultHandler parameter must not be null"); String sf = createSearchFilter(filter); SearchControls sc = getSearchControls(SearchControls.SUBTREE_SCOPE, true, configuration.getEntityAttributeNames()); handler.setEntityFactory(getEntityFactory()); PagedSearchExecutor pse = new PagedSearchExecutor(configuration.getSearchDN(), sf, sc, handler, searchPageSize); ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader()); ldapTemplate.search(pse,pse); } catch (NamingException e) { throw new SecurityException(SecurityException.UNEXPECTED.create(getClass().getName(), "getEntities", e.getMessage()), e); } finally { Thread.currentThread().setContextClassLoader(currentClassLoader); handler.setEntityFactory(null); } }
protected void getEntityByInternalId(String internalId, EntitySearchResultHandler handler) throws SecurityException { DistinguishedName principalDN = getRelativeDN(internalId); if (configuration.getSearchDN().size() == 0 || principalDN.startsWith(configuration.getSearchDN())) { SearchControls sc = getSearchControls(SearchControls.OBJECT_SCOPE, true, configuration.getEntityAttributeNames()); PagedSearchExecutor pse = new PagedSearchExecutor(principalDN, defaultSearchFilterStr, sc, handler); handler.setEntityFactory(getEntityFactory()); ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader()); ldapTemplate.search(pse,pse); } catch (NamingException e) { throw new SecurityException(SecurityException.UNEXPECTED.create(getClass().getName(), "getEntityByInternalId", e.getMessage()), e); } finally { Thread.currentThread().setContextClassLoader(currentClassLoader); handler.setEntityFactory(null); } } }
throw new SecurityException(SecurityException.UNEXPECTED.create(getClass().getName(), "getEntityContext", e.getMessage()), e);
public void getEntities(Entity parent, Filter filter, EntitySearchResultHandler handler) throws SecurityException { ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader(); DistinguishedName parentDN = getRelativeDN(parent.getInternalId()); if (configuration.getSearchDN().size() == 0 || parentDN.startsWith(configuration.getSearchDN())) { String sf = createSearchFilter(filter); SearchControls sc = getSearchControls(SearchControls.ONELEVEL_SCOPE, true, configuration.getEntityAttributeNames()); handler.setEntityFactory(getEntityFactory()); PagedSearchExecutor pse = new PagedSearchExecutor(parentDN, sf, sc, handler, searchPageSize); try { Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader()); ldapTemplate.search(pse, pse); } catch (NamingException e) { throw new SecurityException(SecurityException.UNEXPECTED.create(getClass().getName(), "getEntities", e.getMessage()), e); } finally { Thread.currentThread().setContextClassLoader(currentClassLoader); handler.setEntityFactory(null); } } }
throw new SecurityException(SecurityException.UNEXPECTED.create(getClass().getName(), "getEntityContext", e.getMessage()), e);
throw new SecurityException(SecurityException.UNEXPECTED.create(getClass().getName(), "getInternalId", e.getMessage()), e);
throw new SecurityException(SecurityException.UNEXPECTED.create(getClass().getName(), "addRelation", e.getMessage()), e);
throw new AuthenticationServiceException(ldapAccessFailure.getMessage(), ldapAccessFailure);
throw new SecurityException(SecurityException.UNEXPECTED.create(getClass().getName(), "update", e.getMessage()), e);
@Override protected DirContextOperations doAuthentication( UsernamePasswordAuthenticationToken authentication) { try { return getAuthenticator().authenticate(authentication); } catch (PasswordPolicyException ppe) { // The only reason a ppolicy exception can occur during a bind is that the // account is locked. throw new LockedException(this.messages.getMessage( ppe.getStatus().getErrorCode(), ppe.getStatus().getDefaultMessage())); } catch (UsernameNotFoundException notFound) { if (this.hideUserNotFoundExceptions) { throw new BadCredentialsException(this.messages.getMessage( "LdapAuthenticationProvider.badCredentials", "Bad credentials")); } else { throw notFound; } } catch (NamingException ldapAccessFailure) { throw new InternalAuthenticationServiceException( ldapAccessFailure.getMessage(), ldapAccessFailure); } }
throw new SecurityException(SecurityException.UNEXPECTED.create(getClass().getName(), "removeRelation", e.getMessage()), e);
throw new SecurityException(SecurityException.UNEXPECTED.create(getClass().getName(), "add", e.getMessage()), e);