升级azure spring boot starter active directory以获得ad用户角色

fdbelqdn  于 2021-09-29  发布在  Java
关注(0)|答案(0)|浏览(271)

我正在寻找从azure active directory spring boot starter 2.3.5到最新版本azure spring boot starter active directory 3.6.1的帮助。
我们当前的用例是用户使用aad登录到web应用程序。web应用程序将后端spring引导应用程序与包含用户数据的请求中的jwt联系。我们使用预授权注解通过securitychain将请求发送到aadauthenticationfilter。过滤器破译jwt,联系microsoft graph api,检查用户是否具有具有声明前缀的用户角色(以下示例代码中为“a1”),如果是,则将用户和用户角色添加到请求中,然后返回该请求。这在azure active directory spring boot starter 2.3.5上运行良好,但是当我们尝试升级到3.6.1时,出现了一些突破性的变化,包括现在不推荐使用的aadauthenticationfilter类。我们需要升级以删除2.3.5版存在的一些依赖漏洞。
值得一提的是,我们使用的当前解决方案经过了轻微修改,允许我们检查以声明的前缀开头的用户角色。我们使用了spring security和azure的答案:是否存在active directory组通配符?为了实现这一点。

@PreAuthorize("@RoleCheck.roleHasPrefix(#req, 'ROLE_A1-')")
@CrossOrigin
@GetMapping(path = "/myPermissions", produces = APPLICATION_JSON_VALUE)
public List<Permission> myPermissions(@Context HttpServletRequest req){
    return permHelper.getUserPermissions(permHelper.getAuthorities(req));
}

安全配置

@EnableGlobalMethodSecurity(securedEnabled = true,
        prePostEnabled = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Autowired
    private A1AADAuthenticationFilter aadAuthFilter;

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

        http.cors().and().authorizeRequests().anyRequest().permitAll().and().csrf().disable();
        http.addFilterBefore(aadAuthFilter, UsernamePasswordAuthenticationFilter.class);

    }
}

当升级到3.6.1时,包已被更改,某些类不再存在,例如serviceendpointsproperties,如果我们尝试实现当前正在工作的旧解决方案,我们会始终收到空指针异常,因为我们无法注入某些类。我们必须从api中复制和修改一些类,以使应用程序可能启动,这是不实际的。
如果我们使用api附带的不推荐使用的aadauthenticationfilter,那么前缀检查将不再有效,我们将得到以下错误。

c.a.s.a.aad.AADAuthenticationFilter      : Request token verification success. org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken@40dfe192: Principal: com.azure.spring.autoconfigure.aad.UserPrincipal@4c2e3a2; Credentials: [PROTECTED]; Authenticated: true; Details: null; Granted Authorities: ROLE_USER

如果我们忽略前缀并通过属性“azure.activedirectory.user group.allowed group names”明确声明允许哪些用户角色,我们就可以让它正常工作。但是,这对我们来说不是很实际,因为经常添加新的用户角色。我们很乐意返回用户拥有的每个角色,并使用以下属性在后端对自己进行筛选:
azure.activedirectory.user组。允许的组ID:所有
azure.activedirectory.user组。启用完整列表:true
但是,这再次产生了错误:

c.a.s.a.aad.AADAuthenticationFilter      : Request token verification success. org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken@40dfe192: Principal: com.azure.spring.autoconfigure.aad.UserPrincipal@4c2e3a2; Credentials: [PROTECTED]; Authenticated: true; Details: null; Granted Authorities: ROLE_USER

如果您能提供任何帮助,我们将不胜感激,理想情况下,我们仍然希望首先检查前缀,但是如果这不可能,那么我们很乐意返回所有用户角色,我们可以稍后编写代码对其进行过滤。很遗憾,属性“azure.activedirectory.user group.allowed group Name”不接受通配符,因此我们可以在那里输入前缀。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题