use of javax.security.auth.callback.CallbackHandler in project drill by axbaretto.
the class PlainFactory method createSaslClient.
@Override
public SaslClient createSaslClient(final UserGroupInformation ugi, final Map<String, ?> properties) throws SaslException {
final String userName = (String) properties.get(DrillProperties.USER);
final String password = (String) properties.get(DrillProperties.PASSWORD);
return FastSaslClientFactory.getInstance().createSaslClient(new String[] { SIMPLE_NAME }, null, /**
* authorization ID
*/
null, null, properties, new CallbackHandler() {
@Override
public void handle(final Callback[] callbacks) throws IOException, UnsupportedCallbackException {
for (final Callback callback : callbacks) {
if (callback instanceof NameCallback) {
NameCallback.class.cast(callback).setName(userName);
continue;
}
if (callback instanceof PasswordCallback) {
PasswordCallback.class.cast(callback).setPassword(password.toCharArray());
continue;
}
throw new UnsupportedCallbackException(callback);
}
}
});
}
use of javax.security.auth.callback.CallbackHandler in project polymap4-core by Polymap4.
the class SpnegoProvider method getUsernamePasswordHandler.
/**
* Used by the BASIC Auth mechanism for establishing a LoginContext
* to authenticate a client/caller/request.
*
* @param username client username
* @param password client password
* @return CallbackHandler to be used for establishing a LoginContext
*/
public static CallbackHandler getUsernamePasswordHandler(final String username, final String password) {
LOGGER.fine("username=" + username + "; password=" + password.hashCode());
final CallbackHandler handler = new CallbackHandler() {
public void handle(final Callback[] callback) {
for (int i = 0; i < callback.length; i++) {
if (callback[i] instanceof NameCallback) {
final NameCallback nameCallback = (NameCallback) callback[i];
nameCallback.setName(username);
} else if (callback[i] instanceof PasswordCallback) {
final PasswordCallback passCallback = (PasswordCallback) callback[i];
passCallback.setPassword(password.toCharArray());
} else {
LOGGER.warning("Unsupported Callback i=" + i + "; class=" + callback[i].getClass().getName());
}
}
}
};
return handler;
}
use of javax.security.auth.callback.CallbackHandler in project activemq-artemis by apache.
the class GSSAPIServerSASL method processSASL.
@Override
public byte[] processSASL(byte[] bytes) {
try {
if (jaasId == null) {
// populate subject with acceptor private credentials
LoginContext loginContext = new LoginContext(loginConfigScope);
loginContext.login();
jaasId = loginContext.getSubject();
}
if (saslServer == null) {
saslServer = Subject.doAs(jaasId, (PrivilegedExceptionAction<SaslServer>) () -> Sasl.createSaslServer(NAME, null, null, new HashMap<String, String>(), new CallbackHandler() {
@Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
for (Callback callback : callbacks) {
if (callback instanceof AuthorizeCallback) {
AuthorizeCallback authorizeCallback = (AuthorizeCallback) callback;
// only ok to authenticate as self
authorizeCallback.setAuthorized(authorizeCallback.getAuthenticationID().equals(authorizeCallback.getAuthorizationID()));
}
}
}
}));
}
byte[] challenge = Subject.doAs(jaasId, (PrivilegedExceptionAction<byte[]>) () -> saslServer.evaluateResponse(bytes));
if (saslServer.isComplete()) {
result = new PrincipalSASLResult(true, new KerberosPrincipal(saslServer.getAuthorizationID()));
}
return challenge;
} catch (Exception outOfHere) {
log.info("Error on sasl input: " + outOfHere.toString(), outOfHere);
result = new PrincipalSASLResult(false, null);
}
return null;
}
use of javax.security.auth.callback.CallbackHandler in project atlas by apache.
the class SSLAndKerberosTest method loginTestUser.
protected Subject loginTestUser() throws LoginException, IOException {
LoginContext lc = new LoginContext(TEST_USER_JAAS_SECTION, new CallbackHandler() {
@Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
for (Callback callback : callbacks) {
if (callback instanceof PasswordCallback) {
PasswordCallback passwordCallback = (PasswordCallback) callback;
passwordCallback.setPassword(TESTPASS.toCharArray());
}
if (callback instanceof NameCallback) {
NameCallback nameCallback = (NameCallback) callback;
nameCallback.setName(TESTUSER);
}
}
}
});
// attempt authentication
lc.login();
return lc.getSubject();
}
use of javax.security.auth.callback.CallbackHandler in project atlas by apache.
the class AtlasAuthenticationKerberosFilterTest method loginTestUser.
protected Subject loginTestUser() throws LoginException, IOException {
LoginContext lc = new LoginContext(TEST_USER_JAAS_SECTION, new CallbackHandler() {
@Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
for (Callback callback : callbacks) {
if (callback instanceof PasswordCallback) {
PasswordCallback passwordCallback = (PasswordCallback) callback;
passwordCallback.setPassword(TESTPASS.toCharArray());
}
if (callback instanceof NameCallback) {
NameCallback nameCallback = (NameCallback) callback;
nameCallback.setName(TESTUSER);
}
}
}
});
// attempt authentication
lc.login();
return lc.getSubject();
}
Aggregations