Source Code Cross Referenced for WSTrustElementFactoryImpl.java in  » 6.0-JDK-Modules-com.sun » wsit » com » sun » xml » ws » security » trust » impl » wssx » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Modules com.sun » wsit » com.sun.xml.ws.security.trust.impl.wssx 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: WSTrustElementFactoryImpl.java,v 1.1 2007/08/23 12:40:56 shyam_rao Exp $
003:         */
004:
005:        /*
006:         * The contents of this file are subject to the terms
007:         * of the Common Development and Distribution License
008:         * (the License).  You may not use this file except in
009:         * compliance with the License.
010:         * 
011:         * You can obtain a copy of the license at
012:         * https://glassfish.dev.java.net/public/CDDLv1.0.html.
013:         * See the License for the specific language governing
014:         * permissions and limitations under the License.
015:         * 
016:         * When distributing Covered Code, include this CDDL
017:         * Header Notice in each file and include the License file
018:         * at https://glassfish.dev.java.net/public/CDDLv1.0.html.
019:         * If applicable, add the following below the CDDL Header,
020:         * with the fields enclosed by brackets [] replaced by
021:         * you own identifying information:
022:         * "Portions Copyrighted [year] [name of copyright owner]"
023:         * 
024:         * Copyright 2006 Sun Microsystems Inc. All Rights Reserved
025:         */
026:
027:        package com.sun.xml.ws.security.trust.impl.wssx;
028:
029:        import com.sun.xml.ws.security.secext10.SecurityTokenReferenceType;
030:
031:        import com.sun.xml.ws.security.trust.elements.AllowPostdating;
032:        import com.sun.xml.ws.security.trust.elements.BinarySecret;
033:        import com.sun.xml.ws.security.trust.elements.CancelTarget;
034:        import com.sun.xml.ws.api.security.trust.Claims;
035:        import com.sun.xml.ws.security.trust.elements.Entropy;
036:        import com.sun.xml.ws.security.trust.elements.IssuedTokens;
037:        import com.sun.xml.ws.security.trust.elements.Lifetime;
038:        import com.sun.xml.ws.security.trust.elements.RenewTarget;
039:        import com.sun.xml.ws.security.trust.elements.Renewing;
040:        import com.sun.xml.ws.security.trust.elements.RequestSecurityTokenResponse;
041:        import com.sun.xml.ws.security.trust.elements.RequestSecurityTokenResponseCollection;
042:        import com.sun.xml.ws.security.trust.elements.RequestedProofToken;
043:        import com.sun.xml.ws.security.trust.elements.RequestedAttachedReference;
044:        import com.sun.xml.ws.security.trust.elements.RequestedUnattachedReference;
045:        import com.sun.xml.ws.security.trust.elements.RequestSecurityToken;
046:        import com.sun.xml.ws.security.trust.elements.RequestedSecurityToken;
047:        import com.sun.xml.ws.security.trust.elements.RequestedTokenCancelled;
048:        import com.sun.xml.ws.security.trust.elements.Status;
049:        import com.sun.xml.ws.security.trust.elements.WSTrustElementBase;
050:
051:        import com.sun.xml.ws.security.trust.impl.elements.str.DirectReferenceImpl;
052:        import com.sun.xml.ws.security.trust.impl.elements.str.SecurityTokenReferenceImpl;
053:        import com.sun.xml.ws.security.trust.impl.elements.str.KeyIdentifierImpl;
054:
055:        import com.sun.xml.ws.security.trust.impl.wssx.elements.AllowPostdatingImpl;
056:        import com.sun.xml.ws.security.trust.impl.wssx.elements.BinarySecretImpl;
057:        import com.sun.xml.ws.security.trust.impl.wssx.elements.CancelTargetImpl;
058:        import com.sun.xml.ws.security.trust.impl.wssx.elements.ClaimsImpl;
059:        import com.sun.xml.ws.security.trust.impl.wssx.elements.EntropyImpl;
060:        import com.sun.xml.ws.security.trust.impl.wssx.elements.IssuedTokensImpl;
061:        import com.sun.xml.ws.security.trust.impl.wssx.elements.LifetimeImpl;
062:        import com.sun.xml.ws.security.trust.impl.wssx.elements.RenewTargetImpl;
063:        import com.sun.xml.ws.security.trust.impl.wssx.elements.RenewingImpl;
064:        import com.sun.xml.ws.security.trust.impl.wssx.elements.RequestSecurityTokenResponseImpl;
065:        import com.sun.xml.ws.security.trust.impl.wssx.elements.RequestSecurityTokenResponseCollectionImpl;
066:        import com.sun.xml.ws.security.trust.impl.wssx.elements.RequestedProofTokenImpl;
067:        import com.sun.xml.ws.security.trust.impl.wssx.elements.RequestedAttachedReferenceImpl;
068:        import com.sun.xml.ws.security.trust.impl.wssx.elements.RequestedUnattachedReferenceImpl;
069:        import com.sun.xml.ws.security.trust.impl.wssx.elements.RequestSecurityTokenImpl;
070:        import com.sun.xml.ws.security.trust.impl.wssx.elements.RequestedSecurityTokenImpl;
071:        import com.sun.xml.ws.security.trust.impl.wssx.elements.RequestedTokenCancelledImpl;
072:        import com.sun.xml.ws.security.trust.impl.wssx.elements.StatusImpl;
073:        import com.sun.xml.ws.security.trust.impl.wssx.bindings.BinarySecretType;
074:        import com.sun.xml.ws.security.trust.impl.wssx.bindings.EntropyType;
075:        import com.sun.xml.ws.security.trust.impl.wssx.bindings.RequestSecurityTokenType;
076:        import com.sun.xml.ws.security.trust.impl.wssx.bindings.RequestSecurityTokenResponseType;
077:        import com.sun.xml.ws.security.trust.impl.wssx.bindings.RequestSecurityTokenResponseCollectionType;
078:        import com.sun.xml.ws.security.trust.impl.wssx.bindings.ObjectFactory;
079:        import com.sun.xml.ws.policy.impl.bindings.AppliesTo;
080:
081:        import com.sun.xml.ws.security.trust.elements.str.DirectReference;
082:        import com.sun.xml.ws.security.trust.elements.str.KeyIdentifier;
083:        import com.sun.xml.ws.security.EncryptedKey;
084:        import com.sun.xml.ws.security.trust.elements.str.Reference;
085:        import com.sun.xml.ws.security.trust.elements.str.SecurityTokenReference;
086:        import com.sun.xml.ws.security.Token;
087:        import com.sun.xml.ws.security.wsu10.AttributedDateTime;
088:
089:        import java.net.URI;
090:        import java.util.List;
091:
092:        import javax.xml.transform.Source;
093:        import javax.xml.transform.dom.DOMSource;
094:
095:        import org.w3c.dom.Element;
096:        import org.w3c.dom.Document;
097:
098:        import javax.xml.parsers.DocumentBuilder;
099:        import javax.xml.parsers.DocumentBuilderFactory;
100:
101:        import javax.xml.bind.JAXBElement;
102:        import javax.xml.bind.JAXBException;
103:        import javax.xml.bind.JAXBContext;
104:
105:        import com.sun.xml.ws.security.trust.WSTrustElementFactory;
106:        import com.sun.xml.ws.api.security.trust.WSTrustException;
107:
108:        public class WSTrustElementFactoryImpl extends WSTrustElementFactory {
109:
110:            /**
111:             * Create an RST for Issue from the given arguments
112:             * Any of the arguments can be null since they are all optional, but one of tokenType and AppliesTo must be present
113:             */
114:            public RequestSecurityToken createRSTForIssue(URI tokenType,
115:                    URI requestType, URI context, AppliesTo scopes,
116:                    Claims claims, Entropy entropy, Lifetime lt)
117:                    throws WSTrustException {
118:                // if (tokenType==null || scopes==null)
119:                //   throw new WSTrustException("TokenType and AppliesTo cannot be both null");
120:                RequestSecurityToken rst = new RequestSecurityTokenImpl(
121:                        tokenType, requestType, context, scopes, claims,
122:                        entropy, lt, null);
123:                return rst;
124:            }
125:
126:            /**
127:             * Create an RSTR for Issue from the given arguments. TokenType should be Issue.
128:             * Any of the arguments can be null since they are all optional, but one of RequestedSecurityToken or RequestedProofToken should be returned
129:             */
130:            public RequestSecurityTokenResponse createRSTRForIssue(
131:                    URI tokenType, URI context, RequestedSecurityToken token,
132:                    AppliesTo scopes,
133:                    RequestedAttachedReference attachedReference,
134:                    RequestedUnattachedReference unattachedReference,
135:                    RequestedProofToken proofToken, Entropy entropy, Lifetime lt)
136:                    throws WSTrustException {
137:                return new RequestSecurityTokenResponseImpl(tokenType, context,
138:                        token, scopes, attachedReference, unattachedReference,
139:                        proofToken, entropy, lt, null);
140:            }
141:
142:            /**
143:             * Create  a collection of RequestSecurityTokenResponse(s)
144:             */
145:            public RequestSecurityTokenResponseCollection createRSTRCollectionForIssue(
146:                    URI tokenType, URI context, RequestedSecurityToken token,
147:                    AppliesTo scopes, RequestedAttachedReference attached,
148:                    RequestedUnattachedReference unattached,
149:                    RequestedProofToken proofToken, Entropy entropy, Lifetime lt)
150:                    throws WSTrustException {
151:                return new RequestSecurityTokenResponseCollectionImpl(
152:                        tokenType, context, token, scopes, attached,
153:                        unattached, proofToken, entropy, lt);
154:            }
155:
156:            public RequestSecurityTokenResponseCollection createRSTRCollectionForIssue(
157:                    List rstrs) throws WSTrustException {
158:                //RequestSecurityTokenResponseCollection rstrc = new RequestSecurityTokenResponseCollectionImpl();
159:                RequestSecurityTokenResponseCollectionImpl rstrc = new RequestSecurityTokenResponseCollectionImpl();
160:                for (int i = 0; i < rstrs.size(); i++) {
161:                    rstrc
162:                            .addRequestSecurityTokenResponse((RequestSecurityTokenResponse) rstrs
163:                                    .get(i));
164:                }
165:                return rstrc;
166:            }
167:
168:            /**
169:             * Create a wst:IssuedTokens object
170:             */
171:            public IssuedTokens createIssuedTokens(
172:                    RequestSecurityTokenResponseCollection issuedTokens) {
173:                return new IssuedTokensImpl(issuedTokens);
174:            }
175:
176:            /**
177:             * Create an Entropy with a BinarySecret
178:             */
179:            public Entropy createEntropy(BinarySecret secret) {
180:                return new EntropyImpl(secret);
181:            }
182:
183:            /**
184:             * Create an Entropy with an xenc:EncryptedKey
185:             */
186:            public Entropy createEntropy(EncryptedKey key) {
187:                return new EntropyImpl(key);
188:            }
189:
190:            public BinarySecret createBinarySecret(byte[] rawValue, String type) {
191:                return new BinarySecretImpl(rawValue, type);
192:            }
193:
194:            public BinarySecret createBinarySecret(Element elem)
195:                    throws WSTrustException {
196:                return new BinarySecretImpl(BinarySecretImpl.fromElement(elem));
197:            }
198:
199:            /**
200:             * Create a Lifetime.
201:             */
202:            public Lifetime createLifetime(AttributedDateTime created,
203:                    AttributedDateTime expires) {
204:                return new LifetimeImpl(created, expires);
205:            }
206:
207:            /**
208:             * Create a RequestedSecurityToken.
209:             */
210:            public RequestedSecurityToken createRequestedSecurityToken(
211:                    Token token) {
212:                return new RequestedSecurityTokenImpl(token);
213:            }
214:
215:            /**
216:             * Create a RequestedSecurityToken.
217:             */
218:            public RequestedSecurityToken createRequestedSecurityToken() {
219:                return new RequestedSecurityTokenImpl();
220:            }
221:
222:            public DirectReference createDirectReference(String valueType,
223:                    String uri) {
224:                return new DirectReferenceImpl(valueType, uri);
225:            }
226:
227:            public KeyIdentifier createKeyIdentifier(String valueType,
228:                    String encodingType) {
229:                return new KeyIdentifierImpl(valueType, encodingType);
230:            }
231:
232:            public SecurityTokenReference createSecurityTokenReference(
233:                    Reference ref) {
234:                return new SecurityTokenReferenceImpl(ref);
235:            }
236:
237:            /**
238:             * Create a RequestedAttachedReference.
239:             */
240:            public RequestedAttachedReference createRequestedAttachedReference(
241:                    SecurityTokenReference str) {
242:                return new RequestedAttachedReferenceImpl(str);
243:            }
244:
245:            /**
246:             * Create a RequestedUnattachedReference.
247:             */
248:            public RequestedUnattachedReference createRequestedUnattachedReference(
249:                    SecurityTokenReference str) {
250:                return new RequestedUnattachedReferenceImpl(str);
251:            }
252:
253:            /**
254:             * Create a RequestedProofToken.
255:             */
256:            public RequestedProofToken createRequestedProofToken() {
257:                return new RequestedProofTokenImpl();
258:            }
259:
260:            /**
261:             *Create an RST for a Renewal Request
262:             */
263:            public RequestSecurityToken createRSTForRenew(URI tokenType,
264:                    URI requestType, URI context, RenewTarget target,
265:                    AllowPostdating apd, Renewing renewingInfo) {
266:                return new RequestSecurityTokenImpl(tokenType, requestType,
267:                        context, target, apd, renewingInfo);
268:            }
269:
270:            public CancelTarget createCancelTarget(SecurityTokenReference str) {
271:                return new CancelTargetImpl(str);
272:            }
273:
274:            /**
275:             *Create an RST for Token Cancellation
276:             */
277:            public RequestSecurityToken createRSTForCancel(URI requestType,
278:                    CancelTarget target) {
279:                return new RequestSecurityTokenImpl(null, requestType, target);
280:            }
281:
282:            /**
283:             *Create an RSTR for a Successful Token Cancellation
284:             */
285:            public RequestSecurityTokenResponse createRSTRForCancel() {
286:                RequestSecurityTokenResponse rstr = new RequestSecurityTokenResponseImpl();
287:                rstr
288:                        .setRequestedTokenCancelled(new RequestedTokenCancelledImpl());
289:
290:                return rstr;
291:            }
292:
293:            /**
294:             *Create an RST for Token Validation
295:             *<p>
296:             *TODO: Not clear from Spec whether the Token to be validated is ever sent ?
297:             *TODO: There is a mention of special case where a SOAPEnvelope may be specified as
298:             * a security token if the requestor desires the envelope to be validated.
299:             *</p>
300:             */
301:            public RequestSecurityToken createRSTForValidate(URI tokenType,
302:                    URI requestType) {
303:                return new RequestSecurityTokenImpl(tokenType, requestType);
304:            }
305:
306:            /**
307:             * create an RSTR for validate request.
308:             */
309:            public RequestSecurityTokenResponse createRSTRForValidate(
310:                    URI tokenType, RequestedSecurityToken token, Status status) {
311:                return new RequestSecurityTokenResponseImpl(tokenType, null,
312:                        token, null, null, null, null, null, null, status);
313:            }
314:
315:            /**
316:             * Create an Empty RST
317:             */
318:            public RequestSecurityToken createRST() {
319:                return new RequestSecurityTokenImpl();
320:            }
321:
322:            /**
323:             * Create an Empty RSTR
324:             */
325:            public RequestSecurityTokenResponse createRSTR() {
326:                return new RequestSecurityTokenResponseImpl();
327:            }
328:
329:            /**
330:             * create an RST from a Source
331:             */
332:            public RequestSecurityToken createRSTFrom(Source src) {
333:                try {
334:                    javax.xml.bind.Unmarshaller u = getContext()
335:                            .createUnmarshaller();
336:                    JAXBElement<RequestSecurityTokenType> rstType = u
337:                            .unmarshal(src, RequestSecurityTokenType.class);
338:                    RequestSecurityTokenType type = rstType.getValue();
339:                    return new RequestSecurityTokenImpl(type);
340:                } catch (Exception ex) {
341:                    throw new RuntimeException(ex.getMessage(), ex);
342:                }
343:            }
344:
345:            /**
346:             * create an RST from DOM Element
347:             */
348:            public RequestSecurityToken createRSTFrom(Element elem) {
349:                try {
350:                    javax.xml.bind.Unmarshaller u = getContext()
351:                            .createUnmarshaller();
352:                    JAXBElement<RequestSecurityTokenType> rstType = u
353:                            .unmarshal(elem, RequestSecurityTokenType.class);
354:                    RequestSecurityTokenType type = rstType.getValue();
355:                    return new RequestSecurityTokenImpl(type);
356:                } catch (Exception ex) {
357:                    throw new RuntimeException(ex.getMessage(), ex);
358:                }
359:            }
360:
361:            /**
362:             * create an RSTR from a Source
363:             */
364:            public RequestSecurityTokenResponse createRSTRFrom(Source src) {
365:                try {
366:                    javax.xml.bind.Unmarshaller u = getContext()
367:                            .createUnmarshaller();
368:                    JAXBElement<RequestSecurityTokenResponseType> rstType = u
369:                            .unmarshal(src,
370:                                    RequestSecurityTokenResponseType.class);
371:                    RequestSecurityTokenResponseType type = rstType.getValue();
372:                    return new RequestSecurityTokenResponseImpl(type);
373:                } catch (Exception ex) {
374:                    throw new RuntimeException(ex.getMessage(), ex);
375:                }
376:            }
377:
378:            /**
379:             * create an RSTR from DOM Element
380:             */
381:            public RequestSecurityTokenResponse createRSTRFrom(Element elem) {
382:                try {
383:                    javax.xml.bind.Unmarshaller u = getContext()
384:                            .createUnmarshaller();
385:                    JAXBElement<RequestSecurityTokenResponseType> rstType = u
386:                            .unmarshal(elem,
387:                                    RequestSecurityTokenResponseType.class);
388:                    RequestSecurityTokenResponseType type = rstType.getValue();
389:                    return new RequestSecurityTokenResponseImpl(type);
390:                } catch (Exception ex) {
391:                    throw new RuntimeException(ex.getMessage(), ex);
392:                }
393:            }
394:
395:            /**
396:             * Create RSTR Collection from Source
397:             */
398:            public RequestSecurityTokenResponseCollection createRSTRCollectionFrom(
399:                    Source src) {
400:                throw new UnsupportedOperationException("Not yet implemented!");
401:            }
402:
403:            /**
404:             * Create RSTR Collection from Element
405:             */
406:            public RequestSecurityTokenResponseCollection createRSTRCollectionFrom(
407:                    Element elem) {
408:                throw new UnsupportedOperationException("Not yet implemented!");
409:            }
410:
411:            /**
412:             * create an RST from JAXBElement
413:             * <p>
414:             * NOTE: an STS Implementor can call
415:             * <PRE>
416:             * JAXBElement&lt;RequestSecurityTokenType&gt; elem=
417:             * ObjectFactory.createRequestSecurityToken(&lt;JAXBBean for RST&gt;)
418:             * </PRE>
419:             * The JAXBBean for RST is the one generated from the ws-trust.xsd schema
420:             * The default implementation expects the packagename of the generated JAXB Beans to be fixed.
421:             * </p>
422:             */
423:            public RequestSecurityToken createRSTFrom(JAXBElement elem) {
424:                try {
425:                    RequestSecurityTokenType type = (RequestSecurityTokenType) elem
426:                            .getValue();
427:                    return new RequestSecurityTokenImpl(type);
428:                } catch (Exception e) {
429:                    throw new RuntimeException(
430:                            "There was a problem while creating RST from JAXBElement",
431:                            e);
432:                }
433:            }
434:
435:            /**
436:             * create an RSTR from JAXBElement
437:             * <p>
438:             * NOTE: an STS Implementor can call
439:             * <PRE>
440:             * JAXBElement&lt;RequestSecurityTokenResponseType&gt; elem=
441:             * ObjectFactory.createRequestSecurityTokenResponse(&lt;JAXBBean for RSTR&gt;);
442:             * </PRE>
443:             * The &lt;JAXBBean for RSTR&gt; is the one generated from the ws-trust.xsd schema
444:             * The default implementation expects the packagename of the generated JAXB Beans to be fixed.
445:             * </p>
446:             */
447:            public RequestSecurityTokenResponse createRSTRFrom(JAXBElement elem) {
448:                try {
449:                    RequestSecurityTokenResponseType type = (RequestSecurityTokenResponseType) elem
450:                            .getValue();
451:                    return new RequestSecurityTokenResponseImpl(type);
452:                } catch (Exception e) {
453:                    throw new RuntimeException(
454:                            "There was a problem while creating RSTR from JAXBElement",
455:                            e);
456:                }
457:            }
458:
459:            /**
460:             * create an RSTR Collection from JAXBElement
461:             * <p>
462:             * NOTE: an STS Implementor can call
463:             * <PRE>
464:             * JAXBElement&lt;RequestSecurityTokenResponseCollectionType&gt; elem=
465:             * ObjectFactory.createRequestSecurityTokenResponseCollection(&lt;JAXBBean for RSTR Collection&gt;
466:             * </PRE>
467:             * The &lt;JAXBBean for RSTR Collection&gt; is the one generated from the ws-trust.xsd schema
468:             * The default implementation expects the packagename of the generated JAXB Beans to be fixed.
469:             * </p>
470:             */
471:            public RequestSecurityTokenResponseCollection createRSTRCollectionFrom(
472:                    JAXBElement elem) {
473:                try {
474:                    RequestSecurityTokenResponseCollectionType type = (RequestSecurityTokenResponseCollectionType) elem
475:                            .getValue();
476:                    return new RequestSecurityTokenResponseCollectionImpl(type);
477:                } catch (Exception e) {
478:                    throw new RuntimeException(
479:                            "There was a problem while creating RSTRCollection from JAXBElement",
480:                            e);
481:                }
482:            }
483:
484:            public Object createResponseFrom(JAXBElement elem) {
485:                String local = elem.getName().getLocalPart();
486:                if (local.equalsIgnoreCase("RequestSecurityTokenResponseType")) {
487:                    return createRSTRFrom(elem);
488:                } else {
489:                    return createRSTRCollectionFrom(elem);
490:                }
491:            }
492:
493:            public SecurityTokenReference createSecurityTokenReference(
494:                    JAXBElement elem) {
495:                try {
496:                    SecurityTokenReferenceType type = (SecurityTokenReferenceType) elem
497:                            .getValue();
498:                    return new SecurityTokenReferenceImpl(type);
499:                } catch (Exception e) {
500:                    throw new RuntimeException(
501:                            "There was a problem while creating STR from JAXBElement",
502:                            e);
503:                }
504:            }
505:
506:            /**
507:             * convert an SecurityTokenReference to a JAXBElement
508:             */
509:            public JAXBElement toJAXBElement(SecurityTokenReference str) {
510:                JAXBElement<SecurityTokenReferenceType> strElement = (new com.sun.xml.ws.security.secext10.ObjectFactory())
511:                        .createSecurityTokenReference((SecurityTokenReferenceType) str);
512:                return strElement;
513:            }
514:
515:            /**
516:             * convert an RST to a JAXBElement
517:             */
518:            public JAXBElement toJAXBElement(RequestSecurityToken rst) {
519:                JAXBElement<RequestSecurityTokenType> rstElement = (new ObjectFactory())
520:                        .createRequestSecurityToken((RequestSecurityTokenType) rst);
521:                return rstElement;
522:            }
523:
524:            /**
525:             * convert an RSTR to a JAXBElement
526:             */
527:            public JAXBElement toJAXBElement(RequestSecurityTokenResponse rstr) {
528:                JAXBElement<RequestSecurityTokenResponseType> rstElement = (new ObjectFactory())
529:                        .createRequestSecurityTokenResponse((RequestSecurityTokenResponseType) rstr);
530:                return rstElement;
531:            }
532:
533:            /**
534:             * convert a Entropy to a JAXBElement
535:             */
536:            public JAXBElement toJAXBElement(Entropy entropy) {
537:                JAXBElement<EntropyType> etElement = (new ObjectFactory())
538:                        .createEntropy((EntropyType) entropy);
539:                return etElement;
540:            }
541:
542:            /**
543:             * convert an RSTR Collection to a JAXBElement
544:             */
545:            public JAXBElement toJAXBElement(
546:                    RequestSecurityTokenResponseCollection rstrCollection) {
547:                JAXBElement<RequestSecurityTokenResponseCollectionType> rstElement = (new ObjectFactory())
548:                        .createRequestSecurityTokenResponseCollection((RequestSecurityTokenResponseCollectionType) rstrCollection);
549:                return rstElement;
550:            }
551:
552:            /**
553:             * Marshal an RST to a Source.
554:             * <p>
555:             * Note: Useful for Dispatch Client implementations
556:             * </p>
557:             */
558:            public Source toSource(RequestSecurityToken rst) {
559:                return new DOMSource(toElement(rst));
560:            }
561:
562:            /**
563:             * Marshal an RSTR to a Source
564:             * <p>
565:             * Note: Useful for STS implementations which are JAXWS Providers
566:             * </p>
567:             */
568:            public Source toSource(RequestSecurityTokenResponse rstr) {
569:                return new DOMSource(toElement(rstr));
570:            }
571:
572:            /**
573:             * Marshal an RSTR Collection to a Source
574:             * <p>
575:             * Note: Useful for STS implementations which are JAXWS Providers
576:             * </p>
577:             */
578:            public Source toSource(
579:                    RequestSecurityTokenResponseCollection rstrCollection) {
580:                return new DOMSource(toElement(rstrCollection));
581:            }
582:
583:            /**
584:             * Marshal an RST to a DOM Element.
585:             * <p>
586:             * Note: Useful for Dispatch Client implementations
587:             * </p>
588:             */
589:            public Element toElement(RequestSecurityToken rst) {
590:                try {
591:                    DocumentBuilderFactory dbf = DocumentBuilderFactory
592:                            .newInstance();
593:                    dbf.setNamespaceAware(true);
594:                    DocumentBuilder db = dbf.newDocumentBuilder();
595:                    Document doc = db.newDocument();
596:
597:                    javax.xml.bind.Marshaller marshaller = getContext()
598:                            .createMarshaller();
599:                    JAXBElement<RequestSecurityTokenType> rstElement = (new ObjectFactory())
600:                            .createRequestSecurityToken((RequestSecurityTokenType) rst);
601:                    marshaller.marshal(rstElement, doc);
602:                    return doc.getDocumentElement();
603:
604:                } catch (Exception ex) {
605:                    throw new RuntimeException(ex.getMessage(), ex);
606:                }
607:            }
608:
609:            /**
610:             * Marshal an RSTR to DOM Element
611:             * <p>
612:             * Note: Useful for STS implementations which are JAXWS Providers
613:             * </p>
614:             */
615:            public Element toElement(RequestSecurityTokenResponse rstr) {
616:                try {
617:                    DocumentBuilderFactory dbf = DocumentBuilderFactory
618:                            .newInstance();
619:                    dbf.setNamespaceAware(true);
620:                    DocumentBuilder db = dbf.newDocumentBuilder();
621:                    Document doc = db.newDocument();
622:
623:                    javax.xml.bind.Marshaller marshaller = getContext()
624:                            .createMarshaller();
625:                    JAXBElement<RequestSecurityTokenResponseType> rstrElement = (new ObjectFactory())
626:                            .createRequestSecurityTokenResponse((RequestSecurityTokenResponseType) rstr);
627:                    marshaller.marshal(rstrElement, doc);
628:                    return doc.getDocumentElement();
629:
630:                } catch (Exception ex) {
631:                    throw new RuntimeException(ex.getMessage(), ex);
632:                }
633:            }
634:
635:            public Element toElement(RequestSecurityTokenResponse rstr,
636:                    Document doc) {
637:                try {
638:                    javax.xml.bind.Marshaller marshaller = getContext()
639:                            .createMarshaller();
640:                    JAXBElement<RequestSecurityTokenResponseType> rstrElement = (new ObjectFactory())
641:                            .createRequestSecurityTokenResponse((RequestSecurityTokenResponseType) rstr);
642:                    marshaller.marshal(rstrElement, doc);
643:                    return doc.getDocumentElement();
644:
645:                } catch (Exception ex) {
646:                    throw new RuntimeException(ex.getMessage(), ex);
647:                }
648:            }
649:
650:            /**
651:             * Marshal an RSTR Collection to a DOM Element
652:             * <p>
653:             * Note: Useful for STS implementations which are JAXWS Providers
654:             * </p>
655:             */
656:            public Element toElement(
657:                    RequestSecurityTokenResponseCollection rstrCollection) {
658:                try {
659:                    DocumentBuilderFactory dbf = DocumentBuilderFactory
660:                            .newInstance();
661:                    dbf.setNamespaceAware(true);
662:                    DocumentBuilder db = dbf.newDocumentBuilder();
663:                    Document doc = db.newDocument();
664:                    javax.xml.bind.Marshaller marshaller = getContext()
665:                            .createMarshaller();
666:                    JAXBElement<RequestSecurityTokenResponseCollectionType> rstrElement = (new ObjectFactory())
667:                            .createRequestSecurityTokenResponseCollection((RequestSecurityTokenResponseCollectionType) rstrCollection);
668:                    marshaller.marshal(rstrElement, doc);
669:
670:                    return doc.getDocumentElement();
671:                } catch (Exception ex) {
672:                    throw new RuntimeException(ex.getMessage(), ex);
673:                }
674:            }
675:
676:            public Element toElement(BinarySecret bs) {
677:                try {
678:                    DocumentBuilderFactory dbf = DocumentBuilderFactory
679:                            .newInstance();
680:                    dbf.setNamespaceAware(true);
681:                    DocumentBuilder db = dbf.newDocumentBuilder();
682:                    Document doc = db.newDocument();
683:
684:                    javax.xml.bind.Marshaller marshaller = getContext()
685:                            .createMarshaller();
686:                    JAXBElement<BinarySecretType> bsElement = (new ObjectFactory())
687:                            .createBinarySecret((BinarySecretType) bs);
688:                    marshaller.marshal(bsElement, doc);
689:                    return doc.getDocumentElement();
690:                } catch (Exception ex) {
691:                    throw new RuntimeException(ex.getMessage(), ex);
692:                }
693:            }
694:
695:            /**
696:             * Marshal an STR to a DOM Element.
697:             * <p>
698:             * Note: Useful for Dispatch Client implementations
699:             * </p>
700:             */
701:            public Element toElement(SecurityTokenReference str, Document doc) {
702:                try {
703:                    if (doc == null) {
704:                        DocumentBuilderFactory dbf = DocumentBuilderFactory
705:                                .newInstance();
706:                        dbf.setNamespaceAware(true);
707:                        DocumentBuilder db = dbf.newDocumentBuilder();
708:                        doc = db.newDocument();
709:                    }
710:
711:                    javax.xml.bind.Marshaller marshaller = getContext()
712:                            .createMarshaller();
713:                    JAXBElement<SecurityTokenReferenceType> strElement = (new com.sun.xml.ws.security.secext10.ObjectFactory())
714:                            .createSecurityTokenReference((SecurityTokenReferenceType) str);
715:                    marshaller.marshal(strElement, doc);
716:                    return doc.getDocumentElement();
717:
718:                } catch (Exception ex) {
719:                    throw new RuntimeException(ex.getMessage(), ex);
720:                }
721:            }
722:
723:            /**
724:             * Marshal an BinarySecret to a DOM Element.
725:             * <p>
726:             * Note: Useful for Dispatch Client implementations
727:             * </p>
728:             */
729:            public Element toElement(BinarySecret bs, Document doc) {
730:                try {
731:                    if (doc == null) {
732:                        DocumentBuilderFactory dbf = DocumentBuilderFactory
733:                                .newInstance();
734:                        dbf.setNamespaceAware(true);
735:                        DocumentBuilder db = dbf.newDocumentBuilder();
736:                        doc = db.newDocument();
737:                    }
738:
739:                    javax.xml.bind.Marshaller marshaller = getContext()
740:                            .createMarshaller();
741:                    JAXBElement<BinarySecretType> bsElement = (new ObjectFactory())
742:                            .createBinarySecret((BinarySecretType) bs);
743:                    marshaller.marshal(bsElement, doc);
744:                    return doc.getDocumentElement();
745:
746:                } catch (Exception ex) {
747:                    throw new RuntimeException(ex.getMessage(), ex);
748:                }
749:            }
750:        }
ww_w.__j___ava___2s.__co__m | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.