1

我在 JBossAS 5.1 GA 上部署了一个 Web 服务。要使用 HTTP 基本身份验证,SBC 类的注释方式如下:

    @Stateless
    @SecurityDomain(value = "MyWSSecurity")
    @RolesAllowed(value = "WebserviceUser")
    @WebContext(contextRoot="/MyWS", urlPattern="/*", authMethod="BASIC", transportGuarantee="NONE", secureWSDLAccess=true)
    @WebService(endpointInterface = "MyWS")
    public class MyWSImpl implements MyWS {

      public String doSomething() {
        return "something";
      }
    }

通常这工作正常。但是下面的情景让我很困扰。

角色 WebserviceUser 的用户调用该服务。

Webservice 角色现在已从用户手中夺走。

问题:他仍然可以调用服务。

我猜会发生这种情况,因为用户凭据和角色存储在服务器端的 HttpSession 对象中。服务器重新启动后,用户被拒绝调用服务。

我能做些什么呢?

问候

编辑:该问题不仅适用于 JBOSSWS EJB3 webservices,还适用于任何使用 JAAS 身份验证的东西。

4

1 回答 1

3

找到了 2 个适合我的解决方案。

解决方案 1) 更改 JAAS 缓存的默认超时

您可以通过编辑 $JBOSS_HOME/server/default/conf/jboss-service.conf 来做到这一点。找到配置 JaasSecurityManager MBean 的文件部分,并将属性 DefaultCacheTimeout 更改为可接受的小值(60 秒对我来说很好)。如果要完全禁用安全凭证的缓存,请将值设置为 0。

<!-- JAAS security manager and realm mapping -->
   <mbean code="org.jboss.security.plugins.JaasSecurityManagerService"
      <!-- 
         skipped some configuration
      -->

      <!-- DefaultCacheTimeout: Specifies the default timed cache policy timeout
      in seconds.
      If you want to disable caching of security credentials, set this to 0 to
      force authentication to occur every time. This has no affect if the
      AuthenticationCacheJndiName has been changed from the default value.
      -->
       <attribute name="DefaultCacheTimeout">60</attribute>
      <!-- DefaultCacheResolution: Specifies the default timed cache policy
      resolution in seconds. This controls the interval at which the cache
      current timestamp is updated and should be less than the DefaultCacheTimeout
      in order for the timeout to be meaningful. This has no affect if the
      AuthenticationCacheJndiName has been changed from the default value.
      -->
      <attribute name="DefaultCacheResolution">30</attribute>
      <!-- 
         skipped some configuration
      -->
   </mbean>

解决方案 2:只要用户的角色发生变化,就在 JaasSecurityManager MBean 上调用方法 flushAuthenticationCache("MyWSSecurity")。

问候

于 2011-01-26T08:16:02.330 回答