001: /*
002: * CertAdminFactory.java
003: *
004: */
005:
006: /**
007: *
008: * @author ss133690
009: * @version
010: */package com.sun.portal.cli.cert;
011:
012: import java.util.ResourceBundle;
013: import com.sun.portal.log.common.PortalLogger;
014:
015: public class CertAdminFactory {
016:
017: public static PasswordContext CreatePasswordContext() {
018: return new PasswordContextImpl();
019: }
020:
021: public static JSSContext CreateJSSContext(String inst,
022: String basedir, String dsameLocaledir)
023: throws CertAdminException {
024:
025: String platformFile = basedir + CertAdminConstants.SEPERATOR
026: + CertAdminConstants.PLATFORMFILE + "." + inst;
027: if (!CertAdminUtil.fileExist(platformFile)) {
028: //println("Error!, Cannot locate Platform file.");
029: throw new CertAdminException(CertAdminLocale.getPFString(
030: "m2", CertAdminConstants.m2));
031: }
032: SystemProperties.init(platformFile);
033: String certdir = SystemProperties.get("gateway.certdir");
034: String fqdn = SystemProperties.get("gateway.host");
035: String dsameLocaleFile = dsameLocaledir
036: + CertAdminConstants.SEPERATOR
037: + CertAdminConstants.LOCALEFILE;
038: /* if( !CertAdminUtil.fileExist(dsameLocaleFile) ){
039: throw new CertAdminException(CertAdminLocale.getPFString("m51",CertAdminConstants.m51));
040: }*/
041: // SystemProperties.init(dsameLocaleFile);
042: // String locale = SystemProperties.get("com.iplanet.am.locale", "en_US");
043: ResourceBundle amConfigProps = ResourceBundle
044: .getBundle("AMConfig");
045: String locale = "en_US";
046: try {
047: locale = amConfigProps.getString("com.iplanet.am.locale");
048: } catch (Exception ex) {
049: locale = "en_US";
050: }
051: JSSContext jsscntx = new JSSContextImpl(certdir, fqdn, locale);
052: jsscntx.setPasswordContext(CreatePasswordContext());
053: if (!jsscntx.init()) {
054: throw new CertAdminException(CertAdminLocale.getPFString(
055: "m1", CertAdminConstants.m1));
056: }
057: return jsscntx;
058:
059: }
060:
061: public static CertContext CreateCertificateContext(String fqdn,
062: String o, String ou, String l, String s, String c,
063: String token, String nick, int val) {
064: CertContext certcntx = new CertContext();
065: certcntx.fqdn = fqdn;
066: certcntx.o = o;
067: certcntx.ou = ou;
068: certcntx.l = l;
069: certcntx.s = s;
070: certcntx.c = c;
071: certcntx.token = token;
072: certcntx.nick = nick;
073: certcntx.val = val;
074: return certcntx;
075: }
076:
077: public static Command CreateCommand(int cid) {
078: switch (cid) {
079: case 1: {
080: return new CreateSelfSignedCertificate();
081: }
082: case 2: {
083: return new GenerateCSR();
084: }
085: case 3: {
086: return new AddRootCA();
087: }
088: case 4: {
089: return new InstallCertificate();
090: }
091: case 5: {
092: return new DeleteCertificate();
093: }
094: case 6: {
095: return new ModifyTrustAttributes();
096: }
097: case 7: {
098: return new ListCACertificates();
099: }
100: case 8: {
101: return new ListCertificates();
102: }
103: case 9: {
104: return new PrintCertificate();
105: }
106: default: {
107: return new Exit();
108: }
109: }
110: }
111: }
|