0
私はSpring Securityを使用してSSO SAMLを実装しました。私のSpring Bootプロジェクトでは、基本的にユーザーをidPログインページにリダイレクトする次のコントローラを用意しています。ログインページに成功したら、JWTトークンを生成します。このJWTトークンは、ヘッダーとして索引ページに転送されます。しかし、私はこれが適切に機能するように思えない。認証後のSpringブートレンダリングインデックスページ
認証コントローラ、
@Controller
public class AuthController {
private static final Logger log = LoggerFactory.getLogger(UserAccountResource.class);
@Inject
private TokenProvider tokenProvider;
/**
* Given that a user is already authenticated then generate a token
*
* @return the ResponseEntity with status 200 (OK) and with body of the updated {@link JWTToken} jwt token
*/
@RequestMapping(value = "/auth/login")
public String login(HttpServletResponse response) throws Exception {
final Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (authentication == null) {
throw new UnauthorizedException();
} else {
try {
final SAMLCredential credential = (SAMLCredential) authentication.getCredentials();
final DateTime dateTime = credential.getAuthenticationAssertion()
.getIssueInstant()
.toDateTime(DateTimeZone.forTimeZone(TimeZone.getDefault()));
String jwt = tokenProvider.createToken(authentication, dateTime.getMillis(), false);
response.addHeader(JWTConfigurer.AUTHORIZATION_HEADER, "Bearer " + jwt);
log.debug("Generated jwt {}", jwt);
log.debug("SAMLCredential {}", credential);
return "forward:/";
} catch (Exception e) {
throw new UnauthorizedException(e);
}
}
}
}
WebMvcConfigurerAdapter
次のように限りSAML SSOを経由してすべてが素晴らしい作品になるよう、
@Configuration("webConfigurer")
public class WebConfigurer extends WebMvcConfigurerAdapter {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/").setViewName("forward:/index.html");
}
}
です。ユーザーはidPログインe.t.cにリダイレクトされます。私が理解できないのは、forward
が期待どおりに動作しない理由です。
すべて私のUI(角度4.x)はindex.html
で開始されます。
これをテストしたところ、/
に転送されていることがわかりましたが、ヘッダーは流れません。