为什么可以';使用安装在grails framework 1.3.7中的spring security和weceem插件登录

为什么可以';使用安装在grails framework 1.3.7中的spring security和weceem插件登录,grails,groovy,grails-plugin,spring-security,Grails,Groovy,Grails Plugin,Spring Security,我正在进行一个几乎干净的Grails1.3.7项目,其中安装了weceem 1.0RC2、spring security core 1.1.3、spring security ui 0.1.2、weceem spring security 1.0及其依赖项 除了用户登录外,一切正常。当我想登录时,我只收到以下错误消息: Sorry, we were not able to find a user with that username and password. 但是该用户仍然存在于数据库中,如

我正在进行一个几乎干净的Grails1.3.7项目,其中安装了weceem 1.0RC2、spring security core 1.1.3、spring security ui 0.1.2、weceem spring security 1.0及其依赖项

除了用户登录外,一切正常。当我想登录时,我只收到以下错误消息:

Sorry, we were not able to find a user with that username and password.
但是该用户仍然存在于数据库中,如果使用由SpringSecurityUI创建的用户,我会收到相同的错误消息。要对密码进行编码,我使用springSecurityService.encodePassword(“密码”)。LoginController是由spring security(s2 quickstart)生成的

我想weceem-spring安全桥可能有问题,你有什么建议

致以最良好的祝愿, 怀特尼克斯

import grails.converters.JSON
import javax.servlet.http.HttpServletResponse
import org.codehaus.groovy.grails.plugins.springsecurity.SpringSecurityUtils
import org.springframework.security.authentication.AccountExpiredException
import org.springframework.security.authentication.CredentialsExpiredException
import org.springframework.security.authentication.DisabledException
import org.springframework.security.authentication.LockedException
import org.springframework.security.core.context.SecurityContextHolder as SCH
import org.springframework.security.web.WebAttributes
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter

class LoginController {

/**
 * Dependency injection for the authenticationTrustResolver.
 */
def authenticationTrustResolver

/**
 * Dependency injection for the springSecurityService.
 */
def springSecurityService

/**
 * Default action; redirects to 'defaultTargetUrl' if logged in, /login/auth otherwise.
 */
def index = {
    if (springSecurityService.isLoggedIn()) {
        redirect uri: SpringSecurityUtils.securityConfig.successHandler.defaultTargetUrl
    }
    else {
        redirect action: auth, params: params
    }
}

/**
 * Show the login page.
 */
def auth = {

    def config = SpringSecurityUtils.securityConfig

    if (springSecurityService.isLoggedIn()) {
        redirect uri: config.successHandler.defaultTargetUrl
        return
    }

    String view = 'auth'
    String postUrl = "${request.contextPath}${config.apf.filterProcessesUrl}"
    render view: view, model: [postUrl: postUrl,
                rememberMeParameter: config.rememberMe.parameter]
}

/**
 * The redirect action for Ajax requests. 
 */
def authAjax = {
    response.setHeader 'Location', SpringSecurityUtils.securityConfig.auth.ajaxLoginFormUrl
    response.sendError HttpServletResponse.SC_UNAUTHORIZED
}

/**
 * Show denied page.
 */
def denied = {
    if (springSecurityService.isLoggedIn() &&
    authenticationTrustResolver.isRememberMe(SCH.context?.authentication)) {
        // have cookie but the page is guarded with IS_AUTHENTICATED_FULLY
        redirect action: full, params: params
    }
}

/**
 * Login page for users with a remember-me cookie but accessing a IS_AUTHENTICATED_FULLY page.
 */
def full = {
    def config = SpringSecurityUtils.securityConfig
    render view: 'auth', params: params,
            model: [hasCookie: authenticationTrustResolver.isRememberMe(SCH.context?.authentication),
                postUrl: "${request.contextPath}${config.apf.filterProcessesUrl}"]
}

/**
 * Callback after a failed login. Redirects to the auth page with a warning message.
 */
def authfail = {

    def username = session[UsernamePasswordAuthenticationFilter.SPRING_SECURITY_LAST_USERNAME_KEY]
    String msg = ''
    def exception = session[WebAttributes.AUTHENTICATION_EXCEPTION]
    if (exception) {
        if (exception instanceof AccountExpiredException) {
            msg = SpringSecurityUtils.securityConfig.errors.login.expired
        }
        else if (exception instanceof CredentialsExpiredException) {
            msg = SpringSecurityUtils.securityConfig.errors.login.passwordExpired
        }
        else if (exception instanceof DisabledException) {
            msg = SpringSecurityUtils.securityConfig.errors.login.disabled
        }
        else if (exception instanceof LockedException) {
            msg = SpringSecurityUtils.securityConfig.errors.login.locked
        }
        else {
            msg = SpringSecurityUtils.securityConfig.errors.login.fail
        }
    }

    if (springSecurityService.isAjax(request)) {
        render([error: msg] as JSON)
    }
    else {
        flash.message = msg
        redirect action: auth, params: params
    }
}

/**
 * The Ajax success redirect url.
 */
def ajaxSuccess = {
    render([success: true, username: springSecurityService.authentication.name] as JSON)
}

/**
 * The Ajax denied redirect url.
 */
def ajaxDenied = {
    render([error: 'access denied'] as JSON)
}
}

从你提供的一点信息来判断有点棘手。Weceem Spring安全插件将Spring安全核心与Weceem的身份验证机制连接起来

它通过提供一个自定义UserDetailsService实现来实现这一点,该实现将域类映射到SpringSecurityCore使用的会话数据对象

这个登录URL,是否映射到上面详述的您自己的登录控制器?weceem spring安全插件中的UserDetailsService使用配置的用户域类调用findByUsername(用户名):

从上面可以看出,我认为最后一行可能是因为spring域类/用户名的问题而放弃的

如果问题与安装后登录Weceem有关(看起来不是),则需要确保已配置Weceem Spring Security应如何从用户域类映射到Weceem和Spring sec core运行所需的内部数据,请参阅:


从您提供的小信息中判断有点棘手。Weceem Spring安全插件将Spring安全核心与Weceem的身份验证机制连接起来

它通过提供一个自定义UserDetailsService实现来实现这一点,该实现将域类映射到SpringSecurityCore使用的会话数据对象

这个登录URL,是否映射到上面详述的您自己的登录控制器?weceem spring安全插件中的UserDetailsService使用配置的用户域类调用findByUsername(用户名):

从上面可以看出,我认为最后一行可能是因为spring域类/用户名的问题而放弃的

如果问题与安装后登录Weceem有关(看起来不是),则需要确保已配置Weceem Spring Security应如何从用户域类映射到Weceem和Spring sec core运行所需的内部数据,请参阅:


我刚刚解决了一个症状相同的问题

事实证明,我在Config.groovy中的映射闭包有一个输入错误,我正在将一个不存在的字段映射到用户的weceem视图中的“password”字段

因此,插件注入的自定义UserDetailsService只是讨厌我的用户对象,没有任何东西能正常工作


我在映射的域端将passwd更改为password,以使其与我的用户对象中的实际内容相匹配,并且一切正常。

我刚刚解决了一个具有相同症状的问题

事实证明,我在Config.groovy中的映射闭包有一个输入错误,我正在将一个不存在的字段映射到用户的weceem视图中的“password”字段

因此,插件注入的自定义UserDetailsService只是讨厌我的用户对象,没有任何东西能正常工作


我在映射的域端将passwd更改为password,以使其与我的用户对象中的实际内容相匹配,一切正常。

阅读上面的@Dan解决方案,我建议您更改文档,以便映射闭包中的字段名为password:password,而不是密码:passwd-谢谢:)也许有人可以告诉我如何用SpringSecurity、weceem和SpringSecurity-weceem插件安装Grails1.3.7应用程序?我想我的错误在别处。。谢谢!:)阅读上面的@Dan solution,我是否可以建议您更改文档,以便映射闭包中的字段名是password:password,而不是password:passwd-谢谢:)也许有人可以告诉我如何使用spring security、weceem和spring security weceem插件设置grails 1.3.7应用程序?我想我的错误在别处。。谢谢!:)我记录了mysql查询并发现:选择此id为id9\U 0,此版本为version9\U 0,此帐户过期为account3\U 9\U 0,此帐户锁定为account4\U 9\U 0,此启用为enabled9\U 0,此密码过期为password6\U 9\U 0,此密码过期为password7\U 9\U 0,此用户名为username9\u 0\u来自用户this,where this\u.username='admin'->我认为是错误的?我记录了mysql查询并发现:将此id选择为id9\u 0,将此版本选择为version9\u 0,将此帐户作为account3\u 9\u 0过期,将此帐户锁定为account4\u 9\u 0,将其启用为enabled9\u 0,此密码作为密码6\u 9\u 0\u,此密码作为密码7\u 9\u 0\u过期,此用户名作为用户名9\u 0\u来自用户this\u,此处为\u用户名='admin'->我认为是错误的?
void afterPropertiesSet() {
    def conf = grailsApplication.config
    def clsname = conf.grails.plugins.springsecurity.userLookup.userDomainClassName
    domainClass = grailsApplication.getDomainClass(clsname).clazz

    def mapper = conf.weceem.springsecurity.details.mapper
    if (!(mapper instanceof Closure)) {
        throw new IllegalArgumentException(
            "Your Config must specify a closure in weceem.springsecurity.details.mapper "+
            "that maps the domain model to a non-domain object, providing at least: ${REQUIRED_MAPPED_FIELDS}")
    }
    detailsMapper = mapper
}

UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {

    domainClass.withTransaction { status ->

        def user = domainClass.findByUsername(username)
        if (!user) throw new UsernameNotFoundException('User not found', username)