【问题标题】:Getting 403 Forbidden, trying to access secured web service获取 403 Forbidden,尝试访问安全的 Web 服务
【发布时间】:2015-10-27 13:26:19
【问题描述】:

是否有人成功地使用 Active Directory 凭据而不是应用程序特定的用户名/密码来保护 Web 服务?

我有一个与使用 Axis2 1.5.1 编写并部署在 Tomcat 6.0.24 上、部署在 Linux、FWIW 上的 Web 服务通信的应用程序。

我已将 Tomcat 从 JDBCRealm(针对数据库进行身份验证)更改为 JAASRealm,配置为使用 Centrify(客户端的首选解决方案)访问 AD。

这适用于 Web 应用程序,但对于 Web 服务,我会收到 403 响应。

我使用简单的 Axis2 服务(使用 Axis2 1.5.1 编写)进行了测试,并针对 Tomcat 6.0.24 和 7.0.63 进行了部署。我还尝试过使用 Axis2 1.6.2 编写的 Web 服务。在每种情况下我都得到相同的结果。我正在使用浏览器进行测试,顺便说一句。当服务工作时,我得到 xml;当它没有出现错误时。

我想知道是否需要更改axis2.xml 中的某些内容,因为即使https://tomcat:8443/HelloWorld(我的服务称为HelloWorld)也会生成403。

一些配置细节...

我已将 server.xml 中的领域更改为以下内容

<Realm className="org.apache.catalina.realm.JAASRealm"
       appName="CENTRIFYDC"
       roleClassName="com.centrify.dc.tomcat.RolesPrincipal"
       userClassName="com.centrify.dc.tomcat.LoginPrincipal" />
<Valve className="com.centrify.dc.tomcat.ContextValve" />

在 web.xml 我已经添加了

<security-constraint>
    <display-name>Security Web Service</display-name>
    <web-resource-collection>
        <web-resource-name>Secured Area</web-resource-name>
        <url-pattern>/*</url-pattern>
    </web-resource-collection>
    <auth-constraint>
        <role-name>USER</role-name>
    </auth-constraint>
</security-constraint>

<login-config>
    <auth-method>SPNEGO</auth-method>
    <realm-name>CENTRIFYDC</realm-name>
</login-config>

<!-- Security roles referenced by this web application -->
<security-role>
    <role-name>USER</role-name>
</security-role>

我已将 USER 角色映射到我的一个 AD 组

任何对某人有用的建议或指导或设置都会非常有用,谢谢。

【问题讨论】:

    标签: web-services tomcat active-directory single-sign-on axis2


    【解决方案1】:

    403错误表示认证后权限问题。这是因为在 SSO 之后,服务器将检查组成员身份以查看用户是否获得了适当的权限。 403 错误来自角色映射的配置部分。 SSO 到服务器实际上工作正常。

    我们建议您尝试以下方法(以下示例使用 5.5 版本的 tomcat,但以后版本相同):

    • 为 Centrify 配置 Tomcat

    一个。使用 configure.pl 为 Centrify 配置 tomcat:

     cd /usr/share/centrifydc/java 
    ./configure.pl
    Enter /opt/apache-tomcat-5.5.25 when prompted for the tomcat directory.
    Enter /usr/jdk1.5.0_15 when prompted for the java directory.
    Enter y when prompted if you want to configure Tomcat for SSL
    Enter n when prompted if you want to configure Tomcat for SSL communication with ADFS server
    Take default for everything else.
    
    • 为 Centrify 配置 webdav 并使用 kerberos(SPNEGO) 进行身份验证

    一个。将登录领域设置为 CENTRIFYDC:

    1. cd /opt/apache-tomcat-5.5.25/webapps/
    2. mkdir webdav/META-INF
    3. 创建 webdav/META-INF/context.xml 为:

          <Context path="/webdav">
           <Realm className="org.apache.catalina.realm.JAASRealm"
            appName="CENTRIFYDC"
             roleClassNames="com.centrify.dc.tomcat.RolesPrincipal"
             userClassNames="com.centrify.dc.tomcat.LoginPrincipal"/>
              <Valve className="com.centrify.dc.tomcat.ContextValve"/>     </Context>
      

    b.为 jspwiki 应用配置 AD 组到角色的映射。

    1. cp /usr/share/centrifydc/java/templates/centrifydc.xml webdev/WEB-INF/centrifydc.xml

    2. 修改 webdev/WEB-INF/centrifydc.xml 中的 RoleMapping 部分如下:

       <RoleMapping separator=";">
       <Role name="user" group="*" user="*"/>
       <Role name="@ROLE2@" group="@GROUP2@"/>
       <Role name="@ROLE3@" user="@USER3@"/> 
       </RoleMapping>
      

    c。配置 web.xml 以使用 kerberos(SPNEGO) 进行身份验证:

    1. 编辑 web.xml 并添加

       <login-config>
      
       <auth-method>SPNEGO</auth-method>
      
       <realm-name>Default</realm-name>
      
       </login-config>
      
       <!--
      
       OPTIONAL: Add CentrifyFilter to set the authenticated user's attributes
      
       such as group membership in HTTP headers. You must also configure the
      
       <SetHeaders> element in centrifydc.xml to set user attributes in HTTP
      
       headers.
      
       This filter is not needed if you do not want the authenticated
      
       user's attributes set in HTTP headers.
      
       -->
      
       <filter>
      
       <filter-name>CentrifyFilter</filter-name>
      
       <filter-class>com.centrify.dc.wbase.DCFilter</filter-class>
      
       </filter>
      
       <!--
      
       OPTIONAL: Apply (map) CentrifyFilter to the url patterns in the
      
       <security-constraint> section of this application to set the
      
       authenticated user's attributes in HTTP headers.
      
       This <filter-mapping> is not needed if you do not want the
      
       authenticated user's attributes set in HTTP headers.
      
       -->
      
      <filter-mapping>
      
      <filter-name>CentrifyFilter</filter-name>
      
      <url-pattern>/*</url-pattern>
      
      </filter-mapping>
      
      <security-constraint>
      
      <web-resource-collection>
      
      <web-resource-name>ProtectedResource</web-resource-name>
      
      <url-pattern>/index.html</url-pattern>
      
      </web-resource-collection>
      
      <auth-constraint>
      
      <role-name>user</role-name>
      
      </auth-constraint>
      
      </security-constraint>
      
      <security-role>
      
      <description>
      
      An test role
      
      </description>
      
      <role-name>user</role-name>
      
      </security-role>
      

    您也可以参考 Centrify Java Guide p.135 的角色映射示例,配置如下:

    可扩展标记语言 (XML) 文件(如 centrifydc.xml 文件)是结构化文档,其中包含一组支持的元素,这些元素括在开角和闭角 () 括号中。根据应用程序的要求,这些元素可以是必需的或可选的。以下是 centrifydc.xml 文件中如何定义关键元素的示例:

     <Centrifydc>
     <enableAuthSchemes>Negotiate,NTLM,Basic</enableAuthSchemes>
     <adclientSocket>/var/centrifydc/daemon</adclientSocket>
     <RoleMapping>
     <Role name=”role1” group=”arcade.com/Users/Sales”/>
     </RoleMapping>
     </Centrifydc>
    

    虽然模板 centrifydc.xml 文件包含一些默认设置,但这些默认设置应在您放置在应用程序的 WEB-INF 目录中的 centrifydc.xml 文件的副本中进行修改。下表描述了您可以在 centrifydc.xml 文件中设置的元素。

    如果您需要任何进一步的帮助,请随时直接联系 Centrify 技术支持。

    【讨论】:

    • 谢谢艾伯特。这里有很多有用的信息,尤其是关于过滤器的使用。
    【解决方案2】:

    有几个问题。第一个是 server.xml 文件中的错误。 JAASRealms 可以接受角色和用户的多个类,因此属性是 roleClassNames 和 userClassNames,如下所示

    <Realm className="org.apache.catalina.realm.JAASRealm"
           appName="CENTRIFYDC"
           roleClassNames="com.centrify.dc.tomcat.RolesPrincipal"
           userClassNames="com.centrify.dc.tomcat.LoginPrincipal" />
    

    第二个问题是使用多个使用不同授权的应用程序。当应用程序首次通过身份验证时,centrifydc.xml 文件会映射角色。但是,如果启用了 org.apache.catalina.authenticator.SingleSignOn,则仅为执行身份验证的应用程序设置角色。此后,仅设置身份验证应用程序的 centrifydc.xml 文件中设置的角色。其他应用程序将看到用户已通过身份验证,但没有必要的授权并失败并出现 403 错误。

    在不同的应用程序中使用用户、用户和管理员角色,那么登录应用程序在进行身份验证时必须设置所有三个角色。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-18
      • 1970-01-01
      • 1970-01-01
      • 2018-08-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多