Source Code Cross Referenced for TurbineCryptoService.java in  » Web-Framework » TURBINE » org » apache » turbine » services » crypto » 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 » Web Framework » TURBINE » org.apache.turbine.services.crypto 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.apache.turbine.services.crypto;
002:
003:        /*
004:         * Licensed to the Apache Software Foundation (ASF) under one
005:         * or more contributor license agreements.  See the NOTICE file
006:         * distributed with this work for additional information
007:         * regarding copyright ownership.  The ASF licenses this file
008:         * to you under the Apache License, Version 2.0 (the
009:         * "License"); you may not use this file except in compliance
010:         * with the License.  You may obtain a copy of the License at
011:         *
012:         *   http://www.apache.org/licenses/LICENSE-2.0
013:         *
014:         * Unless required by applicable law or agreed to in writing,
015:         * software distributed under the License is distributed on an
016:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017:         * KIND, either express or implied.  See the License for the
018:         * specific language governing permissions and limitations
019:         * under the License.
020:         */
021:
022:        import java.security.NoSuchAlgorithmException;
023:
024:        import java.util.Hashtable;
025:        import java.util.Iterator;
026:
027:        import org.apache.commons.configuration.Configuration;
028:
029:        import org.apache.turbine.services.BaseService;
030:        import org.apache.turbine.services.InitializationException;
031:        import org.apache.turbine.services.TurbineServices;
032:        import org.apache.turbine.services.crypto.provider.JavaCrypt;
033:        import org.apache.turbine.services.factory.FactoryService;
034:
035:        /**
036:         * An implementation of CryptoService that uses either supplied crypto
037:         * Algorithms (provided in Turbine.Services.properties) or tries to get them via
038:         * the normal java mechanisms if this fails.
039:         *
040:         * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
041:         * @version $Id: TurbineCryptoService.java 534527 2007-05-02 16:10:59Z tv $
042:         */
043:        public class TurbineCryptoService extends BaseService implements 
044:                CryptoService {
045:            /** Key Prefix for our algorithms */
046:            private static final String ALGORITHM = "algorithm";
047:
048:            /** Default Key */
049:            private static final String DEFAULT_KEY = "default";
050:
051:            /** Default Encryption Class */
052:            private static final String DEFAULT_CLASS = JavaCrypt.class
053:                    .getName();
054:
055:            /** Names of the registered algorithms and the wanted classes */
056:            private Hashtable algos = null;
057:
058:            /** A factory to construct CryptoAlgorithm objects  */
059:            private FactoryService factoryService = null;
060:
061:            /**
062:             * There is not much to initialize here. This runs
063:             * as early init method.
064:             *
065:             * @throws InitializationException Something went wrong in the init
066:             *         stage
067:             */
068:            public void init() throws InitializationException {
069:                this .algos = new Hashtable();
070:
071:                /*
072:                 * Set up default (Can be overridden by default key
073:                 * from the properties
074:                 */
075:
076:                algos.put(DEFAULT_KEY, DEFAULT_CLASS);
077:
078:                /* get the parts of the configuration relevant to us. */
079:
080:                Configuration conf = getConfiguration().subset(ALGORITHM);
081:
082:                if (conf != null) {
083:                    for (Iterator it = conf.getKeys(); it.hasNext();) {
084:                        String key = (String) it.next();
085:                        String val = conf.getString(key);
086:                        // Log.debug("Registered " + val
087:                        //            + " for Crypto Algorithm " + key);
088:                        algos.put(key, val);
089:                    }
090:                }
091:
092:                try {
093:                    factoryService = (FactoryService) TurbineServices
094:                            .getInstance().getService(
095:                                    FactoryService.SERVICE_NAME);
096:                } catch (Exception e) {
097:                    throw new InitializationException(
098:                            "Failed to get a Factory object: ", e);
099:                }
100:
101:                setInit(true);
102:            }
103:
104:            /**
105:             * Returns a CryptoAlgorithm Object which represents the requested
106:             * crypto algorithm.
107:             *
108:             * @param algo      Name of the requested algorithm
109:             * @return An Object representing the algorithm
110:             * @throws NoSuchAlgorithmException  Requested algorithm is not available
111:             */
112:            public CryptoAlgorithm getCryptoAlgorithm(String algo)
113:                    throws NoSuchAlgorithmException {
114:                String cryptoClass = (String) algos.get(algo);
115:                CryptoAlgorithm ca = null;
116:
117:                if (cryptoClass == null) {
118:                    cryptoClass = (String) algos.get(DEFAULT_KEY);
119:                }
120:
121:                if (cryptoClass == null || cryptoClass.equalsIgnoreCase("none")) {
122:                    throw new NoSuchAlgorithmException(
123:                            "TurbineCryptoService: No Algorithm for " + algo
124:                                    + " found");
125:                }
126:
127:                try {
128:                    ca = (CryptoAlgorithm) factoryService
129:                            .getInstance(cryptoClass);
130:                } catch (Exception e) {
131:                    throw new NoSuchAlgorithmException(
132:                            "TurbineCryptoService: Error instantiating "
133:                                    + cryptoClass + " for " + algo);
134:                }
135:
136:                ca.setCipher(algo);
137:
138:                return ca;
139:            }
140:
141:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.