2016-03-21 5 views
1

zu registrieren Ich versuche, Frühling Sicherheitsrolle Perle Beadungsrichtlinie Spring Boot basierte Apache Kamel Web App hinzufügen, um die Routen zu sichern.Nicht in der Lage, Sicherheitsrichtlinie für Camel Route

Ich benutze das Beispiel (http://camel.apache.org/spring-security-example.html) als eine Basis, die nicht auf einem Springboot basiert.

Da ich eine Spring Boot basierte Apache Camel Anwendung bin stecken auf, wie Sie vorgehen.

Ich möchte wissen, wie ich Bohnen/Komponenten durch Code für die Registrierung der Autorisierungsrichtlinie hinzufügen kann, um in einer oder mehreren Kamel-Routen verwiesen werden.

Mit Spring Boot hinzugefügt Ich bin mir nicht sicher, wie wir bestimmte Komponenten in Camel XML-Konfiguration beibehalten und andere erforderliche Beans-Komponenten in Java-Konfiguration/Spring-Boot hinzufügen können.

Also, ich bin nicht in der Lage, dieses Nicht-Spring-Boot-Beispiel in eine Apache Camel Spring Boot-basierte Anwendung zu konvertieren.

Kann mir jemand auf dem richtigen Weg helfen, das Problem anzugehen.

Ich habe wie folgt in Java Config definiert.

@Bean(name="roleUserEmp") 
     public SpringSecurityAccessPolicy roleUserEmp() { 
      SpringSecurityAccessPolicy policy = new SpringSecurityAccessPolicy("ROLE_USER_EMP"); 
      return policy; 
     } 

Auch habe ich die Stacktrace wie unten

org.apache.camel.spring.boot.CamelSpringBootInitializationException: org.apache.camel.FailedToCreateRouteException: Failed to create route createEmpFlow at: >>> Policy[ref:roleUserEmp] <<< in route: Route(createEmpFlow)[[From[direct:createEmpFlow]] -> [... because of No bean could be found in the registry for: roleUserEmp of type: org.apache.camel.spi.Policy 
    at org.apache.camel.spring.boot.RoutesCollector.onApplicationEvent(RoutesCollector.java:94) ~[camel-spring-boot-2.16.2.jar:2.16.2] 
    at org.apache.camel.spring.boot.RoutesCollector.onApplicationEvent(RoutesCollector.java:38) ~[camel-spring-boot-2.16.2.jar:2.16.2] 
    at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:163) ~[spring-context-4.2.3.RELEASE.jar:4.2.3.RELEASE] 
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:136) ~[spring-context-4.2.3.RELEASE.jar:4.2.3.RELEASE] 
    at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:380) ~[spring-context-4.2.3.RELEASE.jar:4.2.3.RELEASE] 
    at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:334) ~[spring-context-4.2.3.RELEASE.jar:4.2.3.RELEASE] 
    at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:854) ~[spring-context-4.2.3.RELEASE.jar:4.2.3.RELEASE] 
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.finishRefresh(EmbeddedWebApplicationContext.java:140) ~[spring-boot-1.3.0.RELEASE.jar:1.3.0.RELEASE] 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:540) ~[spring-context-4.2.3.RELEASE.jar:4.2.3.RELEASE] 
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) ~[spring-boot-1.3.0.RELEASE.jar:1.3.0.RELEASE] 
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:752) [spring-boot-1.3.0.RELEASE.jar:1.3.0.RELEASE] 
    at org.springframework.boot.SpringApplication.doRun(SpringApplication.java:347) [spring-boot-1.3.0.RELEASE.jar:1.3.0.RELEASE] 
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:295) [spring-boot-1.3.0.RELEASE.jar:1.3.0.RELEASE] 
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1112) [spring-boot-1.3.0.RELEASE.jar:1.3.0.RELEASE] 
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1101) [spring-boot-1.3.0.RELEASE.jar:1.3.0.RELEASE] 
    at com.company.application.EmpApplication.main(EmpApplication.java:48) [classes/:na] 
Caused by: org.apache.camel.FailedToCreateRouteException: Failed to create route createEmpFlow at: >>> Policy[ref:roleUserEmp] <<< in route: Route(createEmpFlow)[[From[direct:createEmpFlow]] -> [... because of No bean could be found in the registry for: roleUserEmp of type: org.apache.camel.spi.Policy 
    at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:1072) ~[camel-core-2.16.2.jar:2.16.2] 
    at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:196) ~[camel-core-2.16.2.jar:2.16.2] 
    at org.apache.camel.impl.DefaultCamelContext.startRoute(DefaultCamelContext.java:947) ~[camel-core-2.16.2.jar:2.16.2] 
    at org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:3258) ~[camel-core-2.16.2.jar:2.16.2] 
    at org.apache.camel.impl.DefaultCamelContext.doStartCamel(DefaultCamelContext.java:2981) ~[camel-core-2.16.2.jar:2.16.2] 
    at org.apache.camel.impl.DefaultCamelContext.access$000(DefaultCamelContext.java:175) ~[camel-core-2.16.2.jar:2.16.2] 
    at org.apache.camel.impl.DefaultCamelContext$2.call(DefaultCamelContext.java:2812) ~[camel-core-2.16.2.jar:2.16.2] 
    at org.apache.camel.impl.DefaultCamelContext$2.call(DefaultCamelContext.java:2808) ~[camel-core-2.16.2.jar:2.16.2] 
    at org.apache.camel.impl.DefaultCamelContext.doWithDefinedClassLoader(DefaultCamelContext.java:2831) ~[camel-core-2.16.2.jar:2.16.2] 
    at org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:2808) ~[camel-core-2.16.2.jar:2.16.2] 
    at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61) ~[camel-core-2.16.2.jar:2.16.2] 
    at org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:2777) ~[camel-core-2.16.2.jar:2.16.2] 
    at org.apache.camel.spring.boot.RoutesCollector.onApplicationEvent(RoutesCollector.java:92) ~[camel-spring-boot-2.16.2.jar:2.16.2] 
    ... 15 common frames omitted 
Caused by: org.apache.camel.NoSuchBeanException: No bean could be found in the registry for: roleUserEmp of type: org.apache.camel.spi.Policy 
    at org.apache.camel.util.CamelContextHelper.mandatoryLookup(CamelContextHelper.java:159) ~[camel-core-2.16.2.jar:2.16.2] 
    at org.apache.camel.model.TransactedDefinition.doResolvePolicy(TransactedDefinition.java:171) ~[camel-core-2.16.2.jar:2.16.2] 
    at org.apache.camel.model.PolicyDefinition.resolvePolicy(PolicyDefinition.java:158) ~[camel-core-2.16.2.jar:2.16.2] 
    at org.apache.camel.model.PolicyDefinition.createProcessor(PolicyDefinition.java:134) ~[camel-core-2.16.2.jar:2.16.2] 
    at org.apache.camel.model.ProcessorDefinition.makeProcessorImpl(ProcessorDefinition.java:534) ~[camel-core-2.16.2.jar:2.16.2] 
    at org.apache.camel.model.ProcessorDefinition.makeProcessor(ProcessorDefinition.java:495) ~[camel-core-2.16.2.jar:2.16.2] 
    at org.apache.camel.model.ProcessorDefinition.addRoutes(ProcessorDefinition.java:219) ~[camel-core-2.16.2.jar:2.16.2] 
    at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:1069) ~[camel-core-2.16.2.jar:2.16.2] 
    ... 27 common frames omitted 

Danke,

Die Route, die ich habe, wie unten ist,

<route id="createEmpFlow "> 

    <from uri="direct:createEmpFlow "/> 

     <policy ref="roleEmpUser"> 


     </policy> 
</route> 

Ich habe es eingewickelt mit der camel-Tag der Richtlinie, der auf den roleUserEmp verweist.

+0

'SpringSecurityAccessPolicy' ist keine Routenrichtlinie. Bitte zeigen Sie die Route, die Sie verwenden. –

Antwort

2

SpringSecurityAccessPolicy ist kein Policy. Sie sollten SpringSecurityAuthorizationPolicy verwenden und mit Ihrem accessDecisionManager, und SpringSecurityAccessPolicy konfigurieren.

@Bean(name="policy") 
public SpringSecurityAuthorizationPolicy springPolicy(AuthenticationManager authMgr, AccessDecisionManager accessMgr) { 
    SpringSecurityAuthorizationPolicy policy = new SpringSecurityAuthorizationPolicy(); 

    // .. configure 
    policy.setAuthenticationManager(authMgr); 
    policy.setAccessDecisionManager(accessMgr); 
    policy. setSpringSecurityAccessPolicy(new SpringSecurityAccessPolicy("ROLE_USER_EMP")); 
    return policy; 
}