use of org.apache.cxf.security.SecurityContext in project cxf by apache.
the class XACMLAuthorizingInterceptorTest method testPermit.
@org.junit.Test
public void testPermit() throws Exception {
// Mock up a Security Context
SecurityContext sc = createSecurityContext("alice", "manager");
String operation = "{http://www.example.org/contract/DoubleIt}DoubleIt";
MessageImpl msg = new MessageImpl();
msg.put(Message.WSDL_OPERATION, QName.valueOf(operation));
String service = "{http://www.example.org/contract/DoubleIt}DoubleItService";
msg.put(Message.WSDL_SERVICE, QName.valueOf(service));
String resourceURI = "https://localhost:8080/doubleit";
msg.put(Message.REQUEST_URI, resourceURI);
msg.put(SecurityContext.class, sc);
PolicyDecisionPoint pdp = new DummyPDP();
XACMLAuthorizingInterceptor authorizingInterceptor = new XACMLAuthorizingInterceptor(pdp);
authorizingInterceptor.handleMessage(msg);
}
use of org.apache.cxf.security.SecurityContext in project cxf by apache.
the class RESTSecurityTokenServiceImpl method getPrincipal.
@Override
protected Principal getPrincipal() {
// Try JAX-RS SecurityContext first
if (securityContext != null && securityContext.getUserPrincipal() != null) {
return securityContext.getUserPrincipal();
}
// Then try the CXF SecurityContext
SecurityContext sc = (SecurityContext) messageContext.get(SecurityContext.class);
if (sc != null && sc.getUserPrincipal() != null) {
return sc.getUserPrincipal();
}
// Get the TLS client principal if no security context is set up
X509Certificate clientCert = getTLSClientCertificate();
if (clientCert != null) {
return clientCert.getSubjectX500Principal();
}
return null;
}
use of org.apache.cxf.security.SecurityContext in project cxf by apache.
the class JMSDestinationTest method testSecurityContext.
@Test
public void testSecurityContext() throws Exception {
SecurityContext ctx = testSecurityContext(true);
assertNotNull("SecurityContext should be set in message received by JMSDestination", ctx);
assertEquals("Principal in SecurityContext should be", "testUser", ctx.getUserPrincipal().getName());
}
use of org.apache.cxf.security.SecurityContext in project cxf by apache.
the class JMSDestinationTest method testRoundTripDestinationDoNotCreateSecurityContext.
@Test
public void testRoundTripDestinationDoNotCreateSecurityContext() throws Exception {
Message msg = testRoundTripDestination(false);
SecurityContext securityContext = msg.get(SecurityContext.class);
assertNull("SecurityContext should not be set in message received by JMSDestination", securityContext);
}
use of org.apache.cxf.security.SecurityContext in project cxf by apache.
the class AbstractJwtAuthenticationFilter method filter.
@Override
public void filter(ContainerRequestContext requestContext) throws IOException {
String encodedJwtToken = getEncodedJwtToken(requestContext);
JwtToken token = super.getJwtToken(encodedJwtToken);
SecurityContext securityContext = configureSecurityContext(token);
if (securityContext != null) {
JAXRSUtils.getCurrentMessage().put(SecurityContext.class, securityContext);
}
}
Aggregations