Adds methods for displaying authentication status
[mkjsf-moved-to-github.git] / src / main / java / com / indexdata / mkjsf / pazpar2 / sp / auth / ServiceProxyUser.java
index ea0be27..0c4cb92 100644 (file)
@@ -1,26 +1,30 @@
 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
 import javax.inject.Named;\r
 \r
+import org.apache.log4j.Logger;\r
+\r
+import com.indexdata.mkjsf.utils.Utils;\r
+\r
 @Named("user") @SessionScoped\r
 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 credsAuthenticated = false;\r
+  private boolean ipAuthenticated = false;\r
+  private boolean ipAuthFailure = false;\r
+  private boolean credsAuthFailure = false;  \r
 \r
-  public ServiceProxyUser()  {}\r
-  \r
-  public void setAuthenticationMethod() {\r
-    \r
+  public ServiceProxyUser()  {\r
+    logger.debug("ServiceProxyUser instantiated: " + Utils.objectId(this));\r
   }\r
-\r
+  \r
   public String getName() { \r
     return actualProperties.get("name"); \r
   }\r
@@ -44,6 +48,59 @@ public class ServiceProxyUser implements AuthenticationEntity {
   public String getRealm() {\r
     return actualProperties.get("realm");\r
   }\r
+   \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 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 (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
@@ -55,11 +112,16 @@ 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
+    credsAuthenticated = false;\r
+    ipAuthenticated = false;    \r
+  }\r
+  \r
+  public void setSpResponse (String responseXml) {\r
+    \r
+  }\r
   \r
 \r
 }\r