本文整理匯總了Java中javax.security.auth.callback.CallbackHandler.handle方法的典型用法代碼示例。如果您正苦於以下問題:Java CallbackHandler.handle方法的具體用法?Java CallbackHandler.handle怎麽用?Java CallbackHandler.handle使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.security.auth.callback.CallbackHandler
的用法示例。
在下文中一共展示了CallbackHandler.handle方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: openSession
import javax.security.auth.callback.CallbackHandler; //導入方法依賴的package包/類
@Override
public ExchangeSession openSession(ExchangeLogin login) {
ApiKeyCallback apiKey = new ApiKeyCallback();
ApiSecretCallback apiSecret = new ApiSecretCallback();
PasswordCallback password = new PasswordCallback("GDAX passphrase", false);
Callback[] callbacks = new Callback[]{
apiKey,
apiSecret,
password
};
CallbackHandler callbackHandler = login.getCallbackHandler();
try {
callbackHandler.handle(callbacks);
} catch (IOException | UnsupportedCallbackException e) {
throw new RuntimeException(e);
}
String apiKeyTxt = apiKey.getApiKey();
char[] passphrase = password.getPassword();
SecretKeySpec keySpec = new SecretKeySpec(apiSecret.getSecretData(), "HmacSHA256");
return new GdaxExchangeSession(this, apiKeyTxt, keySpec, passphrase);
}
示例2: initialize
import javax.security.auth.callback.CallbackHandler; //導入方法依賴的package包/類
public void initialize(Subject subject, CallbackHandler callbackHandler, Map<String, ?> sharedState,
Map<String, ?> options) {
try {
NameCallback nameCallback = new NameCallback("prompt");
PasswordCallback passwordCallback = new PasswordCallback("prompt", false);
callbackHandler.handle(new Callback[] { nameCallback, passwordCallback });
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例3: login
import javax.security.auth.callback.CallbackHandler; //導入方法依賴的package包/類
@Override
protected List<Principal> login(final Subject subject, final CallbackHandler callbackHandler,
final Map<String, ?> sharedState, final Map<String, ?> options) throws LoginException {
// Retrieve username and password
if (callbackHandler == null) {
throw new LoginException("Could not retrieve credentials: no callback handler");
}
final Callback[] callbacks = new Callback[2];
callbacks[0] = new NameCallback("username");
callbacks[1] = new PasswordCallback("password", false);
final String username;
final char[] password;
try {
callbackHandler.handle(callbacks);
username = ((NameCallback) callbacks[0]).getName();
final char[] tmpPassword = ((PasswordCallback) callbacks[1]).getPassword();
password = new char[tmpPassword.length];
System.arraycopy(tmpPassword, 0,
password, 0, tmpPassword.length);
((PasswordCallback) callbacks[1]).clearPassword();
} catch (final UnsupportedCallbackException | IOException e) {
final LoginException le = new LoginException("Could not retrieve credentials");
le.initCause(e);
throw le;
}
// Validate username and password
final Properties properties = loadProperties(options);
if (validateCredentials(properties, username, password)) {
final Principal userPrincipal = new JMXPrincipal(username);
return Collections.singletonList(userPrincipal);
} else {
throw new FailedLoginException("Invalid credentials");
}
}