View Javadoc

1   /*
2    * Copyright [2005] [University Corporation for Advanced Internet Development, Inc.]
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.opensaml.saml1.core.impl;
18  
19  import org.opensaml.saml1.core.Action;
20  import org.opensaml.saml1.core.AuthorizationDecisionStatement;
21  import org.opensaml.saml1.core.DecisionTypeEnumeration;
22  import org.opensaml.saml1.core.Evidence;
23  import org.opensaml.xml.XMLObject;
24  import org.opensaml.xml.io.UnmarshallingException;
25  import org.slf4j.Logger;
26  import org.slf4j.LoggerFactory;
27  import org.w3c.dom.Attr;
28  
29  /**
30   * A thread-safe Unmarshaller for {@link org.opensaml.saml1.core.impl.AuthorizationDecisionStatementImpl} objects.
31   */
32  public class AuthorizationDecisionStatementUnmarshaller extends SubjectStatementUnmarshaller {
33  
34      /** Logger. */
35      private final Logger log = LoggerFactory.getLogger(AuthorizationDecisionStatementUnmarshaller.class);
36  
37      /** {@inheritDoc} */
38      protected void processChildElement(XMLObject parentSAMLObject, XMLObject childSAMLObject)
39              throws UnmarshallingException {
40  
41          AuthorizationDecisionStatement authorizationDecisionStatement;
42          authorizationDecisionStatement = (AuthorizationDecisionStatement) parentSAMLObject;
43  
44          if (childSAMLObject instanceof Action) {
45              authorizationDecisionStatement.getActions().add((Action) childSAMLObject);
46          } else if (childSAMLObject instanceof Evidence) {
47              authorizationDecisionStatement.setEvidence((Evidence) childSAMLObject);
48          } else {
49              super.processChildElement(parentSAMLObject, childSAMLObject);
50          }
51      }
52  
53      /** {@inheritDoc} */
54      protected void processAttribute(XMLObject samlObject, Attr attribute) throws UnmarshallingException {
55  
56          AuthorizationDecisionStatement authorizationDecisionStatement;
57          authorizationDecisionStatement = (AuthorizationDecisionStatement) samlObject;
58  
59          if (AuthorizationDecisionStatement.DECISION_ATTRIB_NAME.equals(attribute.getLocalName())) {
60              String value = attribute.getValue();
61              if (value.equals(DecisionTypeEnumeration.PERMIT.toString())) {
62                  authorizationDecisionStatement.setDecision(DecisionTypeEnumeration.PERMIT);
63              } else if (value.equals(DecisionTypeEnumeration.DENY.toString())) {
64                  authorizationDecisionStatement.setDecision(DecisionTypeEnumeration.DENY);
65              } else if (value.equals(DecisionTypeEnumeration.INDETERMINATE.toString())) {
66                  authorizationDecisionStatement.setDecision(DecisionTypeEnumeration.INDETERMINATE);
67              } else {
68                  log.error("Unknown value for DecisionType '" + value + "'");
69                  throw new UnmarshallingException("Unknown value for DecisionType '" + value + "'");
70              }
71          } else if (AuthorizationDecisionStatement.RESOURCE_ATTRIB_NAME.equals(attribute.getLocalName())) {
72              authorizationDecisionStatement.setResource(attribute.getValue());
73          } else {
74              super.processAttribute(samlObject, attribute);
75          }
76      }
77  }