001: /*
002: * $Id: WSTrustElementFactory.java,v 1.10 2007/05/29 22:11:29 ofung Exp $
003: */
004:
005: /*
006: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
007: *
008: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
009: *
010: * The contents of this file are subject to the terms of either the GNU
011: * General Public License Version 2 only ("GPL") or the Common Development
012: * and Distribution License("CDDL") (collectively, the "License"). You
013: * may not use this file except in compliance with the License. You can obtain
014: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
015: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
016: * language governing permissions and limitations under the License.
017: *
018: * When distributing the software, include this License Header Notice in each
019: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
020: * Sun designates this particular file as subject to the "Classpath" exception
021: * as provided by Sun in the GPL Version 2 section of the License file that
022: * accompanied this code. If applicable, add the following below the License
023: * Header, with the fields enclosed by brackets [] replaced by your own
024: * identifying information: "Portions Copyrighted [year]
025: * [name of copyright owner]"
026: *
027: * Contributor(s):
028: *
029: * If you wish your version of this file to be governed by only the CDDL or
030: * only the GPL Version 2, indicate your decision by adding "[Contributor]
031: * elects to include this software in this distribution under the [CDDL or GPL
032: * Version 2] license." If you don't indicate a single choice of license, a
033: * recipient has the option to distribute your version of this file under
034: * either the CDDL, the GPL Version 2 or to extend the choice of license to
035: * its licensees as provided above. However, if you add GPL Version 2 code
036: * and therefore, elected the GPL Version 2 license, then the option applies
037: * only if the new code is made subject to such option by the copyright
038: * holder.
039: */
040:
041: package com.sun.xml.ws.security.trust;
042:
043: import com.sun.xml.ws.security.trust.elements.str.DirectReference;
044: import com.sun.xml.ws.security.trust.elements.str.KeyIdentifier;
045:
046: import com.sun.xml.ws.api.security.trust.Claims;
047: import com.sun.xml.ws.api.security.trust.WSTrustException;
048: import com.sun.xml.ws.security.trust.elements.AllowPostdating;
049: import com.sun.xml.ws.security.trust.elements.BinarySecret;
050: import com.sun.xml.ws.security.trust.elements.CancelTarget;
051: import com.sun.xml.ws.security.trust.elements.Entropy;
052: import com.sun.xml.ws.security.trust.elements.IssuedTokens;
053: import com.sun.xml.ws.security.trust.elements.Lifetime;
054: import com.sun.xml.ws.security.trust.elements.RenewTarget;
055: import com.sun.xml.ws.security.trust.elements.Renewing;
056: import com.sun.xml.ws.security.trust.elements.RequestSecurityToken;
057: import com.sun.xml.ws.security.trust.elements.RequestSecurityTokenResponse;
058: import com.sun.xml.ws.security.trust.elements.RequestSecurityTokenResponseCollection;
059: import com.sun.xml.ws.security.trust.elements.RequestedProofToken;
060: import com.sun.xml.ws.security.trust.elements.RequestedAttachedReference;
061: import com.sun.xml.ws.security.trust.elements.RequestedUnattachedReference;
062: import com.sun.xml.ws.security.trust.elements.RequestedSecurityToken;
063: import com.sun.xml.ws.security.trust.elements.Status;
064: import com.sun.xml.ws.security.trust.impl.WSTrustElementFactoryImpl;
065: import java.net.URI;
066:
067: import com.sun.xml.ws.policy.impl.bindings.AppliesTo;
068:
069: import com.sun.xml.ws.security.EncryptedKey;
070: import com.sun.xml.ws.security.trust.elements.str.Reference;
071: import com.sun.xml.ws.security.trust.elements.str.SecurityTokenReference;
072: import com.sun.xml.ws.security.Token;
073: import com.sun.xml.ws.security.wsu10.AttributedDateTime;
074:
075: import javax.xml.transform.Source;
076: import org.w3c.dom.Document;
077: import org.w3c.dom.Element;
078:
079: import javax.xml.bind.JAXBContext;
080: import javax.xml.bind.JAXBElement;
081: import javax.xml.bind.JAXBException;
082:
083: /**
084: * A Factory for creating the WS-Trust schema elements, and marshalling/un-marshalling them
085: * <p>
086: * The default Implementation classes for all these WS-Trust schema Elements would assume
087: * that JAXB Bindings were generated for ws-trust.xsd schema in a particular fixed namespace/package.
088: * The default implementation classes for all these WS-Trust Element Interfaces would hence wrap
089: * the schema generated classes.
090: * </p>
091: * <p>
092: * An STS Service can create a RequestSecurityToken from the JAXBBean(i.e RequestSecurityTokenType)
093: * it receives, as an SEI method parameter, in the following manner
094: * </P>
095: * <PRE>
096: * RequestSecurityTokenType tok=...//obtained as JAXWS SEI method paramater
097: * ObjectFactory factory = new ObjectFactory();
098: * JAXBElement<RequestSecurityTokenType> rst= factory.createRequestSecurityToken(tok);
099: * WSTrustElementFactory fact= ..
100: * RequestSecurityToken requestSecurityToken= fact.createRSTFrom(rst);
101: * </PRE>
102: * <p>
103: * To get back a JAXB Bean from an instance of RequestSecurityToken the following can be done
104: * <PRE>
105: * JAXBElement<RequestSecurityTokenType> elem = fact.toJAXBElement(requestSecurityToken);
106: * RequestSecurityTokenType tok = elem.getValue();
107: * </PRE>
108: * </p>
109: * @author Kumar Jayanti
110: */
111: public abstract class WSTrustElementFactory {
112:
113: // private static WSTrustElementFactory trustElemFactory
114: // = new WSTrustElementFactoryImpl();
115:
116: private static JAXBContext jaxbContext = null;
117:
118: static {
119: try {
120: jaxbContext = JAXBContext
121: .newInstance("com.sun.xml.ws.security.trust.impl.bindings:com.sun.xml.ws.security.secconv.impl.bindings:com.sun.xml.ws.security.secext10:com.sun.xml.ws.policy.impl.bindings");
122: } catch (JAXBException jbe) {
123: throw new RuntimeException(jbe.getMessage(), jbe);
124: }
125: }
126:
127: private static WSTrustElementFactory trustElemFactory = new WSTrustElementFactoryImpl();
128:
129: public static JAXBContext getContext() {
130: return jaxbContext;
131: }
132:
133: public static WSTrustElementFactory newInstance() {
134: return trustElemFactory;
135: }
136:
137: /**
138: * Create an RST for Issue from the given arguments
139: * Any of the arguments can be null since they are all optional, but one of tokenType and AppliesTo must be present
140: */
141: public abstract RequestSecurityToken createRSTForIssue(
142: URI tokenType, URI requestType, URI context,
143: AppliesTo scopes, Claims claims, Entropy entropy,
144: Lifetime lifetime) throws WSTrustException;
145:
146: /**
147: * create an RSTR for Issue from the given arguments
148: * Any of the arguments can be null since they are all optional, but one of RequestedSecurityToken or RequestedProofToken should be returned
149: */
150: public abstract RequestSecurityTokenResponse createRSTRForIssue(
151: URI tokenType, URI context, RequestedSecurityToken token,
152: AppliesTo scopes, RequestedAttachedReference attachedRef,
153: RequestedUnattachedReference unattachedRef,
154: RequestedProofToken proofToken, Entropy entropy,
155: Lifetime lifetime) throws WSTrustException;
156:
157: /**
158: *Create a collection of RequestSecurityTokenResponse(s)
159: */
160: public abstract RequestSecurityTokenResponseCollection createRSTRCollectionForIssue(
161: URI tokenType, URI context, RequestedSecurityToken token,
162: AppliesTo scopes, RequestedAttachedReference attachedRef,
163: RequestedUnattachedReference unattachedRef,
164: RequestedProofToken proofToken, Entropy entropy,
165: Lifetime lifetime) throws WSTrustException;
166:
167: /**
168: * Create a wst:IssuedTokens object
169: */
170: public abstract IssuedTokens createIssuedTokens(
171: RequestSecurityTokenResponseCollection issuedTokens);
172:
173: /**
174: * Create an Entropy with a BinarySecret
175: */
176: public abstract Entropy createEntropy(BinarySecret secret);
177:
178: /**
179: * Create an Entropy with an xenc:EncryptedKey
180: */
181: public abstract Entropy createEntropy(EncryptedKey key);
182:
183: /**
184: * Create a BinarySecret
185: */
186: public abstract BinarySecret createBinarySecret(byte[] rawValue,
187: String type);
188:
189: /**
190: * Create a BinarySecret
191: */
192: public abstract BinarySecret createBinarySecret(Element elem)
193: throws WSTrustException;
194:
195: /**
196: * Create a Lifetime.
197: */
198: public abstract Lifetime createLifetime(AttributedDateTime created,
199: AttributedDateTime expires);
200:
201: /**
202: * Create a RequestedProofToken.
203: */
204: public abstract RequestedProofToken createRequestedProofToken();
205:
206: /**
207: * Create a RequestedSecurityToken.
208: */
209: public abstract RequestedSecurityToken createRequestedSecurityToken(
210: Token token);
211:
212: public abstract RequestedSecurityToken createRequestedSecurityToken();
213:
214: public abstract DirectReference createDirectReference(
215: String valueType, String uri);
216:
217: public abstract KeyIdentifier createKeyIdentifier(String valueType,
218: String encodingType);
219:
220: public abstract SecurityTokenReference createSecurityTokenReference(
221: Reference ref);
222:
223: /**
224: * Create a RequestedAttachedReference.
225: */
226: public abstract RequestedAttachedReference createRequestedAttachedReference(
227: SecurityTokenReference str);
228:
229: /**
230: * Create a RequestedUnattachedReference.
231: */
232: public abstract RequestedUnattachedReference createRequestedUnattachedReference(
233: SecurityTokenReference str);
234:
235: /**
236: *Create an RST for a Renewal Request
237: */
238: public abstract RequestSecurityToken createRSTForRenew(
239: URI tokenType, URI requestType, URI context,
240: RenewTarget target, AllowPostdating apd,
241: Renewing renewingInfo);
242:
243: public abstract CancelTarget createCancelTarget(
244: SecurityTokenReference str);
245:
246: /**
247: *Create an RST for Token Cancellation
248: */
249: public abstract RequestSecurityToken createRSTForCancel(
250: URI requestType, CancelTarget target);
251:
252: /**
253: *Create an RSTR for a Successful Token Cancellation
254: */
255: public abstract RequestSecurityTokenResponse createRSTRForCancel();
256:
257: /**
258: *Create an RST for Token Validation
259: *<p>
260: *TODO: Not clear from Spec whether the Token to be validated is ever sent ?
261: *TODO: There is a mention of special case where a SOAPEnvelope may be specified as
262: * a security token if the requestor desires the envelope to be validated.
263: *</p>
264: */
265: public abstract RequestSecurityToken createRSTForValidate(
266: URI tokenType, URI requestType);
267:
268: /**
269: * create an RSTR for validate request.
270: */
271: public abstract RequestSecurityTokenResponse createRSTRForValidate(
272: URI tokenType, RequestedSecurityToken token, Status status);
273:
274: /**
275: * Create an Empty RST
276: */
277: public abstract RequestSecurityToken createRST();
278:
279: /**
280: * Create an Empty RSTR
281: */
282: public abstract RequestSecurityTokenResponse createRSTR();
283:
284: /**
285: * create an RST from a Source
286: */
287: public abstract RequestSecurityToken createRSTFrom(Source src);
288:
289: /**
290: * create an RST from DOM Element
291: */
292: public abstract RequestSecurityToken createRSTFrom(Element elem);
293:
294: /**
295: * create an RSTR from a Source
296: */
297: public abstract RequestSecurityTokenResponse createRSTRFrom(
298: Source src);
299:
300: /**
301: * create an RSTR from DOM Element
302: */
303: public abstract RequestSecurityTokenResponse createRSTRFrom(
304: Element elem);
305:
306: /**
307: * Create RSTR Collection from Source
308: */
309: public abstract RequestSecurityTokenResponseCollection createRSTRCollectionFrom(
310: Source src);
311:
312: /**
313: * Create RSTR Collection from Element
314: */
315: public abstract RequestSecurityTokenResponseCollection createRSTRCollectionFrom(
316: Element elem);
317:
318: /**
319: * create an RST from JAXBElement
320: * <p>
321: * NOTE: an STS Implementor can call
322: * <PRE>
323: * JAXBElement<RequestSecurityTokenType> elem=
324: * ObjectFactory.createRequestSecurityToken(<JAXBBean for RST>)
325: * </PRE>
326: * The JAXBBean for RST is the one generated from the ws-trust.xsd schema
327: * The default implementation expects the packagename of the generated JAXB Beans to be fixed.
328: * </p>
329: */
330: public abstract RequestSecurityToken createRSTFrom(JAXBElement elem);
331:
332: /**
333: * create an RSTR from JAXBElement
334: * <p>
335: * NOTE: an STS Implementor can call
336: * <PRE>
337: * JAXBElement<RequestSecurityTokenResponseType> elem=
338: * ObjectFactory.createRequestSecurityTokenResponse(<JAXBBean for RSTR>);
339: * </PRE>
340: * The <JAXBBean for RSTR> is the one generated from the ws-trust.xsd schema
341: * The default implementation expects the packagename of the generated JAXB Beans to be fixed.
342: * </p>
343: */
344: public abstract RequestSecurityTokenResponse createRSTRFrom(
345: JAXBElement elem);
346:
347: /**
348: * create an RSTR Collection from JAXBElement
349: * <p>
350: * NOTE: an STS Implementor can call
351: * <PRE>
352: * JAXBElement<RequestSecurityTokenResponseCollectionType> elem=
353: * ObjectFactory.createRequestSecurityTokenResponseCollection(<JAXBBean for RSTR Collection>
354: * </PRE>
355: * The <JAXBBean for RSTR Collection> is the one generated from the ws-trust.xsd schema
356: * The default implementation expects the packagename of the generated JAXB Beans to be fixed.
357: * </p>
358: */
359: public abstract RequestSecurityTokenResponseCollection createRSTRCollectionFrom(
360: JAXBElement elem);
361:
362: public abstract SecurityTokenReference createSecurityTokenReference(
363: JAXBElement elem);
364:
365: /**
366: * convert an SecurityTokenReference to a JAXBElement
367: */
368: public abstract JAXBElement toJAXBElement(SecurityTokenReference str);
369:
370: /**
371: * convert an RST to a JAXBElement
372: */
373: public abstract JAXBElement toJAXBElement(RequestSecurityToken rst);
374:
375: /**
376: * convert an RSTR to a JAXBElement
377: */
378: public abstract JAXBElement toJAXBElement(
379: RequestSecurityTokenResponse rstr);
380:
381: /**
382: * convert an RSTR Collection to a JAXBElement
383: */
384: public abstract JAXBElement toJAXBElement(
385: RequestSecurityTokenResponseCollection rstrCollection);
386:
387: /**
388: * Marshal an RST to a Source.
389: * <p>
390: * Note: Useful for Dispatch Client implementations
391: * </p>
392: */
393: public abstract Source toSource(RequestSecurityToken rst);
394:
395: /**
396: * Marshal an RSTR to a Source
397: * <p>
398: * Note: Useful for STS implementations which are JAXWS Providers
399: * </p>
400: */
401: public abstract Source toSource(RequestSecurityTokenResponse rstr);
402:
403: /**
404: * Marshal an RSTR Collection to a Source
405: * <p>
406: * Note: Useful for STS implementations which are JAXWS Providers
407: * </p>
408: */
409: public abstract Source toSource(
410: RequestSecurityTokenResponseCollection rstrCollection);
411:
412: /**
413: * Marshal an RST to a DOM Element.
414: * <p>
415: * Note: Useful for Dispatch Client implementations
416: * </p>
417: */
418: public abstract Element toElement(RequestSecurityToken rst);
419:
420: /**
421: * Marshal an RSTR to DOM Element
422: * <p>
423: * Note: Useful for STS implementations which are JAXWS Providers
424: * </p>
425: */
426: public abstract Element toElement(RequestSecurityTokenResponse rstr);
427:
428: public abstract Element toElement(
429: RequestSecurityTokenResponse rstr, Document doc);
430:
431: /**
432: * Marshal an RSTR Collection to a DOM Element
433: * <p>
434: * Note: Useful for STS implementations which are JAXWS Providers
435: * </p>
436: */
437: public abstract Element toElement(
438: RequestSecurityTokenResponseCollection rstrCollection);
439:
440: /**
441: * Marshal an BinarySecret to a DOM Element
442: * <p>
443: * Note: Useful for STS implementations which are JAXWS Providers
444: * </p>
445: */
446:
447: public abstract Element toElement(BinarySecret binarySecret);
448:
449: /**
450: * Marshal an STR to a DOM Element.
451: * <p>
452: * Note: Useful for Dispatch Client implementations
453: * </p>
454: */
455: public abstract Element toElement(SecurityTokenReference str,
456: Document doc);
457:
458: /**
459: * Marshal an BinarySecret to a DOM Element.
460: * <p>
461: * Note: Useful for Dispatch Client implementations
462: * </p>
463: */
464: public abstract Element toElement(BinarySecret binarySecret,
465: Document doc);
466: }
|