如何从Spring Boot中的Azure SAML 2.0应用程序中获取角色或组

问题描述 投票:0回答:1

我有一个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个回答
0
投票

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

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

© www.soinside.com 2019 - 2024. All rights reserved.