LDAPセキュリティ構成をxml構成で機能させるのに苦労しています。
次のエラーが表示されます。
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'securityConfig': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.security.ldap.authentication.LdapAuthenticationProvider sgcbmw.security.SecurityConfig.ldapAuthenticationProvider; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.security.ldap.authentication.LdapAuthenticationProvider] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: @org.springframework.beans.factory.annotation.Autowired(required=true)
私のセキュリティ構成:
<bean id="contextSource"class="org.springframework.security.ldap.DefaultSpringSecurityContextSource">
<constructor-arg value="ldap:/ldapserver"/>
<property name="userDn" value="user"/>
<property name="password" value="pass"/>
</bean>
<bean id="ldapAuthProvider"
class="org.springframework.security.ldap.authentication.LdapAuthenticationProvider">
<constructor-arg>
<bean class="org.springframework.security.ldap.authentication.BindAuthenticator">
<constructor-arg ref="contextSource"/>
<property name="userSearch">
<bean id="userSearch"
class="org.springframework.security.ldap.search.FilterBasedLdapUserSearch">
<constructor-arg index="0" value=""/>
<constructor-arg index="1" value="(&(objectClass=user)(sAMAccountName={0}))"/>
<constructor-arg index="2" ref="contextSource" />
</bean>
</property>
<property name="userDnPatterns">
<list><value>uid={0},ou=people</value></list>
</property>
</bean>
</constructor-arg>
<constructor-arg>
<bean class="org.springframework.security.ldap.userdetails.DefaultLdapAuthoritiesPopulator">
<constructor-arg ref="contextSource"/>
<constructor-arg value="ou=groups"/>
<property name="groupRoleAttribute" value="memberOf"/>
</bean>
</constructor-arg>
</bean>
<security:authentication-manager>
<security:authentication-provider ref="ldapAuthProvider" />
</security:authentication-manager>
構成アダプター:
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private LdapAuthenticationProvider ldapAuthenticationProvider;
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.authenticationProvider(ldapAuthenticationProvider);
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.authorizeRequests()
.anyRequest().fullyAuthenticated()
.and()
.formLogin();
}
}
この方法でLdapAuthenticationProviderを注入するべきではありませんか?
私の問題を解決したもの:
セキュリティのためだけに1つのコンテキストxml構成を作成し、web.xmlに以下を追加しました。
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/business-config.xml classpath:spring/spring-security-config.xml</param-value>
</context-param>
そして最後に、Spring-security-config.xmlでBeanを構成し、クラスWebSecurityConfigurerAdapterでそれらを自動配線します。これをxmlから削除しました:
<security:authentication-manager>
<security:authentication-provider ref="ldapAuthProvider" />
</security:authentication-manager>
手伝ってくれてありがとう。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加