From 2e6537e80d42c208a96e218d84ed4fb5c6b7a9d4 Mon Sep 17 00:00:00 2001 From: Christina Fu Date: Wed, 13 May 2015 08:35:34 -0700 Subject: Ticket 1307 (part1 refactoring) [RFE] Support multiple keySets for different cards for ExternalReg This patch is mainly refactoring the names of the Mapping Resolver framework in preparation for ticket 1307 to support keySet mapping in addition to the original purpose of resolving tokenType mapping. The reason to separate out refactoring from the real code is for ease of reviewing. TPS is currently a Tech Preview feature, so upgrade is not of consideration at the moment. --- base/tps/shared/conf/CS.cfg.in | 174 ++++++------ base/tps/shared/conf/registry.cfg | 10 +- .../src/org/dogtagpki/server/tps/TPSSubsystem.java | 12 +- .../org/dogtagpki/server/tps/engine/TPSEngine.java | 2 +- .../server/tps/mapping/BaseMappingResolver.java | 38 +++ .../server/tps/mapping/FilterMappingParams.java | 145 ++++++++++ .../server/tps/mapping/FilterMappingResolver.java | 297 +++++++++++++++++++++ .../server/tps/mapping/MappingResolverManager.java | 114 ++++++++ .../server/tps/processor/TPSProcessor.java | 30 +-- .../tps/profile/BaseTokenProfileResolver.java | 38 --- .../tps/profile/MappingTokenProfileResolver.java | 294 -------------------- .../server/tps/profile/TokenProfileParams.java | 145 ---------- .../tps/profile/TokenProfileResolverManager.java | 114 -------- 13 files changed, 708 insertions(+), 705 deletions(-) create mode 100644 base/tps/src/org/dogtagpki/server/tps/mapping/BaseMappingResolver.java create mode 100644 base/tps/src/org/dogtagpki/server/tps/mapping/FilterMappingParams.java create mode 100644 base/tps/src/org/dogtagpki/server/tps/mapping/FilterMappingResolver.java create mode 100644 base/tps/src/org/dogtagpki/server/tps/mapping/MappingResolverManager.java delete mode 100644 base/tps/src/org/dogtagpki/server/tps/profile/BaseTokenProfileResolver.java delete mode 100644 base/tps/src/org/dogtagpki/server/tps/profile/MappingTokenProfileResolver.java delete mode 100644 base/tps/src/org/dogtagpki/server/tps/profile/TokenProfileParams.java delete mode 100644 base/tps/src/org/dogtagpki/server/tps/profile/TokenProfileResolverManager.java (limited to 'base/tps') diff --git a/base/tps/shared/conf/CS.cfg.in b/base/tps/shared/conf/CS.cfg.in index 4fa477dbc..aadcbfcb1 100644 --- a/base/tps/shared/conf/CS.cfg.in +++ b/base/tps/shared/conf/CS.cfg.in @@ -789,7 +789,7 @@ op.enroll._032=# Token ATR: op.enroll._033=# Web Store - 3B759400006202020201 op.enroll._034=######################################### op.enroll.allowUnknownToken=true -op.enroll.tokenProfileResolver=enrollMappingResolver +op.enroll.mappingResolver=enrollMappingResolver op.enroll.soKey.cuidMustMatchKDD=false op.enroll.soKey.enableBoundedGPKeyVersion=true op.enroll.soKey.minimumGPKeyVersion=01 @@ -1395,7 +1395,7 @@ op.enroll.userKey.update.applet.requiredVersion=1.4.4d40a449 op.enroll.userKey.update.symmetricKeys.enable=false op.enroll.userKey.update.symmetricKeys.requiredVersion=1 op.format.allowUnknownToken=true -op.format.tokenProfileResolver=formatMappingResolver +op.format.mappingResolver=formatMappingResolver op.format.cleanToken.cuidMustMatchKDD=false op.format.cleanToken.enableBoundedGPKeyVersion=true op.format.cleanToken.minimumGPKeyVersion=01 @@ -1543,7 +1543,7 @@ op.format.userKey.update.applet.encryption=true op.format.userKey.update.applet.requiredVersion=1.4.4d40a449 op.format.userKey.update.symmetricKeys.enable=false op.format.userKey.update.symmetricKeys.requiredVersion=1 -op.pinReset.tokenProfileResolver=pinResetMappingResolver +op.pinReset.mappingResolver=pinResetMappingResolver op.pinReset.userKey.cuidMustMatchKDD=false op.pinReset.userKey.enableBoundedGPKeyVersion=true op.pinReset.userKey.minimumGPKeyVersion=01 @@ -1655,89 +1655,89 @@ preop.system.name=TPS preop.wizard.name=TPS Setup Wizard proxy.securePort=[PKI_PROXY_SECURE_PORT] proxy.unsecurePort=[PKI_PROXY_UNSECURE_PORT] -tokenProfileResolver.list=formatMappingResolver,enrollMappingResolver,pinResetMappingResolver -tokenProfileResolver.enrollMappingResolver.class_id=mappingTokenProfileResolverImpl -tokenProfileResolver.enrollMappingResolver.mapping.0.filter.appletMajorVersion=1 -tokenProfileResolver.enrollMappingResolver.mapping.0.filter.appletMinorVersion= -tokenProfileResolver.enrollMappingResolver.mapping.0.filter.tokenATR= -tokenProfileResolver.enrollMappingResolver.mapping.0.filter.tokenCUID.end= -tokenProfileResolver.enrollMappingResolver.mapping.0.filter.tokenCUID.start= -tokenProfileResolver.enrollMappingResolver.mapping.0.filter.tokenType=userKey -tokenProfileResolver.enrollMappingResolver.mapping.0.target.tokenType=userKey -tokenProfileResolver.enrollMappingResolver.mapping.1.filter.appletMajorVersion= -tokenProfileResolver.enrollMappingResolver.mapping.1.filter.appletMinorVersion= -tokenProfileResolver.enrollMappingResolver.mapping.1.filter.tokenATR= -tokenProfileResolver.enrollMappingResolver.mapping.1.filter.tokenCUID.end= -tokenProfileResolver.enrollMappingResolver.mapping.1.filter.tokenCUID.start= -tokenProfileResolver.enrollMappingResolver.mapping.1.filter.tokenType=soKey -tokenProfileResolver.enrollMappingResolver.mapping.1.target.tokenType=soKey -tokenProfileResolver.enrollMappingResolver.mapping.2.filter.appletMajorVersion= -tokenProfileResolver.enrollMappingResolver.mapping.2.filter.appletMinorVersion= -tokenProfileResolver.enrollMappingResolver.mapping.2.filter.tokenATR= -tokenProfileResolver.enrollMappingResolver.mapping.2.filter.tokenCUID.end= -tokenProfileResolver.enrollMappingResolver.mapping.2.filter.tokenCUID.start= -tokenProfileResolver.enrollMappingResolver.mapping.2.filter.tokenType= -tokenProfileResolver.enrollMappingResolver.mapping.2.target.tokenType=userKey -tokenProfileResolver.enrollMappingResolver.mapping.order=0,1,2 -tokenProfileResolver.formatMappingResolver.class_id=mappingTokenProfileResolverImpl -tokenProfileResolver.formatMappingResolver.mapping.0.filter.appletMajorVersion= -tokenProfileResolver.formatMappingResolver.mapping.0.filter.appletMinorVersion= -tokenProfileResolver.formatMappingResolver.mapping.0.filter.tokenATR= -tokenProfileResolver.formatMappingResolver.mapping.0.filter.tokenCUID.end= -tokenProfileResolver.formatMappingResolver.mapping.0.filter.tokenCUID.start= -tokenProfileResolver.formatMappingResolver.mapping.0.filter.tokenType=soCleanUserToken -tokenProfileResolver.formatMappingResolver.mapping.0.target.tokenType=soCleanUserToken -tokenProfileResolver.formatMappingResolver.mapping.1.filter.appletMajorVersion= -tokenProfileResolver.formatMappingResolver.mapping.1.filter.appletMinorVersion= -tokenProfileResolver.formatMappingResolver.mapping.1.filter.tokenATR= -tokenProfileResolver.formatMappingResolver.mapping.1.filter.tokenCUID.end= -tokenProfileResolver.formatMappingResolver.mapping.1.filter.tokenCUID.start= -tokenProfileResolver.formatMappingResolver.mapping.1.filter.tokenType=soUserKey -tokenProfileResolver.formatMappingResolver.mapping.1.target.tokenType=soUserKey -tokenProfileResolver.formatMappingResolver.mapping.2.filter.appletMajorVersion= -tokenProfileResolver.formatMappingResolver.mapping.2.filter.appletMinorVersion= -tokenProfileResolver.formatMappingResolver.mapping.2.filter.tokenATR= -tokenProfileResolver.formatMappingResolver.mapping.2.filter.tokenCUID.end= -tokenProfileResolver.formatMappingResolver.mapping.2.filter.tokenCUID.start= -tokenProfileResolver.formatMappingResolver.mapping.2.filter.tokenType=soKey -tokenProfileResolver.formatMappingResolver.mapping.2.target.tokenType=soKey -tokenProfileResolver.formatMappingResolver.mapping.3.filter.appletMajorVersion= -tokenProfileResolver.formatMappingResolver.mapping.3.filter.appletMinorVersion= -tokenProfileResolver.formatMappingResolver.mapping.3.filter.tokenATR= -tokenProfileResolver.formatMappingResolver.mapping.3.filter.tokenCUID.end= -tokenProfileResolver.formatMappingResolver.mapping.3.filter.tokenCUID.start= -tokenProfileResolver.formatMappingResolver.mapping.3.filter.tokenType=userKey -tokenProfileResolver.formatMappingResolver.mapping.3.target.tokenType=userKey -tokenProfileResolver.formatMappingResolver.mapping.4.filter.appletMajorVersion= -tokenProfileResolver.formatMappingResolver.mapping.4.filter.appletMinorVersion= -tokenProfileResolver.formatMappingResolver.mapping.4.filter.tokenATR= -tokenProfileResolver.formatMappingResolver.mapping.4.filter.tokenCUID.end= -tokenProfileResolver.formatMappingResolver.mapping.4.filter.tokenCUID.start= -tokenProfileResolver.formatMappingResolver.mapping.4.filter.tokenType=soCleanSOToken -tokenProfileResolver.formatMappingResolver.mapping.4.target.tokenType=soCleanSOToken -tokenProfileResolver.formatMappingResolver.mapping.5.filter.appletMajorVersion= -tokenProfileResolver.formatMappingResolver.mapping.5.filter.appletMinorVersion= -tokenProfileResolver.formatMappingResolver.mapping.5.filter.tokenATR= -tokenProfileResolver.formatMappingResolver.mapping.5.filter.tokenCUID.end= -tokenProfileResolver.formatMappingResolver.mapping.5.filter.tokenCUID.start= -tokenProfileResolver.formatMappingResolver.mapping.5.filter.tokenType=cleanToken -tokenProfileResolver.formatMappingResolver.mapping.5.target.tokenType=cleanToken -tokenProfileResolver.formatMappingResolver.mapping.6.filter.appletMajorVersion= -tokenProfileResolver.formatMappingResolver.mapping.6.filter.appletMinorVersion= -tokenProfileResolver.formatMappingResolver.mapping.6.filter.tokenATR= -tokenProfileResolver.formatMappingResolver.mapping.6.filter.tokenCUID.end= -tokenProfileResolver.formatMappingResolver.mapping.6.filter.tokenCUID.start= -tokenProfileResolver.formatMappingResolver.mapping.6.target.tokenType=tokenKey -tokenProfileResolver.formatMappingResolver.mapping.order=0,1,2,3,4,5,6 -tokenProfileResolver.pinResetMappingResolver.class_id=mappingTokenProfileResolverImpl -tokenProfileResolver.pinResetMappingResolver.mapping.0.filter.appletMajorVersion= -tokenProfileResolver.pinResetMappingResolver.mapping.0.filter.appletMinorVersion= -tokenProfileResolver.pinResetMappingResolver.mapping.0.filter.tokenATR= -tokenProfileResolver.pinResetMappingResolver.mapping.0.filter.tokenCUID.end= -tokenProfileResolver.pinResetMappingResolver.mapping.0.filter.tokenCUID.start= -tokenProfileResolver.pinResetMappingResolver.mapping.0.filter.tokenType= -tokenProfileResolver.pinResetMappingResolver.mapping.0.target.tokenType=userKey -tokenProfileResolver.pinResetMappingResolver.mapping.order=0 +mappingResolver.list=formatMappingResolver,enrollMappingResolver,pinResetMappingResolver +mappingResolver.enrollMappingResolver.class_id=filterMappingResolverImpl +mappingResolver.enrollMappingResolver.mapping.0.filter.appletMajorVersion=1 +mappingResolver.enrollMappingResolver.mapping.0.filter.appletMinorVersion= +mappingResolver.enrollMappingResolver.mapping.0.filter.tokenATR= +mappingResolver.enrollMappingResolver.mapping.0.filter.tokenCUID.end= +mappingResolver.enrollMappingResolver.mapping.0.filter.tokenCUID.start= +mappingResolver.enrollMappingResolver.mapping.0.filter.tokenType=userKey +mappingResolver.enrollMappingResolver.mapping.0.target.tokenType=userKey +mappingResolver.enrollMappingResolver.mapping.1.filter.appletMajorVersion= +mappingResolver.enrollMappingResolver.mapping.1.filter.appletMinorVersion= +mappingResolver.enrollMappingResolver.mapping.1.filter.tokenATR= +mappingResolver.enrollMappingResolver.mapping.1.filter.tokenCUID.end= +mappingResolver.enrollMappingResolver.mapping.1.filter.tokenCUID.start= +mappingResolver.enrollMappingResolver.mapping.1.filter.tokenType=soKey +mappingResolver.enrollMappingResolver.mapping.1.target.tokenType=soKey +mappingResolver.enrollMappingResolver.mapping.2.filter.appletMajorVersion= +mappingResolver.enrollMappingResolver.mapping.2.filter.appletMinorVersion= +mappingResolver.enrollMappingResolver.mapping.2.filter.tokenATR= +mappingResolver.enrollMappingResolver.mapping.2.filter.tokenCUID.end= +mappingResolver.enrollMappingResolver.mapping.2.filter.tokenCUID.start= +mappingResolver.enrollMappingResolver.mapping.2.filter.tokenType= +mappingResolver.enrollMappingResolver.mapping.2.target.tokenType=userKey +mappingResolver.enrollMappingResolver.mapping.order=0,1,2 +mappingResolver.formatMappingResolver.class_id=filterMappingResolverImpl +mappingResolver.formatMappingResolver.mapping.0.filter.appletMajorVersion= +mappingResolver.formatMappingResolver.mapping.0.filter.appletMinorVersion= +mappingResolver.formatMappingResolver.mapping.0.filter.tokenATR= +mappingResolver.formatMappingResolver.mapping.0.filter.tokenCUID.end= +mappingResolver.formatMappingResolver.mapping.0.filter.tokenCUID.start= +mappingResolver.formatMappingResolver.mapping.0.filter.tokenType=soCleanUserToken +mappingResolver.formatMappingResolver.mapping.0.target.tokenType=soCleanUserToken +mappingResolver.formatMappingResolver.mapping.1.filter.appletMajorVersion= +mappingResolver.formatMappingResolver.mapping.1.filter.appletMinorVersion= +mappingResolver.formatMappingResolver.mapping.1.filter.tokenATR= +mappingResolver.formatMappingResolver.mapping.1.filter.tokenCUID.end= +mappingResolver.formatMappingResolver.mapping.1.filter.tokenCUID.start= +mappingResolver.formatMappingResolver.mapping.1.filter.tokenType=soUserKey +mappingResolver.formatMappingResolver.mapping.1.target.tokenType=soUserKey +mappingResolver.formatMappingResolver.mapping.2.filter.appletMajorVersion= +mappingResolver.formatMappingResolver.mapping.2.filter.appletMinorVersion= +mappingResolver.formatMappingResolver.mapping.2.filter.tokenATR= +mappingResolver.formatMappingResolver.mapping.2.filter.tokenCUID.end= +mappingResolver.formatMappingResolver.mapping.2.filter.tokenCUID.start= +mappingResolver.formatMappingResolver.mapping.2.filter.tokenType=soKey +mappingResolver.formatMappingResolver.mapping.2.target.tokenType=soKey +mappingResolver.formatMappingResolver.mapping.3.filter.appletMajorVersion= +mappingResolver.formatMappingResolver.mapping.3.filter.appletMinorVersion= +mappingResolver.formatMappingResolver.mapping.3.filter.tokenATR= +mappingResolver.formatMappingResolver.mapping.3.filter.tokenCUID.end= +mappingResolver.formatMappingResolver.mapping.3.filter.tokenCUID.start= +mappingResolver.formatMappingResolver.mapping.3.filter.tokenType=userKey +mappingResolver.formatMappingResolver.mapping.3.target.tokenType=userKey +mappingResolver.formatMappingResolver.mapping.4.filter.appletMajorVersion= +mappingResolver.formatMappingResolver.mapping.4.filter.appletMinorVersion= +mappingResolver.formatMappingResolver.mapping.4.filter.tokenATR= +mappingResolver.formatMappingResolver.mapping.4.filter.tokenCUID.end= +mappingResolver.formatMappingResolver.mapping.4.filter.tokenCUID.start= +mappingResolver.formatMappingResolver.mapping.4.filter.tokenType=soCleanSOToken +mappingResolver.formatMappingResolver.mapping.4.target.tokenType=soCleanSOToken +mappingResolver.formatMappingResolver.mapping.5.filter.appletMajorVersion= +mappingResolver.formatMappingResolver.mapping.5.filter.appletMinorVersion= +mappingResolver.formatMappingResolver.mapping.5.filter.tokenATR= +mappingResolver.formatMappingResolver.mapping.5.filter.tokenCUID.end= +mappingResolver.formatMappingResolver.mapping.5.filter.tokenCUID.start= +mappingResolver.formatMappingResolver.mapping.5.filter.tokenType=cleanToken +mappingResolver.formatMappingResolver.mapping.5.target.tokenType=cleanToken +mappingResolver.formatMappingResolver.mapping.6.filter.appletMajorVersion= +mappingResolver.formatMappingResolver.mapping.6.filter.appletMinorVersion= +mappingResolver.formatMappingResolver.mapping.6.filter.tokenATR= +mappingResolver.formatMappingResolver.mapping.6.filter.tokenCUID.end= +mappingResolver.formatMappingResolver.mapping.6.filter.tokenCUID.start= +mappingResolver.formatMappingResolver.mapping.6.target.tokenType=tokenKey +mappingResolver.formatMappingResolver.mapping.order=0,1,2,3,4,5,6 +mappingResolver.pinResetMappingResolver.class_id=filterMappingResolverImpl +mappingResolver.pinResetMappingResolver.mapping.0.filter.appletMajorVersion= +mappingResolver.pinResetMappingResolver.mapping.0.filter.appletMinorVersion= +mappingResolver.pinResetMappingResolver.mapping.0.filter.tokenATR= +mappingResolver.pinResetMappingResolver.mapping.0.filter.tokenCUID.end= +mappingResolver.pinResetMappingResolver.mapping.0.filter.tokenCUID.start= +mappingResolver.pinResetMappingResolver.mapping.0.filter.tokenType= +mappingResolver.pinResetMappingResolver.mapping.0.target.tokenType=userKey +mappingResolver.pinResetMappingResolver.mapping.order=0 registry.file=[PKI_INSTANCE_PATH]/conf/tps/registry.cfg selftests._000=## selftests._001=## Self Tests @@ -1810,7 +1810,7 @@ target.Generals.displayname=General target.Generals.pattern=^applet\..*\|^general\..*\|^failover.pod.enable\|^channel\..* target.Profile_Mappings.displayname=Token Profile Mapping Resolvers target.Profile_Mappings.list=enrollMappingResolver,formatMappingResolver,pinResetMappingResolver -target.Profile_Mappings.pattern=tokenProfileResolver\.$name\.mapping\..* +target.Profile_Mappings.pattern=mappingResolver\.$name\.mapping\..* target.Profiles.displayname=Token Profile target.Profiles.list=userKey,soKey,soCleanUserToken,soUserKey,cleanToken,soCleanSoToken,tokenKey target.Profiles.pattern=op\..*\.$name\..* diff --git a/base/tps/shared/conf/registry.cfg b/base/tps/shared/conf/registry.cfg index dc26ae861..4315b2f3f 100644 --- a/base/tps/shared/conf/registry.cfg +++ b/base/tps/shared/conf/registry.cfg @@ -1,5 +1,5 @@ -types=tpsTokenProfileResolver -tpsTokenProfileResolver.ids=mappingTokenProfileResolverImpl -tpsTokenProfileResolver.mappingTokenProfileResolverImpl.class=org.dogtagpki.server.tps.profile.MappingTokenProfileResolver -tpsTokenProfileResolver.mappingTokenProfileResolverImpl.desc=Mapping-based Token profile resolver -tpsTokenProfileResolver.mappingTokenProfileResolverImpl.name=Mapping-based Token profile resolver +types=tpsMappingResolver +tpsMappingResolver.ids=filterMappingResolverImpl +tpsMappingResolver.filterMappingResolverImpl.class=org.dogtagpki.server.tps.mapping.FilterMappingResolver +tpsMappingResolver.filterMappingResolverImpl.desc=filter-based Token mapping resolver +tpsMappingResolver.filterMappingResolverImpl.name=filter-based Token mapping resolver diff --git a/base/tps/src/org/dogtagpki/server/tps/TPSSubsystem.java b/base/tps/src/org/dogtagpki/server/tps/TPSSubsystem.java index 75cdddadb..e8734a9b8 100644 --- a/base/tps/src/org/dogtagpki/server/tps/TPSSubsystem.java +++ b/base/tps/src/org/dogtagpki/server/tps/TPSSubsystem.java @@ -28,7 +28,7 @@ import org.dogtagpki.server.tps.dbs.ActivityDatabase; import org.dogtagpki.server.tps.dbs.TPSCertDatabase; import org.dogtagpki.server.tps.dbs.TokenDatabase; import org.dogtagpki.server.tps.engine.TPSEngine; -import org.dogtagpki.server.tps.profile.TokenProfileResolverManager; +import org.dogtagpki.server.tps.mapping.MappingResolverManager; import org.mozilla.jss.CryptoManager; import org.mozilla.jss.CryptoManager.NotInitializedException; import org.mozilla.jss.crypto.ObjectNotFoundException; @@ -69,7 +69,7 @@ public class TPSSubsystem implements IAuthority, ISubsystem { public TokenDatabase tokenDatabase; public ConnectionManager connManager; public AuthenticationManager authManager; - public TokenProfileResolverManager profileResolverManager; + public MappingResolverManager mappingResolverManager; public TPSEngine engine; public TPSTokendb tdb; @@ -119,8 +119,8 @@ public class TPSSubsystem implements IAuthority, ISubsystem { connManager.initConnectors(); authManager = new AuthenticationManager(); authManager.initAuthInstances(); - profileResolverManager = new TokenProfileResolverManager(); - profileResolverManager.initProfileResolverInstances(); + mappingResolverManager = new MappingResolverManager(); + mappingResolverManager.initMappingResolverInstances(); CMS.debug("TPSSubsystem: startup() ends."); } @@ -205,8 +205,8 @@ public class TPSSubsystem implements IAuthority, ISubsystem { return authManager; } - public TokenProfileResolverManager getProfileResolverManager() { - return profileResolverManager; + public MappingResolverManager getMappingResolverManager() { + return mappingResolverManager; } public TPSTokendb getTokendb() { diff --git a/base/tps/src/org/dogtagpki/server/tps/engine/TPSEngine.java b/base/tps/src/org/dogtagpki/server/tps/engine/TPSEngine.java index 7672a9bb7..b24f85d60 100644 --- a/base/tps/src/org/dogtagpki/server/tps/engine/TPSEngine.java +++ b/base/tps/src/org/dogtagpki/server/tps/engine/TPSEngine.java @@ -170,7 +170,7 @@ public class TPSEngine { public static final String RENEWAL_OP = "renewal"; public static final String OP_FORMAT_PREFIX = "op." + FORMAT_OP; - public static final String CFG_PROFILE_RESOLVER = "tokenProfileResolver"; + public static final String CFG_PROFILE_RESOLVER = "mappingResolver"; public static final String CFG_DEF_FORMAT_PROFILE_RESOLVER = "formatMappingResolver"; public static final String CFG_DEF_ENROLL_PROFILE_RESOLVER = "enrollMappingResolver"; public static final String CFG_DEF_PIN_RESET_PROFILE_RESOLVER = "pinResetMappingResolver"; diff --git a/base/tps/src/org/dogtagpki/server/tps/mapping/BaseMappingResolver.java b/base/tps/src/org/dogtagpki/server/tps/mapping/BaseMappingResolver.java new file mode 100644 index 000000000..9b36727be --- /dev/null +++ b/base/tps/src/org/dogtagpki/server/tps/mapping/BaseMappingResolver.java @@ -0,0 +1,38 @@ +package org.dogtagpki.server.tps.mapping; + +import org.dogtagpki.tps.main.TPSException; + +import com.netscape.certsrv.apps.CMS; +import com.netscape.certsrv.base.IConfigStore; + +/** + * This class implements the base TPS mapping filter Resolver instance + * + * @author cfu + */ +public abstract class BaseMappingResolver { + protected IConfigStore configStore = null; + protected String instanceName = ""; + protected String prefix = ""; + + public BaseMappingResolver() { + } + + public void init(String instName) { + instanceName = instName; + prefix = MappingResolverManager.MAPPING_RESOLVER_CFG + + "." + instanceName; + configStore = CMS.getConfigStore(); + } + + public String getName() { + return instanceName; + } + + public String getPrefix() { + return prefix; + } + + public abstract String getResolvedMapping(FilterMappingParams pPram) + throws TPSException; +} diff --git a/base/tps/src/org/dogtagpki/server/tps/mapping/FilterMappingParams.java b/base/tps/src/org/dogtagpki/server/tps/mapping/FilterMappingParams.java new file mode 100644 index 000000000..ee89826fb --- /dev/null +++ b/base/tps/src/org/dogtagpki/server/tps/mapping/FilterMappingParams.java @@ -0,0 +1,145 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2014 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package org.dogtagpki.server.tps.mapping; + +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +import org.dogtagpki.tps.main.TPSException; +import org.dogtagpki.tps.msg.EndOpMsg.TPSStatus; + +import com.netscape.certsrv.apps.CMS; + +/** + * A class represents filter mapping params information. + *

+ * + * @author cfu + */ +public class FilterMappingParams { + + public static final String FILTER_PARAM_MAJOR_VERSION = "fp_major_version"; + public static final String FILTER_PARAM_MINOR_VERSION = "fp_minor_version"; + public static final String FILTER_PARAM_CUID = "fp_cuid"; + public static final String FILTER_PARAM_MSN = "fp_msn"; + public static final String FILTER_PARAM_EXT_TOKEN_TYPE = "fp_ext_tokenType"; + public static final String FILTER_PARAM_EXT_TOKEN_ATR = "fp_ext_tokenATR"; + + private HashMap content = new HashMap(); + + /** + * Constructs a meta information. + *

+ */ + public FilterMappingParams() { + } + + /** + * Returns a short string describing this certificate attribute. + *

+ * + * @return information about this certificate attribute. + */ + public String toString() { + StringBuffer sb = new StringBuffer("[\n" + " Meta information:\n"); + + for (Map.Entry entry : content.entrySet()) { + String key = entry.getKey(); + + sb.append(" " + key + " : " + entry.getValue() + "\n"); + } + sb.append("]\n"); + return sb.toString(); + } + + /** + * Gets a String attribute value. + *

+ * + * @param name the name of the attribute to return. + */ + public String getString(String name) + throws TPSException { + String val = content.get(name); + if (val == null) { + CMS.debug("FilterMappingParams.getString: param null:"+ name); + throw new TPSException ( + "FilterMappingParams.getString: param null:"+ name, + TPSStatus.STATUS_ERROR_MAPPING_RESOLVER_PARAMS_NOT_FOUND); + } + return val; + } + + /** + * Gets an int attribute value. + *

+ * + * @param name the name of the attribute to return. + */ + public int getInt(String name) + throws TPSException { + String val = content.get(name); + if (val == null) { + CMS.debug("FilterMappingParams.getInt: param null:"+ name); + throw new TPSException ( + "FilterMappingParams.getInt: param null:"+ name, + TPSStatus.STATUS_ERROR_MAPPING_RESOLVER_PARAMS_NOT_FOUND); + } + try { + int intVal = Integer.parseInt(val); + return intVal; + } catch (NumberFormatException e) { + CMS.debug("FilterMappingParams.getInt: param "+ name + "=" + val + e); + throw new TPSException ( + "FilterMappingParams.getInt: param major_version:"+ e, + TPSStatus.STATUS_ERROR_MISCONFIGURATION); + } + } + + /** + * Sets an attribute value. + * + * @param name the name of the attribute + * @param val the attribute value. + */ + public void set(String name, String val) { + content.put(name, val); + } + + /** + * Deletes an attribute value from this AttrSet. + *

+ * + * @param name the name of the attribute to delete. + */ + public void delete(String name) { + content.remove(name); + } + + /** + * Returns an enumeration of the names of the attributes existing within + * this attribute. + *

+ * + * @return an enumeration of the attribute names. + */ + public Set getElements() { + return content.keySet(); + } +} diff --git a/base/tps/src/org/dogtagpki/server/tps/mapping/FilterMappingResolver.java b/base/tps/src/org/dogtagpki/server/tps/mapping/FilterMappingResolver.java new file mode 100644 index 000000000..c1fcb974e --- /dev/null +++ b/base/tps/src/org/dogtagpki/server/tps/mapping/FilterMappingResolver.java @@ -0,0 +1,297 @@ +package org.dogtagpki.server.tps.mapping; + +import org.dogtagpki.server.tps.engine.TPSEngine; +import org.dogtagpki.tps.main.TPSException; +import org.dogtagpki.tps.msg.EndOpMsg.TPSStatus; + +import com.netscape.certsrv.apps.CMS; +import com.netscape.certsrv.base.EBaseException; +import com.netscape.certsrv.base.EPropertyNotFound; + +/** + * FilterMappingResolver is a mapping resolver plugin that calculates + * result by sorting through a list of filters in mapping + * + * @author cfu + */ +public class FilterMappingResolver extends BaseMappingResolver { + + public FilterMappingResolver() { + } + + public String getResolvedMapping(FilterMappingParams mappingParams) + throws TPSException { + String method = "FilterMappingResolver.getResolvedMapping: "; + String tokenType = null; + String mappingOrder = null; + int major_version = 0; + int minor_version = 0; + String cuid = null; + // String msn = null; + String extTokenType = null; + String extTokenATR = null; + + CMS.debug(method + " starts"); + + major_version = mappingParams.getInt(FilterMappingParams.FILTER_PARAM_MAJOR_VERSION); + CMS.debug(method + " param major_version =" + major_version); + + minor_version = mappingParams.getInt(FilterMappingParams.FILTER_PARAM_MINOR_VERSION); + CMS.debug(method + " param minor_version =" + minor_version); + + cuid = mappingParams.getString(FilterMappingParams.FILTER_PARAM_CUID); + // msn = (String) mappingParams.get(FilterMappingParams.FILTER_PARAM_MSN); + + // they don't necessarily have extension + try { + extTokenType = mappingParams.getString(FilterMappingParams.FILTER_PARAM_EXT_TOKEN_TYPE); + extTokenATR = mappingParams.getString(FilterMappingParams.FILTER_PARAM_EXT_TOKEN_ATR); + } catch (TPSException e) { + CMS.debug(method + " OK to not have extension. Continue."); + } + + CMS.debug(method + " mapping params retrieved."); + + String configName = prefix + "." + TPSEngine.CFG_PROFILE_MAPPING_ORDER; + + try { + CMS.debug(method + " getting mapping order:" + + configName); + mappingOrder = configStore.getString(configName); + } catch (EPropertyNotFound e) { + CMS.debug(method + " exception:" + e); + throw new TPSException( + method + " configuration incorrect! Mising mapping order:" + configName, + TPSStatus.STATUS_ERROR_MAPPING_RESOLVER_FAILED); + + } catch (EBaseException e1) { + //The whole feature won't work if this is wrong. + CMS.debug(method + " exception:" + e1); + throw new TPSException( + method + " Internal error obtaining config value:" + configName, + TPSStatus.STATUS_ERROR_MAPPING_RESOLVER_FAILED); + } + + String targetTokenType = null; + + for (String mappingId : mappingOrder.split(",")) { + + CMS.debug(method + " mapping: " + mappingId); + + String mappingConfigName = prefix + ".mapping." + mappingId + ".target.tokenType"; + + CMS.debug(method + " mappingConfigName: " + mappingConfigName); + + //We need this to exist. + try { + targetTokenType = configStore.getString(mappingConfigName); + } catch (EPropertyNotFound e) { + throw new TPSException( + method + " Token Type configuration incorrect! No target token type config value found! Config: " + + mappingConfigName, + TPSStatus.STATUS_ERROR_MAPPING_RESOLVER_FAILED); + + } catch (EBaseException e) { + throw new TPSException( + method + " Internal error obtaining config value. Config: " + + mappingConfigName, + TPSStatus.STATUS_ERROR_MAPPING_RESOLVER_FAILED); + } + + mappingConfigName = prefix + ".mapping." + mappingId + ".filter.tokenType"; + + CMS.debug(method + " mappingConfigName: " + mappingConfigName); + + //For this and remaining cases, it is not automatically an error if we don't get anything back + // from the config. + try { + tokenType = configStore.getString(mappingConfigName, null); + } catch (EBaseException e) { + throw new TPSException( + method + " Internal error obtaining config value. Config: " + + mappingConfigName, + TPSStatus.STATUS_ERROR_MAPPING_RESOLVER_FAILED); + + } + + CMS.debug(method + " targetTokenType: " + targetTokenType); + + if (tokenType != null && tokenType.length() > 0) { + + if (extTokenType == null) { + continue; + } + + //String extTokenType = extensions.get("tokenType"); + //if (extTokenType == null) { + // continue; + //} + + if (!extTokenType.equals(tokenType)) { + continue; + } + } + + mappingConfigName = prefix + ".mapping." + mappingId + ".filter.tokenATR"; + + CMS.debug(method + " mappingConfigName: " + mappingConfigName); + + String tokenATR = null; + + try { + tokenATR = configStore.getString(mappingConfigName, null); + } catch (EBaseException e) { + throw new TPSException( + method + " Internal error obtaining config value. Config: " + + mappingConfigName, + TPSStatus.STATUS_ERROR_MAPPING_RESOLVER_FAILED); + } + + CMS.debug(method + " tokenATR: " + tokenATR); + + if (tokenATR != null && tokenATR.length() > 0) { + if (extTokenATR == null) { + continue; + } + + //String extTokenATR = extensions.get("tokenATR"); + + //if (extTokenATR == null) { + // continue; + //} + + if (!extTokenATR.equals(tokenATR)) { + continue; + } + + } + + mappingConfigName = prefix + ".mapping." + mappingId + ".filter.tokenCUID.start"; + + CMS.debug(method + " mappingConfigName: " + mappingConfigName); + + String tokenCUIDStart = null; + + try { + tokenCUIDStart = configStore.getString(mappingConfigName, null); + + } catch (EBaseException e) { + throw new TPSException( + method + " Internal error obtaining config value. Config: " + + mappingConfigName, + TPSStatus.STATUS_ERROR_MAPPING_RESOLVER_FAILED); + } + + CMS.debug(method + " tokenCUIDStart: " + tokenCUIDStart); + + if (tokenCUIDStart != null && tokenCUIDStart.length() > 0) { + if (cuid == null) { + continue; + } + + if (tokenCUIDStart.length() != 20) { + continue; + } + + if (cuid.compareTo(tokenCUIDStart) < 0) { + continue; + } + + } + + mappingConfigName = prefix + ".mapping." + mappingId + ".filter.tokenCUID.end"; + + CMS.debug(method + " mappingConfigName: " + mappingConfigName); + + String tokenCUIDEnd = null; + try { + tokenCUIDEnd = configStore.getString(mappingConfigName, null); + } catch (EBaseException e) { + throw new TPSException( + method + " Internal error obtaining config value. Config: " + + mappingConfigName, + TPSStatus.STATUS_ERROR_MAPPING_RESOLVER_FAILED); + } + + CMS.debug(method + " tokenCUIDEnd: " + tokenCUIDEnd); + + if (tokenCUIDEnd != null && tokenCUIDEnd.length() > 0) { + if (cuid == null) { + continue; + } + + if (tokenCUIDEnd.length() != 20) { + continue; + } + + if (cuid.compareTo(tokenCUIDEnd) > 0) { + continue; + } + + } + + mappingConfigName = prefix + ".mapping." + mappingId + ".filter.appletMajorVersion"; + + CMS.debug(method + " mappingConfigName: " + mappingConfigName); + + String majorVersion = null; + String minorVersion = null; + + try { + majorVersion = configStore.getString(mappingConfigName, null); + } catch (EBaseException e) { + throw new TPSException( + method + " Internal error obtaining config value. Config: " + + mappingConfigName, + TPSStatus.STATUS_ERROR_MAPPING_RESOLVER_FAILED); + } + + CMS.debug(method + " majorVersion: " + majorVersion); + if (majorVersion != null && majorVersion.length() > 0) { + + int major = Integer.parseInt(majorVersion); + + if (major != major_version) { + continue; + } + } + + mappingConfigName = prefix + ".mapping." + mappingId + ".filter.appletMinorVersion"; + + CMS.debug(method + " mappingConfigName: " + mappingConfigName); + + try { + minorVersion = configStore.getString(mappingConfigName, null); + } catch (EBaseException e) { + throw new TPSException( + method + " Internal error obtaining config value. Config: " + + mappingConfigName, + TPSStatus.STATUS_ERROR_MAPPING_RESOLVER_FAILED); + } + CMS.debug(method + " minorVersion " + minorVersion); + + if (minorVersion != null && minorVersion.length() > 0) { + + int minor = Integer.parseInt(minorVersion); + + if (minor != minor_version) { + continue; + } + } + + //if we make it this far, we have a token type + CMS.debug(method + " Selected Token type: " + targetTokenType); + break; + } + + if (targetTokenType == null) { + CMS.debug(method + " end found: " + targetTokenType); + throw new TPSException(method + " Can't find token type!", + TPSStatus.STATUS_ERROR_MAPPING_RESOLVER_FAILED); + } + + return targetTokenType; + + } + +} diff --git a/base/tps/src/org/dogtagpki/server/tps/mapping/MappingResolverManager.java b/base/tps/src/org/dogtagpki/server/tps/mapping/MappingResolverManager.java new file mode 100644 index 000000000..3c9b196da --- /dev/null +++ b/base/tps/src/org/dogtagpki/server/tps/mapping/MappingResolverManager.java @@ -0,0 +1,114 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2014 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- + +package org.dogtagpki.server.tps.mapping; + +import java.util.HashMap; + +import com.netscape.certsrv.apps.CMS; +import com.netscape.certsrv.base.EBaseException; +import com.netscape.certsrv.base.IConfigStore; +import com.netscape.certsrv.registry.IPluginInfo; +import com.netscape.certsrv.registry.IPluginRegistry; + +/** + * mappingResolverManager is a class for mapping resolver plugin + * management + * + * @author cfu + */ +public class MappingResolverManager +{ + private static final String TOKEN_MAPPING_RESOLVER_TYPE = "tpsMappingResolver"; + public static final String PROP_RESOLVER_LIST = "list"; + public static final String PROP_RESOLVER_CLASS_ID = "class_id"; + + protected static final String MAPPING_RESOLVER_CFG = "mappingResolver"; + protected IPluginRegistry registry = null; + protected HashMap mappingResolvers = null; + + public MappingResolverManager() { + mappingResolvers = new HashMap(); + } + + /** + * initializes all mapping resolver plugin instances specified in + * /conf/registry.cfg + * + * configuration e.g. + * + * registry.cfg: + * types=tpsMappingResolver + * tpsMappingResolver.ids=mappingTokenProfileResolverImpl + * tpsMappingResolver.mappingTokenProfileResolverImpl.class=org.dogtagpki.server.tps.mapping.mappingResolver + * tpsMappingResolver.mappingTokenProfileResolverImpl.desc=Mapping-based Token profile resolver + * tpsMappingResolver.mappingTokenProfileResolverImpl.name=Mapping-based Token profile resolver + * + * CS.cfg : + * registry.file=/var/lib/pki/pki-tomcat/conf/tps/registry.cfg + * mappingResolver.list=formatMappingResolver,enrollMappingResolver,pinResetMappingResolver + * mappingResolver.formatMappingResolver.class_id=mappingProfileResolverImpl + * mappingResolver.formatMappingResolver.[plugin-specific configuration] + * + * op.format.mappingResolver=formatMappingResolver + * ... + * op.enroll.mappingResolver=enrollMappingResolver + * + * Note: "none" indicates no resolver plugin applied + * op.format.mappingResolver=none + */ + public void initMappingResolverInstances() + throws EBaseException { + String method = "mappingResolverManager.initMappingResolverInstance:"; + CMS.debug(method + " begins"); + IConfigStore conf = CMS.getConfigStore(); + registry = (IPluginRegistry) CMS.getSubsystem(CMS.SUBSYSTEM_REGISTRY); + if (registry == null) { + CMS.debug(method + " registry null"); + return; + } + + IConfigStore prConf = conf.getSubStore(MAPPING_RESOLVER_CFG); + String profileList = prConf.getString(PROP_RESOLVER_LIST, ""); + + for (String prInst : profileList.split(",")) { + String classID = prConf.getString(prInst + "." + PROP_RESOLVER_CLASS_ID); + CMS.debug(method + " initializing classID=" + classID); + IPluginInfo resolverInfo = + registry.getPluginInfo(TOKEN_MAPPING_RESOLVER_TYPE, classID); + String resolverClass = resolverInfo.getClassName(); + BaseMappingResolver resolver = null; + try { + resolver = (BaseMappingResolver) + Class.forName(resolverClass).newInstance(); + } catch (Exception e) { + // throw Exception + CMS.debug(method + " resolver plugin Class.forName " + + resolverClass + " " + e.toString()); + throw new EBaseException(e.toString()); + } + resolver.init(prInst); + mappingResolvers.put(prInst, resolver); + CMS.debug(method + " resolver instance added: " + prInst); + } + } + + public BaseMappingResolver getResolverInstance(String name) { + return mappingResolvers.get(name); + } +} diff --git a/base/tps/src/org/dogtagpki/server/tps/processor/TPSProcessor.java b/base/tps/src/org/dogtagpki/server/tps/processor/TPSProcessor.java index 27d88c2f1..00303432c 100644 --- a/base/tps/src/org/dogtagpki/server/tps/processor/TPSProcessor.java +++ b/base/tps/src/org/dogtagpki/server/tps/processor/TPSProcessor.java @@ -55,8 +55,8 @@ import org.dogtagpki.server.tps.engine.TPSEngine; import org.dogtagpki.server.tps.main.ExternalRegAttrs; //import org.dogtagpki.server.tps.main.ExternalRegCertToDelete; import org.dogtagpki.server.tps.main.ExternalRegCertToRecover; -import org.dogtagpki.server.tps.profile.BaseTokenProfileResolver; -import org.dogtagpki.server.tps.profile.TokenProfileParams; +import org.dogtagpki.server.tps.mapping.BaseMappingResolver; +import org.dogtagpki.server.tps.mapping.FilterMappingParams; import org.dogtagpki.tps.apdu.APDU; import org.dogtagpki.tps.apdu.APDUResponse; import org.dogtagpki.tps.apdu.GetDataAPDU; @@ -2068,32 +2068,32 @@ public class TPSProcessor { if (!resolverInstName.equals("none") && (selectedTokenType == null)) { try { - TokenProfileParams pParams = new TokenProfileParams(); - CMS.debug("In TPSProcessor.resolveTokenProfile : after new TokenProfileParams"); - pParams.set(TokenProfileParams.PROFILE_PARAM_MAJOR_VERSION, + FilterMappingParams pParams = new FilterMappingParams(); + CMS.debug("In TPSProcessor.resolveTokenProfile : after new MappingFilterParams"); + pParams.set(FilterMappingParams.FILTER_PARAM_MAJOR_VERSION, String.valueOf(major_version)); - pParams.set(TokenProfileParams.PROFILE_PARAM_MINOR_VERSION, + pParams.set(FilterMappingParams.FILTER_PARAM_MINOR_VERSION, String.valueOf(minor_version)); - pParams.set(TokenProfileParams.PROFILE_PARAM_CUID, cuid); - pParams.set(TokenProfileParams.PROFILE_PARAM_MSN, msn); + pParams.set(FilterMappingParams.FILTER_PARAM_CUID, cuid); + pParams.set(FilterMappingParams.FILTER_PARAM_MSN, msn); if (beginMsg.getExtensions() != null) { - pParams.set(TokenProfileParams.PROFILE_PARAM_EXT_TOKEN_TYPE, + pParams.set(FilterMappingParams.FILTER_PARAM_EXT_TOKEN_TYPE, beginMsg.getExtensions().get("tokenType")); - pParams.set(TokenProfileParams.PROFILE_PARAM_EXT_TOKEN_ATR, + pParams.set(FilterMappingParams.FILTER_PARAM_EXT_TOKEN_ATR, beginMsg.getExtensions().get("tokenATR")); } - CMS.debug("In TPSProcessor.resolveTokenProfile : after setting TokenProfileParams"); + CMS.debug("In TPSProcessor.resolveTokenProfile : after setting MappingFilterParams"); TPSSubsystem subsystem = (TPSSubsystem) CMS.getSubsystem(TPSSubsystem.ID); - BaseTokenProfileResolver resolverInst = - subsystem.getProfileResolverManager().getResolverInstance(resolverInstName); - tokenType = resolverInst.getTokenType(pParams); + BaseMappingResolver resolverInst = + subsystem.getMappingResolverManager().getResolverInstance(resolverInstName); + tokenType = resolverInst.getResolvedMapping(pParams); CMS.debug("In TPSProcessor.resolveTokenProfile : profile resolver result: " + tokenType); setSelectedTokenType(tokenType); } catch (EBaseException et) { CMS.debug("In TPSProcessor.resolveTokenProfile exception:" + et); throw new TPSException("TPSProcessor.resolveTokenProfile failed.", - TPSStatus.STATUS_ERROR_DEFAULT_TOKENTYPE_NOT_FOUND); + TPSStatus.STATUS_ERROR_MAPPING_RESOLVER_FAILED); } } else { diff --git a/base/tps/src/org/dogtagpki/server/tps/profile/BaseTokenProfileResolver.java b/base/tps/src/org/dogtagpki/server/tps/profile/BaseTokenProfileResolver.java deleted file mode 100644 index c62d1ed2b..000000000 --- a/base/tps/src/org/dogtagpki/server/tps/profile/BaseTokenProfileResolver.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.dogtagpki.server.tps.profile; - -import org.dogtagpki.tps.main.TPSException; - -import com.netscape.certsrv.apps.CMS; -import com.netscape.certsrv.base.IConfigStore; - -/** - * This class implements the base TPS Profile Resolver instance - * - * @author cfu - */ -public abstract class BaseTokenProfileResolver { - protected IConfigStore configStore = null; - protected String instanceName = ""; - protected String prefix = ""; - - public BaseTokenProfileResolver() { - } - - public void init(String instName) { - instanceName = instName; - prefix = TokenProfileResolverManager.TOKEN_PROFILE_RESOLVER_CFG + - "." + instanceName; - configStore = CMS.getConfigStore(); - } - - public String getName() { - return instanceName; - } - - public String getPrefix() { - return prefix; - } - - public abstract String getTokenType(TokenProfileParams pPram) - throws TPSException; -} diff --git a/base/tps/src/org/dogtagpki/server/tps/profile/MappingTokenProfileResolver.java b/base/tps/src/org/dogtagpki/server/tps/profile/MappingTokenProfileResolver.java deleted file mode 100644 index 264fba882..000000000 --- a/base/tps/src/org/dogtagpki/server/tps/profile/MappingTokenProfileResolver.java +++ /dev/null @@ -1,294 +0,0 @@ -package org.dogtagpki.server.tps.profile; - -import org.dogtagpki.server.tps.engine.TPSEngine; -import org.dogtagpki.tps.main.TPSException; -import org.dogtagpki.tps.msg.EndOpMsg.TPSStatus; - -import com.netscape.certsrv.apps.CMS; -import com.netscape.certsrv.base.EBaseException; -import com.netscape.certsrv.base.EPropertyNotFound; - -/** - * MappingTokenProfileResolver is a profile resolver plugin that calculates - * token type by sorting through a list of filters in mapping - */ -public class MappingTokenProfileResolver extends BaseTokenProfileResolver { - - public MappingTokenProfileResolver() { - } - - public String getTokenType(TokenProfileParams pParam) - throws TPSException { - - String tokenType = null; - String mappingOrder = null; - int major_version = 0; - int minor_version = 0; - String cuid = null; - // String msn = null; - String eTokenType = null; - String eTokenATR = null; - - CMS.debug("MappingTokenProfileResolver.getTokenType: starts"); - - major_version = pParam.getInt(TokenProfileParams.PROFILE_PARAM_MAJOR_VERSION); - CMS.debug("MappingTokenProfileResolver: param major_version =" + major_version); - - minor_version = pParam.getInt(TokenProfileParams.PROFILE_PARAM_MINOR_VERSION); - CMS.debug("MappingTokenProfileResolver: param minor_version =" + minor_version); - - cuid = pParam.getString(TokenProfileParams.PROFILE_PARAM_CUID); - // msn = (String) pParam.get(TokenProfileParams.PROFILE_PARAM_MSN); - // they don't necessarily have extension - try { - eTokenType = pParam.getString(TokenProfileParams.PROFILE_PARAM_EXT_TOKEN_TYPE); - eTokenATR = pParam.getString(TokenProfileParams.PROFILE_PARAM_EXT_TOKEN_ATR); - } catch (TPSException e) { - CMS.debug("MappingTokenProfileResolver: OK to not have extension. Continue."); - } - - CMS.debug("MappingTokenProfileResolver: params retrieved."); - - String configName = prefix + "." + TPSEngine.CFG_PROFILE_MAPPING_ORDER; - - try { - CMS.debug("MappingTokenProfileResolver: getting mapping order:" + - configName); - mappingOrder = configStore.getString(configName); - } catch (EPropertyNotFound e) { - CMS.debug("MappingTokenProfileResolver: exception:" + e); - throw new TPSException( - "MappingTokenProfileResolver.getTokenType: Token Type configuration incorrect! Mising mapping order!", - TPSStatus.STATUS_ERROR_DEFAULT_TOKENTYPE_NOT_FOUND); - - } catch (EBaseException e1) { - //The whole feature won't work if this is wrong. - CMS.debug("MappingTokenProfileResolver: exception:" + e1); - throw new TPSException( - "MappingTokenProfileResolver.getTokenType: Internal error obtaining config value.!", - TPSStatus.STATUS_ERROR_DEFAULT_TOKENTYPE_NOT_FOUND); - } - - String targetTokenType = null; - - for (String mappingId : mappingOrder.split(",")) { - - CMS.debug("MappingTokenProfileResolver.getTokenType: mapping: " + mappingId); - - String mappingConfigName = prefix + ".mapping." + mappingId + ".target.tokenType"; - - CMS.debug("MappingTokenProfileResolver.getTokenType: mappingConfigName: " + mappingConfigName); - - //We need this to exist. - try { - targetTokenType = configStore.getString(mappingConfigName); - } catch (EPropertyNotFound e) { - throw new TPSException( - "MappingTokenProfileResolver.getTokenType: Token Type configuration incorrect! No target token type config value found! Config: " - + mappingConfigName, - TPSStatus.STATUS_ERROR_DEFAULT_TOKENTYPE_NOT_FOUND); - - } catch (EBaseException e) { - throw new TPSException( - "MappingTokenProfileResolver.getTokenType: Internal error obtaining config value. Config: " - + mappingConfigName, - TPSStatus.STATUS_ERROR_DEFAULT_TOKENTYPE_NOT_FOUND); - } - - mappingConfigName = prefix + ".mapping." + mappingId + ".filter.tokenType"; - - CMS.debug("MappingTokenProfileResolver.getTokenType: mappingConfigName: " + mappingConfigName); - - //For this and remaining cases, it is not automatically an error if we don't get anything back - // from the config. - try { - tokenType = configStore.getString(mappingConfigName, null); - } catch (EBaseException e) { - throw new TPSException( - "MappingTokenProfileResolver.getTokenType: Internal error obtaining config value. Config: " - + mappingConfigName, - TPSStatus.STATUS_ERROR_DEFAULT_TOKENTYPE_NOT_FOUND); - - } - - CMS.debug("MappingTokenProfileResolver.getTokenType: targetTokenType: " + targetTokenType); - - if (tokenType != null && tokenType.length() > 0) { - - if (eTokenType == null) { - continue; - } - - //String eTokenType = extensions.get("tokenType"); - //if (eTokenType == null) { - // continue; - //} - - if (!eTokenType.equals(tokenType)) { - continue; - } - } - - mappingConfigName = prefix + ".mapping." + mappingId + ".filter.tokenATR"; - - CMS.debug("MappingTokenProfileResolver.getTokenType: mappingConfigName: " + mappingConfigName); - - String tokenATR = null; - - try { - tokenATR = configStore.getString(mappingConfigName, null); - } catch (EBaseException e) { - throw new TPSException( - "MappingTokenProfileResolver.getTokenType: Internal error obtaining config value. Config: " - + mappingConfigName, - TPSStatus.STATUS_ERROR_DEFAULT_TOKENTYPE_NOT_FOUND); - } - - CMS.debug("MappingTokenProfileResolver.getTokenType: tokenATR: " + tokenATR); - - if (tokenATR != null && tokenATR.length() > 0) { - if (eTokenATR == null) { - continue; - } - - //String eTokenATR = extensions.get("tokenATR"); - - //if (eTokenATR == null) { - // continue; - //} - - if (!eTokenATR.equals(tokenATR)) { - continue; - } - - } - - mappingConfigName = prefix + ".mapping." + mappingId + ".filter.tokenCUID.start"; - - CMS.debug("MappingTokenProfileResolver.getTokenType: mappingConfigName: " + mappingConfigName); - - String tokenCUIDStart = null; - - try { - tokenCUIDStart = configStore.getString(mappingConfigName, null); - - } catch (EBaseException e) { - throw new TPSException( - "MappingTokenProfileResolver.getTokenType: Internal error obtaining config value. Config: " - + mappingConfigName, - TPSStatus.STATUS_ERROR_DEFAULT_TOKENTYPE_NOT_FOUND); - } - - CMS.debug("MappingTokenProfileResolver.getTokenType: tokenCUIDStart: " + tokenCUIDStart); - - if (tokenCUIDStart != null && tokenCUIDStart.length() > 0) { - if (cuid == null) { - continue; - } - - if (tokenCUIDStart.length() != 20) { - continue; - } - - if (cuid.compareTo(tokenCUIDStart) < 0) { - continue; - } - - } - - mappingConfigName = prefix + ".mapping." + mappingId + ".filter.tokenCUID.end"; - - CMS.debug("MappingTokenProfileResolver.getTokenType: mappingConfigName: " + mappingConfigName); - - String tokenCUIDEnd = null; - try { - tokenCUIDEnd = configStore.getString(mappingConfigName, null); - } catch (EBaseException e) { - throw new TPSException( - "MappingTokenProfileResolver.getTokenType: Internal error obtaining config value. Config: " - + mappingConfigName, - TPSStatus.STATUS_ERROR_DEFAULT_TOKENTYPE_NOT_FOUND); - } - - CMS.debug("MappingTokenProfileResolver.getTokenType: tokenCUIDEnd: " + tokenCUIDEnd); - - if (tokenCUIDEnd != null && tokenCUIDEnd.length() > 0) { - if (cuid == null) { - continue; - } - - if (tokenCUIDEnd.length() != 20) { - continue; - } - - if (cuid.compareTo(tokenCUIDEnd) > 0) { - continue; - } - - } - - mappingConfigName = prefix + ".mapping." + mappingId + ".filter.appletMajorVersion"; - - CMS.debug("MappingTokenProfileResolver.getTokenType: mappingConfigName: " + mappingConfigName); - - String majorVersion = null; - String minorVersion = null; - - try { - majorVersion = configStore.getString(mappingConfigName, null); - } catch (EBaseException e) { - throw new TPSException( - "MappingTokenProfileResolver.getTokenType: Internal error obtaining config value. Config: " - + mappingConfigName, - TPSStatus.STATUS_ERROR_DEFAULT_TOKENTYPE_NOT_FOUND); - } - - CMS.debug("MappingTokenProfileResolver.getTokenType: majorVersion: " + majorVersion); - if (majorVersion != null && majorVersion.length() > 0) { - - int major = Integer.parseInt(majorVersion); - - if (major != major_version) { - continue; - } - } - - mappingConfigName = prefix + ".mapping." + mappingId + ".filter.appletMinorVersion"; - - CMS.debug("MappingTokenProfileResolver.getTokenType: mappingConfigName: " + mappingConfigName); - - try { - minorVersion = configStore.getString(mappingConfigName, null); - } catch (EBaseException e) { - throw new TPSException( - "MappingTokenProfileResolver.getTokenType: Internal error obtaining config value. Config: " - + mappingConfigName, - TPSStatus.STATUS_ERROR_DEFAULT_TOKENTYPE_NOT_FOUND); - } - CMS.debug("MappingTokenProfileResolver.getTokenType: minorVersion " + minorVersion); - - if (minorVersion != null && minorVersion.length() > 0) { - - int minor = Integer.parseInt(minorVersion); - - if (minor != minor_version) { - continue; - } - } - - //if we make it this far, we have a token type - CMS.debug("MappingTokenProfileResolver.getTokenType: Selected Token type: " + targetTokenType); - break; - } - - if (targetTokenType == null) { - CMS.debug("MappingTokenProfileResolver.getTokenType: end found: " + targetTokenType); - throw new TPSException("MappingTokenProfileResolver.getTokenType: Can't find token type!", - TPSStatus.STATUS_ERROR_DEFAULT_TOKENTYPE_NOT_FOUND); - } - - return targetTokenType; - - } - -} diff --git a/base/tps/src/org/dogtagpki/server/tps/profile/TokenProfileParams.java b/base/tps/src/org/dogtagpki/server/tps/profile/TokenProfileParams.java deleted file mode 100644 index d04bc9fb8..000000000 --- a/base/tps/src/org/dogtagpki/server/tps/profile/TokenProfileParams.java +++ /dev/null @@ -1,145 +0,0 @@ -// --- BEGIN COPYRIGHT BLOCK --- -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; version 2 of the License. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License along -// with this program; if not, write to the Free Software Foundation, Inc., -// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -// -// (C) 2014 Red Hat, Inc. -// All rights reserved. -// --- END COPYRIGHT BLOCK --- -package org.dogtagpki.server.tps.profile; - -import java.util.HashMap; -import java.util.Map; -import java.util.Set; - -import org.dogtagpki.tps.main.TPSException; -import org.dogtagpki.tps.msg.EndOpMsg.TPSStatus; - -import com.netscape.certsrv.apps.CMS; - -/** - * A class represents profile params information. - *

- * - * @version $Revision$, $Date$ - */ -public class TokenProfileParams { - - public static final String PROFILE_PARAM_MAJOR_VERSION = "pp_major_version"; - public static final String PROFILE_PARAM_MINOR_VERSION = "pp_minor_version"; - public static final String PROFILE_PARAM_CUID = "pp_cuid"; - public static final String PROFILE_PARAM_MSN = "pp_msn"; - public static final String PROFILE_PARAM_EXT_TOKEN_TYPE = "pp_ext_tokenType"; - public static final String PROFILE_PARAM_EXT_TOKEN_ATR = "pp_ext_tokenATR"; - - private HashMap content = new HashMap(); - - /** - * Constructs a meta information. - *

- */ - public TokenProfileParams() { - } - - /** - * Returns a short string describing this certificate attribute. - *

- * - * @return information about this certificate attribute. - */ - public String toString() { - StringBuffer sb = new StringBuffer("[\n" + " Meta information:\n"); - - for (Map.Entry entry : content.entrySet()) { - String key = entry.getKey(); - - sb.append(" " + key + " : " + entry.getValue() + "\n"); - } - sb.append("]\n"); - return sb.toString(); - } - - /** - * Gets a String attribute value. - *

- * - * @param name the name of the attribute to return. - */ - public String getString(String name) - throws TPSException { - String val = content.get(name); - if (val == null) { - CMS.debug("TokenProfileParams.getString: param null:"+ name); - throw new TPSException ( - "TokenProfileParams.getString: param null:"+ name, - TPSStatus.STATUS_ERROR_DEFAULT_TOKENTYPE_PARAMS_NOT_FOUND); - } - return val; - } - - /** - * Gets an int attribute value. - *

- * - * @param name the name of the attribute to return. - */ - public int getInt(String name) - throws TPSException { - String val = content.get(name); - if (val == null) { - CMS.debug("TokenProfileParams.getInt: param null:"+ name); - throw new TPSException ( - "TokenProfileParams.getInt: param null:"+ name, - TPSStatus.STATUS_ERROR_DEFAULT_TOKENTYPE_PARAMS_NOT_FOUND); - } - try { - int intVal = Integer.parseInt(val); - return intVal; - } catch (NumberFormatException e) { - CMS.debug("TokenProfileParams.getInt: param "+ name + "=" + val + e); - throw new TPSException ( - "TokenProfileParams.getInt: param major_version:"+ e, - TPSStatus.STATUS_ERROR_MISCONFIGURATION); - } - } - - /** - * Sets an attribute value. - * - * @param name the name of the attribute - * @param val the attribute value. - */ - public void set(String name, String val) { - content.put(name, val); - } - - /** - * Deletes an attribute value from this AttrSet. - *

- * - * @param name the name of the attribute to delete. - */ - public void delete(String name) { - content.remove(name); - } - - /** - * Returns an enumeration of the names of the attributes existing within - * this attribute. - *

- * - * @return an enumeration of the attribute names. - */ - public Set getElements() { - return content.keySet(); - } -} diff --git a/base/tps/src/org/dogtagpki/server/tps/profile/TokenProfileResolverManager.java b/base/tps/src/org/dogtagpki/server/tps/profile/TokenProfileResolverManager.java deleted file mode 100644 index b6325fcca..000000000 --- a/base/tps/src/org/dogtagpki/server/tps/profile/TokenProfileResolverManager.java +++ /dev/null @@ -1,114 +0,0 @@ -// --- BEGIN COPYRIGHT BLOCK --- -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; version 2 of the License. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License along -// with this program; if not, write to the Free Software Foundation, Inc., -// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -// -// (C) 2014 Red Hat, Inc. -// All rights reserved. -// --- END COPYRIGHT BLOCK --- - -package org.dogtagpki.server.tps.profile; - -import java.util.HashMap; - -import com.netscape.certsrv.apps.CMS; -import com.netscape.certsrv.base.EBaseException; -import com.netscape.certsrv.base.IConfigStore; -import com.netscape.certsrv.registry.IPluginInfo; -import com.netscape.certsrv.registry.IPluginRegistry; - -/** - * TokenProfileResolverManager is a class for profile resolver plugin - * management - * - * @author cfu - */ -public class TokenProfileResolverManager -{ - private static final String TOKEN_PROFILE_RESOLVER_TYPE = "tpsTokenProfileResolver"; - public static final String PROP_RESOLVER_LIST = "list"; - public static final String PROP_RESOLVER_CLASS_ID = "class_id"; - - protected static final String TOKEN_PROFILE_RESOLVER_CFG = "tokenProfileResolver"; - protected IPluginRegistry registry = null; - protected HashMap tokenProfileResolvers = null; - - public TokenProfileResolverManager() { - tokenProfileResolvers = new HashMap(); - } - - /** - * initializes all profile resolver plugin instances specified in - * /conf/registry.cfg - * - * configuration e.g. - * - * registry.cfg: - * types=tpsTokenProfileResolver - * tpsProfileResolver.ids=mappingTokenProfileResolverImpl - * tpsProfileResolver.mappingTokenProfileResolverImpl.class=org.dogtagpki.server.tps.profile.MappingTokenProfileResolver - * tpsProfileResolver.mappingTokenProfileResolverImpl.desc=Mapping-based Token profile resolver - * tpsProfileResolver.mappingTokenProfileResolverImpl.name=Mapping-based Token profile resolver - * - * CS.cfg : - * registry.file=/var/lib/pki/pki-tomcat/conf/tps/registry.cfg - * tokenProfileResolver.list=formatMappingResolver,enrollMappingResolver,pinResetMappingResolver - * tokenProfileResolver.formatMappingResolver.class_id=mappingProfileResolverImpl - * tokenProfileResolver.formatMappingResolver.[plugin-specific configuration] - * - * op.format.tokenProfileResolver=formatMappingResolver - * ... - * op.enroll.tokenProfileResolver=enrollMappingResolver - * - * Note: "none" indicates no resolver plugin applied - * op.format.tokenProfileResolver=none - */ - public void initProfileResolverInstances() - throws EBaseException { - - CMS.debug("TokenProfileResolverManager: initProfileResolverInstances(): begins"); - IConfigStore conf = CMS.getConfigStore(); - registry = (IPluginRegistry) CMS.getSubsystem(CMS.SUBSYSTEM_REGISTRY); - if (registry == null) { - CMS.debug("TokenProfileResolverManager: initProfileResolverInstances(): registry null"); - return; - } - - IConfigStore prConf = conf.getSubStore(TOKEN_PROFILE_RESOLVER_CFG); - String profileList = prConf.getString(PROP_RESOLVER_LIST, ""); - - for (String prInst : profileList.split(",")) { - String classID = prConf.getString(prInst + "." + PROP_RESOLVER_CLASS_ID); - CMS.debug("TokenProfileResolverManager: initProfileResolverInstances(): initializing classID=" + classID); - IPluginInfo resolverInfo = - registry.getPluginInfo(TOKEN_PROFILE_RESOLVER_TYPE, classID); - String resolverClass = resolverInfo.getClassName(); - BaseTokenProfileResolver resolver = null; - try { - resolver = (BaseTokenProfileResolver) - Class.forName(resolverClass).newInstance(); - } catch (Exception e) { - // throw Exception - CMS.debug("TokenProfileResolverManager: resolver plugin Class.forName " + - resolverClass + " " + e.toString()); - throw new EBaseException(e.toString()); - } - resolver.init(prInst); - tokenProfileResolvers.put(prInst, resolver); - CMS.debug("TokenProfileResolverManager: initProfileResolverInstances(): resolver instance added: " + prInst); - } - } - - public BaseTokenProfileResolver getResolverInstance(String name) { - return tokenProfileResolvers.get(name); - } -} -- cgit