spring-boot-admin是否支持sso?

时间:2020-06-25 17:56:33

标签: single-sign-on spring-boot-admin

我正在尝试将spring-boot-admin与公司SSO集成在一起,spring-boot-admin是否支持sso登录?我找不到有关它的文档。

1 个答案:

答案 0 :(得分:0)

我明白了。实施步骤:

  1. 创建具有sso提供程序将调用的端点的控制器。
  2. 在端点中,放入用于sso集成的逻辑,
  3. 成功后,重定向到/ applications
  4. 失败时,引发异常
@Controller
public class SsoIntegration {

    // this does addition authentication stuff, like sets up the 
    // right authorities...etc
    @Autowired
    private AuthenticationProvider authenticationProvider;


    // my sso provider creates a vanity url that redirects to 
    // this endpoint and passes 2 request params using POST
    @RequestMapping(value={"/sso"}, method = {RequestMethod.POST})
    public String ssologin (
              @RequestParam(name="param1") String param1, 
              @RequestParam(name="param2") String param2 ) 
    {

        // do your sso integration logic here
        // eg...
        SsoUtil util = new SsoUtil();
        String userInfo = util.decrypt(param1, param2, ...);

        ...
        if (authenticationProvider.authenticate( userInfo )) {
          Authentication postAuthentication = ...// populate your successfully authenticated user
           

          // these next lines are the important stuff
          // 1. set the postAuthentication into the security context 
          SecurityContextHolder.getContext().setAuthentication(postAuthentication); 

          // 2. redirect to the applications page
          return "redirect:/applications";
        }
        
        // authentication failed, throw an exception...
        throw new RuntimeException ("Sso Authentication failed");
    }
}