use of javax.security.auth.callback.UnsupportedCallbackException in project midpoint by Evolveum.
the class PasswordCallback method handle.
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
LOGGER.trace("Invoked PasswordCallback with {} callbacks: {}", callbacks.length, callbacks);
WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];
String username = pc.getIdentifier();
String wssPasswordType = pc.getType();
LOGGER.trace("Username: '{}', Password type: {}", username, wssPasswordType);
try {
ConnectionEnvironment connEnv = ConnectionEnvironment.create(SchemaConstants.CHANNEL_WEB_SERVICE_URI);
pc.setPassword(passwordAuthenticationEvaluatorImpl.getAndCheckUserPassword(connEnv, username));
} catch (Exception e) {
LOGGER.trace("Exception in password callback: {}: {}", e.getClass().getSimpleName(), e.getMessage(), e);
throw new PasswordCallbackException("Authentication failed");
}
}
use of javax.security.auth.callback.UnsupportedCallbackException in project AuthMeReloaded by AuthMe.
the class OAuth2SaslClient method evaluateChallenge.
public byte[] evaluateChallenge(byte[] challenge) throws SaslException {
if (isComplete) {
// Empty final response from server, just ignore it.
return new byte[] {};
}
NameCallback nameCallback = new NameCallback("Enter name");
Callback[] callbacks = new Callback[] { nameCallback };
try {
callbackHandler.handle(callbacks);
} catch (UnsupportedCallbackException e) {
throw new SaslException("Unsupported callback: " + e);
} catch (IOException e) {
throw new SaslException("Failed to execute callback: " + e);
}
String email = nameCallback.getName();
byte[] response = String.format("user=%s\1auth=Bearer %s\1\1", email, oauthToken).getBytes();
isComplete = true;
return response;
}
use of javax.security.auth.callback.UnsupportedCallbackException in project OpenAM by OpenRock.
the class Anonymous method sendCallback.
private String sendCallback() throws AuthLoginException {
if (callbackHandler == null) {
throw new AuthLoginException(amAuthAnonymous, "NoCallbackHandler", null);
}
String username = null;
try {
Callback[] callbacks = new Callback[2];
String header = bundle.getString("moduleHeader");
PagePropertiesCallback ppc = new PagePropertiesCallback(null, header, null, 0, null, false, null);
callbacks[0] = ppc;
callbacks[1] = new NameCallback(bundle.getString("username"));
if (debug.messageEnabled()) {
debug.message("Callback 0 is.. :" + callbacks[0]);
debug.message("Callback 1 is.. :" + callbacks[1]);
}
callbackHandler.handle(callbacks);
username = ((NameCallback) callbacks[1]).getName();
return username;
} catch (IllegalArgumentException ill) {
debug.message("message type missing");
throw new AuthLoginException(amAuthAnonymous, "IllegalArgs", null);
} catch (java.io.IOException ioe) {
throw new AuthLoginException(ioe);
} catch (UnsupportedCallbackException uce) {
throw new AuthLoginException(amAuthAnonymous, "NoCallbackHandler", null);
}
}
use of javax.security.auth.callback.UnsupportedCallbackException in project jdk8u_jdk by JetBrains.
the class AuthRealmChoices method main.
public static void main(String[] args) throws Exception {
Map props = new HashMap();
props.put("com.sun.security.sasl.digest.realm", "IMC.ORG foo.bar machineX");
SaslClient clnt = Sasl.createSaslClient(new String[] { MECH }, null, PROTOCOL, SERVER_FQDN, null, new CallbackHandler() {
@Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
for (Callback cb : callbacks) {
if (cb instanceof RealmChoiceCallback) {
// 2. No index set at all
if (args[0].equals("1")) {
((RealmChoiceCallback) cb).setSelectedIndex(10);
}
}
}
}
});
SaslServer srv = Sasl.createSaslServer(MECH, PROTOCOL, SERVER_FQDN, props, new CallbackHandler() {
@Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
for (Callback cb : callbacks) {
System.out.println(cb);
}
}
});
byte[] challenge = srv.evaluateResponse(EMPTY);
try {
clnt.evaluateChallenge(challenge);
throw new Exception();
} catch (SaslException se) {
System.out.println(se);
}
}
use of javax.security.auth.callback.UnsupportedCallbackException in project jdk8u_jdk by JetBrains.
the class SampleCallbackHandler method handle.
public void handle(Callback[] callbacks) throws java.io.IOException, UnsupportedCallbackException {
for (int i = 0; i < callbacks.length; i++) {
if (callbacks[i] instanceof NameCallback) {
NameCallback cb = (NameCallback) callbacks[i];
cb.setName(getInput(cb.getPrompt()));
} else if (callbacks[i] instanceof PasswordCallback) {
PasswordCallback cb = (PasswordCallback) callbacks[i];
String pw = getInput(cb.getPrompt());
char[] passwd = new char[pw.length()];
pw.getChars(0, passwd.length, passwd, 0);
cb.setPassword(passwd);
} else if (callbacks[i] instanceof RealmCallback) {
RealmCallback cb = (RealmCallback) callbacks[i];
cb.setText(getInput(cb.getPrompt()));
} else {
throw new UnsupportedCallbackException(callbacks[i]);
}
}
}
Aggregations