亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Java SpringBoot Rest OAuth2 Principal 為空

Java SpringBoot Rest OAuth2 Principal 為空

慕森王 2021-08-13 15:14:47
我嘗試了有關Java SpringBoot REST OAuth2 身份驗證的不同教程。我嘗試將它們與簡單的 Web 表單身份驗證結合起來,但我仍然無法獲得 Principal 類對象。我null每次都在我的休息控制器上(顯示在下面的行中),我錯過了什么嗎?授權服務器配置.javaimport 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@EnableAuthorizationServerpublic 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);    }}
查看完整描述

1 回答

  • 1 回答
  • 0 關注
  • 1862 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號