001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036:
037: /*
038: * SignedElements.java
039: *
040: * Created on February 17, 2006, 9:08 PM
041: *
042: * To change this template, choose Tools | Template Manager
043: * and open the template in the editor.
044: */
045:
046: package com.sun.xml.ws.security.impl.policy;
047:
048: import com.sun.xml.ws.policy.AssertionSet;
049: import com.sun.xml.ws.policy.PolicyAssertion;
050: import com.sun.xml.ws.policy.sourcemodel.AssertionData;
051: import com.sun.xml.ws.security.policy.SecurityAssertionValidator;
052: import java.util.ArrayList;
053: import java.util.Collection;
054: import java.util.Collections;
055: import java.util.Iterator;
056: import java.util.List;
057: import javax.xml.namespace.QName;
058: import static com.sun.xml.ws.security.impl.policy.Constants.*;
059:
060: /**
061: *
062: * @author K.Venugopal@sun.com
063: */
064: public class SignedElements extends PolicyAssertion implements
065: com.sun.xml.ws.security.policy.SignedElements,
066: SecurityAssertionValidator {
067:
068: private String xpathVersion;
069: private List<String> targetList;
070: private boolean populated = false;
071: private static QName XPathVersion = new QName("XPathVersion");
072: private static List<String> emptyList = Collections.emptyList();
073: private AssertionFitness fitness = AssertionFitness.IS_VALID;
074:
075: /** Creates a new instance of SignedElements */
076: public SignedElements() {
077: }
078:
079: public SignedElements(AssertionData name,
080: Collection<PolicyAssertion> nestedAssertions,
081: AssertionSet nestedAlternative) {
082: super (name, nestedAssertions, nestedAlternative);
083: }
084:
085: public String getXPathVersion() {
086: populate();
087: return xpathVersion;
088: }
089:
090: public void setXPathVersion(String version) {
091: this .xpathVersion = version;
092: }
093:
094: public void addTarget(String target) {
095: if (targetList == null) {
096: targetList = new ArrayList<String>();
097: }
098: targetList.add(target);
099: }
100:
101: public void removeTarget(String target) {
102: if (targetList != null) {
103: targetList.remove(target);
104: }
105: }
106:
107: public Iterator<String> getTargets() {
108: populate();
109: if (targetList != null) {
110: return targetList.iterator();
111: }
112: return emptyList.iterator();
113: }
114:
115: public AssertionFitness validate(boolean isServer) {
116: return populate(isServer);
117: }
118:
119: private void populate() {
120: populate(false);
121: }
122:
123: private synchronized AssertionFitness populate(boolean isServer) {
124: if (!populated) {
125: this .xpathVersion = this .getAttributeValue(XPathVersion);
126:
127: if (this .hasNestedAssertions()) {
128:
129: Iterator<PolicyAssertion> it = this
130: .getNestedAssertionsIterator();
131: while (it.hasNext()) {
132: PolicyAssertion assertion = (PolicyAssertion) it
133: .next();
134: if (PolicyUtil.isXPath(assertion)) {
135: addTarget(assertion.getValue());
136: } else {
137: if (!assertion.isOptional()) {
138: log_invalid_assertion(assertion, isServer,
139: SignedElements);
140: fitness = AssertionFitness.HAS_UNKNOWN_ASSERTION;
141: }
142: }
143: }
144: }
145: populated = true;
146: }
147: return fitness;
148: }
149: }
|