use of org.apache.wss4j.common.ext.WSPasswordCallback in project cxf by apache.
the class RSSecurityUtils method getSignaturePassword.
public static String getSignaturePassword(Message message, String userName, Class<?> callingClass) throws WSSecurityException {
CallbackHandler handler = getCallbackHandler(message, callingClass);
if (handler == null) {
// See if we have a signature password we can use here instead
return (String) SecurityUtils.getSecurityPropertyValue(SecurityConstants.SIGNATURE_PASSWORD, message);
}
WSPasswordCallback[] cb = { new WSPasswordCallback(userName, WSPasswordCallback.SIGNATURE) };
try {
handler.handle(cb);
} catch (Exception e) {
return null;
}
// get the password
String password = cb[0].getPassword();
return password == null ? "" : password;
}
use of org.apache.wss4j.common.ext.WSPasswordCallback in project cxf by apache.
the class AbstractBindingBuilder method getPassword.
protected String getPassword(String userName, Assertion info, int usage) {
// Then try to get the password from the given callback handler
Object o = SecurityUtils.getSecurityPropertyValue(SecurityConstants.CALLBACK_HANDLER, message);
final CallbackHandler handler;
try {
handler = SecurityUtils.getCallbackHandler(o);
if (handler == null) {
// Don't unassert for signature as we might get the password from the crypto properties
if (usage == WSPasswordCallback.SIGNATURE) {
LOG.info("No CallbackHandler available to retrieve a password. We will now try the crypto " + "properties file for a private password");
} else {
unassertPolicy(info, "No callback handler and no password available");
}
return null;
}
} catch (Exception ex) {
// Don't unassert for signature as we might get the password from the crypto properties
if (usage == WSPasswordCallback.SIGNATURE) {
LOG.info("No CallbackHandler available to retrieve a password. We will now try the crypto " + "properties file for a private password");
} else {
unassertPolicy(info, "No callback handler and no password available");
}
return null;
}
WSPasswordCallback[] cb = { new WSPasswordCallback(userName, usage) };
try {
handler.handle(cb);
} catch (Exception e) {
unassertPolicy(info, e);
}
// get the password
return cb[0].getPassword();
}
use of org.apache.wss4j.common.ext.WSPasswordCallback in project cxf by apache.
the class AbstractTokenInterceptor method getPassword.
protected String getPassword(String userName, AbstractToken info, int usage, SoapMessage message) {
// Then try to get the password from the given callback handler
final CallbackHandler handler;
try {
Object o = SecurityUtils.getSecurityPropertyValue(SecurityConstants.CALLBACK_HANDLER, message);
handler = SecurityUtils.getCallbackHandler(o);
if (handler == null) {
policyNotAsserted(info, "No callback handler and no password available", message);
return null;
}
} catch (Exception ex) {
policyNotAsserted(info, "No callback handler and no password available", message);
return null;
}
WSPasswordCallback[] cb = { new WSPasswordCallback(userName, usage) };
try {
handler.handle(cb);
} catch (Exception e) {
policyNotAsserted(info, e, message);
}
// get the password
return cb[0].getPassword();
}
use of org.apache.wss4j.common.ext.WSPasswordCallback in project cxf by apache.
the class KeystorePasswordCallback method handle.
/**
* It attempts to get the password from the private
* alias/passwords map.
*/
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
for (int i = 0; i < callbacks.length; i++) {
WSPasswordCallback pc = (WSPasswordCallback) callbacks[i];
if (pc.getUsage() == WSPasswordCallback.PASSWORD_ENCRYPTOR_PASSWORD) {
pc.setPassword("this-is-a-secret");
} else {
String pass = passwords.get(pc.getIdentifier());
if (pass != null) {
pc.setPassword(pass);
return;
}
pc.setPassword("password");
}
}
}
use of org.apache.wss4j.common.ext.WSPasswordCallback in project cxf by apache.
the class TestPwdCallback method handle.
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
for (int i = 0; i < callbacks.length; i++) {
WSPasswordCallback pc = (WSPasswordCallback) callbacks[i];
String pass = passwords.get(pc.getIdentifier());
if (pass != null) {
pc.setPassword(pass);
}
}
}
Aggregations