/** * Creates a new instance of this {@code LDAPRuntimeException} using the * provided {@code LDAPException}. * * @param ldapException The {@code LDAPException} object wrapped by this * runtime exception. */ public LDAPRuntimeException(final LDAPException ldapException) { super(ldapException.getMessage(), ldapException.getCause()); this.ldapException = ldapException; }
/** * Creates a new instance of this {@code LDAPRuntimeException} using the * provided {@code LDAPException}. * * @param ldapException The {@code LDAPException} object wrapped by this * runtime exception. */ public LDAPRuntimeException(final LDAPException ldapException) { super(ldapException.getMessage(), ldapException.getCause()); this.ldapException = ldapException; }
/** * Creates a new {@code LDAPResult} object from this exception. * * @return The {@code LDAPResult} object created from this exception. */ public LDAPResult toLDAPResult() { if ((diagnosticMessage == null) && (getMessage() != null)) { return new LDAPResult(-1, resultCode, getMessage(), matchedDN, referralURLs, responseControls); } else { return new LDAPResult(-1, resultCode, diagnosticMessage, matchedDN, referralURLs, responseControls); } }
/** * Creates a new {@code LDAPResult} object from this exception. * * @return The {@code LDAPResult} object created from this exception. */ public LDAPResult toLDAPResult() { if ((diagnosticMessage == null) && (getMessage() != null)) { return new LDAPResult(-1, resultCode, getMessage(), matchedDN, referralURLs, responseControls); } else { return new LDAPResult(-1, resultCode, diagnosticMessage, matchedDN, referralURLs, responseControls); } }
/** * Creates a new LDAP exception from the provided * {@link com.unboundid.ldap.sdk.LDAPException} object. * * @param ldapException The {@code LDAPException} object to use to create * this LDAP exception. */ public LDAPException(final com.unboundid.ldap.sdk.LDAPException ldapException) { this(ldapException.getMessage(), ldapException.getResultCode().intValue(), ldapException.getMessage(), ldapException.getMatchedDN()); }
/** * Checks if the configured directory base DN for the entries exists. * If not a WARN message is logged. */ private void checkBaseDN() { try { if (ldapConnPool.getEntry(config.ldapDirectory.baseDN.toString()) == null) { Loggers.MAIN_LOG.warn("[IL0101] The configured LDAP store base DN for {} cache doesn't exist: {}", cacheName, config.ldapDirectory.baseDN); } } catch (LDAPException e) { Loggers.MAIN_LOG.warn("[IL0102] Couldn't verify the LDAP store base DN for {} cache: {}", cacheName, e.getMessage()); } }
/** * Checks if the configured directory base DN for the entries exists. * If not a WARN message is logged. */ private void checkBaseDN() { try { if (ldapConnPool.getEntry(config.ldapDirectory.baseDN.toString()) == null) { Loggers.MAIN_LOG.warn("[IL0101] The configured LDAP store base DN for {} cache doesn't exist: {}", cacheName, config.ldapDirectory.baseDN); } } catch (LDAPException e) { Loggers.MAIN_LOG.warn("[IL0102] Couldn't verify the LDAP store base DN for {} cache: {}", cacheName, e.getMessage()); } }
/** * Creates a new {@code LDAPUrl} object from the provided string * representation. * * @param url The string representation of the LDAP URL to create. * * @throws MalformedURLException If the provided string cannot be parsed as * a valid LDAP URL. */ public LDAPUrl(final String url) throws MalformedURLException { try { ldapURL = new LDAPURL(url); } catch (LDAPException le) { debugException(le); throw new MalformedURLException(le.getMessage()); } }
log.warn("LDAP connector health check failure: {}", e.getMessage()); return HealthCheck.Result.unhealthy(e.getMessage());
/** * Deletes all entries under the base DN. * * @return The number of deleted entries, zero if none found. */ public int deleteEntries() { SearchRequest request = new SearchRequest( config.ldapDirectory.baseDN.toString(), SearchScope.ONE, MATCH_ANY_FILTER, SearchRequest.NO_ATTRIBUTES); List<String> entryDNs = new LinkedList<>(); doSearch(request, entry -> entryDNs.add(entry.getDN())); int count = 0; for(String dn: entryDNs) { try { if (deleteEntry(new DN(dn))) { ++count; } } catch (LDAPException e) { throw new PersistenceException(e.getMessage(), e); } } return count; }
/** * Creates a new LDAP search exception from the provided exception. * * @param ldapException The LDAP exception with the information to include * in this LDAP search exception. */ public LDAPSearchException(final LDAPException ldapException) { super(ldapException.getResultCode(), ldapException.getMessage(), ldapException.getMatchedDN(), ldapException.getReferralURLs(), ldapException.getResponseControls(), ldapException); if (ldapException instanceof LDAPSearchException) { final LDAPSearchException lse = (LDAPSearchException) ldapException; searchResult = lse.searchResult; } else { searchResult = new SearchResult(-1, ldapException.getResultCode(), ldapException.getMessage(), ldapException.getMatchedDN(), ldapException.getReferralURLs(), 0, 0, ldapException.getResponseControls()); } }
/** * Creates a new LDAP exception using the information contained in the * provided LDAP exception. * * @param e The LDAP exception to use to create this exception. */ public LDAPException(final LDAPException e) { super(e.getMessage(), e.getCause()); resultCode = e.getResultCode(); matchedDN = e.getMatchedDN(); diagnosticMessage = e.getDiagnosticMessage(); referralURLs = e.getReferralURLs(); responseControls = e.getResponseControls(); }
/** * Creates a new LDAP exception using the information contained in the * provided LDAP exception. * * @param e The LDAP exception to use to create this exception. */ public LDAPException(final LDAPException e) { super(e.getMessage(), e.getCause()); resultCode = e.getResultCode(); matchedDN = e.getMatchedDN(); diagnosticMessage = e.getDiagnosticMessage(); referralURLs = e.getReferralURLs(); responseControls = e.getResponseControls(); }
/** * {@inheritDoc} */ @Override() public ASN1OctetString normalize(final ASN1OctetString value) throws LDAPException { try { final DN dn = new DN(value.stringValue()); return new ASN1OctetString(dn.toNormalizedString()); } catch (LDAPException le) { debugException(le); throw new LDAPException(ResultCode.INVALID_ATTRIBUTE_SYNTAX, le.getMessage(), le); } }
/** * {@inheritDoc} */ @Override() public ASN1OctetString normalize(final ASN1OctetString value) throws LDAPException { try { final DN dn = new DN(value.stringValue()); return new ASN1OctetString(dn.toNormalizedString()); } catch (LDAPException le) { debugException(le); throw new LDAPException(ResultCode.INVALID_ATTRIBUTE_SYNTAX, le.getMessage(), le); } }
@Override public AuthenticationInfo getAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { if (!(token instanceof UsernamePasswordToken)) { throw new UnsupportedTokenException("LDAPRealm only supports UsernamePasswordToken"); } UsernamePasswordToken userNamePasswordToken = (UsernamePasswordToken) token; try { LDAPUserContext userContext = ldapSupport.findUser(userNamePasswordToken.getUsername()); ldapSupport.authenticate(userContext, new String(userNamePasswordToken.getPassword())); AuthenticationInfo authcInfo = new AuthenticationInfo(userNamePasswordToken.getUsername(), userNamePasswordToken.getPassword()); authcInfo.getOtherPrincipals().add(new SimplePrincipalProvider("dn", userContext.getDn())); authcInfo.getOtherPrincipals().add(Principals.fullNamePrincipal(ldapSupport.getAttributeValue(userContext, "cn"))); authcInfo.getOtherPrincipals().add(new LDAPUserContextPrincipalProvider(userContext)); return authcInfo; } catch (org.seedstack.seed.security.ldap.api.LDAPException ex) { LDAPException e = (LDAPException) ex.getCause(); switch (e.getResultCode().intValue()) { case ResultCode.INVALID_CREDENTIALS_INT_VALUE: throw new IncorrectCredentialsException(e.getMessage()); default: throw new AuthenticationException(e.getMessage()); } } }
public void connect(final IAsyncResultHandler<ILdapResult> handler) { try { connection = LDAPConnectionFactory.build(socketFactory, config); BindResult bindResponse = connection.bind(config.getBindDn(), config.getBindPassword()); evalBindReturn(bindResponse.getResultCode(), bindResponse.getDiagnosticMessage(), null, handler); } catch (LDAPException e) { evalBindReturn(e.getResultCode(), e.getMessage(), e, handler); } catch (Exception e) { LDAPConnectionFactory.releaseDefunct(connection); handler.handle(AsyncResultImpl.<ILdapResult>create(e)); } }
public void connect(final IAsyncResultHandler<ILdapResult> handler) { try { connection = LDAPConnectionFactory.build(socketFactory, config); BindResult bindResponse = connection.bind(config.getBindDn(), config.getBindPassword()); evalBindReturn(bindResponse.getResultCode(), bindResponse.getDiagnosticMessage(), null, handler); } catch (LDAPException e) { evalBindReturn(e.getResultCode(), e.getMessage(), e, handler); } catch (Exception e) { LDAPConnectionFactory.releaseDefunct(connection); handler.handle(AsyncResultImpl.<ILdapResult>create(e)); } }
public static void bind(SSLSocketFactory socketFactory, LdapConfigBean config, IAsyncResultHandler<ILdapResult> handler) { LDAPConnection connection = null; try { connection = LDAPConnectionFactory.build(socketFactory, config); BindResult bindResponse = connection.bind(config.getBindDn(), config.getBindPassword()); evalBindReturn(bindResponse.getResultCode(), bindResponse.getDiagnosticMessage(), null, handler); LDAPConnectionFactory.releaseConnection(connection); } catch (LDAPException e) { // generally errors as an exception, also potentially normal return(!). evalBindReturn(e.getResultCode(), e.getMessage(), e, handler); LDAPConnectionFactory.releaseConnectionAfterException(connection, e); } catch (Exception e) { LDAPConnectionFactory.releaseDefunct(connection); handler.handle(AsyncResultImpl.<ILdapResult>create(e)); } }
public static void bind(SSLSocketFactory socketFactory, LdapConfigBean config, IAsyncResultHandler<ILdapResult> handler) { LDAPConnection connection = null; try { connection = LDAPConnectionFactory.build(socketFactory, config); BindResult bindResponse = connection.bind(config.getBindDn(), config.getBindPassword()); evalBindReturn(bindResponse.getResultCode(), bindResponse.getDiagnosticMessage(), null, handler); LDAPConnectionFactory.releaseConnection(connection); } catch (LDAPException e) { // generally errors as an exception, also potentially normal return(!). evalBindReturn(e.getResultCode(), e.getMessage(), e, handler); LDAPConnectionFactory.releaseConnectionAfterException(connection, e); } catch (Exception e) { LDAPConnectionFactory.releaseDefunct(connection); handler.handle(AsyncResultImpl.<ILdapResult>create(e)); } }