【问题标题】:How can I get roles or groups from Azure SAML 2.0 Application in Spring Boot如何在 Spring Boot 中从 Azure SAML 2.0 应用程序获取角色或组
【发布时间】:2019-07-20 06:29:33
【问题描述】:

我有一个 Spring Boot 应用程序,我需要在其中限制对特定端点的访问。到目前为止,我可以使用 SAML 2.0 对 Azure 进行身份验证。

这是Spring中认证的主要配置

@Override
	protected void configure(HttpSecurity http) throws Exception {

		http
				.exceptionHandling()
				.authenticationEntryPoint(samlEntryPoint());

		http
				.csrf()
				.disable();


		http
				.addFilterBefore(metadataGeneratorFilter(), ChannelProcessingFilter.class)
				.addFilterAfter(samlFilter(), BasicAuthenticationFilter.class);

		http
				.authorizeRequests()
				.antMatchers("/error").permitAll()
				.antMatchers("/saml/**").permitAll()
				.anyRequest().authenticated();

		http
				.logout()
				.logoutSuccessUrl("/");

	}

在 Azure 中,我已将角色添加到声明值中,如下图所示

Azure Claims

我的目标是能够立即执行以下操作:

@GetMapping("/")
	@PreAuthorize("hasRole('User')")
	public String getSample(Principal principal) {
		log.info("Get Request");
		return "Hello";
	}

【问题讨论】:

    标签: spring-boot azure-active-directory saml saml-2.0 spring-saml


    【解决方案1】:

    下一步是实现您自己的SAMLUserDetailsService,它将返回相应的UserDetail 实例,并授予用户Authorities 权限。

    您必须从 SAMLCredential 中检索 Azure 角色列表(类似于 credential.getAtttributeAsString(<your_attribute_name>),然后您必须将这些值与您的应用程序中定义的权限列表进行映射。

    【讨论】:

    • 非常感谢您的提示,搜索并为我工作。
    猜你喜欢
    • 2018-02-28
    • 2022-01-02
    • 2018-08-17
    • 2014-06-02
    • 2022-08-10
    • 1970-01-01
    • 1970-01-01
    • 2021-11-17
    • 1970-01-01
    相关资源
    最近更新 更多