@Override protected Object convertValue(final Class<?> type, final String value) { Object newValue = value; if (type != String.class) { if (Credential.class.isAssignableFrom(type)) { newValue = new Credential(value); } else { newValue = convertSimpleType(type, value); } } return newValue; } }
/** * Digests the supplied credential using the supplied algorithm. * * @param credential to digest * @param algorithm type of digest to use * * @return digested credential * * @throws LdapException if the supplied algorithm cannot be found */ protected byte[] digestCredential(final Credential credential, final String algorithm) throws LdapException { try { final MessageDigest md = MessageDigest.getInstance(algorithm); md.update(credential.getBytes()); return md.digest(); } catch (NoSuchAlgorithmException e) { throw new LdapException(e); } }
/** * Returns this credential as a character array. * * @return credential characters */ public char[] getChars() { return getString().toCharArray(); }
@Override protected Object convertValue(final Class<?> type, final String value) { Object newValue = value; if (type != String.class) { if (Credential.class.isAssignableFrom(type)) { if (LdapUtils.isResource(value)) { try { newValue = new Credential(LdapUtils.readInputStream(LdapUtils.getResource(value))); } catch (IOException e) { throw new IllegalArgumentException("Could not read resource: " + value, e); } } else { newValue = new Credential(value); } } else { newValue = convertSimpleType(type, value); } } return newValue; } }
/** * Digests the supplied credential using the supplied algorithm. * * @param credential to digest * @param algorithm type of digest to use * * @return digested credential * * @throws LdapException if the supplied algorithm cannot be found */ protected byte[] digestCredential(final Credential credential, final String algorithm) throws LdapException { try { final MessageDigest md = MessageDigest.getInstance(algorithm); md.update(credential.getBytes()); return md.digest(); } catch (NoSuchAlgorithmException e) { throw new LdapException(e); } }
/** * Returns this credential as a character array. * * @return credential characters */ public char[] getChars() { return getString().toCharArray(); }
private AuthenticationResponse getLdapAuthenticationResponse(final UsernamePasswordCredential upc) throws PreventedException { try { LOGGER.debug("Attempting LDAP authentication for [{}]. Authenticator pre-configured attributes are [{}], " + "additional requested attributes for this authentication request are [{}]", upc, authenticator.getReturnAttributes(), authenticatedEntryAttributes); val request = new AuthenticationRequest(upc.getUsername(), new org.ldaptive.Credential(upc.getPassword()), authenticatedEntryAttributes); return authenticator.authenticate(request); } catch (final LdapException e) { LOGGER.trace(e.getMessage(), e); throw new PreventedException("Unexpected LDAP error", e); } }
/** * Returns this credential as a character array. * * @return credential characters */ public char[] getChars() { return getString().toCharArray(); }
@Override protected Object convertValue(final Class<?> type, final String value) { Object newValue = value; if (type != String.class) { if (Credential.class.isAssignableFrom(type)) { if (LdapUtils.isResource(value)) { try { newValue = new Credential(LdapUtils.readInputStream(LdapUtils.getResource(value))); } catch (IOException e) { throw new IllegalArgumentException("Could not read resource: " + value, e); } } else { newValue = new Credential(value); } } else { newValue = convertSimpleType(type, value); } } return newValue; } }
@Override public byte[] encode() { final List<DEREncoder> l = new ArrayList<>(); if (getUserIdentity() != null) { l.add(new ContextType(0, getUserIdentity())); } if (getOldPassword() != null) { l.add(new ContextType(1, getOldPassword().getString())); } if (getNewPassword() != null) { l.add(new ContextType(2, getNewPassword().getString())); } final ConstructedDEREncoder se = new ConstructedDEREncoder( UniversalDERTag.SEQ, l.toArray(new DEREncoder[l.size()])); return se.encode(); }
@Override public void handle(final DERParser parser, final ByteBuffer encoded) { getObject().setValue(new Credential(OctetStringType.decode(encoded))); } }
@Override public byte[] encode() { final List<DEREncoder> l = new ArrayList<>(); if (getUserIdentity() != null) { l.add(new ContextType(0, getUserIdentity())); } if (getOldPassword() != null) { l.add(new ContextType(1, getOldPassword().getString())); } if (getNewPassword() != null) { l.add(new ContextType(2, getNewPassword().getString())); } final ConstructedDEREncoder se = new ConstructedDEREncoder( UniversalDERTag.SEQ, l.toArray(new DEREncoder[l.size()])); return se.encode(); }
@Override public void handle(final DERParser parser, final ByteBuffer encoded) { getObject().setValue(new Credential(OctetStringType.decode(encoded))); } }
@Override protected AuthenticationHandlerResponse authenticateInternal( final Connection c, final AuthenticationCriteria criteria) throws LdapException { byte[] hash; try { final MessageDigest md = MessageDigest.getInstance(passwordScheme); md.update(criteria.getCredential().getBytes()); hash = md.digest(); } catch (NoSuchAlgorithmException e) { throw new LdapException(e); } final LdapAttribute la = new LdapAttribute( "userPassword", String.format("{%s}%s", passwordScheme, LdapUtils.base64Encode(hash)).getBytes()); final CompareOperation compare = new CompareOperation(c); final CompareRequest request = new CompareRequest(criteria.getDn(), la); request.setControls(getAuthenticationControls()); final Response<Boolean> compareResponse = compare.execute(request); return new AuthenticationHandlerResponse( compareResponse.getResult(), compareResponse.getResultCode(), c, compareResponse.getMessage(), compareResponse.getControls(), compareResponse.getMessageId()); }
@Override public byte[] encode() { final List<DEREncoder> l = new ArrayList<>(); if (getUserIdentity() != null) { l.add(new ContextType(0, getUserIdentity())); } if (getOldPassword() != null) { l.add(new ContextType(1, getOldPassword().getString())); } if (getNewPassword() != null) { l.add(new ContextType(2, getNewPassword().getString())); } final ConstructedDEREncoder se = new ConstructedDEREncoder( UniversalDERTag.SEQ, l.toArray(new DEREncoder[l.size()])); return se.encode(); }
@Override public void handle(final DERParser parser, final ByteBuffer encoded) { getObject().setValue(new Credential(OctetStringType.decode(encoded))); } }
context.addToEnvironment(PRINCIPAL, request.getDn()); if (request.getCredential() != null) { context.addToEnvironment(CREDENTIALS, request.getCredential().getBytes());