1 package com.indexdata.mkjsf.pazpar2.sp.auth;
\r
3 import java.util.HashMap;
\r
4 import java.util.Map;
\r
6 import javax.enterprise.context.SessionScoped;
\r
7 import javax.inject.Named;
\r
9 import org.apache.log4j.Logger;
\r
11 import com.indexdata.mkjsf.utils.Utils;
\r
13 @Named("user") @SessionScoped
\r
14 public class ServiceProxyUser implements AuthenticationEntity {
\r
16 private static final long serialVersionUID = 2351542518778803071L;
\r
17 private Map<String,String> actualProperties = new HashMap<String,String>();
\r
18 private static Logger logger = Logger.getLogger(ServiceProxyUser.class);
\r
19 private boolean credsAuthenticated = false;
\r
20 private boolean ipAuthenticated = false;
\r
21 private boolean ipAuthFailure = false;
\r
22 private boolean credsAuthFailure = false;
\r
24 public ServiceProxyUser() {
\r
25 logger.debug("ServiceProxyUser instantiated: " + Utils.objectId(this));
\r
28 public String getName() {
\r
29 return actualProperties.get("name");
\r
32 public void setName(String newValue) {
\r
33 actualProperties.put("name", newValue);
\r
36 public String getPassword() {
\r
37 return actualProperties.get("password");
\r
40 public void setPassword(String newValue) {
\r
41 actualProperties.put("password", newValue);
\r
44 public void setRealm(String realm) {
\r
45 actualProperties.put("realm", realm);
\r
48 public String getRealm() {
\r
49 return actualProperties.get("realm");
\r
52 public void credentialsAuthenticationSucceeded (boolean success) {
\r
53 this.credsAuthFailure = !success;
\r
54 this.credsAuthenticated = success;
\r
55 this.ipAuthenticated = false;
\r
56 this.ipAuthFailure = false;
\r
59 public void ipAuthenticationSucceeded (boolean success) {
\r
60 this.ipAuthFailure = !success;
\r
61 this.ipAuthenticated = success;
\r
62 this.credsAuthenticated = false;
\r
63 this.credsAuthFailure = false;
\r
66 public boolean isAuthenticated() {
\r
67 return (ipAuthenticated || credsAuthenticated);
\r
70 public boolean isIpAuthenticated () {
\r
71 return ipAuthenticated;
\r
74 public boolean isCredentialsAuthenticated () {
\r
75 return credsAuthenticated;
\r
78 public boolean hasIpAuthFailure () {
\r
79 return ipAuthFailure;
\r
82 public boolean hasCredsAuthFailure () {
\r
83 return credsAuthFailure;
\r
86 public boolean hasAuthenticationFailure () {
\r
87 return credsAuthFailure || ipAuthFailure;
\r
90 public void authenticationCheckFailed () {
\r
91 ipAuthenticated = false;
\r
92 credsAuthenticated = false;
\r
95 public String getAuthenticationStatus () {
\r
96 return (isAuthenticated() ?
\r
97 (isIpAuthenticated()? "IP authenticated" :
\r
98 (isCredentialsAuthenticated() ? "Authenticated by credentials" : "Unknown authentication method")) :
\r
99 (hasAuthenticationFailure() ?
\r
100 (hasIpAuthFailure() ? "Authentication by IP address failed" :
\r
101 (hasCredsAuthFailure() ? "Authentication by credentials failed" : "Unknown authentication failure")) :
\r
102 "Not authenticated"));
\r
107 public String getProperty(String key) {
\r
108 return actualProperties.get(key);
\r
112 public Map<String, String> getPropertyMap() {
\r
113 return actualProperties;
\r
116 public void clear() {
\r
117 actualProperties = new HashMap<String,String>();
\r
118 credsAuthenticated = false;
\r
119 ipAuthenticated = false;
\r
122 public void setSpResponse (String responseXml) {
\r