2012-11-07 2 views
2

Grails 2.1.1Spring Security core 플러그인 1.2.7.3을 설치하고 s2-quickstart 명령을 실행 한 다음 bootstrap.groovy에서 초기 사용자 및 역할을 초기화했습니다. 하지만 여전히 로그인 할 수 없습니다. BootStrap.groovy의 관련 부분의 텍스트는 다음과 같습니다 :이 유형의 대부분의 질문에 대한 답 것으로 보인다 내가, 부트 스트랩의 비밀번호를 암호화하고 있지 않다죄송합니다. 해당 사용자 이름과 암호를 가진 사용자를 찾을 수 없습니다.

if (SecRole.count == 0) { 
     def fUserRole = SecRole.findByAuthority('ROLE_FlowUser') ?: new SecRole(authority: 'ROLE_FlowUser').save(failOnError: true, flush: true) 
     def fAdminRole = SecRole.findByAuthority('ROLE_FlowAdmin') ?: new SecRole(authority: 'ROLE_FlowAdmin').save(failOnError: true, flush: true) 

     def bf = SecUser.findByUsername('bill') ?: new SecUser(
       username: 'bill', 
       password: 'eagle', 
       firstName: 'bill', 
       lastName: 'fly', 
       email: '[email protected]', 
       accountExpired: false, 
       accountLocked: false, 
       passwordExpired: false, 
       enabled: true 
     ).save(failOnError: true, flush: true) 

     if (!bf.authorities.contains(fAdminRole)) { 
      SecUserSecRole.create bf, fAdminRole, true 
     } 
     if (!bf.authorities.contains(fUserRole)) { 
      SecUserSecRole.create bf, fUserRole, true 
     } 
    } 

. 네 개의 레코드가 모두 데이터베이스 테이블에 기록되지만 암호가 올바르게 암호화되었는지는 알 수 없습니다. 내 최초의 컨트롤러는 앞서 class 문 다음과 같은 주석이 있습니다 또한

@Secured(['IS_AUTHENTICATED_FULLY']) 

을, 나는하여 Config.groovy 파일에 다음을 추가 :

을 // 봄 보안 코어 플러그인에 의해 추가 :

grails.plugins.springsecurity.userLookup.userDomainClassName = 'cocktail.SecUser' 
grails.plugins.springsecurity.userLookup.authorityJoinClassName = 'cocktail.SecUserSecRole' 
grails.plugins.springsecurity.authority.className = 'cocktail.SecRole' 
grails.plugins.springsecurity.password.algorithm = 'SHA-256' 

답변

1

이어야합니다. 암호가 두 번 인코딩 될 수 있습니다 (다중 데이터 소스를 사용하는 경우 문제가 발생할 수 있음).

이 시도 :

class User { 
    ... 
    transient bEncoded = false 
    ... 
    protected void encodePassword() { 
     if (!bEncoded) { 
      password = springSecurityService.encodePassword(password); 
      bEncoded = true; 
     } 
    } 
} 
+0

그걸 고쳐 줘! 두 개의 데이터 소스로 인해 beforeInsert가 두 번 실행되지만 위의 코드는 인코딩이 두 번 발생하지 않도록합니다. – user1807149

0

롤 클래스에 hashCodeequals 개의 메소드가 없어서 내 생각에 authorities.contains 체크가 실패했습니다. 어떤 역할 (당신의 첫번째 검사) 다음 사용자가 어떤 부여하지 않았을, 그래서 당신은 단지 그 수표를 제거 할 수없는 경우 :하지만, 그게 해결되지 않으면

SecUserSecRole.create bf, fAdminRole, true 
SecUserSecRole.create bf, fUserRole, true 

를, 그것은 가장 가능성이 암호 인코딩입니다 문제 - Spring Security에 대한 디버그 로깅을 추가하면 실패한 이유를 보여 주어야합니다. Config.groovy의 log4j 블록에 debug 'org.springframework.security'을 추가하십시오.

p.s. if (SecRole.count == 0) {if (SecRole.count() == 0) {이거나 단지 if (!SecRole.count()) {

+0

두 역할, 하나의 사용자, 및 2 개의 사용자 역할 행에 기록되고 있습니다. – user1807149

관련 문제