diff options
Diffstat (limited to 'base/common')
-rw-r--r-- | base/common/src/com/netscape/certsrv/client/PKIConnection.java | 48 | ||||
-rw-r--r-- | base/common/src/com/netscape/cms/tomcat/SSLAuthenticatorWithFallback.java | 8 |
2 files changed, 55 insertions, 1 deletions
diff --git a/base/common/src/com/netscape/certsrv/client/PKIConnection.java b/base/common/src/com/netscape/certsrv/client/PKIConnection.java index 4556f1c6a..2a29db207 100644 --- a/base/common/src/com/netscape/certsrv/client/PKIConnection.java +++ b/base/common/src/com/netscape/certsrv/client/PKIConnection.java @@ -1,7 +1,11 @@ package com.netscape.certsrv.client; import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; import java.lang.reflect.Field; import java.lang.reflect.Modifier; import java.net.InetAddress; @@ -28,12 +32,15 @@ import org.apache.http.ProtocolException; import org.apache.http.auth.AuthScope; import org.apache.http.auth.UsernamePasswordCredentials; import org.apache.http.auth.params.AuthPNames; +import org.apache.http.client.CookieStore; import org.apache.http.client.methods.HttpUriRequest; import org.apache.http.client.params.AuthPolicy; import org.apache.http.client.params.HttpClientParams; import org.apache.http.conn.scheme.LayeredSchemeSocketFactory; import org.apache.http.conn.scheme.Scheme; import org.apache.http.conn.scheme.SchemeSocketFactory; +import org.apache.http.cookie.Cookie; +import org.apache.http.impl.client.BasicCookieStore; import org.apache.http.impl.client.ClientParamsStack; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.impl.client.DefaultRedirectStrategy; @@ -62,7 +69,8 @@ public class PKIConnection { ClientConfig config; - DefaultHttpClient httpClient = new DefaultHttpClient(); + DefaultHttpClient httpClient; + CookieStore cookieStore; ResteasyProviderFactory providerFactory; ClientErrorHandler errorHandler; @@ -71,6 +79,9 @@ public class PKIConnection { public PKIConnection(ClientConfig config) { this.config = config; + httpClient = new DefaultHttpClient(); + cookieStore = httpClient.getCookieStore(); + // Register https scheme. Scheme scheme = new Scheme("https", 443, new JSSProtocolSocketFactory()); httpClient.getConnectionManager().getSchemeRegistry().register(scheme); @@ -345,6 +356,41 @@ public class PKIConnection { } + public void loadCookies(File file) throws IOException, ClassNotFoundException { + + if (verbose) System.out.println("Loading cookies from "+file+":"); + + FileInputStream fis = new FileInputStream(file); + ObjectInputStream ois = new ObjectInputStream(fis); + + BasicCookieStore bcs = (BasicCookieStore)ois.readObject(); + + cookieStore.clear(); + for (Cookie cookie : bcs.getCookies()) { + if (verbose) System.out.println(" "+cookie.getName()+": "+cookie.getValue()); + cookieStore.addCookie(cookie); + } + + ois.close(); + } + + public void saveCookies(File file) throws IOException { + + if (verbose) System.out.println("Storing cookies into "+file+":"); + + BasicCookieStore bcs = new BasicCookieStore(); + + for (Cookie cookie : cookieStore.getCookies()) { + if (verbose) System.out.println(" "+cookie.getName()+": "+cookie.getValue()); + bcs.addCookie(cookie); + } + + FileOutputStream fos = new FileOutputStream(file); + ObjectOutputStream oos = new ObjectOutputStream(fos); + oos.writeObject(bcs); + oos.close(); + } + public <T> T createProxy(Class<T> clazz) throws URISyntaxException { URI uri = new URI(config.getServerURI()+"/rest"); return ProxyFactory.create(clazz, uri, executor, providerFactory); diff --git a/base/common/src/com/netscape/cms/tomcat/SSLAuthenticatorWithFallback.java b/base/common/src/com/netscape/cms/tomcat/SSLAuthenticatorWithFallback.java index d1b3dc3f2..2e4d2002a 100644 --- a/base/common/src/com/netscape/cms/tomcat/SSLAuthenticatorWithFallback.java +++ b/base/common/src/com/netscape/cms/tomcat/SSLAuthenticatorWithFallback.java @@ -19,6 +19,7 @@ package com.netscape.cms.tomcat; import java.io.IOException; +import java.security.Principal; import java.security.cert.X509Certificate; import javax.servlet.http.HttpServletRequest; @@ -77,6 +78,13 @@ public class SSLAuthenticatorWithFallback extends AuthenticatorBase { @Override public boolean authenticate(Request request, HttpServletResponse response, LoginConfig config) throws IOException { + log("Session: "+request.getSession().getId()); + Principal principal = request.getPrincipal(); + if (principal != null) { + log("Already authenticated as "+principal.getName()); + return true; + } + X509Certificate certs[] = (X509Certificate[]) request.getAttribute(Globals.CERTIFICATES_ATTR); boolean result; |