use of org.apache.cxf.configuration.security.AuthorizationPolicy in project testcases by coheigea.
the class WSS4JBasicAuthFilter method filter.
public void filter(ContainerRequestContext requestContext) throws IOException {
Message message = JAXRSUtils.getCurrentMessage();
AuthorizationPolicy policy = message.get(AuthorizationPolicy.class);
if (policy == null || policy.getUserName() == null || policy.getPassword() == null) {
requestContext.abortWith(Response.status(401).header("WWW-Authenticate", "Basic realm=\"IdP\"").build());
return;
}
try {
super.validate(message);
} catch (Exception ex) {
throw ExceptionUtils.toInternalServerErrorException(ex, null);
}
}
use of org.apache.cxf.configuration.security.AuthorizationPolicy in project ipf by oehf.
the class WsSecurityInformation method configureHttpConduit.
protected void configureHttpConduit(HTTPConduit httpConduit) {
if (isSecure()) {
var tlsClientParameters = httpConduit.getTlsClientParameters();
// otherwise we overwrite TLSClientParameters if a custom SslContext is configured
if (tlsClientParameters == null) {
tlsClientParameters = new TLSClientParameters();
maybeUpdateSslContext(tlsClientParameters, true);
} else {
maybeUpdateSslContext(tlsClientParameters, false);
}
if (getHostnameVerifier() != null) {
tlsClientParameters.setHostnameVerifier(getHostnameVerifier());
}
httpConduit.setTlsClientParameters(tlsClientParameters);
}
if (getUsername() != null) {
var authorizationPolicy = new AuthorizationPolicy();
authorizationPolicy.setUserName(getUsername());
authorizationPolicy.setPassword(getPassword());
httpConduit.setAuthorization(authorizationPolicy);
}
}
use of org.apache.cxf.configuration.security.AuthorizationPolicy in project fh by assecopl.
the class WebServiceClientUtil method createBasicPort.
protected <E> E createBasicPort(Class<E> serviceCalzz, String address, String user, String password, AuthorizationTypeEnum authType, boolean logOn, Map<String, List<String>> headers, String proxyHost, Integer proxyPort, String proxyUser, String proxyPassword) {
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.setServiceClass(serviceCalzz);
factory.setAddress(address);
List features = new ArrayList<>(factory.getFeatures());
WSPolicyFeature wsPolicyFeature = new WSPolicyFeature();
wsPolicyFeature.setEnabled(true);
wsPolicyFeature.setIgnoreUnknownAssertions(true);
features.add(wsPolicyFeature);
factory.setFeatures(features);
E port = (E) factory.create();
Client client = ClientProxy.getClient(port);
HTTPConduit http = (HTTPConduit) client.getConduit();
if (authType != null) {
AuthorizationPolicy authPolicy = new AuthorizationPolicy();
authPolicy.setAuthorizationType(authType.name());
authPolicy.setUserName(user);
authPolicy.setPassword(password);
http.setAuthorization(authPolicy);
}
HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
httpClientPolicy.setConnectionTimeout(conectTimeout);
httpClientPolicy.setReceiveTimeout(requestTimeout);
if (StringUtils.isNotBlank(proxyHost) && proxyPort != null) {
httpClientPolicy.setProxyServerType(ProxyServerType.HTTP);
httpClientPolicy.setProxyServer(proxyHost);
httpClientPolicy.setProxyServerPort(proxyPort);
}
http.setClient(httpClientPolicy);
Map<String, Object> requestContext = client.getRequestContext();
requestContext.put(CONNECT_TIMEOUT, httpClientPolicy.getConnectionTimeout());
// Timeout in millis
requestContext.put(REQUEST_TIMEOUT, httpClientPolicy.getReceiveTimeout());
// Add HTTP headers to the web service request
if (headers != null) {
requestContext.put(Message.PROTOCOL_HEADERS, headers);
}
if (address.startsWith("https") || customSSLSocketFactory != null) {
HTTPConduit httpConduit = (HTTPConduit) client.getConduit();
if (customSSLSocketFactory == null) {
customSSLSocketFactory = new BlindSSLSocketFactory();
}
TLSClientParameters tlsCP = new TLSClientParameters();
// you can set up the SSLSocketFactory on the TLSClientParameter
tlsCP.setSSLSocketFactory(customSSLSocketFactory);
tlsCP.setDisableCNCheck(true);
// setup the TLSClientParameters on the HttpConduit
httpConduit.setTlsClientParameters(tlsCP);
}
if (configInterceptors != null) {
configInterceptors.addInterceptor(client);
}
if (!logOn) {
removeLoggingInterceptors(client);
}
if (configWebServiceClient != null) {
configWebServiceClient.configPort(port);
}
return port;
}
use of org.apache.cxf.configuration.security.AuthorizationPolicy in project liima by liimaorg.
the class DynWSAuthHTTPConduitConfigurer method configure.
@Override
public void configure(String name, String address, HTTPConduit conduit) {
if (username != null) {
AuthorizationPolicy ap = new AuthorizationPolicy();
ap.setUserName(username);
ap.setPassword(password);
conduit.setAuthorization(ap);
}
// override the ssl configuration of cxf and use the default implementation instead
// CXF doesn't like pkcs12 keystore for some reason (Default key managers cannot be initialized: Invalid keystore format)
TLSClientParameters tls = new TLSClientParameters();
try {
tls.setSSLSocketFactory(SSLContext.getDefault().getSocketFactory());
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
conduit.setTlsClientParameters(tls);
}
use of org.apache.cxf.configuration.security.AuthorizationPolicy in project jbpm by kiegroup.
the class WebServiceWorkItemHandler method applyAuthorization.
protected void applyAuthorization(String userName, String password, Client client) {
if (userName != null && password != null) {
HTTPConduit httpConduit = (HTTPConduit) client.getConduit();
AuthorizationPolicy authorizationPolicy = new AuthorizationPolicy();
authorizationPolicy.setUserName(userName);
authorizationPolicy.setPassword(password);
authorizationPolicy.setAuthorizationType("Basic");
httpConduit.setAuthorization(authorizationPolicy);
} else {
logger.warn("UserName and Password must be provided to set the authorization policy.");
}
}
Aggregations