📄 defaultvalidityperiodbehaviour.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;
/**
* This class implements the default behaviour of the ValidityPeriod when
* computing intersections of two periods.
*/
public abstract class DefaultValidityPeriodBehaviour extends SubsetCredentials implements ValidityPeriod {
protected DefaultValidityPeriodBehaviour() {
}
/**
* This method checks if this ValidityPeriod contains the given Credentials.
* It makes sense to pass only ValidityPeriod to this method, but it can
* handle other Credentials, too. Bascially, it checks that the notBefore
* of the given ValidityPeriod is not earlier than notBefore of this
* ValidityPeriod, and that notAfter is not later than notAfter of this
* ValidityPeriod. If the given Credentials is not a ValidityPeriod, the
* contains method of the superclass is called.
*
* @param c - the Credentials object that must be contained in this
* ValidityPeriod
* @return true, if the given Credentials is a ValidityPeriod and is fully
* contained in this ValidityPeriod; if it is not a ValidityPeriod, the
* behaviour is defined by the superclass (calls the contains method of the
* superclass); otherwise it is false.
*/
public boolean contains(issrg.pba.Credentials c){
//System.out.println("\n\n\t******** CONTAINS ******\n\t"+this+"\n\t"+c); //***********
boolean b;
if (c==null){
b=false;
}else if (!(c instanceof ValidityPeriod)){
b=super.contains(c);
}else if (c instanceof AdjustedValidityPeriod){
b=contains(((AdjustedValidityPeriod)c).adjust(this));
}else{
ValidityPeriod vp = (ValidityPeriod)c;
java.util.Date time = getNotBefore();
boolean before = time==null || (vp.getNotBefore()!=null && !time.after(vp.getNotBefore())); // this is before vp, if this starts at -oo, or if vp is the same or after time (vp doesn't start at -oo, in particular)
time = getNotAfter();
boolean after = time==null || (vp.getNotAfter()!=null && !time.before(vp.getNotAfter())); // this is after vp, if this ends at +oo, or if vp is the same or before time (vp doesn't end at +oo, in particular)
b = before && after;
}
//System.out.println("\t"+b); //**************
return b;
}
/**
* This method computes an intersection of this ValidityPeriod with the
* given Credentials. It makes sense only to intersect the ValidityPeriod with
* other ValidityPeriods, but other Credentials are supported. Basically, it
* ensures that the result of intersection provides a stricter ValidityPeriod
* than this ValidityPeriod and the provided ValidityPeriod.
*
* @param c - the ValidityPeriod to intersect with; if it is not a
* ValidityPeriod, the result is determined by the inherited intersection
* method
* @return the ValidityPeriod that is the intersection of this and the given
* ValidityPeriod
*/
public issrg.pba.Credentials intersection(issrg.pba.Credentials c){
//System.out.println("\n\t*** INTERSECTION ***\n\t"+this+"\n\t"+c); //*****
if (c==null){
//return null;
}else if (!(c instanceof ValidityPeriod)){
c=super.intersection(c);
}else if (c instanceof AdjustedValidityPeriod){
c=((AdjustedValidityPeriod)c).intersection(this); // if this is AdjustedValidityPeriod, it will never get here
}else c=new IntersectionValidityPeriod(this, (ValidityPeriod)c);
//System.out.println("\n\tresult: "+c); //*****
return c;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -