com.att.research.xacmlatt.pdp.policy.PolicyComponent Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of xacml-pdp Show documentation
Show all versions of xacml-pdp Show documentation
ATT reference implementation of XACML PDP engine
The newest version!
/*
*
* Copyright (c) 2013,2019 AT&T Knowledge Ventures
* SPDX-License-Identifier: MIT
*/
package com.att.research.xacmlatt.pdp.policy;
import com.att.research.xacml.api.StatusCode;
import com.att.research.xacml.std.StdStatusCode;
/**
* PolicyComponent is the base class for all pieces of a XACML Policy or PolicySet that could potentially have errors associated
* with them by the policy loader.
*
* @author car
* @version $Revision: 1.1 $
*/
abstract class PolicyComponent {
private StatusCode statusCode;
private String statusMessage;
/**
* Creates a new PolicyComponent
with the given {@link com.att.research.xacml.api.StatusCode} and
* String
detailed message. If the StatusCode
is null, a default OK status code is used.
*
* @param statusCodeIn the StatusCode
for the new PolicyComponent
* @param statusMessageIn the String
detailed status message for the new PolicyComponent
*/
public PolicyComponent(StatusCode statusCodeIn, String statusMessageIn) {
this.statusCode = statusCodeIn;
this.statusMessage = statusMessageIn;
}
/**
* Creates a new PolicyComponent
with the given StatusCode
and no status message.
*
* @param statusCodeIn the StatusCode
for the new PolicyComponent
*/
public PolicyComponent(StatusCode statusCodeIn) {
this(statusCodeIn, null);
}
/**
* Creates a new PolicyCOmponent
with no StatusCode
or status message.
*/
public PolicyComponent() {
this(null, null);
}
/**
* Gets the StatusCode
associated with this PolicyComponent
.
*
* @return the StatusCode
associated with this PolicyComponent
*/
public StatusCode getStatusCode() {
return this.statusCode;
}
/**
* Gets the String
status message associated with this PolicyComponent
.
*
* @return the String
status message associated with this PolicyComponent
or null if none
*/
public String getStatusMessage() {
return this.statusMessage;
}
/**
* Sets the StatusCode
and String
status message for this PolicyComponent
.
* This method is mainly provided for objects that may have lazy evaluations performed on them, in which case the
* status is not determined until the object is actually used.
*
* @param statusCodeIn the StatusCode
for this PolicyComponent
* @param messageIn the String
status message for this PolicyComponent
*/
public void setStatus(StatusCode statusCodeIn, String messageIn) {
this.statusCode = statusCodeIn;
this.statusMessage = messageIn;
}
/**
* Does a check on the StatusCode
for this element to determine if it is equivalent to the
* OK status code.
*
* @return true if the StatusCode
is equivalent to OK, otherwise false
*/
public boolean isOk() {
return StdStatusCode.STATUS_CODE_OK.equals(this.getStatusCode());
}
/**
* If a StatusCode
has not been set, ask this PolicyComponent
to validate itself and return
* the value from the validation. Otherwise, check to see if the cached StatusCode
indicates this PolicyComponent
is valid.
*
* @return true if this PolicyComponent
is valid, else false.
*/
public boolean validate() {
if (this.getStatusCode() == null) {
return this.validateComponent();
} else {
return this.isOk();
}
}
@Override
public String toString() {
StringBuilder stringBuilder = new StringBuilder("{");
Object objectToDump;
boolean needsComma = false;
if ((objectToDump = this.getStatusCode()) != null) {
stringBuilder.append("statusCode=");
stringBuilder.append(objectToDump.toString());
needsComma = true;
}
if ((objectToDump = this.getStatusMessage()) != null) {
if (needsComma) {
stringBuilder.append(',');
}
stringBuilder.append("statusMessage=");
stringBuilder.append((String)objectToDump);
}
stringBuilder.append('}');
return stringBuilder.toString();
}
/**
* Validates that this PolicyComponent
has all of the required elements according to the XACML 3.0
* specification. If the component is not valid, this method should set the StatusCode
to reflect a
* syntax error, and should set the status message to reflect the invalid piece(s).
*
* PolicyComponent
s that implement this method should only validate their immediate elements and not perform
* a deep validation of descendents.
*
* @return true if the resulting status code is OK, otherwise false
*/
protected abstract boolean validateComponent();
}