【问题标题】:Principal Class Object Null主体类对象空
【发布时间】:2019-04-09 06:43:30
【问题描述】:

我在 Spring Boot 中使用主体类来实现身份验证,每次我将凭据发送到登录时,主体对象都设置为 null。

 @RequestMapping("/user")
 public Principal loginAuthentication(Principal user) {

   LOGGER.debug("Request received from frontend to authenticate the user");

   try {
            LOGGER.debug("In try block to authenticate the user");
            LOGGER.debug("Returning the user object to the front end");
            return user;
   }
   catch(Exception e) {
            LOGGER.error("An exception occured while trying to authenticate the user: " +e);
            LOGGER.error("Returning NULL to front end");
            return null;
   }
 }

【问题讨论】:

    标签: spring-boot spring-mvc authentication


    【解决方案1】:

    这种类型的类通常位于授权服务器上。

    然后从您要检查用户是否已通过身份验证的安全资源服务器,在您放置的 application.properties 或 application.yml 中:

    oauth2:
        resource:
          userInfoUri: ${your_auth_server}/user
    

    spring会自动检查,但对登录没用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-25
      • 1970-01-01
      • 2019-04-26
      相关资源
      最近更新 更多