2016-08-13 6 views
2

스프링 데이터 JPA를 사용하여 Apache Shiro와 Spring Boot를 통합했습니다. Spring Boot 프로젝트는 this GitHub 레포에 있습니다. 내가 실행하고 나는Shiro with Springboot integration

roleAdmin.getId() 1: null 
roleAdmin.getId() 2: 3 
Current user is not authenticated. 
2016-08-13 09:49:45.715 WARN 10528 --- [lication Thread] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 0, SQLState: S0022 
2016-08-13 09:49:45.716 ERROR 10528 --- [lication Thread] o.h.engine.jdbc.spi.SqlExceptionHelper : Column 'id' not found. 
Authentication failed for token submission [org.apache.shiro.authc.UsernamePasswordToken - yunus, rememberMe=false]. Possible unexpected error? (Typical or expected login exceptions should extend from AuthenticationException). 

그것은 완전히 인증하지 못하는 다음과 같은 오류를 얻을 응용 프로그램을 인증 할 때

문제

이며, 나는 내 문제를 정교 this의 repo를 만들 수 있었다. 확인 해봐.

해결 방법과 비판은 매우 수용 가능합니다.

업데이트

여분의 정보가 내 질문을 명확히 할 필요가, 그냥 물어

답변

1

귀하의 오류 메시지가 사용자 저장소의 @Query 정의에 놓여 문제를 나타낸다 :

@Query(value = "SELECT u.username FROM users u WHERE u.username = ?1", nativeQuery = true) 
User findByUsername(String username); 

보시다시피 모든 열을 선택하는 대신 사용자 이름 만 선택하는 것입니다. 당신이 스프링 데이터 JPA를 사용하고 있기 때문에, 당신이 정말로 전혀 @Query 필요하지 않습니다, 그것은 충분는 대답 : 당신이 당신의 사용자 정의 영역에 암호를 비교하는 방법

User findByUsername(String username); 

귀하의 다른 문제는, 그러나,이다. DB를에서 오는 암호는 you'e 그냥 paswords 자신을 확인하기 때문에 그냥,

user.getPassword().equals(new String(upat.getPassword())) 

당신은 그 passwordsMatch 메소드를 호출하여 DefaultPasswordService를 사용하여 암호를 비교해야합니다 말할 수 있다는 것을 의미 암호화됩니다 귀하의 영역에서 AllowAllCredentialsMatcher을 사용해야합니다 :

public class CustomSecurityRealm extends AuthorizingRealm { 

    @Autowired 
    private UserManagerService userManager; 

    @Autowired 
    private DefaultPasswordService passwordService; 

    public CustomSecurityRealm() { 
     this(new AllowAllCredentialsMatcher()); 
    } 

    public CustomSecurityRealm(final CredentialsMatcher matcher) { 
     super(matcher); 
    } 

    @Override 
    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) { 
     // remains the same 
    } 

    @Override 
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { 
     UsernamePasswordToken upat = (UsernamePasswordToken) token; 
     User user = userManager.findByUsername(upat.getUsername());        
     if(user != null && passwordService.passwordsMatch(upat.getPassword(), user.getPassword())) { 
      return new SimpleAuthenticationInfo(user, user.getPassword(), getName()); 
     } 
     else { 
      throw new AuthenticationException("Invalid username/password combination!"); 
     } 
    } 
} 
+0

그것은 당신 덕분에 작동합니다. 이 문제는 저를 loooong 동안 붙들고 있습니다. –

+1

굉장! Btw, 실행 가능한 예제를 게시하면 많은 도움이되었습니다. 더 많은 사람들이 그렇게한다면 문제를 추적하는 데 약 5 분이 걸렸습니다. :) –