有没有办法在Spring Cloud Dataflow中实现jdbc用户身份验证?

时间:2017-05-25 06:57:31

标签: spring-boot spring-security spring-cloud-config spring-cloud-dataflow

这是我编写的My Code,我在这里使用了自定义用户详细信息服务,但每次尝试运行此代码bean时都未找到预期  我想知道有没有办法实现它因为我看到auth对象有一个方法auth.jdbcAuthentication();

package org.springframework.cloud.dataflow.server.config.security;

/**
 * Created by smajumder on 16-May-17.
 */

import org.apache.tomcat.jdbc.pool.DataSource;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.authentication.configurers.GlobalAuthenticationConfigurerAdapter;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;


@Configuration
@EnableWebSecurity
@ConditionalOnProperty("security.authentication.jdbc.enabled")
@ConfigurationProperties(prefix = 
JDBCAuthenticationConfiguration.CONFIGURATION_PROPERTIES_PREFIX)
public class JDBCAuthenticationConfiguration extends 
GlobalAuthenticationConfigurerAdapter {

public static final String CONFIGURATION_PROPERTIES_PREFIX ="security"
        + ".authentication.jdbc";
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(JDBCAuthenticationConfiguration.class);

@Autowired
private CustomUserDetailsService userDetailsService ;

@Autowired
private DataSource dataSource;

@Override
public void init(AuthenticationManagerBuilder auth) throws Exception {
    logger.info("JDBC authentication Starting .....");
    auth.userDetailsService(userDetailsService).passwordEncoder(passwordencoder());
    logger.info("JDBC authentication Enabled .....");


}

@Bean(name="passwordEncoder")
public PasswordEncoder passwordencoder(){
    return new BCryptPasswordEncoder();
}



}

This is the info i got from shell

这是我在init()

中执行此操作后的堆栈跟踪
 securityStateBean.setAuthenticationEnabled(true);
    securityStateBean.setAuthorizationEnabled(false);

org.springframework.beans.factory.BeanCreationException:使用名称' springSecurityFilterChain'创建bean时出错。在类路径资源中定义[org / springframework / security / config / annotation / web / configuration / WebSecurityConfiguration.class]:通过工厂方法的Bean实例化失败;嵌套异常是org.springframework.beans.BeanInstantiationException:无法实例化[javax.servlet.Filter]:工厂方法' springSecurityFilterChain'抛出异常;嵌套异常是java.lang.IllegalStateException:无法将org.springframework.security.config.annotation.authentication.configurers.provisioning.JdbcUserDetailsManagerConfigurer@629f066f应用于已构建的对象         在org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599)〜[spring-beans-4.3.7.RELEASE.jar!/:4.3.7.RELEASE]         在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1173)〜[spring-beans-4.3.7.RELEASE.jar!/:4.3.7.RELEASE]         在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1067)〜[spring-beans-4.3.7.RELEASE.jar!/:4.3.7.RELEASE]         在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513)〜[spring-beans-4.3.7.RELEASE.jar!/:4.3.7.RELEASE]         在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)〜[spring-beans-4.3.7.RELEASE.jar!/:4.3.7.RELEASE]         在org.springframework.beans.factory.support.AbstractBeanFactory $ 1.getObject(AbstractBeanFactory.java:306)〜[spring-beans-4.3.7.RELEASE.jar!/:4.3.7.RELEASE]         在org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)〜[spring-beans-4.3.7.RELEASE.jar!/:4.3.7.RELEASE]         在org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)〜[spring-beans-4.3.7.RELEASE.jar!/:4.3.7.RELEASE]         在org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)〜[spring-beans-4.3.7.RELEASE.jar!/:4.3.7.RELEASE]         在org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:296)〜[spring-beans-4.3.7.RELEASE.jar!/:4.3.7.RELEASE]         在org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)〜[spring-beans-4.3.7.RELEASE.jar!/:4.3.7.RELEASE]         在org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761)〜[spring-beans-4.3.7.RELEASE.jar!/:4.3.7.RELEASE]         在org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:866)〜[spring-context-4.3.7.RELEASE.jar!/:4.3.7.RELEASE]         在org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542)〜[spring-context-4.3.7.RELEASE.jar!/:4.3.7.RELEASE]         at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)~ [spring-boot-1.5.2.RELEASE.jar!/:1.5.2.RELEASE]         在org.springframework.boot.SpringApplication.refresh(SpringApplication.java:737)[spring-boot-1.5.2.RELEASE.jar!/:1.5.2.RELEASE]         在org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:370)[spring-boot-1.5.2.RELEASE.jar!/:1.5.2.RELEASE]         在org.springframework.boot.SpringApplication.run(SpringApplication.java:314)[spring-boot-1.5.2.RELEASE.jar!/:1.5.2.RELEASE]         在org.springframework.boot.SpringApplication.run(SpringApplication.java:1162)[spring-boot-1.5.2.RELEASE.jar!/:1.5.2.RELEASE]         在org.springframework.boot.SpringApplication.run(SpringApplication.java:1151)[spring-boot-1.5.2.RELEASE.jar!/:1.5.2.RELEASE]         在org.springframework.cloud.dataflow.server.local.LocalDataFlowServer.main(LocalDataFlowServer.java:38)[classes!/:1.2.0.RELEASE]         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)〜[na:1.8.0_91]         at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)〜[na:1.8.0_91]         at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)〜[na:1.8.0_91]         at java.lang.reflect.Method.invoke(Unknown Source)〜[na:1.8.0_91]         在org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)[spring-cloud-dataflow-server-local-1.2.0.RELEASE.jar:1.2.0.RELEASE]         在org.springframework.boot.loader.Launcher.launch(Launcher.java:87)[spring-cloud-dataflow-server-local-1.2.0.RELEASE.jar:1.2.0.RELEASE]         在org.springframework.boot.loader.Launcher.launch(Launcher.java:50)[spring-cloud-dataflow-server-local-1.2.0.RELEASE.jar:1.2.0.RELEASE]         在org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)[spring-cloud-dataflow-server-local-1.2.0.RELEASE.jar:1.2.0.RELEASE] 引起:org.springframework.beans.BeanInstantiationException:无法实例化[javax.servlet.Filter]:工厂方法' springSecurityFilterChain'抛出异常;嵌套异常是java.lang.IllegalStateException:无法将org.springframework.security.config.annotation.authentication.configurers.provisioning.JdbcUserDetailsManagerConfigurer@629f066f应用于已构建的对象         在org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)〜[spring-beans-4.3.7.RELEASE.jar!/:4.3.7.RELEASE]         在org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)〜[spring-beans-4.3.7.RELEASE.jar!/:4.3.7.RELEASE]         ...省略了28个常见帧 引起:java.lang.IllegalStateException:无法将org.springframework.security.config.annotation.authentication.configurers.provisioning.JdbcUserDetailsManagerConfigurer@629f066f应用于已构建的对象         在org.springframework.security.config.annotation.AbstractConfiguredSecurityBuilder.add(AbstractConfiguredSecurityBuilder.java:196)〜[spring-security-config-4.2.2.RELEASE.jar!/:4.2.2.RELEASE]         在org.springframework.security.config.annotation.AbstractConfiguredSecurityBuilder.apply(AbstractConfiguredSecurityBuilder.java:133)〜[spring-security-config-4.2.2.RELEASE.jar!/:4.2.2.RELEASE]         在org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder.apply(AuthenticationManagerBuilder.java:290)〜[spring-security-config-4.2.2.RELEASE.jar!/:4.2.2.RELEASE]         在org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder.jdbcAuthentication(AuthenticationManagerBuilder.java:164)〜[spring-security-config-4.2.2.RELEASE.jar!/:4.2.2.RELEASE]         在org.springframework.cloud.dataflow.server.config.security.JDBCAuthenticationConfiguration.configure(JDBCAuthenticationConfiguration.java:72)〜[spring-cloud-dataflow-server-core-1.2.1.RELEASE.jar!/:1.2.1 。发布]         在org.springframework.cloud.dataflow.server.config.security.JDBCAuthenticationConfiguration.configure(JDBCAuthenticationConfiguration.java:37)〜[spring-cloud-dataflow-server-core-1.2.1.RELEASE.jar!/:1.2.1 。发布]         在org.springframework.cloud.dataflow.server.config.security.JDBCAuthenticationConfiguration $$ EnhancerBySpringCGLIB $$ 1a0e187f.configure()〜[spring-cloud-dataflow-server-core-1.2.1.RELEASE.jar!/:1.2。 1.RELEASE]         在org.springframework.security.config.annotation.AbstractConfiguredSecurityBuilder.configure(AbstractConfiguredSecurityBuilder.java:384)〜[spring-security-config-4.2.2.RELEASE.jar!/:4.2.2.RELEASE]         在org.springframework.security.config.annotation.AbstractConfiguredSecurityBuilder.doBuild(AbstractConfiguredSecurityBuilder.java:330)〜[spring-security-config-4.2.2.RELEASE.jar!/:4.2.2.RELEASE]         在org.springframework.security.config.annotation.AbstractSecurityBuilder.build(AbstractSecurityBuilder.java:41)〜[spring-security-config-4.2.2.RELEASE.jar!/:4.2.2.RELEASE]         在org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration.getAuthenticationManager(AuthenticationConfiguration.java:105)〜[spring-security-config-4.2.2.RELEASE.jar!/:4.2.2.RELEASE]         在org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter.authenticationManager(WebSecurityConfigurerAdapter.java:262)〜[spring-security-config-4.2.2.RELEASE.jar!/:4.2.2.RELEASE]         在org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter.getHttp(WebSecurityConfigurerAdapter.java:195)〜[spring-security-config-4.2.2.RELEASE.jar!/:4.2.2.RELEASE]         在org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter.init(WebSecurityConfigurerAdapter.java:315)〜[spring-security-config-4.2.2.RELEASE.jar!/:4.2.2.RELEASE]         在org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter.init(WebSecurityConfigurerAdapter.java:86)〜[spring-security-config-4.2.2.RELEASE.jar!/:4.2.2.RELEASE]         at org.springframework.boot.autoconfigure.security.SpringBootWebSecurityConfiguration $ ApplicationNoWebSecurityConfigurerAdapter $$ EnhancerBySpringCGLIB $$ 36139df2.init()〜[spring-boot-autoconfigure-1.5.2.RELEASE.jar!/:1.5.2.RELEASE]         在org.springframework.security.config.annotation.AbstractConfiguredSecurityBuilder.init(AbstractConfiguredSecurityBuilder.java:371)〜[spring-security-config-4.2.2.RELEASE.jar!/:4.2.2.RELEASE]         在org.springframework.security.config.annotation.AbstractConfiguredSecurityBuilder.doBuild(AbstractConfiguredSecurityBuilder.java:325)〜[spring-security-config-4.2.2.RELEASE.jar!/:4.2.2.RELEASE]         在org.springframework.security.config.annotation.AbstractSecurityBuilder.build(AbstractSecurityBuilder.java:41)〜[spring-security-config-4.2.2.RELEASE.jar!/:4.2.2.RELEASE]         在org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration.springSecurityFilterChain(WebSecurityConfiguration.java:104)〜[spring-security-config-4.2.2.RELEASE.jar!/:4.2.2.RELEASE]         在org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration $$ EnhancerBySpringCGLIB $$ 5141ef61.CGLIB $ springSecurityFilterChain $ 6()〜[spring-security-config-4.2.2.RELEASE.jar!/:4.2.2 。发布]         在org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration $$ EnhancerBySpringCGLIB $$ 5141ef61 $$ FastClassBySpringCGLIB $$ cbf558e0.invoke()〜[spring-security-config-4.2.2.RELEASE.jar!/: 4.2.2.RELEASE]         在org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)〜[spring-core-4.3.7.RELEASE.jar!/:4.3.7.RELEASE]         在org.springframework.context.annotation.ConfigurationClassEnhancer $ BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:358)〜[spring-context-4.3.7.RELEASE.jar!/:4.3.7.RELEASE]         at org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration $$ EnhancerBySpringCGLIB $$ 5141ef61.springSecurityFilterChain()〜[spring-security-config-4.2.2.RELEASE.jar!/:4.2.2.RELEASE]         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)〜[na:1.8.0_91]         at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)〜[na:1.8.0_91]         at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)〜[na:1.8.0_91]         at java.lang.reflect.Method.invoke(Unknown Source)〜[na:1.8.0_91]         在org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)〜[spring-beans-4.3.7.RELEASE.jar!/:4.3.7.RELEASE]         ...省略了29个常见帧

This is the error im getting

1 个答案:

答案 0 :(得分:1)

我想这doc可能会有所帮助。

此外,还有一个sample