本文整理汇总了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");
}
}