2015-02-14 7 views
4

Я использую плагин Grails «Spring Security OAuth Provider». И я могу получить код доступа на ответ ниже URL.Grails Spring Securiy Oauth Плагин провайдера: для доступа к этому ресурсу требуется полная аутентификация

http://localhost:8080/oauthServer/oauth/authorize?response_type=code&client_id=test_client&scope=read&redirect_uri=http://example.com? 

Но когда я отправить запрос, чтобы получить доступ токенов по кода доступа, используя ниже URL, я получаю «Полная проверка подлинности требуется для доступа к этому ресурсу» сообщение об ошибке.

curl -header "Authorization: Basic bnVkZ2VDbGllbnQ6YjRkNzA3NmE3YTA4N2E4MWMzMTE2ZjZlNWQzZWY0MDJjNmQ4ZjM3Nw==" http://localhost:8080/oauthServer/oauth/token?grant_type=authorization_code&code=kuH8aC 

Примечание:base64(client_id:client_secret)=bnVkZ2VDbGllbnQ6YjRkNzA3NmE3YTA4N2E4MWMzMTE2ZjZlNWQzZWY0MDJjNmQ4ZjM3Nw==

Сообщение полная ошибка приводится ниже.

<oauth> 
<error_description> 
    Full authentication is required to access this resource 
</error_description> 
<error>unauthorized</error> 
</oauth> 

Что мне не хватает. Пожалуйста, предложите.

Благодаря

Update 1

На самом деле я вслед за this documentation яровой безопасности плагин поставщика OAuth.

Есть моя настройка конфигурации.

// Added by the Spring Security OAuth2 Provider plugin: 
grails.plugin.springsecurity.oauthProvider.clientLookup.className = 'com.oauth.Client' 
grails.plugin.springsecurity.oauthProvider.authorizationCodeLookup.className = 'com.oauth.AuthorizationCode' 
grails.plugin.springsecurity.oauthProvider.accessTokenLookup.className = 'com.oauth.AccessToken' 
grails.plugin.springsecurity.oauthProvider.refreshTokenLookup.className = 'com.oauth.RefreshToken' 
grails.plugin.springsecurity.logout.postOnly = false 

//grails.plugin.springsecurity.successHandler.defaultTargetUrl = '/client/index' 

// Added by the Spring Security Core plugin: 
grails.plugin.springsecurity.userLookup.userDomainClassName = 'com.auth.User' 
grails.plugin.springsecurity.userLookup.authorityJoinClassName = 'com.auth.UserRole' 
grails.plugin.springsecurity.authority.className = 'com.auth.Role' 
grails.plugin.springsecurity.controllerAnnotations.staticRules = [ 
    '/oauth/authorize.dispatch':  ["isFullyAuthenticated() and (request.getMethod().equals('GET') or request.getMethod().equals('POST'))"], 
    '/oauth/token.dispatch':   ["isFullyAuthenticated() and request.getMethod().equals('POST')"], 
    '/':        ['permitAll'], 
    '/index':       ['permitAll'], 
    '/index.gsp':      ['permitAll'], 
    '/assets/**':      ['permitAll'], 
    '/**/js/**':      ['permitAll'], 
    '/**/css/**':      ['permitAll'], 
    '/**/images/**':     ['permitAll'], 
    '/**/favicon.ico':    ['permitAll'] 
] 

grails.plugin.springsecurity.providerNames = [ 
     'clientCredentialsAuthenticationProvider', 
     'daoAuthenticationProvider', 
     'anonymousAuthenticationProvider', 
     'rememberMeAuthenticationProvider' 
] 

grails.exceptionresolver.params.exclude = ['password', 'client_secret'] 

grails.plugin.springsecurity.filterChain.chainMap = [ 
     '/oauth/token': 'JOINED_FILTERS,-oauth2ProviderFilter,-securityContextPersistenceFilter,-logoutFilter,-rememberMeAuthenticationFilter', 
     '/securedOAuth2Resources/**': 'JOINED_FILTERS,-securityContextPersistenceFilter,-logoutFilter,-rememberMeAuthenticationFilter', 
     '/**': 'JOINED_FILTERS,-statelessSecurityContextPersistenceFilter,-oauth2ProviderFilter,-clientCredentialsTokenEndpointFilter' 
] 

Мой контроллер по умолчанию один.

@Secured(["#oauth2.clientHasRole('ROLE_CLIENT')"]) 
    def clientRoleExpression() { 
     render "client role expression" 
    } 

    @Secured(["ROLE_CLIENT"]) 
    def clientRole() { 
     render "client role" 
    } 

    @Secured(["#oauth2.clientHasAnyRole('ROLE_CLIENT', 'ROLE_TRUSTED_CLIENT')"]) 
    def clientHasAnyRole() { 
     render "client has any role" 
    } 

    @Secured(["#oauth2.isClient()"]) 
    def client() { 
     render "is client" 
    } 

    @Secured(["#oauth2.isUser()"]) 
    def user() { 
     // code 
    } 

    @Secured(["#oauth2.isUser()"]) 
    def getSubscriptionDetail() { 
     //code 
    } 

    @Secured(["#oauth2.isUser()"]) 
    def getHistory(){ 
     //code 
    } 

    @Secured(["#oauth2.denyOAuthClient()"]) 
    def denyClient() { 
     render "no client can see" 
    } 

    @Secured(["permitAll"]) 
    def anyone() { 
     render "anyone can see" 
    } 

    def nobody() { 
     render "nobody can see" 
    } 

    @Secured(["#oauth2.clientHasRole('ROLE_TRUSTED_CLIENT') and #oauth2.isClient() and #oauth2.hasScope('trust')"]) 
    def trustedClient() { 
     render "trusted client" 
    } 

    @Secured(["hasRole('ROLE_USER') and #oauth2.isUser() and #oauth2.hasScope('trust')"]) 
    def trustedUser() { 
     render "trusted user" 
    } 

    @Secured(["hasRole('ROLE_USER') or #oauth2.hasScope('read')"]) 
    def userRoleOrReadScope() { 
     render "user role or read scope" 
    } 
+0

Какую версию grails вы используете? Я думаю, вы должны предоставить полную аутентификацию для своих действий. – user1791574

+0

Вам нужно больше информации. Отправьте свой конфиг, маршрутизацию и контроллер. –

+0

Как вы это решили? У меня такая же проблема – JohnTheBeloved

ответ

0

Для настройки конечной точки маркера требуется, чтобы запрос был POST. Если нет больше вашей команды завитка, чем указано выше, вы должны иметь что-то вроде

curl -X POST 

в дополнение к --header опции.

0

Я не знал точной причины этой проблемы, но этот вопрос не входит в последнюю версию плагина. Используйте последнюю версию этого плагина.