猿问

Java SpringBoot Rest OAuth2 Principal 为空

我尝试了有关Java SpringBoot REST OAuth2 身份验证的不同教程。我尝试将它们与简单的 Web 表单身份验证结合起来,但我仍然无法获得 Principal 类对象。我null每次都在我的休息控制器上(显示在下面的行中),我错过了什么吗?


授权服务器配置.java


import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.context.annotation.Configuration;

import org.springframework.security.authentication.AuthenticationManager;

import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer;

import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter;

import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer;

import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer;

import org.springframework.security.oauth2.provider.token.TokenStore;


@Configuration

@EnableAuthorizationServer

public class AuthorizationServerConfiguration extends AuthorizationServerConfigurerAdapter {


    private static final String REALM = "MY_OAUTH_REALM";


    @Autowired

    private TokenStore tokenStore;


    @Autowired

    private AuthenticationManager authenticationManager;


    @Override

    public void configure(ClientDetailsServiceConfigurer clients) throws Exception {

        clients.inMemory()

                .withClient("my-trusted-client")

                .authorizedGrantTypes("password", "authorization_code", "refresh_token", "implicit")

                .scopes("read", "write", "trust")

                .secret("secret")

                .accessTokenValiditySeconds(120).//Access token is only valid for 2 minutes.

                refreshTokenValiditySeconds(600);//Refresh token is only valid for 10 minutes.

    }


    @Override

    public void configure(AuthorizationServerEndpointsConfigurer endpoints) {

        endpoints.tokenStore(tokenStore).authenticationManager(authenticationManager);

    }


}


慕森王
浏览 1775回答 1
1回答
随时随地看视频慕课网APP

相关分类

Java
我要回答