Java 从spring security标头中的用户名获取权限

Java 从spring security标头中的用户名获取权限,java,spring-security,siteminder,Java,Spring Security,Siteminder,我需要为我的api控制器实现spring安全性 ->每个页面都应该包含一个带有用户名的标题,如Siteminder?。 ->每个用户都已在SpringConfiguration中注册 @Autowired public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { ... gets all users from database with their autho

我需要为我的api控制器实现spring安全性

->每个页面都应该包含一个带有用户名的标题,如Siteminder?。 ->每个用户都已在SpringConfiguration中注册

@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
                ... gets all users from database with their authorities
}
->对于配置的每个页面,用户应该具有哪些权限

@Override
protected void configure(HttpSecurity http) throws Exception { 
        http.authorizeRequests()
            .antMatchers("**/Pagename/**").hasAuthority("authorityName");
    }
我现在不明白,我应该添加什么使程序从页眉读取用户名。RequestHeaderAuthenticationFilter?另一种过滤器


另一个问题是,您是否可以给我一个到教程/examle的链接,说明如何在不使用XML的情况下构建它。

看一下本指南:

尝试将以下JSTL放在需要获取用户名的位置
${pageContext.request.remoteUser}

它对我有什么帮助?页面标题和筛选器中没有用户名的示例。其他的东西,正如你上面看到的,我已经自己实现了。如果您需要用户名HttpServletRequestrequest.getUserPrincipal.getName如果您需要权限SecurityContextHolder.getContext.getAuthentication.GetAuthority第一个方法的链接在该指南中,我需要从页眉提取用户名,然后您可以从HttpServletrequest获取它HttpServletRequestrequest.getUserPrincipal.getNameI不需要显示它。我需要从标题中提取它并检查此用户的权限。然后使用自定义安全筛选器只需在spring 4I中搜索如何使用自定义安全筛选器我发现了一个很好的配置示例: