use of com.sun.identity.xacml.common.XACMLException in project OpenAM by OpenRock.
the class RequestImpl method processElement.
private void processElement(Element element) throws XACMLException {
if (element == null) {
XACMLSDKUtils.debug.error("RequestImpl.processElement(): invalid root element");
throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("invalid_element"));
}
String elemName = element.getLocalName();
if (elemName == null) {
XACMLSDKUtils.debug.error("RequestImpl.processElement(): local name missing");
throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("missing_local_name"));
}
if (!elemName.equals(XACMLConstants.REQUEST)) {
XACMLSDKUtils.debug.error("RequestImpl.processElement(): invalid local name " + elemName);
throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("invalid_local_name"));
}
// starts processing subelements
NodeList nodes = element.getChildNodes();
int numOfNodes = nodes.getLength();
if (numOfNodes < 1) {
XACMLSDKUtils.debug.error("RequestImpl.processElement(): request has no subelements");
throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("missing_subelements"));
}
ContextFactory factory = ContextFactory.getInstance();
List children = new ArrayList();
int i = 0;
Node child;
while (i < numOfNodes) {
child = (Node) nodes.item(i);
if (child.getNodeType() == Node.ELEMENT_NODE) {
children.add(child);
}
i++;
}
if (children.isEmpty()) {
XACMLSDKUtils.debug.error("RequestImpl.processElement():" + " request has no subelements");
throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("missing_subelements"));
}
child = (Node) children.get(0);
// The first subelement should be <Subject>
String childName = child.getLocalName();
if ((childName == null) || (!childName.equals(XACMLConstants.SUBJECT))) {
XACMLSDKUtils.debug.error("RequestImpl.processElement():" + " the first element is not <Subject>");
throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("missing_subelement_subject"));
}
Subject subject = factory.getInstance().createSubject((Element) child);
if (!supportedSubjectCategory.contains(subject.getSubjectCategory().toString())) {
XACMLSDKUtils.debug.error("RequestImpl.processElement():subject " + "category in subject not supported");
throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("unsupported_subject_category"));
}
subjects.add(subject);
boolean resourceFound = false;
boolean actionFound = false;
boolean envFound = false;
for (int j = 1; j < children.size(); j++) {
child = (Node) children.get(j);
// so far <Resource> is not encountered
// Go through next sub elements for <Subject> and <Resource>
// The next subelement may be <Resource> or <Subject>
childName = child.getLocalName();
if ((childName != null) && (childName.equals(XACMLConstants.RESOURCE) || childName.equals(XACMLConstants.SUBJECT))) {
if (resourceFound) {
if (childName.equals(XACMLConstants.SUBJECT)) {
// all <Subject> should be before <Resource>
XACMLSDKUtils.debug.error("RequestImpl." + "processElement(): <Subject> should be " + "before <Resource>");
throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("element_out_of_place"));
} else {
// found another resource
Resource resource = factory.getInstance().createResource((Element) child);
resources.add(resource);
}
} else if (childName.equals(XACMLConstants.SUBJECT)) {
subject = factory.getInstance().createSubject((Element) child);
subjects.add(subject);
} else {
// childname is resource
resourceFound = true;
Resource resource = factory.getInstance().createResource((Element) child);
resources.add(resource);
}
} else if ((childName != null) && (childName.equals(XACMLConstants.ACTION))) {
if (!resourceFound) {
XACMLSDKUtils.debug.error("RequestImpl." + "processElement(): <Resource> should be " + "before <Action>");
throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("element_out_of_place"));
} else {
actionFound = true;
action = factory.createAction((Element) child);
}
} else if ((childName != null) && (childName.equals(XACMLConstants.ENVIRONMENT))) {
if (!resourceFound || !actionFound) {
XACMLSDKUtils.debug.error("RequestImpl." + "processElement(): <Resource> and " + "Action should be before <Environment>");
throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("element_out_of_place"));
} else {
envFound = true;
env = factory.createEnvironment((Element) child);
}
}
}
if (XACMLSDKUtils.debug.messageEnabled()) {
XACMLSDKUtils.debug.message("resourceFound:" + resourceFound);
XACMLSDKUtils.debug.message("actionFound:" + actionFound);
XACMLSDKUtils.debug.message("envFound:" + envFound);
}
if (!resourceFound || !actionFound || !envFound) {
XACMLSDKUtils.debug.error("RequestImpl.processElement(): Some" + "of required elements are missing");
throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("missing_subelements"));
}
}
use of com.sun.identity.xacml.common.XACMLException in project OpenAM by OpenRock.
the class ResponseImpl method processElement.
/**
* Initializes a <code>Response</code> object from an XML DOM element
*
* @param element XML DOM element representing a <code>Response</code>
* object
*
* @throws SAMLException if the DOM element could not be processed
*/
private void processElement(Element element) throws XACMLException {
if (element == null) {
XACMLSDKUtils.debug.error("ResponseImpl.processElement(): invalid root element");
throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("invalid_element"));
}
String elemName = element.getLocalName();
if (elemName == null) {
XACMLSDKUtils.debug.error("ResponseImpl.processElement(): local name missing");
throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("missing_local_name"));
}
if (!elemName.equals(XACMLConstants.RESPONSE)) {
XACMLSDKUtils.debug.error("ResponseImpl.processElement(): invalid local name " + elemName);
throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("invalid_local_name"));
}
// starts processing subelements
NodeList nodes = element.getChildNodes();
int numOfNodes = nodes.getLength();
int nextElem = 0;
while (nextElem < numOfNodes) {
Node child = (Node) nodes.item(nextElem);
if (child.getNodeType() == Node.ELEMENT_NODE) {
String childName = child.getLocalName();
if (childName != null) {
if (childName.equals(XACMLConstants.RESULT)) {
results.add(ContextFactory.getInstance().createResult((Element) child));
//XMLUtils.getElementValue((Element)child));
} else {
XACMLSDKUtils.debug.error("ResponseImpl.processElement(): " + " invalid child element: " + elemName);
throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString(//FIXME: add i18n key
"invalid_child_name"));
}
}
}
nextElem++;
}
}
use of com.sun.identity.xacml.common.XACMLException in project OpenAM by OpenRock.
the class ResourceImpl method processElement.
private void processElement(Element element) throws XACMLException {
if (element == null) {
XACMLSDKUtils.debug.error("ResourceImpl.processElement(): invalid root element");
throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("invalid_element"));
}
String elemName = element.getLocalName();
if (elemName == null) {
XACMLSDKUtils.debug.error("ResourceImpl.processElement(): local name missing");
throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("missing_local_name"));
}
if (!elemName.equals(XACMLConstants.RESOURCE)) {
XACMLSDKUtils.debug.error("ResourceImpl.processElement(): invalid local name " + elemName);
throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("invalid_local_name"));
}
// starts processing subelements
NodeList nodes = element.getChildNodes();
int numOfNodes = nodes.getLength();
if (numOfNodes > 0) {
ContextFactory factory = ContextFactory.getInstance();
for (int i = 0; i < numOfNodes; i++) {
Node child = (Node) nodes.item(i);
if (child.getNodeType() == Node.ELEMENT_NODE) {
String childName = child.getLocalName();
// <ResourceContent>
if (childName.equals(XACMLConstants.ATTRIBUTE)) {
if (attributes == null) {
attributes = new ArrayList();
}
Attribute attribute = factory.getInstance().createAttribute((Element) child);
attributes.add(attribute);
} else if (childName.equals(XACMLConstants.RESOURCE_CONTENT)) {
resourceContent = (Element) child;
}
}
}
} else {
/* not a schema violation
XACMLSDKUtils.debug.error(
"ResourceImpl.processElement(): no attributes or resource "
+"content");
throw new XACMLException(
XACMLSDKUtils.xacmlResourceBundle.getString(
"missing_subelements"));
*/
}
}
use of com.sun.identity.xacml.common.XACMLException in project OpenAM by OpenRock.
the class StatusCodeImpl method processElement.
private void processElement(Element element) throws XACMLException {
if (element == null) {
XACMLSDKUtils.debug.error("StatusMessageImpl.processElement(): invalid root element");
throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("invalid_element"));
}
String elemName = element.getLocalName();
if (elemName == null) {
XACMLSDKUtils.debug.error("StatusMessageImpl.processElement(): local name missing");
throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("missing_local_name"));
}
if (!elemName.equals(XACMLConstants.STATUS_CODE)) {
XACMLSDKUtils.debug.error("StatusMessageImpl.processElement(): invalid local name " + elemName);
throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("invalid_local_name"));
}
String attrValue = element.getAttribute(XACMLConstants.VALUE);
if ((attrValue == null) || (attrValue.length() == 0)) {
XACMLSDKUtils.debug.error("StatusCodeImpl.processElement(): statuscode missing");
throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString(//i18n
"missing_status_code"));
}
if (!XACMLSDKUtils.isValidStatusMessage(attrValue.trim())) {
throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("invalid_value"));
} else {
this.value = attrValue;
}
//process child StatusCode element
NodeList nodes = element.getChildNodes();
int numOfNodes = nodes.getLength();
List childElements = new ArrayList();
int i = 0;
while (i < numOfNodes) {
Node child = (Node) nodes.item(i);
if (child.getNodeType() == Node.ELEMENT_NODE) {
childElements.add(child);
}
i++;
}
int childCount = childElements.size();
if (childCount > 1) {
XACMLSDKUtils.debug.error("ResultImpl.processElement(): invalid child element count: " + childCount);
throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("invalid_child_count"));
}
if (childCount == 1) {
Element childElement = (Element) childElements.get(0);
elemName = childElement.getLocalName();
if (elemName == null) {
XACMLSDKUtils.debug.error("StatusMessageImpl.processElement(): local name missing");
throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("missing_local_name"));
}
if (!elemName.equals(XACMLConstants.STATUS_CODE)) {
XACMLSDKUtils.debug.error("StatusMessageImpl.processElement(): invalid local name " + elemName);
throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("invalid_local_name"));
}
attrValue = childElement.getAttribute(XACMLConstants.VALUE);
if ((attrValue == null) || (attrValue.length() == 0)) {
XACMLSDKUtils.debug.error("StatusCodeImpl.processElement(): minor statuscode missing");
throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("missing_minor_status_code"));
}
if (!XACMLSDKUtils.isValidStatusMessage(attrValue.trim())) {
throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("invalid_value"));
} else {
this.minorCodeValue = attrValue;
}
} else {
}
}
use of com.sun.identity.xacml.common.XACMLException in project OpenAM by OpenRock.
the class ObligationsImpl method setObligations.
/**
* Sets the <code>Obligation</code> objects of this
* <code>Obligations</code>
*
* @param obligations the <code>Obligation</code> objects to set in this
* <code>Obligations</code>
* @throws XACMLException if the object is immutable.
*/
public void setObligations(List obligations) throws XACMLException {
if (!mutable) {
throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("objectImmutable"));
}
if (obligations != null) {
Iterator iter = obligations.iterator();
this.obligations = new ArrayList();
while (iter.hasNext()) {
Obligation obligation = (Obligation) iter.next();
this.obligations.add(obligation);
}
} else {
obligations = null;
}
}
Aggregations