use of javax.security.auth.callback.Callback in project jdk8u_jdk by JetBrains.
the class CleanState method go.
void go() throws Exception {
Krb5LoginModule krb5 = new Krb5LoginModule();
final String name = OneKDC.USER;
final char[] password = OneKDC.PASS;
char[] badpassword = "hellokitty".toCharArray();
Map<String, String> map = new HashMap<>();
map.put("useTicketCache", "false");
map.put("doNotPrompt", "false");
map.put("tryFirstPass", "true");
Map<String, Object> shared = new HashMap<>();
shared.put("javax.security.auth.login.name", name);
shared.put("javax.security.auth.login.password", badpassword);
krb5.initialize(new Subject(), new CallbackHandler() {
@Override
public void handle(Callback[] callbacks) {
for (Callback callback : callbacks) {
if (callback instanceof NameCallback) {
((NameCallback) callback).setName(name);
}
if (callback instanceof PasswordCallback) {
((PasswordCallback) callback).setPassword(password);
}
}
}
}, shared, map);
krb5.login();
}
use of javax.security.auth.callback.Callback in project wildfly by wildfly.
the class TrustedIdentityTokenLoginModule method login.
@Override
@SuppressWarnings("unchecked")
public boolean login() throws LoginException {
// See if shared credentials exist
if (super.login() == true) {
// Setup our view of the user
Object username = sharedState.get("javax.security.auth.login.name");
if (username instanceof Principal)
identity = (Principal) username;
else {
String name = username.toString();
try {
identity = createIdentity(name);
} catch (Exception e) {
LoginException le = new LoginException();
le.initCause(e);
throw le;
}
}
return true;
}
super.loginOk = false;
if (callbackHandler == null) {
throw new LoginException();
}
SecurityAssociationCallback callback = new SecurityAssociationCallback();
Callback[] callbacks = { callback };
final String username;
try {
callbackHandler.handle(callbacks);
username = callback.getPrincipal().getName();
final Object c = callback.getCredential();
if (c instanceof SASCurrent) {
credential = (SASCurrent) c;
} else {
return false;
}
} catch (IOException e) {
LoginException le = new LoginException();
le.initCause(e);
throw le;
} catch (UnsupportedCallbackException e) {
LoginException le = new LoginException();
le.initCause(e);
throw le;
}
validateCredential(username, credential);
if (username == null) {
return false;
}
if (identity == null) {
try {
identity = createIdentity(username);
} catch (Exception e) {
LoginException le = new LoginException();
le.initCause(e);
throw le;
}
}
if (getUseFirstPass() == true) {
// Add the principal to the shared state map
sharedState.put("javax.security.auth.login.name", identity);
sharedState.put("javax.security.auth.login.password", credential);
}
super.loginOk = true;
return true;
}
use of javax.security.auth.callback.Callback in project wildfly by wildfly.
the class DefaultApplicationClientCallbackHandler method handle.
@Override
public void handle(final Callback[] callbacks) throws IOException, UnsupportedCallbackException {
final SecurityContext context = doPrivileged(SECURITY_CONTEXT);
for (final Callback current : callbacks) {
if (current instanceof NameCallback) {
final NameCallback ncb = (NameCallback) current;
if (context != null) {
final Set<Identity> identities = getSubjectInfo(context).getIdentities();
if (identities.isEmpty()) {
ncb.setName(DOLLAR_LOCAL);
} else {
final Identity identity = identities.iterator().next();
ncb.setName(identity.getName());
}
} else {
ncb.setName(DOLLAR_LOCAL);
}
} else if (current instanceof PasswordCallback) {
if (context != null) {
final PasswordCallback pcb = (PasswordCallback) current;
final Set<Identity> identities = getSubjectInfo(context).getIdentities();
if (identities.isEmpty()) {
throw new UnsupportedCallbackException(current);
} else {
final Identity identity = identities.iterator().next();
if (identity instanceof CredentialIdentity) {
pcb.setPassword((char[]) ((CredentialIdentity) identity).getCredential());
} else {
throw new UnsupportedCallbackException(current);
}
}
}
} else if (current instanceof RealmCallback) {
final RealmCallback realmCallback = (RealmCallback) current;
if (realmCallback.getText() == null) {
realmCallback.setText(realmCallback.getDefaultText());
}
}
}
}
use of javax.security.auth.callback.Callback in project adempiere by adempiere.
the class EMailOAuth2SaslClient method evaluateChallenge.
@Override
public byte[] evaluateChallenge(byte[] challenge) throws SaslException {
if (isComplete) {
return new byte[] {};
}
NameCallback nameCallback = new NameCallback("Enter name");
Callback[] callbacks = new Callback[] { nameCallback };
try {
callback.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, token).getBytes();
isComplete = true;
return response;
}
use of javax.security.auth.callback.Callback in project zm-mailbox by Zimbra.
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 username = nameCallback.getName();
byte[] response = String.format("user=%s\1auth=Bearer %s\1\1", username, oauthToken).getBytes();
isComplete = true;
return response;
}
Aggregations