use of javax.security.auth.login.AccountException in project cxf by apache.
the class WSDLGetAuthenticatorInterceptor method doAuthenticate.
public Subject doAuthenticate(final String username, final String password) {
try {
Subject subject = new Subject();
LoginContext loginContext = new LoginContext(getContextName(), subject, new CallbackHandler() {
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
for (int i = 0; i < callbacks.length; i++) {
if (callbacks[i] instanceof NameCallback) {
((NameCallback) callbacks[i]).setName(username);
} else if (callbacks[i] instanceof PasswordCallback) {
((PasswordCallback) callbacks[i]).setPassword(password.toCharArray());
} else {
throw new UnsupportedCallbackException(callbacks[i]);
}
}
}
});
loginContext.login();
return subject;
} catch (FailedLoginException e) {
LOG.log(Level.FINE, "Login failed ", e);
return null;
} catch (AccountException e) {
LOG.log(Level.WARNING, "Account failure ", e);
return null;
} catch (GeneralSecurityException e) {
LOG.log(Level.SEVERE, "General Security Exception ", e);
return null;
}
}
use of javax.security.auth.login.AccountException in project karaf by apache.
the class JaasSecurityProvider method doAuthenticate.
public Subject doAuthenticate(final String address, final String username, final String password) {
try {
Subject subject = new Subject();
subject.getPrincipals().add(new ClientPrincipal("webconsole", address));
LoginContext loginContext = new LoginContext(realm, subject, callbacks -> {
for (Callback callback : callbacks) {
if (callback instanceof NameCallback) {
((NameCallback) callback).setName(username);
} else if (callback instanceof PasswordCallback) {
((PasswordCallback) callback).setPassword(password.toCharArray());
} else {
throw new UnsupportedCallbackException(callback);
}
}
});
loginContext.login();
if (role != null && role.length() > 0) {
String clazz = "org.apache.karaf.jaas.boot.principal.RolePrincipal";
String name = role;
int idx = role.indexOf(':');
if (idx > 0) {
clazz = role.substring(0, idx);
name = role.substring(idx + 1);
}
boolean found = false;
for (Principal p : subject.getPrincipals()) {
if (p.getClass().getName().equals(clazz) && p.getName().equals(name)) {
found = true;
break;
}
}
if (!found) {
throw new FailedLoginException("User does not have the required role " + role);
}
}
return subject;
} catch (FailedLoginException e) {
LOG.debug("Login failed", e);
return null;
} catch (AccountException e) {
LOG.warn("Account failure", e);
return null;
} catch (GeneralSecurityException e) {
LOG.error("General Security Exception", e);
return null;
}
}
use of javax.security.auth.login.AccountException in project fabric8 by jboss-fuse.
the class JolokiaSecureHttpContext method doAuthenticate.
private Subject doAuthenticate(final String username, final String password) {
try {
Subject subject = new Subject();
LoginContext loginContext = new LoginContext(realm, subject, new CallbackHandler() {
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
for (int i = 0; i < callbacks.length; i++) {
if (callbacks[i] instanceof NameCallback) {
((NameCallback) callbacks[i]).setName(username);
} else if (callbacks[i] instanceof PasswordCallback) {
((PasswordCallback) callbacks[i]).setPassword(password.toCharArray());
} else {
throw new UnsupportedCallbackException(callbacks[i]);
}
}
}
});
loginContext.login();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Login successful: {}", subject);
}
boolean found = false;
for (String role : roles) {
if (role != null && role.length() > 0 && !found) {
String roleName = role.trim();
int idx = roleName.indexOf(':');
if (idx > 0) {
roleName = roleName.substring(idx + 1);
}
for (Principal p : subject.getPrincipals()) {
if (p.getName().equals(roleName)) {
found = true;
break;
}
}
}
}
if (!found) {
throw new FailedLoginException("User does not have the required role " + Arrays.asList(roles));
}
return subject;
} catch (AccountException e) {
LOGGER.warn("Account failure", e);
return null;
} catch (LoginException e) {
LOGGER.debug("Login failed", e);
return null;
}
}
use of javax.security.auth.login.AccountException in project fabric8 by jboss-fuse.
the class GitSecureHttpContext method doAuthenticate.
private Subject doAuthenticate(final String username, final String password) {
try {
Subject subject = new Subject();
LoginContext loginContext = new LoginContext(realm, subject, new CallbackHandler() {
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
for (int i = 0; i < callbacks.length; i++) {
if (callbacks[i] instanceof NameCallback) {
((NameCallback) callbacks[i]).setName(username);
} else if (callbacks[i] instanceof PasswordCallback) {
((PasswordCallback) callbacks[i]).setPassword(password.toCharArray());
} else {
throw new UnsupportedCallbackException(callbacks[i]);
}
}
}
});
loginContext.login();
boolean found = false;
main: for (String role : roles) {
if (role != null && role.length() > 0) {
for (Principal p : subject.getPrincipals()) {
if (role.equals(p.getName()) || p instanceof Group && isGroupMember((Group) p, role)) {
found = true;
break main;
}
}
}
}
if (!found) {
throw new FailedLoginException("User does not have any of the required roles: " + Arrays.asList(roles));
}
return subject;
} catch (AccountException e) {
LOGGER.debug("Account failure", e);
return null;
} catch (LoginException e) {
LOGGER.debug("Login failed", e);
return null;
}
}
use of javax.security.auth.login.AccountException in project tomee by apache.
the class ServiceListJAASAuthenticator method doAuthenticate.
public Subject doAuthenticate(final String username, final String password) {
try {
Subject subject = new Subject();
LoginContext loginContext = new LoginContext(realm, subject, new CallbackHandler() {
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
for (int i = 0; i < callbacks.length; i++) {
if (callbacks[i] instanceof NameCallback) {
((NameCallback) callbacks[i]).setName(username);
} else if (callbacks[i] instanceof PasswordCallback) {
((PasswordCallback) callbacks[i]).setPassword(password.toCharArray());
} else {
throw new UnsupportedCallbackException(callbacks[i]);
}
}
}
});
loginContext.login();
return subject;
} catch (FailedLoginException e) {
LOG.log(Level.FINE, "Login failed ", e);
return null;
} catch (AccountException e) {
LOG.log(Level.WARNING, "Account failure ", e);
return null;
} catch (GeneralSecurityException e) {
LOG.log(Level.SEVERE, "General Security Exception ", e);
return null;
}
}
Aggregations