|
From: <pe...@us...> - 2003-12-15 23:32:43
|
Update of /cvsroot/neuclear/neuclear-commons/src/java/org/neuclear/commons/crypto/signers
In directory sc8-pr-cvs1:/tmp/cvs-serv26173/src/java/org/neuclear/commons/crypto/signers
Modified Files:
ServletSignerFactory.java
Log Message:
added ServletTools.getInitParam() which first tries the ServletConfig, then the context config.
All the web.xml's have been updated to support this. Also various further generalizations have been done throughout
for getServiceid(), getTitle(), getSigner()
Index: ServletSignerFactory.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-commons/src/java/org/neuclear/commons/crypto/signers/ServletSignerFactory.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** ServletSignerFactory.java 15 Dec 2003 14:38:23 -0000 1.2
--- ServletSignerFactory.java 15 Dec 2003 23:32:40 -0000 1.3
***************
*** 3,6 ****
--- 3,7 ----
import org.neuclear.commons.Utility;
import org.neuclear.commons.NeuClearException;
+ import org.neuclear.commons.servlets.ServletTools;
import org.neuclear.commons.crypto.CryptoTools;
import org.neuclear.commons.crypto.passphraseagents.*;
***************
*** 39,54 ****
map=Collections.synchronizedMap(new HashMap());
}
-
public synchronized Signer createSigner(ServletConfig config) throws FileNotFoundException, GeneralSecurityException, NeuClearException {
! final String keystore=config.getInitParameter("keystore");
! final String keeppassphrase=config.getInitParameter("keeppassphrase");
! final String agenttype=config.getInitParameter("passphraseagent");
! final String serviceid = config.getInitParameter("serviceid");
final String hash = getConfigHash(keystore, keeppassphrase, agenttype,serviceid);
if (map.containsKey(hash))
return (Signer)map.get(hash);
! final InteractiveAgent coreagent=getAgent(agenttype);
! final PassPhraseAgent agent=(!Utility.isEmpty(keeppassphrase)&&keeppassphrase.equals("1"))?(PassPhraseAgent)new AskAtStartupAgent(coreagent,serviceid):coreagent;
// If keystore is "test" setup the TestCaseSigner otherwise use the JCESigner
final Signer signer=createSigner(keystore, agent);
--- 40,54 ----
map=Collections.synchronizedMap(new HashMap());
}
public synchronized Signer createSigner(ServletConfig config) throws FileNotFoundException, GeneralSecurityException, NeuClearException {
! final String keystore=ServletTools.getInitParam("keystore",config);
! final String keeppassphrase=ServletTools.getInitParam("keeppassphrase",config);
! final String agenttype=ServletTools.getInitParam("passphraseagent",config);
! final String serviceid = ServletTools.getInitParam("serviceid",config);
final String hash = getConfigHash(keystore, keeppassphrase, agenttype,serviceid);
if (map.containsKey(hash))
return (Signer)map.get(hash);
! final PassPhraseAgent coreagent=getAgent(agenttype);
! final PassPhraseAgent agent=createWrapperAgent(keeppassphrase, coreagent, serviceid);
// If keystore is "test" setup the TestCaseSigner otherwise use the JCESigner
final Signer signer=createSigner(keystore, agent);
***************
*** 57,64 ****
}
! private JCESigner createSigner(final String keystore, final PassPhraseAgent agent) throws GeneralSecurityException, NeuClearException, FileNotFoundException {
if (!Utility.isEmpty(keystore)){
if (keystore.toLowerCase().equals("test"))
return new TestCaseSigner(agent);
if (!keystore.toLowerCase().equals("default"))
return new JCESigner(keystore,"jks", "SUN",agent);
--- 57,71 ----
}
! private static final PassPhraseAgent createWrapperAgent(final String keeppassphrase, final PassPhraseAgent coreagent, final String serviceid) {
! if (!Utility.isEmpty(keeppassphrase)&&keeppassphrase.equals("1")&&coreagent instanceof InteractiveAgent)
! return new AskAtStartupAgent((InteractiveAgent)coreagent,serviceid);
! return coreagent;
! }
!
! private static final JCESigner createSigner(final String keystore, final PassPhraseAgent agent) throws GeneralSecurityException, NeuClearException, FileNotFoundException {
if (!Utility.isEmpty(keystore)){
if (keystore.toLowerCase().equals("test"))
return new TestCaseSigner(agent);
+
if (!keystore.toLowerCase().equals("default"))
return new JCESigner(keystore,"jks", "SUN",agent);
***************
*** 67,71 ****
}
! private InteractiveAgent getAgent(final String agenttype) {
if (!Utility.isEmpty(agenttype)){
if (agenttype.toLowerCase().equals("console"))
--- 74,78 ----
}
! private static final PassPhraseAgent getAgent(final String agenttype) {
if (!Utility.isEmpty(agenttype)){
if (agenttype.toLowerCase().equals("console"))
***************
*** 73,76 ****
--- 80,85 ----
if (agenttype.toLowerCase().equals("servlet"))
return new ServletPassPhraseAgent();
+ if (agenttype.toLowerCase().equals("test"))
+ return new AlwaysTheSamePassphraseAgent("neuclear");
}
return new GuiDialogAgent(); //The default DialogAgent
|