Adds methods for displaying authentication status
authorNiels Erik G. Nielsen <nielserik@indexdata.com>
Wed, 1 May 2013 01:13:14 +0000 (21:13 -0400)
committerNiels Erik G. Nielsen <nielserik@indexdata.com>
Wed, 1 May 2013 01:13:14 +0000 (21:13 -0400)
src/main/java/com/indexdata/mkjsf/pazpar2/Pz2ProxyBean.java
src/main/java/com/indexdata/mkjsf/pazpar2/sp/ServiceProxyClient.java
src/main/java/com/indexdata/mkjsf/pazpar2/sp/auth/AuthenticationEntity.java
src/main/java/com/indexdata/mkjsf/pazpar2/sp/auth/ServiceProxyUser.java

index 09e500a..f5c0ad0 100644 (file)
@@ -94,6 +94,10 @@ public class Pz2ProxyBean extends Pz2Bean implements ServiceProxyInterface {
     return ((ServiceProxyClient)searchClient).getServiceProxyUrl();\r
   }\r
   \r
+  public boolean getServiceProxyUrlIsDefined() {\r
+    return ((ServiceProxyClient)searchClient).getServiceProxyUrl().length()>0;\r
+  }\r
+  \r
   public List<String> getServiceProxyUrls() {\r
     List<String> urls = new ArrayList<String>();\r
     urls.add("");\r
index fb3c867..92e46a7 100644 (file)
@@ -109,10 +109,10 @@ public class ServiceProxyClient implements SearchClient {
       String responseStr = new String(response,"UTF-8");\r
       logger.info(responseStr);      \r
       if (responseStr.contains("FAIL")) {\r
-        user.isAuthenticated(false);\r
+        user.credentialsAuthenticationSucceeded(false);\r
         return false;\r
       } else {\r
-        user.isAuthenticated(true);\r
+        user.credentialsAuthenticationSucceeded(true);\r
         return true;\r
       }      \r
     } catch (ClientProtocolException e) {\r
@@ -132,10 +132,9 @@ public class ServiceProxyClient implements SearchClient {
       logger.info(new String(response,"UTF-8"));\r
       String responseStr = new String(response,"UTF-8");    \r
       if (responseStr.contains("FAIL")) {  \r
-        user.isAuthenticated(false);\r
+        user.authenticationCheckFailed();\r
         return false;\r
-      } else {        \r
-        user.isAuthenticated(true);\r
+      } else {                \r
         return true;\r
       }      \r
     } catch (ClientProtocolException e) {\r
@@ -155,10 +154,10 @@ public class ServiceProxyClient implements SearchClient {
       logger.info(new String(response,"UTF-8"));\r
       String responseStr = new String(response,"UTF-8");    \r
       if (responseStr.contains("FAIL")) {\r
-        user.isAuthenticated(false);\r
+        user.ipAuthenticationSucceeded(false);        \r
         return false;\r
       } else {\r
-        user.isAuthenticated(true);\r
+        user.ipAuthenticationSucceeded(true);\r
         return true;\r
       }      \r
     } catch (ClientProtocolException e) {\r
index 9f8b0cb..8d05fd6 100644 (file)
@@ -1,7 +1,6 @@
 package com.indexdata.mkjsf.pazpar2.sp.auth;\r
 \r
 import java.io.Serializable;\r
-import java.util.List;\r
 import java.util.Map;\r
 \r
 public interface AuthenticationEntity extends Serializable{\r
@@ -10,7 +9,5 @@ public interface AuthenticationEntity extends Serializable{
   public String getProperty(String key); \r
   \r
   public Map<String,String> getPropertyMap();\r
-\r
-  public List<String> getPossibleProperties();\r
   \r
 }\r
index 43971df..0c4cb92 100644 (file)
@@ -1,8 +1,6 @@
 package com.indexdata.mkjsf.pazpar2.sp.auth;\r
 \r
-import java.util.Arrays;\r
 import java.util.HashMap;\r
-import java.util.List;\r
 import java.util.Map;\r
 \r
 import javax.enterprise.context.SessionScoped;\r
@@ -16,11 +14,12 @@ import com.indexdata.mkjsf.utils.Utils;
 public class ServiceProxyUser implements AuthenticationEntity {\r
 \r
   private static final long serialVersionUID = 2351542518778803071L;\r
-  private List<String> possibleProperties = Arrays.asList("name","password","realm");\r
   private Map<String,String> actualProperties = new HashMap<String,String>();\r
   private static Logger logger = Logger.getLogger(ServiceProxyUser.class);\r
-  private boolean authenticated = false;\r
+  private boolean credsAuthenticated = false;\r
   private boolean ipAuthenticated = false;\r
+  private boolean ipAuthFailure = false;\r
+  private boolean credsAuthFailure = false;  \r
 \r
   public ServiceProxyUser()  {\r
     logger.debug("ServiceProxyUser instantiated: " + Utils.objectId(this));\r
@@ -50,22 +49,59 @@ public class ServiceProxyUser implements AuthenticationEntity {
     return actualProperties.get("realm");\r
   }\r
    \r
-  public void isAuthenticated(boolean authenticated) {\r
-    this.authenticated = authenticated;\r
+  public void credentialsAuthenticationSucceeded (boolean success) {\r
+    this.credsAuthFailure = !success;\r
+    this.credsAuthenticated = success;\r
+    this.ipAuthenticated = false;\r
+    this.ipAuthFailure = false;\r
   }\r
   \r
-  public void isIpAuthenticated (boolean authenticated) {\r
-    this.ipAuthenticated = authenticated;\r
+  public void ipAuthenticationSucceeded (boolean success) {\r
+    this.ipAuthFailure = !success;    \r
+    this.ipAuthenticated = success;\r
+    this.credsAuthenticated = false;\r
+    this.credsAuthFailure = false;\r
   }\r
   \r
   public boolean isAuthenticated() {\r
-    return authenticated;\r
+    return (ipAuthenticated || credsAuthenticated);\r
   }\r
   \r
   public boolean isIpAuthenticated () {\r
     return ipAuthenticated;\r
   }\r
   \r
+  public boolean isCredentialsAuthenticated () {\r
+    return credsAuthenticated;\r
+  }\r
+  \r
+  public boolean hasIpAuthFailure () {\r
+    return ipAuthFailure;\r
+  }\r
+  \r
+  public boolean hasCredsAuthFailure () {\r
+    return credsAuthFailure;\r
+  }\r
+  \r
+  public boolean hasAuthenticationFailure () {\r
+    return credsAuthFailure || ipAuthFailure;\r
+  }\r
+  \r
+  public void authenticationCheckFailed () {\r
+    ipAuthenticated = false;\r
+    credsAuthenticated = false;\r
+  }\r
+  \r
+  public String getAuthenticationStatus () {\r
+    return (isAuthenticated() ? \r
+              (isIpAuthenticated()? "IP authenticated" : \r
+                 (isCredentialsAuthenticated() ? "Authenticated by credentials" : "Unknown authentication method")) :\r
+              (hasAuthenticationFailure() ? \r
+                  (hasIpAuthFailure() ? "Authentication by IP address failed" :\r
+                      (hasCredsAuthFailure() ? "Authentication by credentials failed" : "Unknown authentication failure")) :\r
+                "Not authenticated"));\r
+  }\r
+  \r
 \r
   @Override\r
   public String getProperty(String key) {\r
@@ -76,16 +112,15 @@ public class ServiceProxyUser implements AuthenticationEntity {
   public Map<String, String> getPropertyMap() {\r
     return actualProperties;\r
   }\r
-\r
-  @Override\r
-  public List<String> getPossibleProperties() {\r
-    return possibleProperties;\r
-  } \r
   \r
   public void clear() {\r
     actualProperties = new HashMap<String,String>();\r
-    authenticated = false;\r
-    ipAuthenticated = false;\r
+    credsAuthenticated = false;\r
+    ipAuthenticated = false;    \r
+  }\r
+  \r
+  public void setSpResponse (String responseXml) {\r
+    \r
   }\r
   \r
 \r