use of org.eclipse.jetty.util.security.Credential in project jetty.project by eclipse.
the class LdapLoginModule method getUserInfo.
/**
* get the available information about the user
* <p>
* for this LoginModule, the credential can be null which will result in a
* binding ldap authentication scenario
* <p>
* roles are also an optional concept if required
*
* @param username the user name
* @return the userinfo for the username
* @throws Exception if unable to get the user info
*/
public UserInfo getUserInfo(String username) throws Exception {
Attributes attributes = getUserAttributes(username);
String pwdCredential = getUserCredentials(attributes);
if (pwdCredential == null) {
return null;
}
pwdCredential = convertCredentialLdapToJetty(pwdCredential);
Credential credential = Credential.getCredential(pwdCredential);
return new LDAPUserInfo(username, credential, attributes);
}
use of org.eclipse.jetty.util.security.Credential in project blade by biezhi.
the class PropertyUserStore method loadUsers.
/* ------------------------------------------------------------ */
protected void loadUsers() throws IOException {
if (_configPath == null)
return;
if (LOG.isDebugEnabled()) {
LOG.debug("Loading " + this + " from " + _configPath);
}
Properties properties = new Properties();
if (getConfigResource().exists())
properties.load(getConfigResource().getInputStream());
Set<String> known = new HashSet<String>();
for (Map.Entry<Object, Object> entry : properties.entrySet()) {
String username = ((String) entry.getKey()).trim();
String credentials = ((String) entry.getValue()).trim();
String roles = null;
int c = credentials.indexOf(',');
if (c > 0) {
roles = credentials.substring(c + 1).trim();
credentials = credentials.substring(0, c).trim();
}
if (username != null && username.length() > 0 && credentials != null && credentials.length() > 0) {
String[] roleArray = IdentityService.NO_ROLES;
if (roles != null && roles.length() > 0) {
roleArray = StringUtil.csvSplit(roles);
}
known.add(username);
Credential credential = Credential.getCredential(credentials);
Principal userPrincipal = new AbstractLoginService.UserPrincipal(username, credential);
Subject subject = new Subject();
subject.getPrincipals().add(userPrincipal);
subject.getPrivateCredentials().add(credential);
if (roles != null) {
for (String role : roleArray) {
subject.getPrincipals().add(new AbstractLoginService.RolePrincipal(role));
}
}
subject.setReadOnly();
_knownUserIdentities.put(username, _identityService.newUserIdentity(subject, userPrincipal, roleArray));
notifyUpdate(username, credential, roleArray);
}
}
synchronized (_knownUsers) {
/*
* if its not the initial load then we want to process removed users
*/
if (!_firstLoad) {
Iterator<String> users = _knownUsers.iterator();
while (users.hasNext()) {
String user = users.next();
if (!known.contains(user)) {
_knownUserIdentities.remove(user);
notifyRemove(user);
}
}
}
/*
* reset the tracked _users list to the known users we just processed
*/
_knownUsers.clear();
_knownUsers.addAll(known);
}
/*
* set initial load to false as there should be no more initial loads
*/
_firstLoad = false;
if (LOG.isDebugEnabled()) {
LOG.debug("Loaded " + this + " from " + _configPath);
}
}
use of org.eclipse.jetty.util.security.Credential in project jetty.project by eclipse.
the class PropertyFileLoginModule method getUserInfo.
/**
*
*
* @param userName the user name
* @throws Exception if unable to get the user information
*/
public UserInfo getUserInfo(String userName) throws Exception {
PropertyUserStore propertyUserStore = _propertyUserStores.get(_filename);
if (propertyUserStore == null)
throw new IllegalStateException("PropertyUserStore should never be null here!");
LOG.debug("Checking PropertyUserStore " + _filename + " for " + userName);
UserIdentity userIdentity = propertyUserStore.getUserIdentity(userName);
if (userIdentity == null)
return null;
//TODO in future versions change the impl of PropertyUserStore so its not
//storing Subjects etc, just UserInfo
Set<Principal> principals = userIdentity.getSubject().getPrincipals();
List<String> roles = new ArrayList<String>();
for (Principal principal : principals) {
roles.add(principal.getName());
}
Credential credential = (Credential) userIdentity.getSubject().getPrivateCredentials().iterator().next();
LOG.debug("Found: " + userName + " in PropertyUserStore " + _filename);
return new UserInfo(userName, credential, roles);
}
use of org.eclipse.jetty.util.security.Credential in project jetty.project by eclipse.
the class PropertyUserStore method loadUsers.
/* ------------------------------------------------------------ */
protected void loadUsers() throws IOException {
if (_configPath == null)
return;
if (LOG.isDebugEnabled()) {
LOG.debug("Loading " + this + " from " + _configPath);
}
Properties properties = new Properties();
if (getConfigResource().exists())
properties.load(getConfigResource().getInputStream());
Set<String> known = new HashSet<String>();
for (Map.Entry<Object, Object> entry : properties.entrySet()) {
String username = ((String) entry.getKey()).trim();
String credentials = ((String) entry.getValue()).trim();
String roles = null;
int c = credentials.indexOf(',');
if (c > 0) {
roles = credentials.substring(c + 1).trim();
credentials = credentials.substring(0, c).trim();
}
if (username != null && username.length() > 0 && credentials != null && credentials.length() > 0) {
String[] roleArray = IdentityService.NO_ROLES;
if (roles != null && roles.length() > 0) {
roleArray = StringUtil.csvSplit(roles);
}
known.add(username);
Credential credential = Credential.getCredential(credentials);
Principal userPrincipal = new AbstractLoginService.UserPrincipal(username, credential);
Subject subject = new Subject();
subject.getPrincipals().add(userPrincipal);
subject.getPrivateCredentials().add(credential);
if (roles != null) {
for (String role : roleArray) {
subject.getPrincipals().add(new AbstractLoginService.RolePrincipal(role));
}
}
subject.setReadOnly();
_knownUserIdentities.put(username, _identityService.newUserIdentity(subject, userPrincipal, roleArray));
notifyUpdate(username, credential, roleArray);
}
}
synchronized (_knownUsers) {
/*
* if its not the initial load then we want to process removed users
*/
if (!_firstLoad) {
Iterator<String> users = _knownUsers.iterator();
while (users.hasNext()) {
String user = users.next();
if (!known.contains(user)) {
_knownUserIdentities.remove(user);
notifyRemove(user);
}
}
}
/*
* reset the tracked _users list to the known users we just processed
*/
_knownUsers.clear();
_knownUsers.addAll(known);
}
/*
* set initial load to false as there should be no more initial loads
*/
_firstLoad = false;
if (LOG.isDebugEnabled()) {
LOG.debug("Loaded " + this + " from " + _configPath);
}
}
use of org.eclipse.jetty.util.security.Credential in project elasticsearch-jetty by sonian.
the class ESLoginService method loadUser.
@Override
public UserIdentity loadUser(String user) {
Log.debug("attempting to load user [{}]", user);
try {
GetResponse response = client.prepareGet(authIndex, authType, user).setFields(passwordField, rolesField).execute().actionGet();
if (response.isExists()) {
Log.debug("user [{}] exists; looking for credentials...", user);
Credential credential = null;
GetField passwordGetField = response.getField(passwordField);
if (passwordGetField != null) {
Log.debug("user [{}] using password auth", user);
credential = Credential.getCredential((String) passwordGetField.getValue());
}
String[] roles = getStringValues(response.getField(rolesField));
return putUser(user, credential, roles);
}
} catch (IndexMissingException e) {
Log.warn("no auth index [{}]", authIndex);
} catch (Exception e) {
Log.warn("error finding user [" + user + "] in [" + authIndex + "]", e);
}
return null;
}
Aggregations