您所在的位置: 首页>>读书频道>>安全>>网络安全>>

5.6.2 应用XACML实现访问控制的实例

http://book.51cto.com  2007-12-21 10:59  马恒太等著  电子工业出版社博文视点  我要评论(0)
  • 摘要:《Web服务安全》第5章详细的介绍了Web服务安全认证和访问控制机制。本文主要介绍的是应用XACML实现访问控制的实例。
  • 标签:Web  XACML  控制  实现  Web服务安全

5.6.2  应用XACML实现访问控制的实例

我们使用SUN公司开发的免费工具sunxacml-1.2给出一个实例并说明。

1.安装工具

(1)源代码下载

网址:http://sunxacml.sourceforge.net

(2)包结构说明

解压压缩包,sunxacml-1.2中包含如下4个目录。
—  doc/:包含sunxacml-1.2工程的文档资料。
—  lib/:库文件目录。
—  sample/:实例。
—  src/:包含sunxacml-1.2工程的源代码。

(3)编译例子中的程序

在编译前,将lib目录下的sunxacml.jar和samples.jar库文件包含在CLASSPATH目录中。编译命令如下:
javac *.java

这样即可得到所需要的运行实例。

(4)测试运行结果

运行命令如下:
java SimplePDP ./request/sentitive.xml ./policy/*.xml

本命令调用PDP来进行访问决策判决,请求信息包含在sentitive.xml中,而策略在policy目录下。运行结果如图5-18所示。

图5-18 sunxacml测试命令的执行结果

2.应用XACML实现访问控制的过程

应用XACML实现访问控制的基本过程如下。

① 从策略文件中得到相应的策略信息,在本实例中策略文件名为“TestPolicy.xml”。
② 建立策略查找点。
③ 建立属性查找点。
④ 根据前3步得到的信息生成策略信息。
⑤ 接收请求信息,本实例的请求信息存放在一个TestRequest.xml的文件中,直接从该文件中得到相应的请求信息。
⑥ 利用策略对请求进行判决。

决策判决的代码如下:

/* 
  This is a test program of SUNXACML1.2. This program is just to test 
  the process of XACML. 
  The policy file is TestPolicy.xml.
  The request file is TestRequest.xml.
*/

import com.sun.xacml.ConfigurationStore;
import com.sun.xacml.Indenter;
import com.sun.xacml.ParsingException;
import com.sun.xacml.PDP;
import com.sun.xacml.PDPConfig;

import com.sun.xacml.cond.FunctionFactory;
import com.sun.xacml.cond.FunctionFactoryProxy;
import com.sun.xacml.cond.StandardFunctionFactory;

import com.sun.xacml.ctx.RequestCtx;
import com.sun.xacml.ctx.ResponseCtx;

import com.sun.xacml.finder.AttributeFinder;
import com.sun.xacml.finder.PolicyFinder;

import com.sun.xacml.finder.impl.CurrentEnvModule;
import com.sun.xacml.finder.impl.FilePolicyModule;
import com.sun.xacml.finder.impl.SelectorModule;

import java.io.FileInputStream;
import java.io.IOException;

import java.net.URI;
import java.net.URISyntaxException;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;


class TestPDP
{
  static public void main(String [] args) throws Exception 
  {
    System.out.println("\n\t\t This is a test of PDP!\n");
    System.out.println("\t\t write by 张三,2005/07/20\n");
    System.out.println("\t\t中科院软件所\n");
      
    PDP pdp;   //存放策略结果
    //首先从文件系统中得到相应的策略文件
    FilePolicyModule filePolicy=new FilePolicyModule();
    filePolicy.addPolicy("./TestPolicy.xml");  //加入策略文件TestPolicy. xml
   
    //通过文件,建立策略寻找点—PolicyFinder
    PolicyFinder policyF=new PolicyFinder();
    Set policyModules=new HashSet();
    policyModules.add(filePolicy);
    policyF.setModules(policyModules);
    
    //建立属性查找点—AttributeFinder
    CurrentEnvModule envAttr=new CurrentEnvModule();
    SelectorModule   selectorAttr=new SelectorModule();
    AttributeFinder attrFinder=new AttributeFinder();
    List attributeModules=new ArrayList();
    attributeModules.add(envAttr);
    attributeModules.add(selectorAttr);
    attrFinder.setModules(attributeModules);

    //最后建立我们的PDP,即策略库信息
    pdp = new PDP(new PDPConfig(attrFinder, policyF, null));

    //下面接收请求信息,该请求信息存放在文件TestRequest.xml中
    RequestCtx request=RequestCtx.getInstance(new FileInputStream ("./TestRequest.xml"));
    ResponseCtx  response=pdp.evaluate(request);

    response.encode(System.out, new Indenter()); //输出结果
    
  }
}

(1)策略文件

针对http://server.example.com/sensitive/目录下文件的访问控制制定本策略,即只允许users.example.com上的用户读(read)该目录下的文件,其他操作都被禁止。同时无论操作是否被允许,都需要记录到日志中。

策略文件的内容如下:




  
    This protects access to all documents in the "sensitive" directory.
    All users @users.example.com are allowed to read this documents, but
    all other access is denied. Logging is done all access attempts
    using Obligations, though the logged information is different
    depending on whether or not the access attempt is allowed.
  

  
    
         //这里指定访问资源的客体,它只能是users.example.com下的用户
          
//匹配的方法rfc822Name-match
          users.example.com
             //属性ID
        
      
    
    
        
//受保护的资源,即http://server.example.com/sensitive/目录下的所有文件
        
          http://server.example.com/sensitive/.*
          
        
      
    
    
      
    
  

  
    
      
        
      
      
        
      
      
        
          
            read
              
          
        
      
    
  
    
  

  
    
      urn:oasis:names:tc:xacml:1.0: subject:subject-id
      urn:oasis:names:tc:xacml:1.0: resource:resource-id
    
    
      urn:oasis:names:tc:xacml:1.0: subject:subject-id
      urn:oasis:names:tc:xacml:1.0: resource:resource-id
      urn:oasis:names:tc:xacml:1.0: action:action-id
    
  

(2)请求文件

请求文件的内容如下:

?xml version="1.0" encoding="UTF-8"?
Request xmlns="urn:oasis:names:tc:xacml:1.0:context"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  Subject
    Attribute AttributeId="urn:oasis:names:tc:xacml:1.0:subject:subject-id"
         DataType="urn:oasis:names:tc:xacml:1.0:data-type: rfc822Name"
      seth@users.example.com   
//客体值,这个值要和Policy中的Subject中的值进行比较
    /Attribute
  /Subject
  Resource
    Attribute AttributeId="urn:oasis:names:tc:xacml:1.0:resource:resource-id"
          DataType="http://www.w3.org/2001/XMLSchema#string"
      http://server.example.com/sensitive/financial- report
  //访问的资源financial-report,这个值也需要和Policy中资源的值进行比较
    /Attribute
  /Resource
  Action
    Attribute AttributeId="urn:oasis:names:tc:xacml:1.0:action:action-id"
          DataType="http://www.w3.org/2001/XMLSchema#string"
      read
    /Attribute
  /Action
/Request

(3)运行结果

只有当request中的<subject, resource, action>和Policy中的<subject, resource, action>通过一定的匹配算法(在Policy中已经指定了匹配算法)得到匹配的结果时,策略才能够发挥作用。上例的运行结果如图5-19所示。

如果请求修改文档,将subject的值由seth@users.example.com改为seth@users.example1.com,则策略和请求不匹配。因此策略没有发挥效果,将得到NotApplicable的结果,如图5-20所示。

图5-19 运行结果1

图5-20 运行结果2

参考文献

[1]  P.Hallam-Baker,Verisign,S.H.Mysore.XML Key Management Specification (XKMS 2.0) Version 2.0.W3C Recommendation,2005

[2]  S.Cantor,J.Kemp,R.Philpott,E.Maler.Assertions and Protocols for the OASIS Security Assertion Markup Language (SAML) V2.0.OASIS Standard,15 March 2005

[3]  A.Nadalin,C.Kaler,R.Monzillo,P.H.Baker.Web Services Security: SOAP Message Security 1.1 (WS-Security 2004).OASIS Standard,1 February 2006

[4]  J.Rosenberg,D.L.Remy.Securing Web Services with WS-Security.Sams,2004

[5]  M.O’Neill,P.allam-Baker,S.M.Cann,M.Shema,E.Simon,P.A.Watters,A.White.Web Services Security.McGraw-Hill,2003

[6]  Microsoft Passport Service.http://www.passport.net/

[7]  The Liberty Alliance Project.http://www.projectliberty.org/

[8]  I.T.Union.ITU-T recommendation X.509 (08/97) – information technology - open systems interconnection – the directory: Authentication framework,Aug.1997

[9]  P.Zimmerman.The Qficial PGP User’s Guide.MIT Press,Cambridge,1995

[10]  C.M.Ellison,B.Frantz,B.Lampson,R.L.Rivest,B.M.Thomas,and T.Ylonen.SPKI certificate theory.RFC 2693,Sept.1999

[11]  T.Moses.eXtensible Access Control Markup Language (XACML) Version 2.0.OASIS Standard,1 Feb 2005

[12] 李劲编著.精通IIS5系统规划与管理.北京:中国青年出版社,2001年5月

【责任编辑:董书 TEL:(010)68476606】

回书目   上一节   下一节
上一篇: 5.6.1 Web服务身份验证 下一篇: 6.1.9 ASP
企业级Web2.0 你准备好了么?
WebSphere 实现SOA的利器
Web安全云时代
NAC安全访问控制
如何优化IT 控制能耗
 
 验证码: (点击刷新验证码)   匿名发表
  • Visual C++ 完全自学宝典

  • 作者:强锋科技,朱洪波
  • Visual C++ 6.0是微软公司为程序人员提供的Visual Studio 6.0工具套件中的重要组成部分。本书由浅入深地介绍使用Visual C++ 6.0..
Copyright©2005-2008 51CTO.COM 版权所有