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);
}
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);
}
}
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;
}
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);
}
}
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;
}
Aggregations