本文整理汇总了Java中javax.security.auth.callback.UnsupportedCallbackException类的典型用法代码示例。如果您正苦于以下问题:Java UnsupportedCallbackException类的具体用法?Java UnsupportedCallbackException怎么用?Java UnsupportedCallbackException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UnsupportedCallbackException类属于javax.security.auth.callback包,在下文中一共展示了UnsupportedCallbackException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleUsernameTokenPrincipal
import javax.security.auth.callback.UnsupportedCallbackException; //导入依赖的package包/类
@Override
protected void handleUsernameTokenPrincipal(UsernameTokenPrincipalCallback callback) throws IOException,
UnsupportedCallbackException {
UserDetails user = loadUserDetails(callback.getPrincipal().getName());
WSUsernameTokenPrincipal principal = callback.getPrincipal();
UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken(
principal, principal.getPassword(), user.getAuthorities());
if (logger.isDebugEnabled()) {
logger.debug("Authentication success: " + authRequest.toString());
}
SecurityContextHolder.getContext().setAuthentication(authRequest);
if (user instanceof IUser) {
HttpSession session=ContextHolder.getHttpSession();
session.setAttribute(ContextHolder.LOGIN_USER_SESSION_KEY, user);
session.setAttribute(ContextHolder.USER_LOGIN_WAY_KEY,IWebservice.WS_LOGIN_WAY);
}
}
示例2: handle
import javax.security.auth.callback.UnsupportedCallbackException; //导入依赖的package包/类
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
WSPasswordCallback pwcb = (WSPasswordCallback) callbacks[0];
String id = pwcb.getIdentifier();
int usage = pwcb.getUsage();
if (usage == WSPasswordCallback.USERNAME_TOKEN) {
if ("admin".equals(id)) {
pwcb.setPassword("admin");
} else if ("[email protected]".equals(id)) {
pwcb.setPassword("admin123");
}
} else if (usage == WSPasswordCallback.SIGNATURE || usage == WSPasswordCallback.DECRYPT) {
if ("wso2carbon".equals(id)) {
pwcb.setPassword("wso2carbon");
}
}
}
示例3: handle
import javax.security.auth.callback.UnsupportedCallbackException; //导入依赖的package包/类
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
for (Callback c: callbacks) {
if (c instanceof NameCallback) {
((NameCallback) c).setName(username);
} else if (c instanceof PasswordCallback) {
((PasswordCallback) c).setPassword(password.toCharArray());
}
else if (c instanceof KeyChoiceCallback) {
KeyChoiceCallback kcc = (KeyChoiceCallback)c;
try {
int idx = kcc.lookupKey(key);
kcc.setSelectedIndex(idx);
}
catch (IllegalArgumentException e) {
throw new MissingCredsException(kcc);
}
}
else {
throw new UnsupportedCallbackException(c);
}
}
}
示例4: handle
import javax.security.auth.callback.UnsupportedCallbackException; //导入依赖的package包/类
public void handle(Callback[] callbacks)
throws UnsupportedCallbackException {
boolean didSetName = false;
boolean didSetPassword = false;
for (Callback cb : callbacks)
if (cb instanceof NameCallback) {
((NameCallback) cb).setName(u);
didSetName = true;
} else if (cb instanceof PasswordCallback) {
((PasswordCallback) cb).setPassword(p);
didSetPassword = true;
} else {
throw new UnsupportedCallbackException(cb,
"Unsupported Callback type: "
+ cb.getClass().getName());
}
if (!didSetName)
throw new IllegalStateException(
"Supplied Callbacks does not include a NameCallback");
if (!didSetPassword)
throw new IllegalStateException("Supplied Callbacks "
+ "does not include a PasswordCallback");
}
示例5: handle
import javax.security.auth.callback.UnsupportedCallbackException; //导入依赖的package包/类
@Override
public void handle(final Callback[] callbacks) throws UnsupportedCallbackException {
Arrays.stream(callbacks).filter(callback -> {
if (callback.getClass().equals(NameCallback.class)) {
((NameCallback) callback).setName(this.userName);
return false;
}
if (callback.getClass().equals(PasswordCallback.class)) {
((PasswordCallback) callback).setPassword(this.password.toCharArray());
return false;
}
return true;
}).findFirst().ifPresent(callback -> {
throw new RuntimeException(new UnsupportedCallbackException(callback, "Unrecognized Callback"));
});
}
示例6: process
import javax.security.auth.callback.UnsupportedCallbackException; //导入依赖的package包/类
@Override
protected Document process(Document document) throws WSSecurityException {
WSSecurityEngine secEngine = new WSSecurityEngine();
WSHandlerResult results = secEngine.processSecurityHeader(document, null,
new CallbackHandler() {
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
for (Callback callback : callbacks) {
if (callback instanceof WSPasswordCallback) {
((WSPasswordCallback)callback).setPassword(getCertPassword());
}
}
}
}, getCrypto());
return document;
}
示例7: handle
import javax.security.auth.callback.UnsupportedCallbackException; //导入依赖的package包/类
@Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
if (callbacks != null) {
for (Callback callback : callbacks) {
if (callback instanceof NameCallback) {
((NameCallback) callback).setName(username);
} else if (callback instanceof PasswordCallback) {
((PasswordCallback) callback).setPassword(password);
} else {
throw new UnsupportedCallbackException(callback);
}
}
clearCredentials();
}
}
示例8: handle
import javax.security.auth.callback.UnsupportedCallbackException; //导入依赖的package包/类
/**
* Retrieve or display the information requested in the provided Callbacks.
*
* @param callbacks
* an array of <code>Callback</code> objects provided by an
* underlying security service which contains the information
* requested to be retrieved or displayed.
*
* @throws IOException
* if an input or output error occurs.
*
* @throws UnsupportedCallbackException
* if the implementation of this method does not support one or
* more of the Callbacks specified in the <code>callbacks</code>
* parameter.
*/
@Override
public void handle(Callback[] callbacks) throws IOException,
UnsupportedCallbackException {
for (Callback callback : callbacks) {
if (callback instanceof NameCallback) {
((NameCallback) callback).setName(wsProxyInfo
.getUserCredentials().getUser());
} else if (callback instanceof PasswordCallback) {
((PasswordCallback) callback).setPassword(wsProxyInfo
.getUserCredentials().getPassword().toCharArray());
} else {
throw new UnsupportedCallbackException(callback,
"Unrecognized Callback");
}
}
}
示例9: handle
import javax.security.auth.callback.UnsupportedCallbackException; //导入依赖的package包/类
public void handle(Callback[] callbacks)
throws IOException, UnsupportedCallbackException {
System.out.println("Callback Handler - handle called");
for (int i = 0; i < callbacks.length; i++) {
if (callbacks[i] instanceof NameCallback) {
NameCallback nameCallback = (NameCallback) callbacks[i];
nameCallback.setName(name);
} else if (callbacks[i] instanceof PasswordCallback) {
PasswordCallback passwordCallback = (PasswordCallback) callbacks[i];
passwordCallback.setPassword(password.toCharArray());
} else {
throw new UnsupportedCallbackException(callbacks[i],
"The submitted Callback is unsupported");
}
}
}
示例10: createSaslClient
import javax.security.auth.callback.UnsupportedCallbackException; //导入依赖的package包/类
static SaslClient createSaslClient(final String user, final String password) throws SaslException {
return Sasl.createSaslClient(new String[]{"PLAIN"}, user, null, null, null,
new CallbackHandler() {
@Override
public void handle(final Callback[] callbacks)
throws IOException, UnsupportedCallbackException {
for (final Callback callback : callbacks) {
if (callback instanceof PasswordCallback) {
((PasswordCallback) callback).setPassword(password.toCharArray());
} else if (callback instanceof NameCallback) {
((NameCallback) callback).setName(user);
}
}
}
});
}
示例11: handle
import javax.security.auth.callback.UnsupportedCallbackException; //导入依赖的package包/类
public void handle(Callback[] callbacks) throws IOException,
UnsupportedCallbackException {
for (Callback callback : callbacks) {
if (callback instanceof NameCallback) {
NameCallback ncb = (NameCallback) callback;
ncb.setName(username);
} else if (callback instanceof PasswordCallback) {
PasswordCallback pwcb = (PasswordCallback) callback;
pwcb.setPassword(password.toCharArray());
} else {
throw new UnsupportedCallbackException(
callback,
"We got a "
+ callback.getClass().getCanonicalName()
+ ", but only NameCallback and PasswordCallback is supported");
}
}
}
示例12: handle
import javax.security.auth.callback.UnsupportedCallbackException; //导入依赖的package包/类
public void handle(Callback[] callbacks) throws
UnsupportedCallbackException, IOException {
for (int i=0; i<callbacks.length; i++) {
Callback callBack = callbacks[i];
if (callBack instanceof NameCallback) {
getAnswer();
((NameCallback)callBack).setName(username);
} else if (callBack instanceof PasswordCallback) {
getAnswer();
((PasswordCallback)callBack).setPassword(password);
if (password != null) Arrays.fill(password, ' ');
} else {
throw new UnsupportedCallbackException(callBack,
"Call back not supported");
}
}
}
示例13: handle
import javax.security.auth.callback.UnsupportedCallbackException; //导入依赖的package包/类
/**
* Retrieve the information requested in the provided Callbacks. This
* implementation only recognizes <code>NameCallback</code> and
* <code>PasswordCallback</code> instances.
*
* @param callbacks The set of callbacks to be processed
*
* @exception IOException if an input/output error occurs
* @exception UnsupportedCallbackException if the login method requests
* an unsupported callback type
*/
public void handle(Callback callbacks[])
throws IOException, UnsupportedCallbackException {
for (int i = 0; i < callbacks.length; i++) {
if (callbacks[i] instanceof NameCallback) {
if (realm.getDebug() >= 3)
realm.log("Returning username " + username);
((NameCallback) callbacks[i]).setName(username);
} else if (callbacks[i] instanceof PasswordCallback) {
if (realm.getDebug() >= 3)
realm.log("Returning password " + password);
((PasswordCallback) callbacks[i]).setPassword
(password.toCharArray());
} else {
throw new UnsupportedCallbackException(callbacks[i]);
}
}
}
示例14: openSession
import javax.security.auth.callback.UnsupportedCallbackException; //导入依赖的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);
}
示例15: getCallbackHandler
import javax.security.auth.callback.UnsupportedCallbackException; //导入依赖的package包/类
@Override
public CallbackHandler getCallbackHandler() {
return callbacks -> {
for (Callback cb : callbacks) {
if (cb instanceof ApiKeyCallback) {
((ApiKeyCallback) cb).setApiKey(apiKey);
} else if (cb instanceof ApiSecretCallback) {
((ApiSecretCallback) cb).setSecretData(apiSecret);
} else if (cb instanceof PasswordCallback) {
((PasswordCallback) cb).setPassword(passphrase);
} else {
throw new UnsupportedCallbackException(cb);
}
}
};
}