common-authorization/src/main/java/org/gcube/common/authorization/library/policies/EnvironmentPolicy.java

78 lines
1.7 KiB
Java

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)
public class EnvironmentPolicy extends Policy{
private String environment;
private ServiceAccess service;
protected EnvironmentPolicy() {}
public EnvironmentPolicy(String environment, ServiceAccess service) {
super();
this.environment = environment;
this.service = service;
}
@Override
public PolicyType getPolicyType() {
return PolicyType.ENVIRONMENT;
}
@Override
public String getPolicyAsString() {
return service.getAsString();
}
public String getEnvironment() {
return environment;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result
+ ((environment == null) ? 0 : environment.hashCode());
result = prime * result + ((service == null) ? 0 : service.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;
EnvironmentPolicy other = (EnvironmentPolicy) obj;
if (environment == null) {
if (other.environment != null)
return false;
} else if (!environment.equals(other.environment))
return false;
if (service == null) {
if (other.service != null)
return false;
} else if (!service.equals(other.service))
return false;
return true;
}
@Override
public String toString() {
return "EnvironmentPolicy [environment=" + environment + ", service="
+ service + "]";
}
}