本文整理汇总了Java中org.apache.ws.security.WSPasswordCallback.USERNAME_TOKEN属性的典型用法代码示例。如果您正苦于以下问题:Java WSPasswordCallback.USERNAME_TOKEN属性的具体用法?Java WSPasswordCallback.USERNAME_TOKEN怎么用?Java WSPasswordCallback.USERNAME_TOKEN使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.apache.ws.security.WSPasswordCallback
的用法示例。
在下文中一共展示了WSPasswordCallback.USERNAME_TOKEN属性的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handle
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");
}
}
}
示例2: handle
@Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
log.info("handle({})", callbacks);
WSPasswordCallback pwdCallback = (WSPasswordCallback) callbacks[0];
log.debug("identifier: " + pwdCallback.getIdentifier());
log.debug("usage: " + pwdCallback.getUsage());
int usage = pwdCallback.getUsage();
if (usage == WSPasswordCallback.USERNAME_TOKEN) {
String password = pwdCallback.getPassword();
Authentication authentication = new UsernamePasswordAuthenticationToken(pwdCallback.getIdentifier(), password);
authentication = authenticationManager.authenticate(authentication);
SecurityContextHolder.getContext().setAuthentication(authentication);
// Return the password to the caller
pwdCallback.setPassword(password);
}
}
示例3: constructPasswordCallback
private WSPasswordCallback constructPasswordCallback(
String username,
int doAction
) throws WSSecurityException {
int reason = WSPasswordCallback.UNKNOWN;
switch (doAction) {
case WSConstants.UT:
case WSConstants.UT_SIGN:
reason = WSPasswordCallback.USERNAME_TOKEN;
break;
case WSConstants.SIGN:
reason = WSPasswordCallback.SIGNATURE;
break;
case WSConstants.ENCR:
reason = WSPasswordCallback.KEY_NAME;
break;
}
return new WSPasswordCallback(username, reason);
}
示例4: handle
public void handle(Callback[] callbacks)
throws IOException, UnsupportedCallbackException {
for (int i = 0; i < callbacks.length; i++) {
if (callbacks[i] instanceof WSPasswordCallback) {
WSPasswordCallback pc = (WSPasswordCallback) callbacks[i];
if (pc.getUsage() == WSPasswordCallback.USERNAME_TOKEN
&& "alice".equals(pc.getIdentifier())) {
pc.setPassword("verySecret");
} else if (pc.getUsage() == WSPasswordCallback.SIGNATURE
&& "wss86".equals(pc.getIdentifier())) {
pc.setPassword("security");
} else {
throw new IOException("Authentication failed");
}
} else {
throw new UnsupportedCallbackException(callbacks[i], "Unrecognized Callback");
}
}
}
示例5: handle
public void handle(Callback[] callbacks) throws IOException,
UnsupportedCallbackException {
for (int i = 0; i < callbacks.length; i++) {
if (callbacks[i] instanceof WSPasswordCallback) {
WSPasswordCallback pc = (WSPasswordCallback) callbacks[i];
if (pc.getUsage() == WSPasswordCallback.USERNAME_TOKEN) {
pc.setPassword("Sri Lanka Sri Lanka UOM ");
} else if (pc.getUsage() == WSPasswordCallback.DECRYPT) {
pc.setKey("Sri Lanka Sri Lanka UOM ".getBytes());
}
} else {
throw new UnsupportedCallbackException(callbacks[i],
"Unrecognized Callback");
}
}
}
示例6: handle
public void handle(Callback[] callbacks)
throws IOException, UnsupportedCallbackException {
for (int i = 0; i < callbacks.length; i++) {
if (callbacks[i] instanceof WSPasswordCallback) {
WSPasswordCallback pc = (WSPasswordCallback) callbacks[i];
if (pc.getUsage() == WSPasswordCallback.USERNAME_TOKEN_UNKNOWN
&& "bob".equals(pc.getIdentifier())) {
pc.setPassword("security");
} else if (pc.getUsage() == WSPasswordCallback.USERNAME_TOKEN
&& "bob".equals(pc.getIdentifier())) {
pc.setPassword("security");
} else {
throw new IOException("Authentication failed");
}
} else {
throw new UnsupportedCallbackException(callbacks[i], "Unrecognized Callback");
}
}
}
示例7: getPassword
public WSPasswordCallback getPassword(final String username,
final int doAction, final String clsProp, final String refProp,
final RequestData reqData) throws WSSecurityException {
final UsernamePasswordCredentials c = (UsernamePasswordCredentials) this.credentialsSource
.getCredentials(this.serviceConfiguration.getEndpointUrl().toString());
return new WSPasswordCallback(c.getUsername(), c.getPassword(), null,
WSPasswordCallback.USERNAME_TOKEN);
}
示例8: handle
public void handle(Callback[] callbacks)
throws IOException, UnsupportedCallbackException {
for (int i = 0; i < callbacks.length; i++) {
if (callbacks[i] instanceof WSPasswordCallback) {
WSPasswordCallback pc = (WSPasswordCallback) callbacks[i];
boolean passwordsAreEncoded = WSSecurityEngine.getInstance().getWssConfig().getPasswordsAreEncoded();
if (pc.getUsage() == WSPasswordCallback.USERNAME_TOKEN
&& "wernerd".equals(pc.getIdentifier())) {
if (passwordsAreEncoded) {
// "hGqoUreBgahTJblQ3DbJIkE6uNs=" is the Base64 encoded SHA-1 hash of "verySecret".
pc.setPassword("hGqoUreBgahTJblQ3DbJIkE6uNs=");
} else {
pc.setPassword("verySecret");
}
} else if (pc.getUsage() == WSPasswordCallback.USERNAME_TOKEN
&& "emptyuser".equals(pc.getIdentifier())) {
pc.setPassword("");
}
else if (
pc.getUsage() == WSPasswordCallback.USERNAME_TOKEN_UNKNOWN
) {
if ("wernerd".equals(pc.getIdentifier())
&& "verySecret".equals(pc.getPassword())) {
return;
} else if ("customUser".equals(pc.getIdentifier())) {
return;
} else if ("wernerd".equals(pc.getIdentifier())
&& "".equals(pc.getPassword())) {
return;
} else {
throw new IOException("Authentication failed");
}
}
} else {
throw new UnsupportedCallbackException(callbacks[i], "Unrecognized Callback");
}
}
}
示例9: handle
public void handle(Callback[] callbacks) throws IOException,
UnsupportedCallbackException {
for (Callback callback : callbacks) {
WSPasswordCallback pc = (WSPasswordCallback) callback;
if (pc.getUsage() == WSPasswordCallback.USERNAME_TOKEN) {
//you can source the username and password from
//other sources like login context, LDAP, DB etc
pc.setIdentifier(_username);
pc.setPassword(_password);
}
}
}