为什么带有ldap的java安全应用程序没有运行sun.reflect.reflection错误?

bprjcwpo  于 2021-10-10  发布在  Java
关注(0)|答案(0)|浏览(412)

我遇到了一个问题,没有分析带有java问题的堆栈跟踪。我以前有过多个错误,这些错误都是通过添加依赖项来修复的,我尝试使用与在google上搜索sun.reflect.reflection相同的技巧,但搜索结果不是很清楚,而且我还得到了一些提示,可能是一个过时的类,或者是一个适用于特定版本java的类。顺便说一下,我的是Java8。
这是错误的堆栈跟踪:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springSecurityFilterChain' defined in class path resource [org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.servlet.Filter]: Factory method 'springSecurityFilterChain' threw exception; nested exception is java.lang.RuntimeException: Could not postProcess org.springframework.security.ldap.server.ApacheDSContainer@2354c1ea of type class org.springframework.security.ldap.server.ApacheDSContainer
    at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:658) ~[spring-beans-5.3.7.jar:5.3.7]
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:486) ~[spring-beans-5.3.7.jar:5.3.7]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1334) ~[spring-beans-5.3.7.jar:5.3.7]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1177) ~[spring-beans-5.3.7.jar:5.3.7]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:564) ~[spring-beans-5.3.7.jar:5.3.7]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:524) ~[spring-beans-5.3.7.jar:5.3.7]
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.7.jar:5.3.7]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.7.jar:5.3.7]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.7.jar:5.3.7]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.7.jar:5.3.7]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) ~[spring-beans-5.3.7.jar:5.3.7]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.7.jar:5.3.7]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:944) ~[spring-beans-5.3.7.jar:5.3.7]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918) ~[spring-context-5.3.7.jar:5.3.7]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[spring-context-5.3.7.jar:5.3.7]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145) ~[spring-boot-2.5.0.jar:2.5.0]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758) ~[spring-boot-2.5.0.jar:2.5.0]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:438) ~[spring-boot-2.5.0.jar:2.5.0]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:337) ~[spring-boot-2.5.0.jar:2.5.0]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1336) ~[spring-boot-2.5.0.jar:2.5.0]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1325) ~[spring-boot-2.5.0.jar:2.5.0]
    at com.todotrackingsystem.TodotrackingsystemApplication.main(TodotrackingsystemApplication.java:10) ~[classes/:na]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64) ~[na:na]
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
    at java.base/java.lang.reflect.Method.invoke(Method.java:564) ~[na:na]
    at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) ~[spring-boot-devtools-2.5.0.jar:2.5.0]
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.servlet.Filter]: Factory method 'springSecurityFilterChain' threw exception; nested exception is java.lang.RuntimeException: Could not postProcess org.springframework.security.ldap.server.ApacheDSContainer@2354c1ea of type class org.springframework.security.ldap.server.ApacheDSContainer
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.3.7.jar:5.3.7]
    at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653) ~[spring-beans-5.3.7.jar:5.3.7]
    ... 26 common frames omitted
Caused by: java.lang.RuntimeException: Could not postProcess org.springframework.security.ldap.server.ApacheDSContainer@2354c1ea of type class org.springframework.security.ldap.server.ApacheDSContainer
    at org.springframework.security.config.annotation.configuration.AutowireBeanFactoryObjectPostProcessor.postProcess(AutowireBeanFactoryObjectPostProcessor.java:69) ~[spring-security-config-5.5.0.jar:5.5.0]
    at org.springframework.security.config.annotation.SecurityConfigurerAdapter$CompositeObjectPostProcessor.postProcess(SecurityConfigurerAdapter.java:118) ~[spring-security-config-5.5.0.jar:5.5.0]
    at org.springframework.security.config.annotation.SecurityConfigurerAdapter.postProcess(SecurityConfigurerAdapter.java:79) ~[spring-security-config-5.5.0.jar:5.5.0]
    at org.springframework.security.config.annotation.authentication.configurers.ldap.LdapAuthenticationProviderConfigurer.access$600(LdapAuthenticationProviderConfigurer.java:60) ~[spring-security-config-5.5.0.jar:5.5.0]
    at org.springframework.security.config.annotation.authentication.configurers.ldap.LdapAuthenticationProviderConfigurer$ContextSourceBuilder.startEmbeddedLdapServer(LdapAuthenticationProviderConfigurer.java:568) ~[spring-security-config-5.5.0.jar:5.5.0]
    at org.springframework.security.config.annotation.authentication.configurers.ldap.LdapAuthenticationProviderConfigurer$ContextSourceBuilder.build(LdapAuthenticationProviderConfigurer.java:550) ~[spring-security-config-5.5.0.jar:5.5.0]
    at org.springframework.security.config.annotation.authentication.configurers.ldap.LdapAuthenticationProviderConfigurer$ContextSourceBuilder.access$100(LdapAuthenticationProviderConfigurer.java:445) ~[spring-security-config-5.5.0.jar:5.5.0]
    at org.springframework.security.config.annotation.authentication.configurers.ldap.LdapAuthenticationProviderConfigurer.getContextSource(LdapAuthenticationProviderConfigurer.java:380) ~[spring-security-config-5.5.0.jar:5.5.0]
    at org.springframework.security.config.annotation.authentication.configurers.ldap.LdapAuthenticationProviderConfigurer.build(LdapAuthenticationProviderConfigurer.java:94) ~[spring-security-config-5.5.0.jar:5.5.0]
    at org.springframework.security.config.annotation.authentication.configurers.ldap.LdapAuthenticationProviderConfigurer.configure(LdapAuthenticationProviderConfigurer.java:374) ~[spring-security-config-5.5.0.jar:5.5.0]
    at org.springframework.security.config.annotation.authentication.configurers.ldap.LdapAuthenticationProviderConfigurer.configure(LdapAuthenticationProviderConfigurer.java:60) ~[spring-security-config-5.5.0.jar:5.5.0]
    at org.springframework.security.config.annotation.AbstractConfiguredSecurityBuilder.configure(AbstractConfiguredSecurityBuilder.java:349) ~[spring-security-config-5.5.0.jar:5.5.0]
    at org.springframework.security.config.annotation.AbstractConfiguredSecurityBuilder.doBuild(AbstractConfiguredSecurityBuilder.java:303) ~[spring-security-config-5.5.0.jar:5.5.0]
    at org.springframework.security.config.annotation.AbstractSecurityBuilder.build(AbstractSecurityBuilder.java:38) ~[spring-security-config-5.5.0.jar:5.5.0]
    at org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter.authenticationManager(WebSecurityConfigurerAdapter.java:269) ~[spring-security-config-5.5.0.jar:5.5.0]
    at org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter.getHttp(WebSecurityConfigurerAdapter.java:204) ~[spring-security-config-5.5.0.jar:5.5.0]
    at org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter.init(WebSecurityConfigurerAdapter.java:315) ~[spring-security-config-5.5.0.jar:5.5.0]
    at org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter.init(WebSecurityConfigurerAdapter.java:93) ~[spring-security-config-5.5.0.jar:5.5.0]
    at com.todotrackingsystem.SecurityConfiguration$$EnhancerBySpringCGLIB$$d50958ea.init(<generated>) ~[classes/:na]
    at org.springframework.security.config.annotation.AbstractConfiguredSecurityBuilder.init(AbstractConfiguredSecurityBuilder.java:338) ~[spring-security-config-5.5.0.jar:5.5.0]
    at org.springframework.security.config.annotation.AbstractConfiguredSecurityBuilder.doBuild(AbstractConfiguredSecurityBuilder.java:300) ~[spring-security-config-5.5.0.jar:5.5.0]
    at org.springframework.security.config.annotation.AbstractSecurityBuilder.build(AbstractSecurityBuilder.java:38) ~[spring-security-config-5.5.0.jar:5.5.0]
    at org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration.springSecurityFilterChain(WebSecurityConfiguration.java:127) ~[spring-security-config-5.5.0.jar:5.5.0]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64) ~[na:na]
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
    at java.base/java.lang.reflect.Method.invoke(Method.java:564) ~[na:na]
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.3.7.jar:5.3.7]
    ... 27 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.ldap.server.ApacheDSContainer@2354c1ea': Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: sun/reflect/Reflection
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1786) ~[spring-beans-5.3.7.jar:5.3.7]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:413) ~[spring-beans-5.3.7.jar:5.3.7]
    at org.springframework.security.config.annotation.configuration.AutowireBeanFactoryObjectPostProcessor.postProcess(AutowireBeanFactoryObjectPostProcessor.java:65) ~[spring-security-config-5.5.0.jar:5.5.0]
    ... 54 common frames omitted
Caused by: java.lang.NoClassDefFoundError: sun/reflect/Reflection
    at org.apache.directory.server.core.avltree.ArrayMarshaller.deserialize(ArrayMarshaller.java:153) ~[apacheds-core-avl-1.5.5.jar:na]
    at org.apache.directory.server.core.avltree.ArrayMarshaller.deserialize(ArrayMarshaller.java:43) ~[apacheds-core-avl-1.5.5.jar:na]
    at org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmTable.getDupsContainer(JdbmTable.java:988) ~[apacheds-jdbm-store-1.5.5.jar:na]
    at org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmTable.get(JdbmTable.java:382) ~[apacheds-jdbm-store-1.5.5.jar:na]
    at org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmIndex.forwardLookup(JdbmIndex.java:436) ~[apacheds-jdbm-store-1.5.5.jar:na]
    at org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmStore.getEntryId(JdbmStore.java:904) ~[apacheds-jdbm-store-1.5.5.jar:na]
    at org.apache.directory.server.xdbm.search.impl.DefaultSearchEngine.cursor(DefaultSearchEngine.java:99) ~[apacheds-xdbm-search-1.5.5.jar:na]
    at org.apache.directory.server.core.partition.impl.btree.BTreePartition.search(BTreePartition.java:243) ~[apacheds-core-1.5.5.jar:na]
    at org.apache.directory.server.core.schema.SchemaPartitionDao.listSchemas(SchemaPartitionDao.java:208) ~[apacheds-core-1.5.5.jar:na]
    at org.apache.directory.server.core.schema.SchemaPartitionDao.getSchemas(SchemaPartitionDao.java:168) ~[apacheds-core-1.5.5.jar:na]
    at org.apache.directory.server.core.DefaultDirectoryService.initialize(DefaultDirectoryService.java:1548) ~[apacheds-core-1.5.5.jar:na]
    at org.apache.directory.server.core.DefaultDirectoryService.startup(DefaultDirectoryService.java:971) ~[apacheds-core-1.5.5.jar:na]
    at org.springframework.security.ldap.server.ApacheDSContainer.start(ApacheDSContainer.java:236) ~[spring-security-ldap-5.5.0.jar:5.5.0]
    at org.springframework.security.ldap.server.ApacheDSContainer.afterPropertiesSet(ApacheDSContainer.java:155) ~[spring-security-ldap-5.5.0.jar:5.5.0]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1845) ~[spring-beans-5.3.7.jar:5.3.7]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1782) ~[spring-beans-5.3.7.jar:5.3.7]
    ... 56 common frames omitted
Caused by: java.lang.ClassNotFoundException: sun.reflect.Reflection
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:606) ~[na:na]
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:168) ~[na:na]
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522) ~[na:na]
    ... 72 common frames omitted

下面是我的更多代码片段:

@Configuration
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {

        auth.ldapAuthentication()
            .userSearchBase("ou=Developer")
            .userSearchFilter("(uid={0})")
            .groupSearchBase("ou=Maintainer")
            .groupSearchFilter("uid={0}")
            .contextSource()
            .root("dc=todotrackingsystem,dc=com")
            .ldif("classpath:users.ldif");
    }
    @Override
    protected void configure(HttpSecurity http) throws Exception {

    }
}
@Service
public class UserRepository implements com.todotrackingsystem.Repository.UserRepository {

    @Autowired
    private LdapTemplate ldapTemplate;

    @Override
    public List<User> getAllUsers() {
        return null;
    }

    @Override
    public List<String> getAllUserNames() {
        List<String> list = ldapTemplate.search(query().where("objectclass").is("person"),
                new UserNameAttributesMapper());
        return list;
    }

    @Override
    public User getUserNamesByUid(String userId) {
        List<User> user = ldapTemplate.search(query().where("uid").is(userId), new UserAttributesMapper());
        return ((null != user && !user.isEmpty()) ? user.get(0) : null);
    }

    private class UserAttributesMapper implements AttributesMapper<User> {
        public User mapFromAttributes(Attributes attrs) throws NamingException {
            User user = new User();
            user.setUserID(null != attrs.get("uid") ? (String) attrs.get("uid").get() : null);
            user.setFullName((String) attrs.get("cn").get());
            user.setLastName((String) attrs.get("sn").get());
            user.setDescription(null != attrs.get("description") ? (String) attrs.get("description").get() : null);
            user.setEmail((String) attrs.get("email").get());
            user.setOrganization((String) attrs.get("ou").get());
            user.setTitle((String) attrs.get("title").get());

            return user;
        }
    }

    private class UserNameAttributesMapper implements AttributesMapper<String> {
        public String mapFromAttributes(Attributes attrs) throws NamingException {
            return attrs.get("cn").get().toString();
        }
    }

}
spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration

spring.jpa.hibernate.ddl-auto=create-only
spring.datasource.url=jdbc:mysql://localhost:3306/todo-tracking-system
spring.datasource.username=springstudent
spring.datasource.password=springstudent

spring.ldap.embedded.base-dn=dc=todotrackingsystem,dc=com
spring.ldap.embedded.ldif=classpath:users.ldif
spring.ldap.embedded.port=123
spring.ldap.embedded.validation.enabled=false

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题