use of org.apache.wss4j.common.ext.WSPasswordCallback in project tesb-rt-se by Talend.
the class PasswordCallbackHandlerTest method testPasswordCallbackHandlerNotCorrectIdentifier.
@Test
public void testPasswordCallbackHandlerNotCorrectIdentifier() throws Exception {
PasswordCallbackHandler handler = new PasswordCallbackHandler();
List<Callback> callbacksList = new ArrayList<Callback>();
WSPasswordCallback callback = new WSPasswordCallback("id", 0);
callback.setIdentifier("notMystskey");
callbacksList.add(callback);
handler.handle(callbacksList.toArray(new Callback[callbacksList.size()]));
Assert.assertNull(callback.getPassword());
}
use of org.apache.wss4j.common.ext.WSPasswordCallback in project tesb-rt-se by Talend.
the class PasswordCallbackHandlerTest method testPasswordCallbackHandler.
@Test
public void testPasswordCallbackHandler() throws Exception {
PasswordCallbackHandler handler = new PasswordCallbackHandler();
List<Callback> callbacksList = new ArrayList<Callback>();
WSPasswordCallback callback = new WSPasswordCallback("id", 0);
callback.setIdentifier("mystskey");
callbacksList.add(callback);
handler.handle(callbacksList.toArray(new Callback[callbacksList.size()]));
assertSame("stskpass", callback.getPassword());
}
use of org.apache.wss4j.common.ext.WSPasswordCallback in project tesb-rt-se by Talend.
the class PasswordCallbackHandlerTest method testPasswordCallbackHandlerNotCorrectIdentifier.
@Test
public void testPasswordCallbackHandlerNotCorrectIdentifier() throws Exception {
PasswordCallbackHandler handler = new PasswordCallbackHandler();
List<Callback> callbacksList = new ArrayList<Callback>();
WSPasswordCallback callback = new WSPasswordCallback("id", 0);
callback.setIdentifier("notMystskey");
callbacksList.add(callback);
handler.handle(callbacksList.toArray(new Callback[callbacksList.size()]));
Assert.assertNull(callback.getPassword());
}
use of org.apache.wss4j.common.ext.WSPasswordCallback in project tesb-rt-se by Talend.
the class SAMClientSecurityProvider method init.
@PostConstruct
public void init() {
final EsbSecurityConstants esbSecurity = EsbSecurityConstants.fromString(authenticationType);
if (EsbSecurityConstants.NO == esbSecurity) {
return;
}
Bus bus = client.getBus();
List<Policy> policies = new ArrayList<Policy>();
WSPolicyFeature policyFeature = new WSPolicyFeature();
policyFeature.setPolicies(policies);
Map<String, Object> properties = client.getRequestContext();
if (null == properties) {
properties = new HashMap<String, Object>();
}
if (EsbSecurityConstants.BASIC == esbSecurity) {
AuthorizationPolicy authzPolicy = new AuthorizationPolicy();
authzPolicy.setUserName(username);
authzPolicy.setPassword(password);
authzPolicy.setAuthorizationType(HttpAuthHeader.AUTH_TYPE_BASIC);
HTTPConduit conduit = (HTTPConduit) client.getConduit();
conduit.setAuthorization(authzPolicy);
} else if (EsbSecurityConstants.USERNAMETOKEN == esbSecurity) {
policies.add(loadPolicy(policyUsernameToken, bus));
java.util.Map<String, Object> wssProps = new java.util.HashMap<String, Object>();
wssProps.put(ConfigurationConstants.ACTION, ConfigurationConstants.USERNAME_TOKEN);
wssProps.put(ConfigurationConstants.USER, username);
wssProps.put(ConfigurationConstants.PASSWORD_TYPE, WSS4JConstants.PW_TEXT);
wssProps.put(ConfigurationConstants.PW_CALLBACK_REF, new CallbackHandler() {
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
((WSPasswordCallback) callbacks[0]).setPassword(password);
}
});
client.getEndpoint().getOutInterceptors().add(new WSS4JOutInterceptor(wssProps));
client.getRequestContext().put("security.username", username);
client.getRequestContext().put("security.password", password);
} else if (EsbSecurityConstants.SAML == esbSecurity) {
policies.add(loadPolicy(policySaml, bus));
properties.put(SecurityConstants.SIGNATURE_PROPERTIES, processFileURI(getSignatureProperties()));
properties.put(SecurityConstants.SIGNATURE_USERNAME, getSignatureUsername());
properties.put(ENDPOINT_SIGNATURE_PASSWORD, getSignaturePassword());
properties.put(SecurityConstants.CALLBACK_HANDLER, new WSPasswordCallbackHandler(getSignatureUsername(), getSignaturePassword()));
// STS client
STSClient stsClient = new STSClient(bus);
stsClient.setWsdlLocation(stsWsdlLocation);
stsClient.setServiceQName(new QName(stsNamespace, stsServiceName));
stsClient.setEndpointQName(new QName(stsNamespace, stsEndpointName));
Map<String, Object> stsProperties = new HashMap<String, Object>();
stsProperties.put(SecurityConstants.USERNAME, username);
stsProperties.put(SecurityConstants.PASSWORD, password);
stsProperties.put(SecurityConstants.CALLBACK_HANDLER, new WSPasswordCallbackHandler(username, password));
stsProperties.put(SecurityConstants.STS_TOKEN_PROPERTIES, processFileURI(getSignatureProperties()));
stsProperties.put(SecurityConstants.STS_TOKEN_USERNAME, signatureUsername);
stsProperties.put(SecurityConstants.STS_TOKEN_USE_CERT_FOR_KEYINFO, stsTokenUsecert);
stsProperties.put(SecurityConstants.ENCRYPT_PROPERTIES, processFileURI(getSignatureProperties()));
stsProperties.put(SecurityConstants.ENCRYPT_USERNAME, encryptionUsername);
stsProperties.put(SecurityConstants.IS_BSP_COMPLIANT, isBspCompliant);
stsClient.setProperties(stsProperties);
properties.put(SecurityConstants.STS_CLIENT, stsClient);
}
client.getEndpoint().getActiveFeatures().add(policyFeature);
policyFeature.initialize(client, bus);
}
use of org.apache.wss4j.common.ext.WSPasswordCallback in project jbossws-cxf by jbossws.
the class PasswordCallbackHandler 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++) {
final Callback c = callbacks[i];
if (c != null && c instanceof WSPasswordCallback) {
final WSPasswordCallback pc = (WSPasswordCallback) c;
String pass = passwords.get(pc.getIdentifier());
if (pass != null) {
pc.setPassword(pass);
return;
}
}
}
}
Aggregations