English 中文(简体)
使用自定义验证仪时, 弹簧杯安全服务. getCtrentUnderer () () 是 Null 。
原标题:Grails springSecurityService.getCurrentUser() is Null when using custom AuthenticationProvider

我的应用程序中有一个控制器 需要用户使用外部数据库 进行验证

我已经设置了一个自定义用户对象,

class CustomUserDetails extends GrailsUser {

    final String externalId

    CustomUserDetails(String username, String password, boolean enabled,
        boolean accountNonExpired, boolean credentialsNonExpired,
        boolean accountNonLocked,
        Collection<GrantedAuthority> authorities,
        long id, String externalId) {

        super(username, password, enabled, accountNonExpired,
        credentialsNonExpired, accountNonLocked, authorities, id)

        this.externalId = externalId 
    }       
}

和自定义验证文件Provider

class CustomAuthenticationProvider implements AuthenticationProvider {
    def springSecurityService

    Authentication authenticate(Authentication customAuth) {

    /* Do stuff to validate the user s credentials here */

        def userDetails = new CustomUserDetails(customAuth.getPrincipal(), customAuth.getCredentials(), true, true, true, true, 
                [new GrantedAuthorityImpl( ROLE_SPECIAL_USER )], 9999999, "externalDatabaseIdString")

        def token = new UsernamePasswordAuthenticationToken(userDetails, null, userDetails.authorities)

        return token
    }

    boolean supports(Class authentication) {
        return true
    }
}

我在配置. groovy 中输入了条目, 将它添加到春季安全性。 提供者Names 列表中, 并在 conf/ spring/ resources. groovy 中添加了以下内容。 groovy

beans = {
customAuthenticationProvider(info.proadvisors.auth.CustomAuthenticationProvider){ bean ->   bean.autowire = "byName" }

userDetailsService(org.codehaus.groovy.grails.plugins.springsecurity.GormUserDetailsService){ bean -> bean.autowire = "byName" }
}

这里的问题 - 在我的控制器中, 弹簧保安正在被注射, 但弹簧保安是无效的。 getCrentUser () 。 当我试图访问外部标识属性时, 返回一个无效指针例外 。 外部标识属性应该在验证的用户对象上 。

如果在我的自定义授权Provider中,我用GormUser Details Service给我一个圣杯用户的物品,并用它来制造标记,那么控制器就能正常工作,获得当前用户的作品。

有什么想法 为什么这不起作用吗?

最佳回答

弹簧安全服务。 get Priot () 给了我我要找的东西 。

不清楚为什么获得当前用户 () 在获得 Princpal () 时不工作, 但事实就是这样 。

问题回答

暂无回答




相关问题
grails + gwt request handling via controllers

I am new to gwt. I am trying to integrate gwt+grails.Can anybody provide me a good example for handling the request using grails controllers and not a custom servlet.I will be really thankful if ...

Error loading the grails gwt module xml

I ve installed the plugin from this article by Peter http://www.cacoethes.co.uk/blog/groovyandgrails/the-command-pattern-w.... While compile time its not able to find the module file which is present ...

Sorting Objects Based on Custom Domain Class Methods

I have a domain class, in which I ve defined some methods which give the object a score based on different algorithms (eg. popularity). I now want to retrieve a list of these objects sorted by one of ...

Grails Packaging and Naming Conventions

Packaging Controllers, Services,etc. i.e. - com.company.controllers - com.company.services Is this a good practice or should be avoided by all means?? Another worth mentioning problem I encountered ...

Hibernate/GORM: collection was not processed by flush()

I have an integration test in my Grails application that fails when I try to save an entity of type Member invitingMember.save(flush: true) This raises the following exception org.hibernate....

热门标签