use of com.sun.identity.xacml.common.XACMLException in project OpenAM by OpenRock.
the class XACMLAuthzDecisionQueryImpl method parseDOMElement.
protected void parseDOMElement(Element element) throws SAML2Exception {
//TODO: fix
String value = null;
if (element == null) {
XACMLSDKUtils.debug.error("XACMLAuthzDecisionQueryImpl.processElement(): " + "invalid root element");
throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("invalid_element"));
}
// First check that we're really parsing an XACMLAuthzDecisionQuery
if (!element.getLocalName().equals(XACMLConstants.REQUEST_ABSTRACT)) {
XACMLSDKUtils.debug.error("XACMLAuthzDecisionQueryImpl.processElement(): " + "invalid root element");
throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("missing_local_name"));
}
//TODO: check for xsi:type=
// now we get the request
NodeList nodes = element.getChildNodes();
ContextFactory factory = ContextFactory.getInstance();
for (int i = 0; i < nodes.getLength(); i++) {
Node node = nodes.item(i);
if ((node.getNodeType() == Node.ELEMENT_NODE) || (node.getNodeType() == Node.ATTRIBUTE_NODE)) {
if (node.getLocalName().equals(XACMLConstants.REQUEST)) {
if (request != null) {
//validation error, throw error
} else {
request = factory.getInstance().createRequest((Element) node);
}
}
}
}
// make sure we got a request
if (request == null) {
//throw new XACMLException(
// XACMLSDKUtils.xacmlResourceBundle.getString(
// "null_not_valid"));
}
System.out.println("ReturnContex:" + element.getAttributeNS(XACMLConstants.XACML_SAMLP_NS_URI, XACMLConstants.RETURN_CONTEXT));
System.out.println("InputContextOnly:" + element.getAttributeNS(XACMLConstants.XACML_SAMLP_NS_URI, XACMLConstants.INPUT_CONTEXT_ONLY));
String returnContextString = element.getAttributeNS(XACMLConstants.XACML_SAMLP_NS_URI, XACMLConstants.RETURN_CONTEXT);
if (returnContextString != null) {
returnContext = Boolean.valueOf(returnContextString).booleanValue();
}
String inputContextOnlyString = element.getAttributeNS(XACMLConstants.XACML_SAMLP_NS_URI, XACMLConstants.INPUT_CONTEXT_ONLY);
if (inputContextOnlyString != null) {
inputContextOnly = Boolean.valueOf(inputContextOnlyString).booleanValue();
}
NamedNodeMap attrs = element.getAttributes();
//TODO: change the baseclass impl and call super.parse...
//parse the attributes of base class RequestAbstract
NamedNodeMap atts = ((Node) element).getAttributes();
if (atts != null) {
int length = atts.getLength();
for (int i = 0; i < length; i++) {
Attr attr = (Attr) atts.item(i);
String attrName = attr.getName();
String attrValue = attr.getValue().trim();
if (attrName.equals("ID")) {
requestId = attrValue;
} else if (attrName.equals("Version")) {
version = attrValue;
} else if (attrName.equals("IssueInstant")) {
try {
issueInstant = DateUtils.stringToDate(attrValue);
} catch (ParseException pe) {
throw new XACMLException(pe.getMessage());
}
} else if (attrName.equals("Destination")) {
destinationURI = attrValue;
}
}
}
//parse the elements of base class RequestAbstract
NodeList nl = element.getChildNodes();
Node child;
String childName;
int length = nl.getLength();
for (int i = 0; i < length; i++) {
child = nl.item(i);
if ((childName = child.getLocalName()) != null) {
if (childName.equals("Issuer")) {
if (nameID != null) {
if (XACMLSDKUtils.debug.messageEnabled()) {
XACMLSDKUtils.debug.message("ArtifactResolveImpl.parse" + "Element: included more than one Issuer.");
}
throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("invalid_duplicate_element"));
}
if (signatureString != null || extensions != null) {
if (XACMLSDKUtils.debug.messageEnabled()) {
XACMLSDKUtils.debug.message("ArtifactResolveImpl.parse" + "Element:wrong sequence.");
}
throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("schemaViolation"));
}
nameID = AssertionFactory.getInstance().createIssuer((Element) child);
} else if (childName.equals("Signature")) {
if (signatureString != null) {
if (XACMLSDKUtils.debug.messageEnabled()) {
XACMLSDKUtils.debug.message("ArtifactResolveImpl.parse" + "Element:included more than one Signature.");
}
throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("invalid_duplicate_element"));
}
if (extensions != null) {
if (XACMLSDKUtils.debug.messageEnabled()) {
XACMLSDKUtils.debug.message("ArtifactResolveImpl.parse" + "Element:wrong sequence.");
}
throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("schemaViolation"));
}
signatureString = XMLUtils.print((Element) child);
isSigned = true;
} else if (childName.equals("Extensions")) {
if (extensions != null) {
if (XACMLSDKUtils.debug.messageEnabled()) {
XACMLSDKUtils.debug.message("ArtifactResolveImpl.parse" + "Element:included more than one Extensions.");
}
throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("invalid_duplicate_element"));
}
extensions = ProtocolFactory.getInstance().createExtensions((Element) child);
} else if (childName.equals("Request")) {
//no action, it has been processd already
} else {
if (XACMLSDKUtils.debug.messageEnabled()) {
XACMLSDKUtils.debug.message("XACMLAuthzDecisionQueryImpl.parseDOMElement" + "Element: Invalid element:" + childName);
}
throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("invalidElement"));
}
}
}
validateData();
}
use of com.sun.identity.xacml.common.XACMLException in project OpenAM by OpenRock.
the class StatusImpl method processElement.
private void processElement(Element element) throws XACMLException {
if (element == null) {
XACMLSDKUtils.debug.error("StatusImpl.processElement(): invalid root element");
throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("invalid_element"));
}
String elemName = element.getLocalName();
if (elemName == null) {
XACMLSDKUtils.debug.error("StatusImpl.processElement(): local name missing");
throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("missing_local_name"));
}
if (!elemName.equals(XACMLConstants.STATUS)) {
XACMLSDKUtils.debug.error("StatusImpl.processElement(): invalid local name " + elemName);
throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("invalid_local_name"));
}
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("StatusImpl.processElement(): invalid child element count: " + childCount);
throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString(//FIXME: add i18n key
"invalid_child_count"));
} else if (childCount > 3) {
XACMLSDKUtils.debug.error("StatusImpl.processElement(): invalid child element count: " + childCount);
throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString(//FIXME: add i18n key
"invalid_child_count"));
}
Element firstChild = (Element) childElements.get(0);
String firstChildName = firstChild.getLocalName();
if (firstChildName.equals(XACMLConstants.STATUS_CODE)) {
statusCode = ContextFactory.getInstance().createStatusCode(firstChild);
} else {
XACMLSDKUtils.debug.error("StatusImpl.processElement(): invalid first child element: " + firstChildName);
throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString(//FIXME: add i18n key
"invalid_first_child"));
}
//process statusMessage element
if (childCount > 1) {
Element secondChild = (Element) childElements.get(1);
String secondChildName = secondChild.getLocalName();
if (secondChildName.equals(XACMLConstants.STATUS_MESSAGE)) {
statusMessage = ContextFactory.getInstance().createStatusMessage(secondChild);
} else if (secondChildName.equals(XACMLConstants.STATUS_DETAIL)) {
if (childCount == 2) {
statusDetail = ContextFactory.getInstance().createStatusDetail(secondChild);
} else {
XACMLSDKUtils.debug.error("StatusImpl.processElement(): " + "invalid second child element: " + secondChildName);
throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString(//FIXME: add i18n key
"invalid_second_child"));
}
}
if (childCount > 2) {
Element thirdChild = (Element) childElements.get(2);
String thirdChildName = thirdChild.getLocalName();
if (thirdChildName.equals(XACMLConstants.STATUS_DETAIL)) {
statusDetail = ContextFactory.getInstance().createStatusDetail(thirdChild);
} else {
XACMLSDKUtils.debug.error("StatusImpl.processElement(): invalid third child element: " + thirdChildName);
throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString(//FIXME: add i18n key
"invalid_third_child"));
}
}
}
}
use of com.sun.identity.xacml.common.XACMLException in project OpenAM by OpenRock.
the class SubjectImpl method processElement.
private void processElement(Element element) throws XACMLException {
if (element == null) {
XACMLSDKUtils.debug.error("SubjectImpl.processElement(): invalid root element");
throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("invalid_element"));
}
String elemName = element.getLocalName();
if (elemName == null) {
XACMLSDKUtils.debug.error("SubjectImpl.processElement(): local name missing");
throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("missing_local_name"));
}
if (!elemName.equals(XACMLConstants.SUBJECT)) {
XACMLSDKUtils.debug.error("SubjectImpl.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) {
ContextFactory factory = ContextFactory.getInstance();
for (int nextElem = 0; nextElem < numOfNodes; nextElem++) {
Node child = (Node) nodes.item(nextElem);
if ((child.getNodeType() == Node.ELEMENT_NODE) || (child.getNodeType() == Node.ATTRIBUTE_NODE)) {
// The child nodes should be <Attribute>
// or <SubjectCategory>
String attrChildName = child.getLocalName();
if (attrChildName.equals(XACMLConstants.ATTRIBUTE)) {
if (this.attributes == null) {
this.attributes = new ArrayList();
}
Attribute attribute = factory.getInstance().createAttribute((Element) child);
attributes.add(attribute);
} else if (attrChildName.equals(XACMLConstants.SUBJECT_CATEGORY)) {
try {
subjectCategory = new URI(child.getNodeValue());
} catch (Exception e) {
throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("attribute_not_uri"));
}
} else {
XACMLSDKUtils.debug.error("RequestImpl." + "processElement(): Invalid element :" + attrChildName);
throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("invalid_element"));
}
}
}
}
}
use of com.sun.identity.xacml.common.XACMLException in project OpenAM by OpenRock.
the class ObligationImpl method setAttributeAssignments.
/**
* Sets XML elements corresponding to
* <code>AttributeAssignment</code> elements for this obligation.
*
* @param attributeAssignments XML elements corresponding to
* <code>AttributeAssignment</code> elements for this obligation.
*/
public void setAttributeAssignments(List attributeAssignments) throws XACMLException {
if (attributeAssignments == null) {
return;
}
Iterator iter = attributeAssignments.iterator();
while (iter.hasNext()) {
Object obj = iter.next();
if (!(obj instanceof Element)) {
throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("not_xml_element"));
}
Element elem = (Element) obj;
String aid = elem.getAttribute(XACMLConstants.ATTRIBUTE_ID);
if ((aid == null) || (aid.length() == 0)) {
throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("missing_attribute"));
}
String dt = elem.getAttribute(XACMLConstants.DATA_TYPE);
if ((dt == null) || (dt.length() == 0)) {
throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("missing_attribute"));
}
}
this.attributeAssignments = attributeAssignments;
}
use of com.sun.identity.xacml.common.XACMLException in project OpenAM by OpenRock.
the class ActionImpl method processElement.
private void processElement(Element element) throws XACMLException {
if (element == null) {
XACMLSDKUtils.debug.error("ActionImpl.processElement(): invalid root element");
throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("invalid_element"));
}
String elemName = element.getLocalName();
if (elemName == null) {
XACMLSDKUtils.debug.error("ActionImpl.processElement(): local name missing");
throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("missing_local_name"));
}
if (!elemName.equals(XACMLConstants.ACTION)) {
XACMLSDKUtils.debug.error("ActionImpl.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) {
ContextFactory factory = ContextFactory.getInstance();
for (int nextElem = 0; nextElem < numOfNodes; nextElem++) {
Node child = (Node) nodes.item(nextElem);
if (child.getNodeType() == Node.ELEMENT_NODE) {
// The child nodes should be <Attribute>
String attrChildName = child.getLocalName();
if (attrChildName.equals(XACMLConstants.ATTRIBUTE)) {
if (this.attributes == null) {
this.attributes = new ArrayList();
}
Attribute attribute = factory.getInstance().createAttribute((Element) child);
attributes.add(attribute);
} else {
XACMLSDKUtils.debug.error("ActionImpl." + "processElement(): Invalid element :" + attrChildName);
throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("invalid_element"));
}
}
}
}
}
Aggregations