camel-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Stephan Siano (JIRA)" <>
Subject [jira] [Created] (CAMEL-10830) Race condition when reading principal for one-way web services
Date Wed, 15 Feb 2017 07:47:41 GMT
Stephan Siano created CAMEL-10830:

             Summary: Race condition when reading principal for one-way web services
                 Key: CAMEL-10830
             Project: Camel
          Issue Type: Bug
          Components: camel-cxf
    Affects Versions: 2.16.2
            Reporter: Stephan Siano
            Assignee: Stephan Siano
            Priority: Minor

This is an issue of the more esoteric kind.

If camel-cxf is running on Tomcat 7 and the provided web service is a one-way webservice and
if the robust feature is not set in very rare cases the following exception can occur:
nowjava.lang.SecurityException: attempting to add an object which is not an instance of
to a Subject's Principal Set
        at java.util.Collections$SynchronizedCollection.add(
        at org.apache.camel.component.cxf.DefaultCxfBinding.populateExchangeFromCxfRequest(
        at org.apache.camel.component.cxf.CxfConsumer$1.prepareCamelExchange(
        at org.apache.camel.component.cxf.CxfConsumer$1.syncInvoke(
        at org.apache.camel.component.cxf.CxfConsumer$1.invoke(
        at org.apache.cxf.interceptor.ServiceInvokerInterceptor$
        at java.util.concurrent.Executors$
        at org.apache.cxf.interceptor.ServiceInvokerInterceptor$
        at org.apache.cxf.workqueue.SynchronousExecutor.execute(
        at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(
        at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(
        at org.apache.cxf.phase.PhaseInterceptorChain.resume(
        at org.apache.cxf.interceptor.OneWayProcessorInterceptor$
        at org.apache.cxf.workqueue.AutomaticWorkQueueImpl$
        at java.util.concurrent.ThreadPoolExecutor.runWorker(
        at java.util.concurrent.ThreadPoolExecutor$
        at org.apache.cxf.workqueue.AutomaticWorkQueueImpl$AWQThreadFactory$

The reason for that is in the combination of this code
        if (securityContext instanceof LoginSecurityContext
            && ((LoginSecurityContext)securityContext).getSubject() != null) {
        } else if (securityContext != null && securityContext.getUserPrincipal() !=
null) {
            Subject subject = new Subject();
            camelExchange.getIn().getHeaders().put(Exchange.AUTHENTICATION, subject);
with the implementation of the CXF securtyContext, the way Tomcat implements the login context,
and the thread context change created by CXF for the one-way web services. As a result the
behaviour of securityContext.getUserPrincipal() may change asynchonously at any time (so it
may return a principal when the null check happens and may return null on the second call).
Trying to add null to the principals will create above exception.

The fix for this is to call getUserPrincipal() only once and perform the null check and the
add() operation with the result.

Obviously the issue is not testable (because even in the environment where this may happen
it is very improbable that it can be reproduced).

This message was sent by Atlassian JIRA

View raw message