📄 subsetcredentials.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;
/**
* This abstract class defines some basic behaviour, taking into account that
* a SetOfSubsets class exists.
*
* @author A Otenko
* @version 1.0
*/
public abstract class SubsetCredentials implements Credentials {
protected SubsetCredentials() {
}
/**
* This method tells if the given set of credentials is contained within this
* credentials object. If the credentials object is a SetOfSubsetsCredentials
* it deploys its
* <code>partOf</code> method. All of the subclasses should call this method,
* if they do not handle a SetOfSubsetsCredentials.
*
* @param cred is the credential to compare
*
* @return true if the given credential is contained within this credential
*
* @see SetOfSubsetsCredentials
*/
public boolean contains(Credentials cred){
if (cred instanceof SetOfSubsetsCredentials){
return ((SetOfSubsetsCredentials)cred).partOf(this/*cred*/); //Tuan Anh: why Sassa used "cred" here? it always return true!!
}
return false;
}
/**
* This method compares two credentials for equality. The result is equal to
* <p><code>contains(cred) && cred.contains(this)</code>,
* <p>if cred is
* a credentials object. The result is always false if cred is not a
* Credentials object.
*
* @param cred is the object to compare with
*
* @result true, if the objects are equal
*/
public boolean equals(Object cred){
if (cred instanceof Credentials){
Credentials c = (Credentials)cred;
return c.contains(this) && this.contains(c);
}
return false;
}
/**
* This method implements the basic intersection rule: the intersection is
* the biggest common part. In particular, if this object
* contains
* the other object, then the intersection is that object; if this object is
* contained within the other object, then the intersection is this object.
* Otherwise the intersection is null.
*
* @param cred is the credential to intersect with
*
* @return the Credential that is the intersection of the two
*/
public Credentials intersection(Credentials cred){
/*
*
* <p>TODO: do I change it to call some other protected method to determine the
* actual intersection?
*/
if (contains(cred)){
return cred;
}
if (cred.contains(this)){
return this;
}
return null;
}
/**
* This method implements the default behaviour for the union operation: the
* union is the smallest set containing both objects. In particular, if
* cred contains this object, then the result is cred; if this object
* contains cred, then
* the result is this. Otherwise the union is a SetOfSubsetsCredential,
* containing both.
*
* @param cred is the credentials object to join with
*
* @return the Credentials object that is the union of the two
*/
public Credentials union(Credentials cred){
if (contains(cred)){
return this;
}
if (cred.contains(this)){
return cred;
}
return new SetOfSubsetsCredentials(new Credentials []{this, cred});
}
/**
* This method creates a copy of the credentials object. Requires
* overriding in implementations of subclasses.
*/
public abstract Object clone();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -