0
votes

I am trying to deploy apache-camel spring-security-example https://github.com/apache/camel/tree/master/examples/camel-example-spring-security .

Steps I followed.

  1. Downloaded apache-camel-2.17.3 release.
  2. run mvn clean install
  3. mvn jetty:run

Then the following exception was thrown.

2016-09-30 10:07:37,517 [main ] ERROR ContextLoader
- Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'accessDecisionManager' defined in class path resource [camel-context.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.security.access.vote.AffirmativeBased]: No default constructor found; nested exception is java.lang.NoSuchMethodException: org.springframework.security.access.vote.AffirmativeBased.() at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1105) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1050) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538) at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:444) at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:326) at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107) at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:782) at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:424) at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:774) at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:249) at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1242) at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:717) at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:494) at org.mortbay.jetty.plugin.JettyWebAppContext.doStart(JettyWebAppContext.java:298) at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64) at org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:229) at org.eclipse.jetty.server.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:172) at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64) at org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:229) at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64) at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:95) at org.eclipse.jetty.server.Server.doStart(Server.java:282) at org.mortbay.jetty.plugin.JettyServer.doStart(JettyServer.java:65) at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64) at org.mortbay.jetty.plugin.AbstractJettyMojo.startJetty(AbstractJettyMojo.java:520) at org.mortbay.jetty.plugin.AbstractJettyMojo.execute(AbstractJettyMojo.java:365) at org.mortbay.jetty.plugin.JettyRunMojo.execute(JettyRunMojo.java:523) at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:133) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:108) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:76) at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51) at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:116) at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:361) at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:155) at org.apache.maven.cli.MavenCli.execute(MavenCli.java:584) at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:213) at org.apache.maven.cli.MavenCli.main(MavenCli.java:157) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289) at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229) at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415) at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356) Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.security.access.vote.AffirmativeBased]: No default constructor found; nested exception is java.lang.NoSuchMethodException: org.springframework.security.access.vote.AffirmativeBased.() at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:85) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1098) ... 55 more

Please, someone let me know the reason.

1
@OlgaKhylkouskaya Actually, I don't think this is duplicated because I have tried this example just out of the box. I have not done any changes for the example. - Udara Seneviratne
According to the camel.465427.n5.nabble.com/… this is a bug in apache-camel-2.17.3 release. - Udara Seneviratne

1 Answers

0
votes

Though this is old, I also had to trawl around to find a solution to the camel-eaxmple-spring-security example on 2.17.x (and Others I presume). I wanted to do BASIC Authentication with both HTTP GET & POST. I don't think it is a bug , just there were probably changes to the Spring Security versions, so the 2.17.x example hasn't been updated since it was first created.

There are already references to several changes that need to be made to the example in order to make it work. Here is the list , in one place, of changes I made; 1) change

 <spring-security:intercept-url pattern="/camel/**" access="ROLE_User"/> to
 <spring-security:intercept-url pattern="/camel/**" access="hasRole ('ROLE_User')"/> 

(can't remember the link where I found this) 2) change the access decision manager bean to include a constructor, the link http://stackoverflow.com/questions/29495283/no-default-constructor-found-nested-exception-is-java-lang-nosuchmethodexceptio deals with this too my change looked like this

    <bean id="accessDecisionManager" class="org.springframework.security.access.vote.AffirmativeBased">
        <constructor-arg>
            <bean class="org.springframework.security.access.vote.RoleVoter"/>
       </constructor-arg>
       <property name="allowIfAllAbstainDecisions" value="true"/>
   </bean>

These changes made the example work as expected for HTTP GET requests, But I also wanted HTTP POST request to work but "as is" I still got a 403 error - these would be from a different server to my server - rather than a web client - whilst disabling csrf isn't recommended for my use I think it is acceptable. To disable csrf I added <spring-security:csrf disabled="true"/> to the <spring-security:http> settings

To make the HTTP POST Call you need to add the Authorization header with Base64 encoded credentials i.e.

<!-- for bob and bobspassword -->
<setHeader headername="Authorization">
    <constant>Basic amlt0mppbXNwYXNzd29yZA==</constant>
</setHeader>

You must also check you get the Content-Type set correctly for the body you are sending e.g. application/json ...