use of org.apache.cxf.configuration.security.AuthorizationPolicy in project tbd-studio-se by Talend.
the class HCatalogServiceUtil method addKerberos2Client.
private static void addKerberos2Client(WebClient client, HCatalogConnection connection) throws Exception {
HadoopClusterConnection hcConnection = HCRepositoryUtil.getRelativeHadoopClusterConnection(connection);
if (hcConnection != null) {
if (hcConnection.isEnableMaprT()) {
setMaprTicketPropertiesConfig(hcConnection);
}
if (hcConnection.isEnableKerberos()) {
KerberosAuthOutInterceptor kbInterceptor = new KerberosAuthOutInterceptor();
AuthorizationPolicy policy = new AuthorizationPolicy();
policy.setAuthorizationType(HttpAuthHeader.AUTH_TYPE_NEGOTIATE);
kbInterceptor.setPolicy(policy);
java.util.Map<String, String> properties = new HashMap<String, String>();
String krbPrincipal = ConnectionContextHelper.getParamValueOffContext(connection, StringUtils.trimToEmpty(connection.getKrbPrincipal()));
kbInterceptor.setServicePrincipalName(StringUtils.trimToEmpty(krbPrincipal));
String krbRealm = ConnectionContextHelper.getParamValueOffContext(connection, StringUtils.trimToEmpty(connection.getKrbRealm()));
kbInterceptor.setRealm(StringUtils.trimToEmpty(krbRealm));
// $NON-NLS-1$ //$NON-NLS-2$
properties.put("useTicketCache", "true");
// $NON-NLS-1$ //$NON-NLS-2$
properties.put("refreshKrb5Config", "true");
// $NON-NLS-1$ //$NON-NLS-2$
properties.put("renewTGT", "true");
if (hcConnection.isUseKeytab()) {
// $NON-NLS-1$//$NON-NLS-2$
properties.put("useKeyTab", "true");
// $NON-NLS-1$
properties.put(// $NON-NLS-1$
"principal", ConnectionContextHelper.getParamValueOffContext(hcConnection, hcConnection.getKeytabPrincipal()));
properties.put("keyTab", // $NON-NLS-1$
ConnectionContextHelper.getParamValueOffContext(hcConnection, hcConnection.getKeytab()));
}
kbInterceptor.setLoginConfig(new KerberosPolicyConfig(properties));
WebClient.getConfig(client).getOutInterceptors().add(kbInterceptor);
}
if (hcConnection.isEnableMaprT()) {
setMaprTicketConfig(hcConnection, getClassLoader(hcConnection, connection), hcConnection.isEnableKerberos());
}
}
}
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=\"STS\"").build());
return;
}
try {
super.validate(message);
} catch (Exception ex) {
throw ExceptionUtils.toInternalServerErrorException(ex, null);
}
}
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 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 testcases by coheigea.
the class SyncopeBasicAuthInterceptor method handleMessage.
public void handleMessage(Message message) throws Fault {
AuthorizationPolicy policy = message.get(AuthorizationPolicy.class);
if (policy == null || policy.getUserName() == null || policy.getPassword() == null) {
String name = null;
if (policy != null) {
name = policy.getUserName();
}
String error = "No user credentials are available";
LOG.warning(error + " " + "for name: " + name);
throw new SecurityException(error);
}
try {
UsernameToken token = convertPolicyToToken(policy);
Credential credential = new Credential();
credential.setUsernametoken(token);
RequestData data = new RequestData();
data.setMsgContext(message);
credential = validator.validate(credential, data);
// Create a Principal/SecurityContext
Principal p = null;
if (credential != null && credential.getPrincipal() != null) {
p = credential.getPrincipal();
} else {
p = new WSUsernameTokenPrincipalImpl(policy.getUserName(), false);
((WSUsernameTokenPrincipalImpl) p).setPassword(policy.getPassword());
}
message.put(SecurityContext.class, createSecurityContext(p));
} catch (Exception ex) {
throw new Fault(ex);
}
}
Aggregations