使用webgate的Spring Security

时间:2015-02-28 09:24:01

标签: spring-security

我正在开发一个spring MVC应用程序。我正在使用webgate实现spring security。我正在关注this文章。当我实现与在博客中相同时,我收到以下错误。

java.lang.IllegalStateException:找不到方法:找不到可以采用类型为org.springframework.security.web.firewall.RequestWrapper

类型的单个参数的构造函数

enter image description here

我的buildDetails( - )代码是这样的

public Object buildDetails(Object context)
 {
     System.out.println("HeaderAuthenticationDetails:buildDetails::: "+context);

    Object result = super.buildDetails(context);  //getting error in super class
        List<GrantedAuthority> userGas = new ArrayList<GrantedAuthority>();
        if (result instanceof MutableGrantedAuthoritiesContainer) {
          Collection<String> userRoles = getUserRoles(context, allRoles);
          userGas = (List<GrantedAuthority>) grantedAuthoritiesMapper.getGrantedAuthorities(userRoles);
          ((MutableGrantedAuthoritiesContainer) result).setGrantedAuthorities(userGas);
        }
        return result;
 }

1 个答案:

答案 0 :(得分:0)

我可以通过修改buildDetails( - )来解决这个问题,如下所示

public Object buildDetails(Object context)
 {       
     List<GrantedAuthority> userGas = new ArrayList<GrantedAuthority>();
     MutableGrantedAuthoritiesContainer container=new PreAuthenticatedGrantedAuthoritiesAuthenticationDetails(context);
     Collection<String> userRoles = getUserRoles(context, allRoles);
     userGas = (List<GrantedAuthority>) grantedAuthoritiesMapper.getGrantedAuthorities(userRoles);
      container.setGrantedAuthorities(userGas);
        return container;
 }

在我的getUserRoles( - , - )方法的请求标头中没有角色时添加了“匿名”角色