2015-11-24 19:26:46 +01:00
|
|
|
package org.gcube.common.authorization.library.policies;
|
|
|
|
|
|
|
|
import javax.xml.bind.annotation.XmlAccessType;
|
|
|
|
import javax.xml.bind.annotation.XmlAccessorType;
|
|
|
|
import javax.xml.bind.annotation.XmlRootElement;
|
|
|
|
|
|
|
|
@XmlRootElement
|
|
|
|
@XmlAccessorType(XmlAccessType.FIELD)
|
2016-01-19 18:49:25 +01:00
|
|
|
public class Service2ServicePolicy extends Policy{
|
2015-11-24 19:26:46 +01:00
|
|
|
|
2016-01-19 18:49:25 +01:00
|
|
|
private ServiceAccess client;
|
|
|
|
private String context;
|
2015-11-24 19:26:46 +01:00
|
|
|
private ServiceAccess serviceAccess;
|
2016-02-01 15:14:51 +01:00
|
|
|
private Mode mode = Mode.ALL;
|
|
|
|
|
2016-01-19 18:49:25 +01:00
|
|
|
protected Service2ServicePolicy(){}
|
2015-11-24 19:26:46 +01:00
|
|
|
|
2016-01-19 18:49:25 +01:00
|
|
|
public Service2ServicePolicy(String context, ServiceAccess serviceAccess,
|
|
|
|
ServiceAccess client) {
|
|
|
|
this.context = context;
|
2015-11-24 19:26:46 +01:00
|
|
|
this.serviceAccess = serviceAccess;
|
2016-01-19 18:49:25 +01:00
|
|
|
this.client = client;
|
2015-11-24 19:26:46 +01:00
|
|
|
}
|
2016-01-21 19:37:31 +01:00
|
|
|
|
2016-02-01 15:14:51 +01:00
|
|
|
public Service2ServicePolicy(String context, ServiceAccess serviceAccess,
|
|
|
|
ServiceAccess client, Mode mode) {
|
|
|
|
this(context, serviceAccess, client);
|
|
|
|
this.mode = mode;
|
|
|
|
}
|
|
|
|
|
2015-11-24 19:26:46 +01:00
|
|
|
@Override
|
|
|
|
public PolicyType getPolicyType() {
|
|
|
|
return PolicyType.SERVICE;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getPolicyAsString() {
|
2016-02-01 15:14:51 +01:00
|
|
|
return this.context+","+serviceAccess.getAsString()+","+serviceAccess.getAsString()+"["+mode.toString()+"]";
|
2015-11-24 19:26:46 +01:00
|
|
|
}
|
|
|
|
|
2016-01-19 18:49:25 +01:00
|
|
|
public ServiceAccess getClient() {
|
|
|
|
return client;
|
2015-11-24 19:26:46 +01:00
|
|
|
}
|
|
|
|
|
2016-01-19 18:49:25 +01:00
|
|
|
public String getContext() {
|
|
|
|
return context;
|
2015-11-24 19:26:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public ServiceAccess getServiceAccess() {
|
|
|
|
return serviceAccess;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int hashCode() {
|
|
|
|
final int prime = 31;
|
|
|
|
int result = 1;
|
2016-01-19 18:49:25 +01:00
|
|
|
result = prime * result + ((client == null) ? 0 : client.hashCode());
|
2016-02-01 15:14:51 +01:00
|
|
|
result = prime * result + ((context == null) ? 0 : context.hashCode());
|
|
|
|
result = prime * result + ((mode == null) ? 0 : mode.hashCode());
|
2015-11-24 19:26:46 +01:00
|
|
|
result = prime * result
|
|
|
|
+ ((serviceAccess == null) ? 0 : serviceAccess.hashCode());
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean equals(Object obj) {
|
|
|
|
if (this == obj)
|
|
|
|
return true;
|
|
|
|
if (obj == null)
|
|
|
|
return false;
|
|
|
|
if (getClass() != obj.getClass())
|
|
|
|
return false;
|
2016-01-19 18:49:25 +01:00
|
|
|
Service2ServicePolicy other = (Service2ServicePolicy) obj;
|
|
|
|
if (client == null) {
|
|
|
|
if (other.client != null)
|
2015-11-24 19:26:46 +01:00
|
|
|
return false;
|
2016-01-19 18:49:25 +01:00
|
|
|
} else if (!client.equals(other.client))
|
2015-11-24 19:26:46 +01:00
|
|
|
return false;
|
2016-01-19 18:49:25 +01:00
|
|
|
if (context == null) {
|
|
|
|
if (other.context != null)
|
2015-11-24 19:26:46 +01:00
|
|
|
return false;
|
2016-01-19 18:49:25 +01:00
|
|
|
} else if (!context.equals(other.context))
|
2015-11-24 19:26:46 +01:00
|
|
|
return false;
|
2016-02-01 15:14:51 +01:00
|
|
|
if (mode != other.mode)
|
|
|
|
return false;
|
2015-11-24 19:26:46 +01:00
|
|
|
if (serviceAccess == null) {
|
|
|
|
if (other.serviceAccess != null)
|
|
|
|
return false;
|
|
|
|
} else if (!serviceAccess.equals(other.serviceAccess))
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
2016-02-01 15:14:51 +01:00
|
|
|
|
2015-11-24 19:26:46 +01:00
|
|
|
@Override
|
|
|
|
public String toString() {
|
2016-02-01 15:14:51 +01:00
|
|
|
return "Service2ServicePolicy [id="+getId()+" client=" + client + ", context="
|
|
|
|
+ context + ", serviceAccess=" + serviceAccess + ", mode="
|
|
|
|
+ mode + "]";
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Mode getMode() {
|
|
|
|
return this.mode;
|
2015-11-24 19:26:46 +01:00
|
|
|
}
|
2016-01-19 18:49:25 +01:00
|
|
|
|
2015-11-24 19:26:46 +01:00
|
|
|
|
|
|
|
|
|
|
|
}
|