public boolean authenticate(LdapNetworkConnection connection, String principal, String credentials) throws LdapException { checkArgument(!isNullOrEmpty(principal), "Binding with empty principal is forbidden."); checkArgument(!isNullOrEmpty(credentials), "Binding with empty credentials is forbidden."); final BindRequestImpl bindRequest = new BindRequestImpl(); bindRequest.setName(principal); bindRequest.setCredentials(credentials); LOG.trace("Re-binding with DN {} using password", principal); final BindResponse bind = connection.bind(bindRequest); if (!bind.getLdapResult().getResultCode().equals(ResultCodeEnum.SUCCESS)) { LOG.trace("Re-binding DN {} failed", principal); throw new RuntimeException(bind.toString()); } LOG.trace("Binding DN {} did not throw, connection authenticated: {}", principal, connection.isAuthenticated()); return connection.isAuthenticated(); } }
public boolean authenticate(LdapNetworkConnection connection, String principal, String credentials) throws LdapException { checkArgument(!isNullOrEmpty(principal), "Binding with empty principal is forbidden."); checkArgument(!isNullOrEmpty(credentials), "Binding with empty credentials is forbidden."); final BindRequestImpl bindRequest = new BindRequestImpl(); bindRequest.setName(principal); bindRequest.setCredentials(credentials); LOG.trace("Re-binding with DN {} using password", principal); final BindResponse bind = connection.bind(bindRequest); if (!bind.getLdapResult().getResultCode().equals(ResultCodeEnum.SUCCESS)) { LOG.trace("Re-binding DN {} failed", principal); throw new RuntimeException(bind.toString()); } LOG.trace("Binding DN {} did not throw, connection authenticated: {}", principal, connection.isAuthenticated()); return connection.isAuthenticated(); } }
if ( bindResponse.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS )
if ( bindResponse.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS )
if ( bindResponse.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS )
if ( bindResponse.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS )
if ( bindResponse.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS )
if ( bindResponse.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS )
if ( bindResponse.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS )
if ( bindResponse.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS )
if ( bindResponse.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS )
if ( bindResponse.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS )
if ( bindResponse.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS )
if ( bindResponse.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS )
if ( bindResponse.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS )
if ( bindResponse.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS )
/** * {@inheritDoc} */ @Override public Element toDsml( Element root ) { Element element = root.addElement( "authResponse" ); LdapResultDsml ldapResultDsml = new LdapResultDsml( getCodecService(), getDecorated().getLdapResult(), getDecorated() ); ldapResultDsml.toDsml( element ); return element; }
if ( bindResponse.getLdapResult().getResultCode() != ResultCodeEnum.SUCCESS ) LOG.warn( I18n.msg( I18n.MSG_02003_ERROR, bindResponse.getLdapResult().getDiagnosticMessage() ) );
bindResp.getLdapResult().setResultCode( ResultCodeEnum.SUCCESS ); LdapResult res = bindResp.getLdapResult(); res.setDiagnosticMessage( e.getMessage() ); res.setResultCode( e.getResultCode() );
/** * Send a SUCCESS message back to the client. */ private void sendBindSuccess( LdapSession ldapSession, BindRequest bindRequest, byte[] tokenBytes ) { // Return the successful response BindResponse response = ( BindResponse ) bindRequest.getResultResponse(); response.getLdapResult().setResultCode( ResultCodeEnum.SUCCESS ); response.setServerSaslCreds( tokenBytes ); if ( !ldapSession.getCoreSession().isAnonymous() ) { // If we have not been asked to authenticate as Anonymous, authenticate the user ldapSession.setAuthenticated(); } else { // Otherwise, switch back to Anonymous ldapSession.setAnonymous(); } // Clean the SaslProperties, we don't need them anymore MechanismHandler handler = ( MechanismHandler ) ldapSession.getSaslProperty( SaslConstants.SASL_MECH_HANDLER ); if ( handler != null ) { handler.cleanup( ldapSession ); } ldapSession.getIoSession().write( response ); LOG.debug( "Returned SUCCESS message: {}.", response ); }