@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; } }
@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; } }
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); } }
@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 void handle(final DERParser parser, final ByteBuffer encoded) { getObject().setValue(new Credential(OctetStringType.decode(encoded))); } }
@Override public void handle(final DERParser parser, final ByteBuffer encoded) { getObject().setValue(new Credential(OctetStringType.decode(encoded))); } }
@Override public void handle(final DERParser parser, final ByteBuffer encoded) { getObject().setValue(new Credential(OctetStringType.decode(encoded))); } }
@Bean public ConnectionConfig connectionConfig() { ConnectionConfig connectionConfig = new ConnectionConfig(); connectionConfig.setConnectTimeout(Duration.ofMillis(configuration.getConnectTimeout())); connectionConfig.setResponseTimeout(Duration.ofMillis(configuration.getResponseTimeout())); connectionConfig.setLdapUrl(configuration.getContextSourceUrl()); BindConnectionInitializer connectionInitializer = new BindConnectionInitializer(configuration.getContextSourceUsername(), new Credential(configuration.getContextSourcePassword())); connectionConfig.setConnectionInitializer(connectionInitializer); return connectionConfig; }
@Override public Check check() { final StringBuilder description = new StringBuilder(); description.append(String.format("LDAP bind to %s as %s checked.", url, bindDn)); final Connection conn = DefaultConnectionFactory.getConnection(url); try { conn.open(); BindOperation bind = new BindOperation(conn); bind.execute(new BindRequest(bindDn, new Credential(bindPassword))); } catch (LdapException e) { description.append(" ").append(e.getMessage()); LOGGER.warning(HealthCheckCodes.HS_LDAP_FAILED, "Healthcheck failed, unable to bind as {0} to {1}. Error {2}", e, bindDn, url, e.getMessage()); return new Check(getName(), description.toString(), Status.DOWN); } catch (Throwable t) { description.append(" ").append(t.getMessage()); LOGGER.severe(HealthCheckCodes.HS_LDAP_FAILED_ERROR, "Healthcheck failed, unexpected error, unable to bind as {0} to {1}. Error {2}", t, bindDn, url, t.getMessage()); return new Check(getName(), description.toString(), Status.DOWN); } finally { conn.close(); } return new Check(getName(), description.toString(), Status.UP); }
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); newValue = new Credential(value);
@Override public void validate(final UsernamePasswordCredentials credentials, final WebContext context) { init(); final String username = credentials.getUsername(); CommonHelper.assertNotBlank(Pac4jConstants.USERNAME, username); final AuthenticationResponse response; try { logger.debug("Attempting LDAP authentication for: {}", credentials); final List<String> attributesToRead = defineAttributesToRead(); final AuthenticationRequest request = new AuthenticationRequest(username, new Credential(credentials.getPassword()), attributesToRead.toArray(new String[attributesToRead.size()])); response = this.ldapAuthenticator.authenticate(request); } catch (final LdapException e) { throw new TechnicalException("Unexpected LDAP error", e); } logger.debug("LDAP response: {}", response); if (response.getResult()) { final LdapEntry entry = response.getLdapEntry(); final List<Map<String, Object>> listAttributes = new ArrayList<>(); listAttributes.add(getAttributesFromEntry(entry)); final LdapProfile profile = convertAttributesToProfile(listAttributes, username); credentials.setUserProfile(profile); return; } if (AuthenticationResultCode.DN_RESOLUTION_FAILURE == response.getAuthenticationResultCode()) { throw new AccountNotFoundException(username + " not found"); } throw new BadCredentialsException("Invalid credentials for: " + username); }
/** * Initialize an authentication request with command line options. * * @param line parsed command line arguments * * @return authentication request that has been initialized */ protected AuthenticationRequest initAuthenticationRequest(final CommandLine line) { final AuthenticationRequest request = new AuthenticationRequest(); final AuthenticationRequestPropertySource arSource = new AuthenticationRequestPropertySource( request, getPropertiesFromOptions(PropertyDomain.AUTH.value(), line)); arSource.initialize(); if (request.getUser() == null) { // prompt for a user name final String user = System.console().readLine("[Enter user name]: "); request.setUser(user); } if (request.getCredential() == null) { // prompt the user to enter a password final char[] pass = System.console().readPassword("[Enter password for %s]: ", request.getUser()); request.setCredential(new Credential(pass)); } return request; }
@Override protected Object convertValue(final Class<?> type, final String value) { Object newValue = value; if (type != String.class) { if (SaslConfig.class.isAssignableFrom(type)) { if ("null".equals(value)) { newValue = null; } else { if (PropertyValueParser.isParamsOnlyConfig(value)) { final PropertyValueParser configParser = new PropertyValueParser(value, "org.ldaptive.sasl.SaslConfig"); newValue = configParser.initializeType(); } else if (PropertyValueParser.isConfig(value)) { final PropertyValueParser configParser = new PropertyValueParser(value); newValue = configParser.initializeType(); } else { newValue = instantiateType(SaslConfig.class, value); } } } else if (RequestControl[].class.isAssignableFrom(type)) { newValue = createArrayTypeFromPropertyValue(RequestControl.class, value); } else if (Credential.class.isAssignableFrom(type)) { newValue = new Credential(value); } else { newValue = convertSimpleType(type, value); } } return newValue; } }
/** * Initialize an authentication request with command line options. * * @param line parsed command line arguments * * @return authentication request that has been initialized */ protected AuthenticationRequest initAuthenticationRequest(final CommandLine line) { final AuthenticationRequest request = new AuthenticationRequest(); final AuthenticationRequestPropertySource arSource = new AuthenticationRequestPropertySource( request, getPropertiesFromOptions(PropertyDomain.AUTH.value(), line)); arSource.initialize(); if (request.getUser() == null) { // prompt for a user name final String user = System.console().readLine("[Enter user name]: "); request.setUser(new User(user)); } if (request.getCredential() == null) { // prompt the user to enter a password final char[] pass = System.console().readPassword("[Enter password for %s]: ", request.getUser()); request.setCredential(new Credential(pass)); } return request; }
/** * Initialize an authentication request with command line options. * * @param line parsed command line arguments * * @return authentication request that has been initialized */ protected AuthenticationRequest initAuthenticationRequest(final CommandLine line) { final AuthenticationRequest request = new AuthenticationRequest(); final AuthenticationRequestPropertySource arSource = new AuthenticationRequestPropertySource( request, getPropertiesFromOptions(PropertyDomain.AUTH.value(), line)); arSource.initialize(); if (request.getUser() == null) { // prompt for a user name final String user = System.console().readLine("[Enter user name]: "); request.setUser(new User(user)); } if (request.getCredential() == null) { // prompt the user to enter a password final char[] pass = System.console().readPassword("[Enter password for %s]: ", request.getUser()); request.setCredential(new Credential(pass)); } return request; }
final String password = getPasswordEncoder().encode(upc.getPassword()); final AuthenticationRequest request = new AuthenticationRequest(upc.getUsername(), new org.ldaptive.Credential(password), this.authenticatedEntryAttributes); response = this.authenticator.authenticate(request);
/** * Initialize a connection factory with command line options. * * @param line parsed command line arguments * * @return connection factory that has been initialized */ protected ConnectionFactory initConnectionFactory(final CommandLine line) { final DefaultConnectionFactory factory = new DefaultConnectionFactory(); final DefaultConnectionFactoryPropertySource cfSource = new DefaultConnectionFactoryPropertySource( factory, getPropertiesFromOptions(PropertyDomain.LDAP.value(), line)); cfSource.initialize(); final ConnectionInitializer ci = factory.getConnectionConfig().getConnectionInitializer(); if (ci instanceof BindConnectionInitializer) { final BindConnectionInitializer bci = (BindConnectionInitializer) ci; if (bci.getBindDn() != null && bci.getBindCredential() == null) { // prompt the user to enter a password final char[] pass = System.console().readPassword("[Enter password for %s]: ", bci.getBindDn()); bci.setBindCredential(new Credential(pass)); } } return factory; }
/** * Initialize a connection factory with command line options. * * @param line parsed command line arguments * * @return connection factory that has been initialized */ protected ConnectionFactory initConnectionFactory(final CommandLine line) { final DefaultConnectionFactory factory = new DefaultConnectionFactory(); final DefaultConnectionFactoryPropertySource cfSource = new DefaultConnectionFactoryPropertySource( factory, getPropertiesFromOptions(PropertyDomain.LDAP.value(), line)); cfSource.initialize(); final ConnectionInitializer ci = factory.getConnectionConfig().getConnectionInitializer(); if (ci instanceof BindConnectionInitializer) { final BindConnectionInitializer bci = (BindConnectionInitializer) ci; if (bci.getBindDn() != null && bci.getBindCredential() == null) { // prompt the user to enter a password final char[] pass = System.console().readPassword("[Enter password for %s]: ", bci.getBindDn()); bci.setBindCredential(new Credential(pass)); } } return factory; }
/** * Initialize a connection factory with command line options. * * @param line parsed command line arguments * * @return connection factory that has been initialized */ protected ConnectionFactory initConnectionFactory(final CommandLine line) { final DefaultConnectionFactory factory = new DefaultConnectionFactory(); final DefaultConnectionFactoryPropertySource cfSource = new DefaultConnectionFactoryPropertySource( factory, getPropertiesFromOptions(PropertyDomain.LDAP.value(), line)); cfSource.initialize(); final ConnectionInitializer ci = factory.getConnectionConfig().getConnectionInitializer(); if (ci instanceof BindConnectionInitializer) { final BindConnectionInitializer bci = (BindConnectionInitializer) ci; if (bci.getBindDn() != null && bci.getBindCredential() == null) { // prompt the user to enter a password final char[] pass = System.console().readPassword("[Enter password for %s]: ", bci.getBindDn()); bci.setBindCredential(new Credential(pass)); } } return factory; }
final BindRequest bindRequest = new BindRequest(); bindRequest.setDn(l.getBindDn()); bindRequest.setCredential(new Credential(l.getBindCredential())); cp.setPassivator(new BindPassivator(bindRequest)); break;