Source Code Cross Referenced for WSTrustElementFactoryImpl.java in  » 6.0-JDK-Modules-com.sun » wsit » com » sun » xml » ws » security » trust » impl » 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 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: WSTrustElementFactoryImpl.java,v 1.14 2007/05/29 22:11:33 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.impl;
042:
043:        import com.sun.xml.ws.security.secext10.SecurityTokenReferenceType;
044:
045:        import com.sun.xml.ws.api.security.trust.Claims;
046:        import com.sun.xml.ws.api.security.trust.WSTrustException;
047:        import com.sun.xml.ws.security.trust.elements.AllowPostdating;
048:        import com.sun.xml.ws.security.trust.elements.BinarySecret;
049:        import com.sun.xml.ws.security.trust.elements.CancelTarget;
050:        import com.sun.xml.ws.security.trust.elements.Entropy;
051:        import com.sun.xml.ws.security.trust.elements.IssuedTokens;
052:        import com.sun.xml.ws.security.trust.elements.Lifetime;
053:        import com.sun.xml.ws.security.trust.elements.RenewTarget;
054:        import com.sun.xml.ws.security.trust.elements.Renewing;
055:        import com.sun.xml.ws.security.trust.elements.RequestSecurityTokenResponse;
056:        import com.sun.xml.ws.security.trust.elements.RequestSecurityTokenResponseCollection;
057:        import com.sun.xml.ws.security.trust.elements.RequestedProofToken;
058:        import com.sun.xml.ws.security.trust.elements.RequestedAttachedReference;
059:        import com.sun.xml.ws.security.trust.elements.RequestedUnattachedReference;
060:        import com.sun.xml.ws.security.trust.elements.RequestSecurityToken;
061:        import com.sun.xml.ws.security.trust.elements.RequestedSecurityToken;
062:        import com.sun.xml.ws.security.trust.elements.Status;
063:
064:        import com.sun.xml.ws.security.trust.impl.elements.BinarySecretImpl;
065:        import com.sun.xml.ws.security.trust.impl.elements.CancelTargetImpl;
066:        import com.sun.xml.ws.security.trust.impl.elements.EntropyImpl;
067:        import com.sun.xml.ws.security.trust.impl.elements.IssuedTokensImpl;
068:        import com.sun.xml.ws.security.trust.impl.elements.LifetimeImpl;
069:        import com.sun.xml.ws.security.trust.impl.elements.RequestSecurityTokenResponseImpl;
070:        import com.sun.xml.ws.security.trust.impl.elements.RequestSecurityTokenResponseCollectionImpl;
071:        import com.sun.xml.ws.security.trust.impl.elements.RequestedProofTokenImpl;
072:        import com.sun.xml.ws.security.trust.impl.elements.RequestedAttachedReferenceImpl;
073:        import com.sun.xml.ws.security.trust.impl.elements.RequestedUnattachedReferenceImpl;
074:        import com.sun.xml.ws.security.trust.impl.elements.RequestSecurityTokenImpl;
075:        import com.sun.xml.ws.security.trust.impl.elements.RequestedSecurityTokenImpl;
076:        import com.sun.xml.ws.security.trust.impl.elements.RequestedTokenCancelledImpl;
077:        import com.sun.xml.ws.security.trust.impl.elements.str.DirectReferenceImpl;
078:        import com.sun.xml.ws.security.trust.impl.elements.str.SecurityTokenReferenceImpl;
079:        import com.sun.xml.ws.security.trust.impl.elements.str.KeyIdentifierImpl;
080:        import com.sun.xml.ws.security.trust.impl.bindings.BinarySecretType;
081:        import com.sun.xml.ws.security.trust.impl.bindings.RequestSecurityTokenType;
082:        import com.sun.xml.ws.security.trust.impl.bindings.RequestSecurityTokenResponseType;
083:        import com.sun.xml.ws.security.trust.impl.bindings.ObjectFactory;
084:        import com.sun.xml.ws.security.trust.impl.bindings.EntropyType;
085:        import com.sun.xml.ws.policy.impl.bindings.AppliesTo;
086:
087:        import com.sun.xml.ws.security.trust.elements.str.DirectReference;
088:        import com.sun.xml.ws.security.trust.elements.str.KeyIdentifier;
089:        import com.sun.xml.ws.security.EncryptedKey;
090:        import com.sun.xml.ws.security.trust.elements.str.Reference;
091:        import com.sun.xml.ws.security.trust.elements.str.SecurityTokenReference;
092:        import com.sun.xml.ws.security.Token;
093:        import com.sun.xml.ws.security.wsu10.AttributedDateTime;
094:
095:        import javax.xml.bind.PropertyException;
096:
097:        import java.net.URI;
098:
099:        import java.util.logging.Level;
100:        import java.util.logging.Logger;
101:        import com.sun.xml.ws.security.trust.logging.LogDomainConstants;
102:
103:        import javax.xml.transform.Source;
104:
105:        import org.w3c.dom.Element;
106:        import org.w3c.dom.Document;
107:        import javax.xml.parsers.DocumentBuilder;
108:        import javax.xml.parsers.DocumentBuilderFactory;
109:
110:        import javax.xml.bind.JAXBElement;
111:        import javax.xml.bind.JAXBException;
112:
113:        import com.sun.xml.ws.security.trust.WSTrustElementFactory;
114:        import com.sun.xml.ws.api.security.trust.WSTrustException;
115:        import com.sun.xml.ws.security.trust.impl.bindings.RequestSecurityTokenResponseCollectionType;
116:        import javax.xml.bind.util.JAXBSource;
117:
118:        import javax.xml.bind.Marshaller;
119:
120:        import com.sun.xml.ws.security.trust.logging.LogStringsMessages;
121:
122:        /**
123:         * A Factory for creating the WS-Trust schema elements,
124:         * and marshalling/un-marshalling them.
125:         *
126:         * @author Manveen Kaur
127:         */
128:        public class WSTrustElementFactoryImpl extends WSTrustElementFactory {
129:
130:            private static final Logger log = Logger.getLogger(
131:                    LogDomainConstants.TRUST_IMPL_DOMAIN,
132:                    LogDomainConstants.TRUST_IMPL_DOMAIN_BUNDLE);
133:
134:            private Marshaller marshaller = null;
135:            private static final String RST = "RST";
136:            private static final String RSTRCollection = "RSTRCollection";
137:
138:            public WSTrustElementFactoryImpl() {
139:                try {
140:                    marshaller = getContext().createMarshaller();
141:                    marshaller
142:                            .setProperty(
143:                                    "com.sun.xml.bind.namespacePrefixMapper",
144:                                    new com.sun.xml.ws.security.trust.util.TrustNamespacePrefixMapper());
145:                } catch (PropertyException e) {
146:                    log.log(Level.SEVERE, LogStringsMessages
147:                            .WST_0003_ERROR_CREATING_WSTRUSTFACT(), e);
148:                    throw new RuntimeException(LogStringsMessages
149:                            .WST_0003_ERROR_CREATING_WSTRUSTFACT(), e);
150:                } catch (JAXBException jbe) {
151:                    log.log(Level.SEVERE, LogStringsMessages
152:                            .WST_0003_ERROR_CREATING_WSTRUSTFACT(), jbe);
153:                    throw new RuntimeException(LogStringsMessages
154:                            .WST_0003_ERROR_CREATING_WSTRUSTFACT(), jbe);
155:                }
156:            }
157:
158:            /**
159:             * Create an RST for Issue from the given arguments
160:             * Any of the arguments can be null since they are all optional, but one of tokenType and AppliesTo must be present
161:             */
162:            public RequestSecurityToken createRSTForIssue(final URI tokenType,
163:                    final URI requestType, final URI context,
164:                    final AppliesTo scopes, final Claims claims,
165:                    final Entropy entropy, final Lifetime lifetime)
166:                    throws WSTrustException {
167:
168:                if (tokenType == null && scopes == null) {
169:                    log.log(Level.WARNING, LogStringsMessages
170:                            .WST_1003_TOKENTYPE_APPLIESTO_NULL());
171:                }
172:                return new RequestSecurityTokenImpl(tokenType, requestType,
173:                        context, scopes, claims, entropy, lifetime, null);
174:            }
175:
176:            /**
177:             * Create an RSTR for Issue from the given arguments. TokenType should be Issue.
178:             * Any of the arguments can be null since they are all optional, but one of RequestedSecurityToken or RequestedProofToken should be returned
179:             */
180:            public RequestSecurityTokenResponse createRSTRForIssue(
181:                    final URI tokenType, final URI context,
182:                    final RequestedSecurityToken token, final AppliesTo scopes,
183:                    final RequestedAttachedReference attachedReference,
184:                    final RequestedUnattachedReference unattachedRef,
185:                    final RequestedProofToken proofToken,
186:                    final Entropy entropy, final Lifetime lifetime)
187:                    throws WSTrustException {
188:                final RequestSecurityTokenResponse rstr = new RequestSecurityTokenResponseImpl(
189:                        tokenType, context, token, scopes, attachedReference,
190:                        unattachedRef, proofToken, entropy, lifetime, null);
191:                return rstr;
192:            }
193:
194:            /**
195:             * Create a collection of RequestSecurityTokenResponse(s)
196:             */
197:            public RequestSecurityTokenResponseCollection createRSTRCollectionForIssue(
198:                    final URI tokenType, final URI context,
199:                    final RequestedSecurityToken token, final AppliesTo scopes,
200:                    final RequestedAttachedReference attached,
201:                    final RequestedUnattachedReference unattached,
202:                    final RequestedProofToken proofToken,
203:                    final Entropy entropy, final Lifetime lifetime)
204:                    throws WSTrustException {
205:                final RequestSecurityTokenResponseCollection rstrCollection = new RequestSecurityTokenResponseCollectionImpl(
206:                        tokenType, context, token, scopes, attached,
207:                        unattached, proofToken, entropy, lifetime);
208:                return rstrCollection;
209:            }
210:
211:            /**
212:             * Create a wst:IssuedTokens object
213:             */
214:            public IssuedTokens createIssuedTokens(
215:                    final RequestSecurityTokenResponseCollection issuedTokens) {
216:                return new IssuedTokensImpl(issuedTokens);
217:            }
218:
219:            /**
220:             * Create an Entropy with a BinarySecret
221:             */
222:            public Entropy createEntropy(final BinarySecret secret) {
223:                return new EntropyImpl(secret);
224:            }
225:
226:            /**
227:             * Create an Entropy with an xenc:EncryptedKey
228:             */
229:            public Entropy createEntropy(final EncryptedKey key) {
230:                return new EntropyImpl(key);
231:            }
232:
233:            public BinarySecret createBinarySecret(final byte[] rawValue,
234:                    final String type) {
235:                return new BinarySecretImpl(rawValue, type);
236:            }
237:
238:            public BinarySecret createBinarySecret(final Element elem)
239:                    throws WSTrustException {
240:                return new BinarySecretImpl(BinarySecretImpl.fromElement(elem));
241:            }
242:
243:            /**
244:             * Create a Lifetime.
245:             */
246:            public Lifetime createLifetime(final AttributedDateTime created,
247:                    final AttributedDateTime expires) {
248:                return new LifetimeImpl(created, expires);
249:            }
250:
251:            /**
252:             * Create a RequestedSecurityToken.
253:             */
254:            public RequestedSecurityToken createRequestedSecurityToken(
255:                    final Token token) {
256:                return new RequestedSecurityTokenImpl(token);
257:            }
258:
259:            /**
260:             * Create a RequestedSecurityToken.
261:             */
262:            public RequestedSecurityToken createRequestedSecurityToken() {
263:                return new RequestedSecurityTokenImpl();
264:            }
265:
266:            public DirectReference createDirectReference(
267:                    final String valueType, final String uri) {
268:                return new DirectReferenceImpl(valueType, uri);
269:            }
270:
271:            public KeyIdentifier createKeyIdentifier(final String valueType,
272:                    final String encodingType) {
273:                return new KeyIdentifierImpl(valueType, encodingType);
274:            }
275:
276:            public SecurityTokenReference createSecurityTokenReference(
277:                    final Reference ref) {
278:                return new SecurityTokenReferenceImpl(ref);
279:            }
280:
281:            /**
282:             * Create a RequestedAttachedReference.
283:             */
284:            public RequestedAttachedReference createRequestedAttachedReference(
285:                    final SecurityTokenReference str) {
286:                return new RequestedAttachedReferenceImpl(str);
287:            }
288:
289:            /**
290:             * Create a RequestedUnattachedReference.
291:             */
292:            public RequestedUnattachedReference createRequestedUnattachedReference(
293:                    final SecurityTokenReference str) {
294:                return new RequestedUnattachedReferenceImpl(str);
295:            }
296:
297:            /**
298:             * Create a RequestedProofToken.
299:             */
300:            public RequestedProofToken createRequestedProofToken() {
301:                return new RequestedProofTokenImpl();
302:            }
303:
304:            /**
305:             *Create an RST for a Renewal Request
306:             */
307:            public RequestSecurityToken createRSTForRenew(final URI tokenType,
308:                    final URI requestType, final URI context,
309:                    final RenewTarget target, final AllowPostdating apd,
310:                    final Renewing renewingInfo) {
311:                return new RequestSecurityTokenImpl(tokenType, requestType,
312:                        context, target, apd, renewingInfo);
313:            }
314:
315:            public CancelTarget createCancelTarget(
316:                    final SecurityTokenReference str) {
317:                return new CancelTargetImpl(str);
318:            }
319:
320:            /**
321:             *Create an RST for Token Cancellation
322:             */
323:            public RequestSecurityToken createRSTForCancel(
324:                    final URI requestType, final CancelTarget target) {
325:                return new RequestSecurityTokenImpl(null, requestType, target);
326:            }
327:
328:            /**
329:             *Create an RSTR for a Successful Token Cancellation
330:             */
331:            public RequestSecurityTokenResponse createRSTRForCancel() {
332:                final RequestSecurityTokenResponse rstr = new RequestSecurityTokenResponseImpl();
333:                rstr
334:                        .setRequestedTokenCancelled(new RequestedTokenCancelledImpl());
335:                if (log.isLoggable(Level.FINE)) {
336:                    log.log(Level.FINE, LogStringsMessages
337:                            .WST_1008_CREATED_RSTR_CANCEL(rstr.toString()));
338:                }
339:                return rstr;
340:            }
341:
342:            /**
343:             *Create an RST for Token Validation
344:             *<p>
345:             *TODO: Not clear from Spec whether the Token to be validated is ever sent ?
346:             *TODO: There is a mention of special case where a SOAPEnvelope may be specified as
347:             * a security token if the requestor desires the envelope to be validated.
348:             *</p>
349:             */
350:            public RequestSecurityToken createRSTForValidate(
351:                    final URI tokenType, final URI requestType) {
352:                return new RequestSecurityTokenImpl(tokenType, requestType);
353:            }
354:
355:            /**
356:             * create an RSTR for validate request.
357:             */
358:            public RequestSecurityTokenResponse createRSTRForValidate(
359:                    final URI tokenType, final RequestedSecurityToken token,
360:                    final Status status) {
361:                return new RequestSecurityTokenResponseImpl(tokenType, null,
362:                        token, null, null, null, null, null, null, status);
363:            }
364:
365:            /**
366:             * Create an Empty RST
367:             */
368:            public RequestSecurityToken createRST() {
369:                return new RequestSecurityTokenImpl();
370:            }
371:
372:            /**
373:             * Create an Empty RSTR
374:             */
375:            public RequestSecurityTokenResponse createRSTR() {
376:                return new RequestSecurityTokenResponseImpl();
377:            }
378:
379:            /**
380:             * create an RST from a Source
381:             */
382:            public RequestSecurityToken createRSTFrom(final Source src) {
383:                try {
384:                    final javax.xml.bind.Unmarshaller unmarshaller = getContext()
385:                            .createUnmarshaller();
386:                    final JAXBElement<RequestSecurityTokenType> rstType = unmarshaller
387:                            .unmarshal(src, RequestSecurityTokenType.class);
388:                    final RequestSecurityTokenType type = rstType.getValue();
389:                    return new RequestSecurityTokenImpl(type);
390:                } catch (Exception ex) {
391:                    log.log(Level.SEVERE, LogStringsMessages
392:                            .WST_0006_FAIL_RST_SOURCE(src.toString()), ex);
393:                    throw new RuntimeException(LogStringsMessages
394:                            .WST_0006_FAIL_RST_SOURCE(src.toString()), ex);
395:                }
396:            }
397:
398:            /**
399:             * create an RST from DOM Element
400:             */
401:            public RequestSecurityToken createRSTFrom(final Element elem) {
402:                try {
403:                    final javax.xml.bind.Unmarshaller unmarshaller = getContext()
404:                            .createUnmarshaller();
405:                    final JAXBElement<RequestSecurityTokenType> rstType = unmarshaller
406:                            .unmarshal(elem, RequestSecurityTokenType.class);
407:                    final RequestSecurityTokenType type = rstType.getValue();
408:                    return new RequestSecurityTokenImpl(type);
409:                } catch (Exception ex) {
410:                    log.log(Level.SEVERE, LogStringsMessages
411:                            .WST_0007_FAIL_RST_ELEM(elem.toString()), ex);
412:                    throw new RuntimeException(LogStringsMessages
413:                            .WST_0007_FAIL_RST_ELEM(elem.toString()), ex);
414:                }
415:            }
416:
417:            /**
418:             * create an RSTR from a Source
419:             */
420:            public RequestSecurityTokenResponse createRSTRFrom(final Source src) {
421:                try {
422:                    final javax.xml.bind.Unmarshaller unmarshaller = getContext()
423:                            .createUnmarshaller();
424:                    final JAXBElement<RequestSecurityTokenResponseType> rstType = unmarshaller
425:                            .unmarshal(src,
426:                                    RequestSecurityTokenResponseType.class);
427:                    final RequestSecurityTokenResponseType type = rstType
428:                            .getValue();
429:                    return new RequestSecurityTokenResponseImpl(type);
430:                } catch (Exception ex) {
431:                    log.log(Level.SEVERE, LogStringsMessages
432:                            .WST_0008_FAIL_RSTR_SOURCE(src.toString()), ex);
433:                    throw new RuntimeException(LogStringsMessages
434:                            .WST_0008_FAIL_RSTR_SOURCE(src.toString()), ex);
435:                }
436:            }
437:
438:            /**
439:             * create an RSTR from DOM Element
440:             */
441:            public RequestSecurityTokenResponse createRSTRFrom(
442:                    final Element elem) {
443:                try {
444:                    final javax.xml.bind.Unmarshaller unmarshaller = getContext()
445:                            .createUnmarshaller();
446:                    final JAXBElement<RequestSecurityTokenResponseType> rstType = unmarshaller
447:                            .unmarshal(elem,
448:                                    RequestSecurityTokenResponseType.class);
449:                    final RequestSecurityTokenResponseType type = rstType
450:                            .getValue();
451:                    return new RequestSecurityTokenResponseImpl(type);
452:                } catch (Exception ex) {
453:                    log.log(Level.SEVERE, LogStringsMessages
454:                            .WST_0008_FAIL_RSTR_SOURCE(elem.toString()), ex);
455:                    throw new RuntimeException(LogStringsMessages
456:                            .WST_0008_FAIL_RSTR_SOURCE(elem.toString()), ex);
457:                }
458:            }
459:
460:            /**
461:             * Create RSTR Collection from Source
462:             */
463:            public RequestSecurityTokenResponseCollection createRSTRCollectionFrom(
464:                    final Source src) {
465:                throw new UnsupportedOperationException("Not yet implemented!");
466:            }
467:
468:            /**
469:             * Create RSTR Collection from Element
470:             */
471:            public RequestSecurityTokenResponseCollection createRSTRCollectionFrom(
472:                    final Element elem) {
473:                throw new UnsupportedOperationException("Not yet implemented!");
474:            }
475:
476:            /**
477:             * create an RST from JAXBElement
478:             * <p>
479:             * NOTE: an STS Implementor can call
480:             * <PRE>
481:             * JAXBElement&lt;RequestSecurityTokenType&gt; elem=
482:             * ObjectFactory.createRequestSecurityToken(&lt;JAXBBean for RST&gt;)
483:             * </PRE>
484:             * The JAXBBean for RST is the one generated from the ws-trust.xsd schema
485:             * The default implementation expects the packagename of the generated JAXB Beans to be fixed.
486:             * </p>
487:             */
488:            public RequestSecurityToken createRSTFrom(final JAXBElement elem) {
489:                try {
490:                    final RequestSecurityTokenType type = (RequestSecurityTokenType) elem
491:                            .getValue();
492:                    return new RequestSecurityTokenImpl(type);
493:                } catch (Exception e) {
494:                    log.log(Level.SEVERE, LogStringsMessages
495:                            .WST_0010_FAILED_CREATION_FROM_JAXBELE(RST), e);
496:                    throw new RuntimeException(LogStringsMessages
497:                            .WST_0010_FAILED_CREATION_FROM_JAXBELE(RST), e);
498:                }
499:            }
500:
501:            /**
502:             * create an RSTR from JAXBElement
503:             * <p>
504:             * NOTE: an STS Implementor can call
505:             * <PRE>
506:             * JAXBElement&lt;RequestSecurityTokenResponseType&gt; elem=
507:             * ObjectFactory.createRequestSecurityTokenResponse(&lt;JAXBBean for RSTR&gt;);
508:             * </PRE>
509:             * The &lt;JAXBBean for RSTR&gt; is the one generated from the ws-trust.xsd schema
510:             * The default implementation expects the packagename of the generated JAXB Beans to be fixed.
511:             * </p>
512:             */
513:            public RequestSecurityTokenResponse createRSTRFrom(
514:                    final JAXBElement elem) {
515:                try {
516:                    final RequestSecurityTokenResponseType type = (RequestSecurityTokenResponseType) elem
517:                            .getValue();
518:                    return new RequestSecurityTokenResponseImpl(type);
519:                } catch (Exception e) {
520:                    log.log(Level.SEVERE, LogStringsMessages
521:                            .WST_0009_FAIL_RSTR_ELEM(elem.toString()), e);
522:                    throw new RuntimeException(LogStringsMessages
523:                            .WST_0009_FAIL_RSTR_ELEM(elem.toString()), e);
524:                }
525:            }
526:
527:            /**
528:             * create an RSTR Collection from JAXBElement
529:             * <p>
530:             * NOTE: an STS Implementor can call
531:             * <PRE>
532:             * JAXBElement&lt;RequestSecurityTokenResponseCollectionType&gt; elem=
533:             * ObjectFactory.createRequestSecurityTokenResponseCollection(&lt;JAXBBean for RSTR Collection&gt;
534:             * </PRE>
535:             * The &lt;JAXBBean for RSTR Collection&gt; is the one generated from the ws-trust.xsd schema
536:             * The default implementation expects the packagename of the generated JAXB Beans to be fixed.
537:             * </p>
538:             */
539:            public RequestSecurityTokenResponseCollection createRSTRCollectionFrom(
540:                    final JAXBElement elem) {
541:                try {
542:                    final RequestSecurityTokenResponseCollectionType type = (RequestSecurityTokenResponseCollectionType) elem
543:                            .getValue();
544:                    return new RequestSecurityTokenResponseCollectionImpl(type);
545:                } catch (Exception e) {
546:                    log
547:                            .log(
548:                                    Level.SEVERE,
549:                                    LogStringsMessages
550:                                            .WST_0010_FAILED_CREATION_FROM_JAXBELE(RSTRCollection),
551:                                    e);
552:                    throw new RuntimeException(
553:                            LogStringsMessages
554:                                    .WST_0010_FAILED_CREATION_FROM_JAXBELE(RSTRCollection),
555:                            e);
556:                }
557:            }
558:
559:            public SecurityTokenReference createSecurityTokenReference(
560:                    final JAXBElement elem) {
561:                try {
562:                    final SecurityTokenReferenceType type = (SecurityTokenReferenceType) elem
563:                            .getValue();
564:                    return new SecurityTokenReferenceImpl(type);
565:                } catch (Exception e) {
566:                    log.log(Level.SEVERE, LogStringsMessages
567:                            .WST_0010_FAILED_CREATION_FROM_JAXBELE("STR"), e);
568:                    throw new RuntimeException(LogStringsMessages
569:                            .WST_0010_FAILED_CREATION_FROM_JAXBELE("STR"), e);
570:                }
571:            }
572:
573:            /**
574:             * convert an SecurityTokenReference to a JAXBElement
575:             */
576:            public JAXBElement toJAXBElement(final SecurityTokenReference str) {
577:                final JAXBElement<SecurityTokenReferenceType> strElement = (new com.sun.xml.ws.security.secext10.ObjectFactory())
578:                        .createSecurityTokenReference((SecurityTokenReferenceType) str);
579:                return strElement;
580:            }
581:
582:            /**
583:             * convert an RST to a JAXBElement
584:             */
585:            public JAXBElement toJAXBElement(final RequestSecurityToken rst) {
586:                final JAXBElement<RequestSecurityTokenType> rstElement = (new ObjectFactory())
587:                        .createRequestSecurityToken((RequestSecurityTokenType) rst);
588:                return rstElement;
589:            }
590:
591:            /**
592:             * convert an RSTR to a JAXBElement
593:             */
594:            public JAXBElement toJAXBElement(
595:                    final RequestSecurityTokenResponse rstr) {
596:                final JAXBElement<RequestSecurityTokenResponseType> rstElement = (new ObjectFactory())
597:                        .createRequestSecurityTokenResponse((RequestSecurityTokenResponseType) rstr);
598:                return rstElement;
599:            }
600:
601:            /**
602:             * convert a Entropy to a JAXBElement
603:             */
604:            public JAXBElement toJAXBElement(final Entropy entropy) {
605:                final JAXBElement<EntropyType> etElement = (new ObjectFactory())
606:                        .createEntropy((EntropyType) entropy);
607:                return etElement;
608:            }
609:
610:            /**
611:             * convert an RSTR Collection to a JAXBElement
612:             */
613:            public JAXBElement toJAXBElement(
614:                    final RequestSecurityTokenResponseCollection rstrCollection) {
615:                final JAXBElement<RequestSecurityTokenResponseCollectionType> rstElement = (new ObjectFactory())
616:                        .createRequestSecurityTokenResponseCollection((RequestSecurityTokenResponseCollectionType) rstrCollection);
617:                return rstElement;
618:            }
619:
620:            /**
621:             * Marshal an RST to a Source.
622:             * <p>
623:             * Note: Useful for Dispatch Client implementations
624:             * </p>
625:             */
626:            public Source toSource(final RequestSecurityToken rst) {
627:                try {
628:                    return new JAXBSource(marshaller, toJAXBElement(rst));
629:                } catch (JAXBException ex) {
630:                    log.log(Level.SEVERE, LogStringsMessages
631:                            .WST_0002_FAIL_MARSHAL_TOSOURCE(RST), ex);
632:                    throw new RuntimeException(LogStringsMessages
633:                            .WST_0002_FAIL_MARSHAL_TOSOURCE(RST), ex);
634:                }
635:            }
636:
637:            /**
638:             * Marshal an RSTR to a Source
639:             * <p>
640:             * Note: Useful for STS implementations which are JAXWS Providers
641:             * </p>
642:             */
643:            public Source toSource(final RequestSecurityTokenResponse rstr) {
644:                //return new DOMSource(toElement(rstr));
645:                try {
646:                    return new JAXBSource(marshaller, toJAXBElement(rstr));
647:                } catch (JAXBException ex) {
648:                    log.log(Level.SEVERE, LogStringsMessages
649:                            .WST_0002_FAIL_MARSHAL_TOSOURCE("RSTR"), ex);
650:                    throw new RuntimeException(LogStringsMessages
651:                            .WST_0002_FAIL_MARSHAL_TOSOURCE("RSTR"), ex);
652:                }
653:            }
654:
655:            /**
656:             * Marshal an RSTR Collection to a Source
657:             * <p>
658:             * Note: Useful for STS implementations which are JAXWS Providers
659:             * </p>
660:             */
661:            public Source toSource(
662:                    final RequestSecurityTokenResponseCollection rstrCollection) {
663:                try {
664:                    return new JAXBSource(marshaller,
665:                            toJAXBElement(rstrCollection));
666:                } catch (JAXBException ex) {
667:                    log
668:                            .log(
669:                                    Level.SEVERE,
670:                                    LogStringsMessages
671:                                            .WST_0002_FAIL_MARSHAL_TOSOURCE(RSTRCollection),
672:                                    ex);
673:                    throw new RuntimeException(LogStringsMessages
674:                            .WST_0002_FAIL_MARSHAL_TOSOURCE(RSTRCollection), ex);
675:                }
676:            }
677:
678:            /**
679:             * Marshal an RST to a DOM Element.
680:             * <p>
681:             * Note: Useful for Dispatch Client implementations
682:             * </p>
683:             */
684:            public Element toElement(final RequestSecurityToken rst) {
685:                try {
686:                    final DocumentBuilderFactory dbf = DocumentBuilderFactory
687:                            .newInstance();
688:                    dbf.setNamespaceAware(true);
689:                    final DocumentBuilder builder = dbf.newDocumentBuilder();
690:                    final Document doc = builder.newDocument();
691:
692:                    //javax.xml.bind.Marshaller marshaller = getContext().createMarshaller();
693:                    final JAXBElement<RequestSecurityTokenType> rstElement = (new ObjectFactory())
694:                            .createRequestSecurityToken((RequestSecurityTokenType) rst);
695:                    marshaller.marshal(rstElement, doc);
696:                    return doc.getDocumentElement();
697:
698:                } catch (javax.xml.parsers.ParserConfigurationException ex) {
699:                    log.log(Level.SEVERE, LogStringsMessages
700:                            .WST_0011_PARSERCONFIG_EX_TO_ELEMENT(), ex);
701:                    throw new RuntimeException(LogStringsMessages
702:                            .WST_0011_PARSERCONFIG_EX_TO_ELEMENT(), ex);
703:                } catch (JAXBException e) {
704:                    log.log(Level.SEVERE, LogStringsMessages
705:                            .WST_0012_JAXB_EX_TO_ELEMENT(), e);
706:                    throw new RuntimeException(LogStringsMessages
707:                            .WST_0012_JAXB_EX_TO_ELEMENT(), e);
708:                }
709:            }
710:
711:            /**
712:             * Marshal an RSTR to DOM Element
713:             * <p>
714:             * Note: Useful for STS implementations which are JAXWS Providers
715:             * </p>
716:             */
717:            public Element toElement(final RequestSecurityTokenResponse rstr) {
718:                try {
719:                    final DocumentBuilderFactory dbf = DocumentBuilderFactory
720:                            .newInstance();
721:                    dbf.setNamespaceAware(true);
722:                    final DocumentBuilder builder = dbf.newDocumentBuilder();
723:                    final Document doc = builder.newDocument();
724:
725:                    //javax.xml.bind.Marshaller marshaller = getContext().createMarshaller();
726:                    final JAXBElement<RequestSecurityTokenResponseType> rstrElement = (new ObjectFactory())
727:                            .createRequestSecurityTokenResponse((RequestSecurityTokenResponseType) rstr);
728:                    marshaller.marshal(rstrElement, doc);
729:                    return doc.getDocumentElement();
730:
731:                } catch (Exception ex) {
732:                    log.log(Level.SEVERE, LogStringsMessages
733:                            .WST_0012_JAXB_EX_TO_ELEMENT(), ex);
734:                    throw new RuntimeException(LogStringsMessages
735:                            .WST_0012_JAXB_EX_TO_ELEMENT(), ex);
736:                }
737:            }
738:
739:            public Element toElement(final RequestSecurityTokenResponse rstr,
740:                    final Document doc) {
741:                try {
742:                    final JAXBElement<RequestSecurityTokenResponseType> rstrElement = (new ObjectFactory())
743:                            .createRequestSecurityTokenResponse((RequestSecurityTokenResponseType) rstr);
744:                    marshaller.marshal(rstrElement, doc);
745:                    return doc.getDocumentElement();
746:
747:                } catch (JAXBException ex) {
748:                    log.log(Level.SEVERE, LogStringsMessages
749:                            .WST_0012_JAXB_EX_TO_ELEMENT(), ex);
750:                    throw new RuntimeException(LogStringsMessages
751:                            .WST_0012_JAXB_EX_TO_ELEMENT(), ex);
752:                }
753:            }
754:
755:            /**
756:             * Marshal an RSTR Collection to a DOM Element
757:             * <p>
758:             * Note: Useful for STS implementations which are JAXWS Providers
759:             * </p>
760:             */
761:            public Element toElement(
762:                    final RequestSecurityTokenResponseCollection rstrCollection) {
763:                try {
764:                    final DocumentBuilderFactory dbf = DocumentBuilderFactory
765:                            .newInstance();
766:                    dbf.setNamespaceAware(true);
767:                    final DocumentBuilder builder = dbf.newDocumentBuilder();
768:                    final Document doc = builder.newDocument();
769:
770:                    //javax.xml.bind.Marshaller marshaller = getContext().createMarshaller();
771:                    final JAXBElement<RequestSecurityTokenResponseCollectionType> rstElement = (new ObjectFactory())
772:                            .createRequestSecurityTokenResponseCollection((RequestSecurityTokenResponseCollectionType) rstrCollection);
773:                    marshaller.marshal(rstElement, doc);
774:                    return doc.getDocumentElement();
775:                } catch (javax.xml.parsers.ParserConfigurationException pe) {
776:                    log.log(Level.SEVERE, LogStringsMessages
777:                            .WST_0011_PARSERCONFIG_EX_TO_ELEMENT(), pe);
778:                    throw new RuntimeException(LogStringsMessages
779:                            .WST_0011_PARSERCONFIG_EX_TO_ELEMENT(), pe);
780:                } catch (JAXBException ex) {
781:                    log.log(Level.SEVERE, LogStringsMessages
782:                            .WST_0012_JAXB_EX_TO_ELEMENT(), ex);
783:                    throw new RuntimeException(LogStringsMessages
784:                            .WST_0012_JAXB_EX_TO_ELEMENT(), ex);
785:                }
786:            }
787:
788:            public Element toElement(final BinarySecret secret) {
789:                try {
790:                    final DocumentBuilderFactory dbf = DocumentBuilderFactory
791:                            .newInstance();
792:                    dbf.setNamespaceAware(true);
793:                    final DocumentBuilder builder = dbf.newDocumentBuilder();
794:                    final Document doc = builder.newDocument();
795:
796:                    //javax.xml.bind.Marshaller marshaller = getContext().createMarshaller();
797:                    final JAXBElement<BinarySecretType> bsElement = (new ObjectFactory())
798:                            .createBinarySecret((BinarySecretType) secret);
799:                    marshaller.marshal(bsElement, doc);
800:                    return doc.getDocumentElement();
801:                } catch (javax.xml.parsers.ParserConfigurationException pe) {
802:                    log.log(Level.SEVERE, LogStringsMessages
803:                            .WST_0011_PARSERCONFIG_EX_TO_ELEMENT(), pe);
804:                    throw new RuntimeException(LogStringsMessages
805:                            .WST_0011_PARSERCONFIG_EX_TO_ELEMENT(), pe);
806:                } catch (JAXBException ex) {
807:                    log.log(Level.SEVERE, LogStringsMessages
808:                            .WST_0012_JAXB_EX_TO_ELEMENT(), ex);
809:                    throw new RuntimeException(LogStringsMessages
810:                            .WST_0012_JAXB_EX_TO_ELEMENT(), ex);
811:                }
812:            }
813:
814:            /**
815:             * Marshal an STR to a DOM Element.
816:             * <p>
817:             * Note: Useful for Dispatch Client implementations
818:             * </p>
819:             */
820:            public Element toElement(final SecurityTokenReference str,
821:                    Document doc) {
822:                try {
823:                    if (doc == null) {
824:                        final DocumentBuilderFactory dbf = DocumentBuilderFactory
825:                                .newInstance();
826:                        dbf.setNamespaceAware(true);
827:                        final DocumentBuilder builder = dbf
828:                                .newDocumentBuilder();
829:                        doc = builder.newDocument();
830:                    }
831:
832:                    //javax.xml.bind.Marshaller marshaller = getContext().createMarshaller();
833:                    final JAXBElement<SecurityTokenReferenceType> strElement = (new com.sun.xml.ws.security.secext10.ObjectFactory())
834:                            .createSecurityTokenReference((SecurityTokenReferenceType) str);
835:                    marshaller.marshal(strElement, doc);
836:                    return doc.getDocumentElement();
837:                } catch (javax.xml.parsers.ParserConfigurationException pe) {
838:                    log.log(Level.SEVERE, LogStringsMessages
839:                            .WST_0011_PARSERCONFIG_EX_TO_ELEMENT(), pe);
840:                    throw new RuntimeException(LogStringsMessages
841:                            .WST_0011_PARSERCONFIG_EX_TO_ELEMENT(), pe);
842:                } catch (JAXBException ex) {
843:                    log.log(Level.SEVERE, LogStringsMessages
844:                            .WST_0012_JAXB_EX_TO_ELEMENT(), ex);
845:                    throw new RuntimeException(LogStringsMessages
846:                            .WST_0012_JAXB_EX_TO_ELEMENT(), ex);
847:                }
848:            }
849:
850:            /**
851:             * Marshal an BinarySecret to a DOM Element.
852:             * <p>
853:             * Note: Useful for Dispatch Client implementations
854:             * </p>
855:             */
856:            public Element toElement(final BinarySecret secret, Document doc) {
857:                try {
858:                    if (doc == null) {
859:                        final DocumentBuilderFactory dbf = DocumentBuilderFactory
860:                                .newInstance();
861:                        dbf.setNamespaceAware(true);
862:                        final DocumentBuilder builder = dbf
863:                                .newDocumentBuilder();
864:                        doc = builder.newDocument();
865:                    }
866:
867:                    //javax.xml.bind.Marshaller marshaller = getContext().createMarshaller();
868:                    final JAXBElement<BinarySecretType> bsElement = (new ObjectFactory())
869:                            .createBinarySecret((BinarySecretType) secret);
870:                    marshaller.marshal(bsElement, doc);
871:                    return doc.getDocumentElement();
872:
873:                } catch (javax.xml.parsers.ParserConfigurationException pe) {
874:                    log.log(Level.SEVERE, LogStringsMessages
875:                            .WST_0011_PARSERCONFIG_EX_TO_ELEMENT(), pe);
876:                    throw new RuntimeException(LogStringsMessages
877:                            .WST_0011_PARSERCONFIG_EX_TO_ELEMENT(), pe);
878:                } catch (JAXBException ex) {
879:                    log.log(Level.SEVERE, LogStringsMessages
880:                            .WST_0012_JAXB_EX_TO_ELEMENT(), ex);
881:                    throw new RuntimeException(LogStringsMessages
882:                            .WST_0012_JAXB_EX_TO_ELEMENT(), ex);
883:                }
884:            }
885:
886:        }
ww___w_.___j_a__v_a___2_s___.___c___o__m__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.