Search in sources :

Example 16 with NamingException

use of javax.naming.NamingException in project jetty.project by eclipse.

the class LdapLoginModule method getUserRoles.

/**
     * attempts to get the users roles from the root context
     * <p>
     * NOTE: this is not an user authenticated operation
     *
     * @param dirContext
     * @param username
     * @return
     * @throws LoginException
     */
private List<String> getUserRoles(DirContext dirContext, String username, Attributes attributes) throws LoginException, NamingException {
    String rdnValue = username;
    Attribute attribute = attributes.get(_userRdnAttribute);
    if (attribute != null) {
        try {
            // switch to the value stored in the _userRdnAttribute if we can
            rdnValue = (String) attribute.get();
        } catch (NamingException e) {
        }
    }
    String userDn = _userRdnAttribute + "=" + rdnValue + "," + _userBaseDn;
    return getUserRolesByDn(dirContext, userDn);
}
Also used : Attribute(javax.naming.directory.Attribute) NamingException(javax.naming.NamingException)

Example 17 with NamingException

use of javax.naming.NamingException in project jetty.project by eclipse.

the class LdapLoginModule method initialize.

/**
     * Init LoginModule.
     * <p>
     * Called once by JAAS after new instance is created.
     *
     * @param subject the subect
     * @param callbackHandler the callback handler
     * @param sharedState the shared state map
     * @param options the option map
     */
public void initialize(Subject subject, CallbackHandler callbackHandler, Map<String, ?> sharedState, Map<String, ?> options) {
    super.initialize(subject, callbackHandler, sharedState, options);
    _hostname = (String) options.get("hostname");
    _port = Integer.parseInt((String) options.get("port"));
    _contextFactory = (String) options.get("contextFactory");
    _bindDn = (String) options.get("bindDn");
    _bindPassword = (String) options.get("bindPassword");
    _authenticationMethod = (String) options.get("authenticationMethod");
    _userBaseDn = (String) options.get("userBaseDn");
    _roleBaseDn = (String) options.get("roleBaseDn");
    if (options.containsKey("forceBindingLogin")) {
        _forceBindingLogin = Boolean.parseBoolean((String) options.get("forceBindingLogin"));
    }
    if (options.containsKey("useLdaps")) {
        _useLdaps = Boolean.parseBoolean((String) options.get("useLdaps"));
    }
    _userObjectClass = getOption(options, "userObjectClass", _userObjectClass);
    _userRdnAttribute = getOption(options, "userRdnAttribute", _userRdnAttribute);
    _userIdAttribute = getOption(options, "userIdAttribute", _userIdAttribute);
    _userPasswordAttribute = getOption(options, "userPasswordAttribute", _userPasswordAttribute);
    _roleObjectClass = getOption(options, "roleObjectClass", _roleObjectClass);
    _roleMemberAttribute = getOption(options, "roleMemberAttribute", _roleMemberAttribute);
    _roleNameAttribute = getOption(options, "roleNameAttribute", _roleNameAttribute);
    _debug = Boolean.parseBoolean(String.valueOf(getOption(options, "debug", Boolean.toString(_debug))));
    try {
        _rootContext = new InitialDirContext(getEnvironment());
    } catch (NamingException ex) {
        throw new IllegalStateException("Unable to establish root context", ex);
    }
}
Also used : NamingException(javax.naming.NamingException) InitialDirContext(javax.naming.directory.InitialDirContext)

Example 18 with NamingException

use of javax.naming.NamingException in project jetty.project by eclipse.

the class LdapLoginModule method getUserCredentials.

private String getUserCredentials(Attributes attributes) throws LoginException {
    String ldapCredential = null;
    Attribute attribute = attributes.get(_userPasswordAttribute);
    if (attribute != null) {
        try {
            byte[] value = (byte[]) attribute.get();
            ldapCredential = new String(value);
        } catch (NamingException e) {
            LOG.debug("no password available under attribute: " + _userPasswordAttribute);
        }
    }
    LOG.debug("user cred is: " + ldapCredential);
    return ldapCredential;
}
Also used : Attribute(javax.naming.directory.Attribute) NamingException(javax.naming.NamingException)

Example 19 with NamingException

use of javax.naming.NamingException in project jetty.project by eclipse.

the class Transaction method unbindENC.

/**
     * Unbind this Transaction from a java:comp
     */
public void unbindENC() {
    try {
        InitialContext ic = new InitialContext();
        Context env = (Context) ic.lookup("java:comp");
        __log.debug("Unbinding java:comp/" + getJndiName());
        env.unbind(getJndiName());
    } catch (NamingException e) {
        __log.warn(e);
    }
}
Also used : InitialContext(javax.naming.InitialContext) Context(javax.naming.Context) NamingException(javax.naming.NamingException) InitialContext(javax.naming.InitialContext)

Example 20 with NamingException

use of javax.naming.NamingException in project jetty.project by eclipse.

the class DataSourceLoginService method loadRoleInfo.

/* ------------------------------------------------------------ */
public String[] loadRoleInfo(UserPrincipal user) {
    DBUserPrincipal dbuser = (DBUserPrincipal) user;
    try {
        try (Connection connection = getConnection();
            PreparedStatement statement2 = connection.prepareStatement(_roleSql)) {
            List<String> roles = new ArrayList<String>();
            statement2.setInt(1, dbuser.getKey());
            try (ResultSet rs2 = statement2.executeQuery()) {
                while (rs2.next()) {
                    roles.add(rs2.getString(_roleTableRoleField));
                }
                return roles.toArray(new String[roles.size()]);
            }
        }
    } catch (NamingException e) {
        LOG.warn("No datasource for " + _jndiName, e);
    } catch (SQLException e) {
        LOG.warn("Problem loading user info for " + user.getName(), e);
    }
    return null;
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) NamingException(javax.naming.NamingException)

Aggregations

NamingException (javax.naming.NamingException)1246 InitialContext (javax.naming.InitialContext)417 Context (javax.naming.Context)259 IOException (java.io.IOException)163 Attribute (javax.naming.directory.Attribute)111 DirContext (javax.naming.directory.DirContext)100 SearchResult (javax.naming.directory.SearchResult)98 ArrayList (java.util.ArrayList)95 SQLException (java.sql.SQLException)93 NameNotFoundException (javax.naming.NameNotFoundException)88 Attributes (javax.naming.directory.Attributes)85 DataSource (javax.sql.DataSource)84 Properties (java.util.Properties)77 Reference (javax.naming.Reference)77 InitialDirContext (javax.naming.directory.InitialDirContext)77 Test (org.junit.Test)75 Hashtable (java.util.Hashtable)73 SearchControls (javax.naming.directory.SearchControls)73 HashMap (java.util.HashMap)55 LdapContext (javax.naming.ldap.LdapContext)55