Example usage for javax.naming NamingException toString

List of usage examples for javax.naming NamingException toString

Introduction

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

Prototype

public String toString(boolean detail) 

Source Link

Document

Generates the string representation in more detail.

Usage

From source file:org.rhq.enterprise.server.core.jaas.JDBCLoginModule.java

/**
 * @see org.jboss.security.auth.spi.UsernamePasswordLoginModule#getUsersPassword()
 *//*from w ww .  ja  v  a2  s  .com*/
@Override
protected String getUsersPassword() throws LoginException {
    String username = getUsername();
    if ("admin".equals(username)) {
        throw new FailedLoginException("Cannot log in as overlord");
    }
    String password = null;
    Connection conn = null;
    PreparedStatement ps = null;
    ResultSet rs = null;

    try {
        Properties props = getProperties();
        InitialContext ctx = new InitialContext(props);
        DataSource ds = (DataSource) ctx.lookup(dsJndiName);
        conn = ds.getConnection();

        ps = conn.prepareStatement(principalsQuery);
        ps.setString(1, username);
        rs = ps.executeQuery();
        if (rs.next() == false) {
            throw new FailedLoginException("No matching username found in principals");
        }

        password = rs.getString(1);
    } catch (NamingException ex) {
        throw new LoginException(ex.toString(true));
    } catch (SQLException ex) {
        throw new LoginException(ex.toString());
    } finally {
        if (rs != null) {
            try {
                rs.close();
            } catch (Exception e) {
            }
        }

        if (ps != null) {
            try {
                ps.close();
            } catch (Exception e) {
            }
        }

        if (conn != null) {
            try {
                conn.close();
            } catch (Exception ex) {
            }
        }
    }

    return password;
}

From source file:org.rhq.enterprise.server.core.jaas.JDBCPrincipalCheckLoginModule.java

/**
 * @see org.jboss.security.auth.spi.UsernamePasswordLoginModule#getUsersPassword()
 *///  w w w .j  a v  a 2 s  . c o m
@Override
protected String getUsersPassword() throws LoginException {
    String username = getUsername();
    if ("admin".equals(username)) {
        throw new FailedLoginException("Cannot log in as overlord");
    }
    String password = getUsernameAndPassword()[1]; // what did the user enter?
    Connection conn = null;
    PreparedStatement ps = null;
    ResultSet rs = null;

    try {
        Properties props = getProperties();
        InitialContext ctx = new InitialContext(props);
        DataSource ds = (DataSource) ctx.lookup(dsJndiName);
        conn = ds.getConnection();

        ps = conn.prepareStatement(principalsQuery);
        ps.setString(1, username);
        rs = ps.executeQuery();
        if (rs.next() == true) {
            throw new FailedLoginException("username found in principals - do not continue");
        }

        password = Util.createPasswordHash("MD5", "base64", null, null, password); // return back the string entered by the user as a hash
    } catch (NamingException ex) {
        throw new LoginException(ex.toString(true));
    } catch (SQLException ex) {
        throw new LoginException(ex.toString());
    } finally {
        if (rs != null) {
            try {
                rs.close();
            } catch (Exception e) {
            }
        }

        if (ps != null) {
            try {
                ps.close();
            } catch (Exception e) {
            }
        }

        if (conn != null) {
            try {
                conn.close();
            } catch (Exception ex) {
            }
        }
    }

    return password;
}

From source file:org.zanata.ZanataInit.java

/**
 * Utility to debug JBoss JNDI problems/*from www.  j a va2s. c  o m*/
 */
public static String listJNDITree(String namespace) {
    StringBuffer buffer = new StringBuffer(4096);
    try {
        Properties props = new Properties();
        Context context = new InitialContext(props); // From jndi.properties
        if (namespace != null) {
            context = (Context) context.lookup(namespace);
        }
        buffer.append("Namespace: ").append(namespace).append("\n");
        buffer.append("#####################################\n");
        list(context, " ", buffer, true);
        buffer.append("#####################################\n");
    } catch (NamingException e) {
        buffer.append("Failed to get InitialContext, ").append(e.toString(true));
    }
    return buffer.toString();
}