2014-01-18 6 views
1

저는 봄 보안에 아주 새로운 기술입니다. 스프링 보안 기능을 사용하고 싶습니다. 다음 코드를 사용하고 있습니다.인증이 봄에 작동하지 않습니다.

내 security.xml는

.... 코드는 다음과 같습니다이

<http auto-config="true" use-expressions="true"> 
     <intercept-url pattern="/css/**" filters="none" /> 
     <intercept-url pattern="/sign/**" access="isAnonymous()"/> 
<!--   <intercept-url pattern="/signin" access="ROLE_USER" /> --> 
     <intercept-url pattern="/singout" access="permitAll" /> 
     <intercept-url pattern="/accessdenied" access="permitAll" /> 
     <intercept-url pattern="/**" access="hasRole('ROLE_USER')" /> 
     <form-login login-page="/signin" default-target-url="/home" authentication-failure-url="/signin" /> 
     <logout logout-success-url="/logout" /> 
    </http> 

    <authentication-manager> 
      <authentication-provider user-service-ref="userLoginService"> 
       <password-encoder hash="plaintext"/> 
<!--   <user-service> --> 
<!--    <user name="mkyong" password="123456" authorities="ROLE_USER" /> --> 
<!--   </user-service> --> 
      </authentication-provider> 
     </authentication-manager> 

사용자 로그인 서비스 .....

public class UserLoginService implements UserDetailsService { 

    @Autowired 
    IDaoSupport loginDao; 

    public void setLoginDao(IDaoSupport loginDao) { 
     this.loginDao = loginDao; 
    } 

    public Collection<? extends GrantedAuthority> getAuthorities(Integer role) { 
     List<GrantedAuthority> authList = getGrantedAuthorities(getRoles(role)); 
     return authList; 
    } 

    public List<String> getRoles(Integer role) { 

     List<String> roles = new ArrayList<String>(); 

     if (role.intValue() == 1) { 
      roles.add("ROLE_MODERATOR"); 
      roles.add("ROLE_ADMIN"); 
      roles.add("ROLE_USER"); 
     } else if (role.intValue() == 2) { 
      roles.add("ROLE_MODERATOR"); 
     } 
     return roles; 
    } 

    public static List<GrantedAuthority> getGrantedAuthorities(List<String> roles) { 
     List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>(); 

     for (String role : roles) { 


      authorities.add(new SimpleGrantedAuthority(role)); 

     } 
     return authorities; 
    } 

    @Override 
    public UserDetails loadUserByUsername(String email) 
      throws UsernameNotFoundException { 

     Person person = loginDao.findByProp(Person.class, "loginId", email); 
     return new User(person.getLoginId(), person.getPassword(), getAuthorities(1)); 
    } 
} 

web.xml 파일은 다음과 같습니다과 같이

하지만이 코드를 사용하면 다음 코드가 표시됩니다.

.service() for servlet [rrank] in context with path [/sample] threw exception [Filter execution threw an exception] with root cause 
java.lang.NoSuchMethodError: org.springframework.security.authentication.AnonymousAuthenticationToken.<init>(Ljava/lang/String;Ljava/lang/Object;Ljava/util/List;)V 
    at org. 

일부 신체는이 코드에서 나에게 무슨 문제가 있는지 말해 줄 수 있습니다.

+3

것 같습니다 MAVEN REPOSITARY SPRING SECURITY

행운의 일치하는 버전을 선택할 수 있습니다. 그것은'NoSuchMethodError'가 보통 의미하는 것입니다. –

답변

2

스프링 프레임 워크 lib 버전이 사용자의 스프링 보안 lib 버전과 일치하지 않습니다.

당신은 당신이 아마 어딘가에 일부 라이브러리의 미스 매치 버전이 같은

관련 문제