Source Code Cross Referenced for CertUtil.java in  » Portal » Open-Portal » com » sun » portal » cli » cert » 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 » Portal » Open Portal » com.sun.portal.cli.cert 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * CertUtil.java
003:         * @author  ss133690
004:         * @version 0.1
005:         */package com.sun.portal.cli.cert;
006:
007:        import java.io.*;
008:        import com.sun.portal.log.common.PortalLogger;
009:        import java.util.*;
010:        import java.util.regex.Matcher;
011:        import java.util.regex.Pattern;
012:
013:        /**
014:         * This class will help the administrator to perform SRA certificate related operations.
015:         * @version 
016:         */
017:
018:        public final class CertUtil {
019:
020:            public static final String DEFAULT = "default";
021:            public static final String CREATE_SELF_SIGN = "createselfsigncert";
022:            public static final String VERIFY_CERT = "verifycert";
023:            public static final String CREATE_LOG_USER_PASSWORD = "createloguserpassword";
024:
025:            public static void main(String args[]) {
026:                /*
027:                 System.out.println(CreateSelfSignedCertificate("/etc/opt/SUNWportal/cert/default", "testing123", "en_US", "sunone086.india.sun.com", "Sun", "IEC", "blr", "kar", "in", "", "install-cert", 6));
028:                 */
029:                String option = DEFAULT;
030:                int i = 0;
031:                if (args[0].toLowerCase().startsWith("-option=")) {
032:                    option = args[0].substring(8, args[0].length());
033:                    i = i + 1;
034:                }
035:
036:                if ((option.equalsIgnoreCase(DEFAULT))
037:                        || (option.equalsIgnoreCase(CREATE_SELF_SIGN))) {
038:
039:                    String dir = args[i++];
040:                    String password = args[i++];
041:                    String locale = args[i++];
042:                    String other_info = args[i++];
043:                    String token = args[i++];
044:                    String nickname = args[i++];
045:                    int validity = 6;
046:                    try {
047:                        validity = Integer.parseInt(args[i++]);
048:                    } catch (Exception ex) {
049:                    }
050:
051:                    String cn = "";
052:                    String l = "";
053:                    String st = "";
054:                    String c = "";
055:                    String o = "";
056:                    String ou = "";
057:
058:                    cn = getDistinguishedNameComponent(other_info, "CN");
059:                    l = getDistinguishedNameComponent(other_info, "L");
060:                    st = getDistinguishedNameComponent(other_info, "ST");
061:                    c = getDistinguishedNameComponent(other_info, "C");
062:                    o = getDistinguishedNameComponent(other_info, "O");
063:                    ou = getDistinguishedNameComponent(other_info, "OU");
064:
065:                    CreateSelfSignedCertificate(dir, password, locale, cn, o,
066:                            ou, l, st, c, token, nickname, validity);
067:                } else if (option.equalsIgnoreCase(VERIFY_CERT)) {
068:                    String dir = args[i++];
069:                    String locale = args[i++];
070:                    String nickname = args[i++];
071:                    CertAdminUtil.println(VerifyCertificate(dir, locale,
072:                            nickname));
073:                } else if (option.equalsIgnoreCase(CREATE_LOG_USER_PASSWORD)) {
074:                    createLogUserPassword(args[i++], args[i++], args[i++]);
075:                }
076:            }
077:
078:            public static String getDistinguishedNameComponent(
079:                    String searchString, String toFind) {
080:                String match = "";
081:                Matcher m;
082:
083:                Pattern p_quotes = Pattern.compile(toFind + "=\"",
084:                        Pattern.CASE_INSENSITIVE);
085:                Pattern p_noquotes = Pattern.compile(toFind + "=([^,]+),?",
086:                        Pattern.CASE_INSENSITIVE);
087:
088:                m = p_quotes.matcher(searchString);
089:
090:                if (m.find()) {
091:                    // Has a begining quote
092:                    Pattern p_find = Pattern.compile(toFind + "=\"([^\"]+)\"",
093:                            Pattern.CASE_INSENSITIVE);
094:                    m = p_find.matcher(searchString);
095:
096:                    if (m.find() && m.groupCount() > 0)
097:                        match = m.group(1);
098:                } else {
099:                    m = p_noquotes.matcher(searchString);
100:
101:                    if (m.find() && m.groupCount() > 0)
102:                        match = m.group(1);
103:                }
104:                return match;
105:            }
106:
107:            public static void createLogUserPassword(String confFile,
108:                    String certDir, String plainPassword) {
109:                try {
110:                    JSSUtil.setDefaultDecoder(certDir);
111:                    String password = JSSUtil.encryptPassword(plainPassword);
112:                    Properties prop = new Properties();
113:                    InputStream inpstrm = new FileInputStream(confFile);
114:                    prop.load(inpstrm);
115:                    inpstrm.close();
116:                    prop.put("gateway.logging.password", password);
117:                    OutputStream outstrm = new FileOutputStream(confFile);
118:                    prop.store(outstrm, null);
119:                    outstrm.close();
120:                    //CertAdminUtil.writeLine("gateway.logging.password="+password, confFile, true);
121:                } catch (IOException ioex) {
122:                    ioex.printStackTrace();
123:                } catch (SRADecoderException ex) {
124:                    ex.printStackTrace();
125:                }
126:            }
127:
128:            public static boolean CreateSelfSignedCertificate(String certdir,
129:                    String jsspass, String locale, String fqdn, String o,
130:                    String ou, String l, String s, String c, String token,
131:                    String nick, int val) {
132:                //JSSContext jsscntx = new JSSContextImpl(certdir, fqdn, locale, false, false,true);
133:                JSSContext jsscntx = new JSSContextImpl(certdir, fqdn, locale);
134:                PasswordContext passwdcntx = new InstallPasswordContextImpl(
135:                        jsspass);
136:                jsscntx.setPasswordContext(passwdcntx);
137:                if (!jsscntx.init()) {
138:                    CertAdminUtil.println(CertAdminLocale.getPFString("m1",
139:                            CertAdminConstants.m1));
140:                    return false;
141:                }
142:
143:                CertContext certcntx = CertAdminFactory
144:                        .CreateCertificateContext(fqdn, o, ou, l, s, c, token,
145:                                nick, val);
146:                CreateSelfSignedCertificate cmd = new CreateSelfSignedCertificate();
147:                return cmd.execute(jsscntx, certcntx);
148:            }
149:
150:            public static String VerifyCertificate(String certdir,
151:                    String locale, String nick) {
152:                //JSSContext jsscntx = new JSSContextImpl(certdir, fqdn, locale, false, false,true);
153:                JSSContext jsscntx = new JSSContextImpl(certdir, locale);
154:                jsscntx.setPasswordContext(CertAdminFactory
155:                        .CreatePasswordContext());
156:                if (!jsscntx.init()) {
157:                    return CertAdminLocale.getPFString("m58",
158:                            CertAdminConstants.m58)
159:                            + CertAdminConstants.SPACE
160:                            + nick
161:                            + CertAdminConstants.SPACE
162:                            + CertAdminLocale.getPFString("m1",
163:                                    CertAdminConstants.m1);
164:                }
165:                VerifyCertificate cmd = new VerifyCertificate();
166:                cmd.execute(jsscntx, nick);
167:                return cmd.getMessage();
168:            }
169:
170:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.