Example usage for javax.naming AuthenticationException toString

List of usage examples for javax.naming AuthenticationException toString

Introduction

In this page you can find the example usage for javax.naming AuthenticationException toString.

Prototype

public String toString() 

Source Link

Document

Generates the string representation of this exception.

Usage

From source file:ome.logic.LdapImpl.java

/**
 * Creates the initial context with no connection request controls in order
 * to check authentication. If authentication fails, this method throws
 * a {@link SecurityViolation}./*from w w w  . j a v a 2s . c  o  m*/
 *
 * @return {@link javax.naming.ldap.LdapContext}
 */
@SuppressWarnings("unchecked")
private void isAuthContext(String username, String password) {

    Hashtable<String, String> env = new Hashtable<String, String>(5, 0.75f);
    try {
        env = (Hashtable<String, String>) ctx.getReadOnlyContext().getEnvironment();

        if (username != null && !username.equals("")) {
            env.put(Context.SECURITY_PRINCIPAL, username);
            if (password != null) {
                env.put(Context.SECURITY_CREDENTIALS, password);
            }
        }
        new InitialLdapContext(env, null);
    } catch (AuthenticationException authEx) {
        throw new SecurityViolation("Authentication falilure! " + authEx.toString());
    } catch (NamingException e) {
        throw new SecurityViolation("Naming exception! " + e.toString());
    }
}

From source file:org.openadaptor.auxil.connector.jndi.JNDIReadConnector.java

/**
 * Establish an external JNDI connection.
 * <p/>//from  w ww. jav a2  s  . co m
 * If already connected, do nothing.
 *
 * @throws ConnectionException if an AuthenticationException or NamingException occurs
 */
public void connect() {
    try {
        _ctxt = jndiConnection.connect();
    } catch (AuthenticationException ae) {
        log.warn("Failed JNDI authentication for principal: " + jndiConnection.getSecurityPrincipal());
        throw new ConnectionException("Failed to Authenticate JNDI connection - " + ae.toString(), ae, this);
    } catch (NamingException ne) {
        log.warn(ne.getMessage());
        throw new ConnectionException("Failed to establish JNDI connection - " + ne.toString(), ne, this);
    }
    log.info(getId() + " connected");
}