⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 expirablecredentials.java

📁 一个完整的XACML工程,学习XACML技术的好例子!
💻 JAVA
字号:
/*
* Copyright (c) 2000-2005, University of Salford
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without 
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this 
* list of conditions and the following disclaimer.
* 
* Redistributions in binary form must reproduce the above copyright notice, 
* this list of conditions and the following disclaimer in the documentation 
* and/or other materials provided with the distribution. 
*
* Neither the name of the University of Salford nor the names of its 
* contributors may be used to endorse or promote products derived from this 
* software without specific prior written permission. 
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
* POSSIBILITY OF SUCH DAMAGE.
*/

package issrg.pba.rbac;

import issrg.pba.Credentials;
import issrg.pba.rbac.SubsetCredentials;
import java.util.Date;

/**
 * This class is intended to provide expiration service, so that any given 
 * Credentials are constrained in the time dimension. The objects can embed
 * any Credentials, and ExpirableCredentials will perform expiration checks 
 * when intersecting the credentials.
 *
 * <p>Note that the methods call the inherited methods to ensure that the other
 * types of Credentials are handled correctly, e.g. SetOfSubsetsCredentials
 * are intersected correctly.
 */

public class ExpirableCredentials extends SubsetCredentials{

  protected Credentials expirable;
  protected ValidityPeriod when;

  protected ExpirableCredentials() {
  }

  /**
   * This constructor builds a credential with Validity Period. If the 
   * credential is used
   * outside the specified period, it will be ignored.
   *
   * @param expirable - the Credentials with which the Validity Period is 
   *   associated
   * @param vp - the ValidityPeriod of the Credentials; should not be null
   */
  public ExpirableCredentials(Credentials expirable,
                  ValidityPeriod vp){
    this.expirable = expirable;
    when = vp;//==null?new NowValidityPeriod():vp;
  }

  /**
   * This method checks if this ExpirableCredentials contains the other 
   * Credentials. If it is an ExpirableCredentials, then their embedded
   * Credentials are tested, and the ValidityPeriods are tested separately;
   * otherwise the inherited behaviour of the method determines the result.
   *
   * @param c - the Credentials that must be contained in this one
   * @return true, if the embedded Credentials and the ValidityPeriod of this
   *   ExpirableCredentials contain the corresponding components of the given
   *   Credentials, if it is ExpirableCredentials; otherwise the inherited
   *   contains method is called to test if this ExpirableCredentials contains
   *   the given Credentials
   */
  public boolean contains(Credentials c){
    //System.out.println("\n\t*** CONTAINS ***\n\t"+this+"\n\t"+c); //*******

    boolean b;
    if (c instanceof ExpirableCredentials){
      if (when==null){
        b=false;
      }else{

        ExpirableCredentials ec = (ExpirableCredentials)c;
        b=expirable.contains(ec.expirable) && when.contains(ec.when);
      }
    }else b=super.contains(c);

    //System.out.println("\n\tresult: "+b); //*******
    return b;
  }

  /**
   * This method builds an intersection of this ExpirableCredentials with the
   * given Credentials. If it is an ExpirableCredentials, then the result is
   * the ExpirableCredentials, consisting of the intersection of the embedded
   * Credentials and their ValidityPeriods. Otherwise the inherited intersection
   * method determines the result.
   *
   * @param c - the Credentials to intersect with
   * @return Credentials that is the result of intersecting the embedded 
   *   Credentials and the ValidityPeriods if the given Credentials is an
   *   ExpirableCredentials; otherwise, the inherited intersection method 
   *   determines the result.
   */
  public Credentials intersection(Credentials c){
    //System.out.println("\n\t*** INTERSECTION ***\n\t"+this+"\n\t"+c); //*******

    Credentials c1;
    if (!(c instanceof ExpirableCredentials)){
      c1=super.intersection(c);
    }else if (when==null){
      c1=null;
    }else{

      ExpirableCredentials e=(ExpirableCredentials)c;

      if ((c1=expirable.intersection(e.expirable))!=null){
        c1=new ExpirableCredentials(c1, (ValidityPeriod)when.intersection(e.when));
      }
    }

    //System.out.println("\n\tresult: "+c1); //*******
    return c1;
  }

  /**
   * This method returns the ValidityPeriod associated with the embedded 
   * Credentials.
   */
  public ValidityPeriod getValidityPeriod() {
      return when;
  }

  /**
   * This method returns the Credentials embedded inside this object and 
   * associated with the ValidityPeriod.
   */
  public Credentials getExpirable() {
      return expirable;
  }

  public Object clone(){
    return new ExpirableCredentials(this.expirable, this.when);
  }

  public String toString(){
    return "<"+expirable+" "+when+">";
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -