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;
}
}
}
}
use of org.apache.wss4j.common.ext.WSPasswordCallback in project jbossws-cxf by jbossws.
the class UsernamePasswordCallback method handle.
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];
final String id = pc.getIdentifier();
if ("kermit".equals(id))
pc.setPassword("thefrog");
else if ("alice".equals(id) || "bob".equals(id))
pc.setPassword("password");
else
pc.setPassword("wrong password");
}
use of org.apache.wss4j.common.ext.WSPasswordCallback in project midpoint by Evolveum.
the class PasswordCallback method handle.
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
LOGGER.trace("Invoked PasswordCallback with {} callbacks: {}", callbacks.length, callbacks);
WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];
String username = pc.getIdentifier();
String wssPasswordType = pc.getType();
LOGGER.trace("Username: '{}', Password type: {}", username, wssPasswordType);
try {
ConnectionEnvironment connEnv = ConnectionEnvironment.create(SchemaConstants.CHANNEL_WEB_SERVICE_URI);
pc.setPassword(passwordAuthenticationEvaluatorImpl.getAndCheckUserPassword(connEnv, username));
} catch (Exception e) {
LOGGER.trace("Exception in password callback: {}: {}", e.getClass().getSimpleName(), e.getMessage(), e);
throw new PasswordCallbackException("Authentication failed");
}
}
Aggregations