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


001:        /*
002:         * JAXBSignatureHeaderElement.java
003:         *
004:         * Created on August 18, 2006, 2:29 PM
005:         *
006:         * To change this template, choose Tools | Template Manager
007:         * and open the template in the editor.
008:         */
009:
010:        package com.sun.xml.ws.security.opt.impl.dsig;
011:
012:        import com.sun.xml.ws.api.SOAPVersion;
013:        import com.sun.xml.ws.security.opt.api.SecurityElementWriter;
014:        import com.sun.xml.ws.security.opt.api.SecurityHeaderElement;
015:        import com.sun.xml.ws.security.opt.crypto.dsig.keyinfo.KeyInfo;
016:        import com.sun.xml.wss.impl.MessageConstants;
017:
018:        import java.util.HashMap;
019:        import java.util.Iterator;
020:        import java.util.List;
021:        import java.util.Map;
022:        import java.io.OutputStream;
023:
024:        import javax.xml.bind.JAXBElement;
025:        import javax.xml.bind.Marshaller;
026:        import javax.xml.bind.JAXBException;
027:        import javax.xml.crypto.MarshalException;
028:        import javax.xml.crypto.dsig.XMLSignContext;
029:        import javax.xml.crypto.dsig.XMLSignatureException;
030:        import com.sun.xml.ws.security.opt.crypto.dsig.Signature;
031:        import com.sun.xml.ws.security.opt.impl.util.JAXBUtil;
032:        import com.sun.xml.stream.buffer.XMLStreamBufferResult;
033:        import javax.xml.stream.XMLStreamException;
034:
035:        /**
036:         *
037:         * @author Ashutosh.Shahi@sun.com
038:         */
039:        public class JAXBSignatureHeaderElement implements 
040:                SecurityHeaderElement, SecurityElementWriter {
041:
042:            /* true if this signature header element is canonicalized before*/
043:            private boolean isCanonicalized = false;
044:            /*canonicalized signature value - for future use*/
045:            private byte[] cs = null;
046:
047:            private Signature signature = null;
048:            private SOAPVersion soapVersion = SOAPVersion.SOAP_11;
049:            private Marshaller marshaller = null;
050:            private XMLSignContext signContext = null;
051:
052:            /** Creates a new instance of JAXBSignatureHeaderElement */
053:            public JAXBSignatureHeaderElement(Signature signature,
054:                    SOAPVersion soapVersion) {
055:                this .signature = signature;
056:                this .soapVersion = soapVersion;
057:
058:            }
059:
060:            public JAXBSignatureHeaderElement(Signature signature,
061:                    SOAPVersion soapVersion, XMLSignContext signctx) {
062:                this .signature = signature;
063:                this .soapVersion = soapVersion;
064:                this .signContext = signctx;
065:            }
066:
067:            public String getId() {
068:                return signature.getId();
069:            }
070:
071:            public void setId(String id) {
072:                throw new UnsupportedOperationException();
073:            }
074:
075:            public String getNamespaceURI() {
076:                return MessageConstants.DSIG_NS;
077:            }
078:
079:            public String getLocalPart() {
080:                return MessageConstants.SIGNATURE_LNAME;
081:            }
082:
083:            public javax.xml.stream.XMLStreamReader readHeader()
084:                    throws XMLStreamException {
085:                XMLStreamBufferResult xbr = new XMLStreamBufferResult();
086:                try {
087:                    getMarshaller().marshal(signature, xbr);
088:                } catch (JAXBException je) {
089:                    throw new XMLStreamException(je);
090:                }
091:                return xbr.getXMLStreamBuffer().readAsXMLStreamReader();
092:            }
093:
094:            public void writeTo(javax.xml.stream.XMLStreamWriter streamWriter)
095:                    throws XMLStreamException {
096:                try {
097:                    // If writing to Zephyr, get output stream and use JAXB UTF-8 writer
098:                    if (streamWriter instanceof  Map) {
099:                        OutputStream os = (OutputStream) ((Map) streamWriter)
100:                                .get("sjsxp-outputstream");
101:                        if (os != null) {
102:                            streamWriter.writeCharacters(""); // Force completion of open elems
103:                            getMarshaller().marshal(signature, os);
104:                            return;
105:                        }
106:                    }
107:                    getMarshaller().marshal(signature, streamWriter);
108:                } catch (JAXBException e) {
109:                    throw new XMLStreamException(e);
110:                }
111:            }
112:
113:            public void writeTo(javax.xml.stream.XMLStreamWriter streamWriter,
114:                    HashMap props) throws XMLStreamException {
115:                try {
116:                    Marshaller marshaller = getMarshaller();
117:                    Iterator<Map.Entry<Object, Object>> itr = props.entrySet()
118:                            .iterator();
119:                    while (itr.hasNext()) {
120:                        Map.Entry<Object, Object> entry = itr.next();
121:                        marshaller.setProperty((String) entry.getKey(), entry
122:                                .getValue());
123:                    }
124:
125:                    //writeTo(streamWriter);
126:                    marshaller.marshal(signature, streamWriter);
127:                } catch (JAXBException jbe) {
128:                    throw new XMLStreamException(jbe);
129:                }
130:            }
131:
132:            public byte[] canonicalize(
133:                    final String algorithm,
134:                    final List<com.sun.xml.wss.impl.c14n.AttributeNS> namespaceDecls) {
135:                if (!isCanonicalized()) {
136:                    canonicalizeSignature();
137:                }
138:                return cs;
139:            }
140:
141:            public boolean isCanonicalized() {
142:                return isCanonicalized;
143:            }
144:
145:            private Marshaller getMarshaller() throws JAXBException {
146:                if (marshaller == null) {
147:                    marshaller = JAXBUtil.createMarshaller(soapVersion);
148:                }
149:                return marshaller;
150:            }
151:
152:            private void canonicalizeSignature() {
153:                throw new UnsupportedOperationException("Not yet implemented");
154:            }
155:
156:            public void writeTo(OutputStream os) {
157:                throw new UnsupportedOperationException("Not yet implemented");
158:            }
159:
160:            public boolean refersToSecHdrWithId(final String id) {
161:
162:                StringBuffer sb = new StringBuffer();
163:                sb.append("#");
164:                sb.append(id);
165:                String refId = sb.toString();
166:                KeyInfo ki = signature.getKeyInfo();
167:                if (ki != null) {
168:                    List list = ki.getContent();
169:                    if (list.size() > 0) {
170:                        JAXBElement je = (JAXBElement) list.get(0);
171:                        Object data = je.getValue();
172:
173:                        if (data instanceof  SecurityHeaderElement) {
174:                            if (((SecurityHeaderElement) data)
175:                                    .refersToSecHdrWithId(id)) {
176:                                return true;
177:                            }
178:                        }
179:                    }
180:                }
181:                List refList = signature.getSignedInfo().getReferences();
182:                for (int i = 0; i < refList.size(); i++) {
183:                    com.sun.xml.ws.security.opt.crypto.dsig.Reference ref = (com.sun.xml.ws.security.opt.crypto.dsig.Reference) refList
184:                            .get(i);
185:                    if (ref.getURI().equals(refId)) {
186:                        return true;
187:                    }
188:                }
189:                return false;
190:            }
191:
192:            public void sign() throws XMLStreamException {
193:                try {
194:                    signature.sign(signContext);
195:                } catch (MarshalException me) {
196:                    throw new XMLStreamException(me);
197:                } catch (XMLSignatureException xse) {
198:                    throw new XMLStreamException(xse);
199:                }
200:            }
201:        }
w_w_w__.___ja___v___a__2___s.co_m_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.