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
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.identity.profile.api.configurator;
043:
044: import java.util.ArrayList;
045: import java.util.Collection;
046: import java.util.Collections;
047: import org.netbeans.modules.identity.profile.api.configurator.impl.dynamic.SecurityMechanismRetriever;
048:
049: /**
050: * Helper class for retrieving various collections of SecurityMechanism
051: * from the AM client sdk.
052: *
053: * Created on July 12, 2006, 11:58 AM
054: *
055: * @author ptliu
056: */
057: public class SecurityMechanismHelper {
058:
059: private static final String LIBERTY_PREFIX = "Liberty"; //NOI18N
060:
061: private Collection<SecurityMechanism> allSecurityMechs;
062:
063: private Collection<SecurityMechanism> allMsgLevelSecurityMechs;
064:
065: private Collection<SecurityMechanism> allWSPLibertySecurityMechs;
066:
067: private Collection<SecurityMechanism> allWSCLibertySecurityMechs;
068:
069: private Collection<SecurityMechanism> allWSPSecurityMechs;
070:
071: private Collection<SecurityMechanism> allWSCSecurityMechs;
072:
073: private SecurityMechanismRetriever retriever;
074:
075: public SecurityMechanismHelper(String id) {
076: retriever = new SecurityMechanismRetriever(id);
077: }
078:
079: /**
080: * Returns all the security mechanism including Liberty.
081: *
082: */
083: public Collection<SecurityMechanism> getAllSecurityMechanisms() {
084: if (allSecurityMechs == null) {
085: ArrayList<SecurityMechanism> list = new ArrayList<SecurityMechanism>();
086: list.addAll(getAllMessageLevelSecurityMechanisms());
087: list.addAll(getAllWSPLibertySecurityMechanisms());
088: list.addAll(getAllWSCLibertySecurityMechanisms());
089:
090: allSecurityMechs = Collections.unmodifiableCollection(list);
091: }
092:
093: return allSecurityMechs;
094: }
095:
096: public Collection<SecurityMechanism> getAllMessageLevelSecurityMechanisms() {
097: if (allMsgLevelSecurityMechs == null) {
098: allMsgLevelSecurityMechs = retriever
099: .getAllMessageLevelSecurityMechanism();
100: }
101:
102: return allMsgLevelSecurityMechs;
103: }
104:
105: public Collection<SecurityMechanism> getAllWSPLibertySecurityMechanisms() {
106: if (allWSPLibertySecurityMechs == null) {
107: Collection<SecurityMechanism> secMechs = retriever
108: .getAllWSPLibertySecurityMechanisms();
109:
110: allWSPLibertySecurityMechs = new ArrayList<SecurityMechanism>();
111:
112: for (SecurityMechanism secMech : secMechs) {
113: if (secMech.getName().startsWith(LIBERTY_PREFIX)) {
114: allWSPLibertySecurityMechs.add(secMech);
115: }
116: }
117:
118: allWSPLibertySecurityMechs = Collections
119: .unmodifiableCollection(allWSPLibertySecurityMechs);
120: }
121:
122: return allWSPLibertySecurityMechs;
123: }
124:
125: public Collection<SecurityMechanism> getAllWSCLibertySecurityMechanisms() {
126: if (allWSCLibertySecurityMechs == null) {
127: Collection<SecurityMechanism> secMechs = retriever
128: .getAllWSCLibertySecurityMechanisms();
129:
130: allWSCLibertySecurityMechs = new ArrayList<SecurityMechanism>();
131:
132: for (SecurityMechanism secMech : secMechs) {
133: if (secMech.getName().startsWith(LIBERTY_PREFIX)) {
134: allWSCLibertySecurityMechs.add(secMech);
135: }
136: }
137:
138: allWSCLibertySecurityMechs = Collections
139: .unmodifiableCollection(allWSCLibertySecurityMechs);
140: }
141:
142: return allWSCLibertySecurityMechs;
143: }
144:
145: public Collection<SecurityMechanism> getAllWSPSecurityMechanisms() {
146: if (allWSPSecurityMechs == null) {
147: allWSPSecurityMechs = new ArrayList<SecurityMechanism>();
148: allWSPSecurityMechs
149: .addAll(getAllMessageLevelSecurityMechanisms());
150: allWSPSecurityMechs
151: .addAll(getAllWSPLibertySecurityMechanisms());
152:
153: allWSPSecurityMechs = Collections
154: .unmodifiableCollection(allWSPSecurityMechs);
155: }
156:
157: return allWSPSecurityMechs;
158: }
159:
160: public Collection<SecurityMechanism> getAllWSCSecurityMechanisms() {
161: if (allWSCSecurityMechs == null) {
162: allWSCSecurityMechs = new ArrayList<SecurityMechanism>();
163: allWSCSecurityMechs
164: .addAll(getAllMessageLevelSecurityMechanisms());
165: allWSCSecurityMechs
166: .addAll(getAllWSCLibertySecurityMechanisms());
167:
168: allWSCSecurityMechs = Collections
169: .unmodifiableCollection(allWSCSecurityMechs);
170: }
171:
172: return allWSCSecurityMechs;
173: }
174:
175: public Collection<String> getSecurityMechanismURIs(
176: Collection<SecurityMechanism> secMechs) {
177: Collection<String> uris = new ArrayList<String>();
178:
179: if (secMechs != null) {
180: for (SecurityMechanism secMech : secMechs) {
181: uris.add(secMech.getURI());
182: }
183: }
184:
185: return uris;
186: }
187:
188: public Collection<SecurityMechanism> getSecurityMechanismsFromURIs(
189: Collection<String> uris) {
190: Collection<SecurityMechanism> secMechs = new ArrayList<SecurityMechanism>();
191: Collection<SecurityMechanism> allMechs = getAllSecurityMechanisms();
192:
193: if (uris != null) {
194: for (String uri : uris) {
195: for (SecurityMechanism mech : allMechs) {
196: if (uri.equals(mech.getURI())) {
197: secMechs.add(mech);
198: break;
199: }
200: }
201: }
202: }
203:
204: return secMechs;
205: }
206:
207: public Collection<String> getSecurityMechanismURIsFromNames(
208: Collection<String> secMechNames) {
209: Collection<String> uris = new ArrayList<String>();
210: Collection<SecurityMechanism> allMechs = getAllSecurityMechanisms();
211:
212: for (String name : secMechNames) {
213: for (SecurityMechanism mech : allMechs) {
214: if (name.equals(mech.getName())) {
215: uris.add(mech.getURI());
216: }
217: }
218: }
219:
220: return uris;
221: }
222: }
|