저는 응용 프로그램 엔진에 스프링 보안을 사용하려고합니다. 내 자신의 userdetailsservice를 구현했습니다. 여기 봄 보안 사용자 정의 UserDetailsService를 찾을 수 없습니다.
package com.example.mymodule.app2;
import com.example.mymodule.repoobject.MutiboUser;
import com.example.mymodule.repository.MutiboUserRepo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;
import java.util.Collection;
import java.util.List;
@Component
public class MutiboUserDetailsService implements UserDetailsService {
private final MutiboUserRepo mutiboUserRepo;
@Autowired
public MutiboUserDetailsService(MutiboUserRepo mutiboUserRepo) {
if (mutiboUserRepo == null) {
throw new IllegalArgumentException("mutiboUserRepo cannot be null");
}
this.mutiboUserRepo = mutiboUserRepo;
}
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
MutiboUser mutiboUser = mutiboUserRepo.findByName(username);
if (mutiboUser == null) {
throw new UsernameNotFoundException("Invalid username/password.");
}
List<GrantedAuthority> authorityList = AuthorityUtils
.createAuthorityList("ROLE_USER");
return new User(mutiboUser.getEmail(), mutiboUser.getPassword(), authorityList);
}
}
내 web.xml을
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">
<context:component-scan base-package="com.example.mymodule">
<context:exclude-filter type="regex" expression="com.example.mymodule.*"/>
</context:component-scan>
</beans>
및 security.xml
<?xml version="1.0" encoding="UTF-8"?>
<b:beans xmlns="http://www.springframework.org/schema/security"
xmlns:b="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd">
<http auto-config="true">
<intercept-url access="ROLE_USER" pattern="/*" />
</http>
<authentication-manager>
<authentication-provider
ref="mutiboUserDetailsService"/>
</authentication-manager>
</b:beans>
하지만 내 응용 프로그램을 테스트 할 피곤 때마다
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring/services.xml
/WEB-INF/spring/security.xml
</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<!-- intercept all requests -->
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>
org.springframework.web.filter.DelegatingFilterProxy
</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>
<!-- Spring MVC DispatcherServelt -->
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextClass</param-name>
<param-value>
org.springframework.web.context.support.AnnotationConfigWebApplicationContext
</param-value>
</init-param>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
com.example.mymodule.app2.Application
</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<!-- to mora it preko https (app engine)-->
<security-constraint>
<web-resource-collection>
<web-resource-name>question</web-resource-name>
<url-pattern>/question/*</url-pattern>
</web-resource-collection>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
</web-app>
services.xml 파일입니다 이 오류가 발생합니다.
'org.springframework.security.authentication.dao.DaoAuthenticationProvider#0': Cannot
resolve reference to bean 'mutiboUserDetailsService' while setting bean property
'userDetailsService'; nested exception is
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named
'mutiboUserDetailsService' is defined.
나를 도와 줄 사람이 있습니까? 감사.
감사합니다. 하지만 이제이 오류가 발생합니다. FactoryBean은 객체 생성시 예외를 던졌습니다. 중첩 예외는 org.springframework.beans.factory.BeanCreationException입니다 : 이름 'org.springframework.security.authenticationManager'로 bean을 생성하는 중 오류가 발생했습니다 : 일치하는 생성자를 해결할 수 없습니다 (힌트 : 유형 모호성을 피하기 위해 간단한 매개 변수에 대한 색인/유형/이름 인수 지정) – usil
업데이트 된 답변보기. – pgiecek