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


001:        /*
002:         * Transform.java
003:         *
004:         * Created on January 24, 2006, 3:42 PM
005:         */
006:
007:        /*
008:         * The contents of this file are subject to the terms
009:         * of the Common Development and Distribution License
010:         * (the License).  You may not use this file except in
011:         * compliance with the License.
012:         *
013:         * You can obtain a copy of the license at
014:         * https://glassfish.dev.java.net/public/CDDLv1.0.html.
015:         * See the License for the specific language governing
016:         * permissions and limitations under the License.
017:         *
018:         * When distributing Covered Code, include this CDDL
019:         * Header Notice in each file and include the License file
020:         * at https://glassfish.dev.java.net/public/CDDLv1.0.html.
021:         * If applicable, add the following below the CDDL Header,
022:         * with the fields enclosed by brackets [] replaced by
023:         * you own identifying information:
024:         * "Portions Copyrighted [year] [name of copyright owner]"
025:         *
026:         * Copyright 2006 Sun Microsystems Inc. All Rights Reserved
027:         */
028:
029:        package com.sun.xml.ws.security.opt.crypto.dsig;
030:
031:        import com.sun.xml.ws.security.opt.impl.dsig.StAXEnvelopedTransformWriter;
032:        import com.sun.xml.ws.security.opt.impl.dsig.StAXSTRTransformWriter;
033:        import com.sun.xml.ws.security.secext10.TransformationParametersType;
034:        import com.sun.xml.wss.impl.MessageConstants;
035:        import com.sun.xml.wss.impl.c14n.StAXEXC14nCanonicalizerImpl;
036:        import com.sun.xml.wss.logging.LogDomainConstants;
037:        import java.io.ByteArrayOutputStream;
038:        import java.io.IOException;
039:        import java.io.OutputStream;
040:        import java.security.InvalidAlgorithmParameterException;
041:        import java.security.spec.AlgorithmParameterSpec;
042:        import java.util.List;
043:        import java.util.logging.Level;
044:        import java.util.logging.Logger;
045:        import javax.xml.bind.JAXBElement;
046:        import javax.xml.bind.annotation.XmlRootElement;
047:        import javax.xml.bind.annotation.XmlTransient;
048:        import javax.xml.crypto.Data;
049:        import javax.xml.crypto.XMLCryptoContext;
050:        import javax.xml.crypto.dsig.TransformException;
051:        import javax.xml.stream.XMLStreamException;
052:        import com.sun.xml.wss.logging.impl.opt.signature.LogStringsMessages;
053:
054:        /**
055:         *
056:         * @author Abhijit Das
057:         * @author K.Venugopal@sun.com
058:         */
059:        @XmlRootElement(name="Transform",namespace="http://www.w3.org/2000/09/xmldsig#")
060:        public class Transform extends
061:                com.sun.xml.security.core.dsig.TransformType implements 
062:                javax.xml.crypto.dsig.Transform {
063:            @XmlTransient
064:            private static final Logger logger = Logger.getLogger(
065:                    LogDomainConstants.IMPL_OPT_SIGNATURE_DOMAIN,
066:                    LogDomainConstants.IMPL_OPT_SIGNATURE_DOMAIN_BUNDLE);
067:
068:            @XmlTransient
069:            private AlgorithmParameterSpec algSpec = null;
070:            @XmlTransient
071:            private Exc14nCanonicalizer _exc14nTransform;
072:            @XmlTransient
073:            private String refId = "";
074:
075:            /** Creates a new instance of Transform */
076:            public Transform() {
077:            }
078:
079:            public AlgorithmParameterSpec getParameterSpec() {
080:                return algSpec;
081:            }
082:
083:            public void setParameterSpec(AlgorithmParameterSpec algSpec) {
084:                this .algSpec = algSpec;
085:            }
086:
087:            public void setContent(List content) {
088:                this .content = content;
089:            }
090:
091:            public Data transform(Data data, XMLCryptoContext xMLCryptoContext)
092:                    throws TransformException {
093:                if (getAlgorithm() == javax.xml.crypto.dsig.CanonicalizationMethod.EXCLUSIVE) {
094:                    if (_exc14nTransform == null) {
095:                        _exc14nTransform = new Exc14nCanonicalizer();
096:                    }
097:                    return _exc14nTransform.transform(data, xMLCryptoContext);
098:                } else if (getAlgorithm().equals(Transform.ENVELOPED)) {
099:                    return new StAXEnvelopedTransformWriter(data);
100:                } else if (getAlgorithm().equals(
101:                        MessageConstants.STR_TRANSFORM_URI)) {
102:                    return new StAXSTRTransformWriter(data, xMLCryptoContext,
103:                            refId);
104:                }
105:                throw new UnsupportedOperationException("Algorithm Transform "
106:                        + getAlgorithm() + " not supported yet");
107:            }
108:
109:            public Data transform(Data data, XMLCryptoContext xMLCryptoContext,
110:                    OutputStream outputStream) throws TransformException {
111:
112:                if (getAlgorithm().equals(MessageConstants.STR_TRANSFORM_URI)) {
113:                    ByteArrayOutputStream bos = new ByteArrayOutputStream();
114:                    OutputStream fis = outputStream;
115:                    if (logger.isLoggable(Level.FINEST)) {
116:                        fis = bos;
117:                    }
118:                    StAXEXC14nCanonicalizerImpl _canonicalizer = null;
119:                    if (algSpec != null || content.size() > 0) {
120:                        Object ob = content.get(0);
121:                        if (ob instanceof  JAXBElement) {
122:                            JAXBElement el = (JAXBElement) ob;
123:                            TransformationParametersType tp = (TransformationParametersType) el
124:                                    .getValue();
125:                            CanonicalizationMethod cm = (CanonicalizationMethod) tp
126:                                    .getAny().get(0);
127:                            String algo = cm.getAlgorithm();
128:                            if (javax.xml.crypto.dsig.CanonicalizationMethod.EXCLUSIVE
129:                                    .equals(algo)) {
130:                                _canonicalizer = new StAXEXC14nCanonicalizerImpl();
131:                                if (!logger.isLoggable(Level.FINEST)) {
132:                                    _canonicalizer.setStream(outputStream);
133:                                } else {
134:                                    _canonicalizer.setStream(fis);
135:                                }
136:                            }
137:                        }
138:                    }
139:
140:                    StAXSTRTransformWriter strWriter = new StAXSTRTransformWriter(
141:                            data, xMLCryptoContext, refId);
142:                    try {
143:                        strWriter.write(_canonicalizer);
144:                    } catch (XMLStreamException ex) {
145:                        throw new TransformException(ex);
146:                    }
147:
148:                    if (logger.isLoggable(Level.FINEST)) {
149:                        logger.log(Level.FINEST, LogStringsMessages
150:                                .WSS_1757_CANONICALIZED_TARGET_VALUE(bos
151:                                        .toString()));
152:                        try {
153:                            outputStream.write(bos.toByteArray());
154:                            return null;
155:                        } catch (IOException ex) {
156:                            throw new TransformException(ex);
157:                        }
158:                    }
159:                    return null;
160:                }
161:
162:                ByteArrayOutputStream bos = new ByteArrayOutputStream();
163:                OutputStream fis = outputStream;
164:                if (logger.isLoggable(Level.FINEST)) {
165:                    fis = bos;
166:                }
167:                if (getAlgorithm().intern() == javax.xml.crypto.dsig.CanonicalizationMethod.EXCLUSIVE
168:                        .intern()) {
169:                    if (_exc14nTransform == null) {
170:                        _exc14nTransform = new Exc14nCanonicalizer();
171:                        try {
172:                            _exc14nTransform
173:                                    .init((javax.xml.crypto.dsig.spec.TransformParameterSpec) algSpec);
174:                        } catch (InvalidAlgorithmParameterException e) {
175:                            throw new TransformException(e);
176:                        }
177:                    }
178:                    if (!logger.isLoggable(Level.FINEST)) {
179:                        return _exc14nTransform.transform(data,
180:                                xMLCryptoContext, fis);
181:                    } else {
182:                        _exc14nTransform.transform(data, xMLCryptoContext, fis);
183:                        logger.log(Level.FINEST, LogStringsMessages
184:                                .WSS_1757_CANONICALIZED_TARGET_VALUE(bos
185:                                        .toString()));
186:                        try {
187:                            outputStream.write(bos.toByteArray());
188:                            return null;
189:                        } catch (IOException ex) {
190:                            throw new TransformException(ex);
191:                        }
192:                    }
193:                }
194:                throw new UnsupportedOperationException("Algorithm Transform "
195:                        + getAlgorithm() + " not supported yet");
196:            }
197:
198:            public boolean isFeatureSupported(String string) {
199:                return false;
200:            }
201:
202:            public void setReferenceId(String id) {
203:                this.refId = id;
204:            }
205:
206:        }
w__w___w.__j_a___v___a2___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.