common-authorization/src/main/java/org/gcube/common/authorization/library/AuthorizationEntry.java

133 lines
3.2 KiB
Java
Raw Normal View History

package org.gcube.common.authorization.library;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElementRef;
import javax.xml.bind.annotation.XmlElementRefs;
import javax.xml.bind.annotation.XmlRootElement;
import org.gcube.common.scope.api.ServiceMap;
import org.gcube.common.scope.impl.DefaultServiceMap;
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class AuthorizationEntry {
private String clientId;
private List<String> roles;
private String context;
@XmlElementRefs({@XmlElementRef(type=DefaultServiceMap.class)})
private ServiceMap map;
private List<CalledService> bannedServices = new ArrayList<CalledService>();
protected AuthorizationEntry(){}
public AuthorizationEntry(String clientId, List<String> roles, String context) {
super();
this.clientId = clientId;
this.roles = roles;
this.context = context;
}
public AuthorizationEntry(String userName, List<String> roles, String context , List<CalledService> bannedServices) {
this(userName, roles, context);
this.bannedServices = bannedServices;
}
public String getClientId() {
return clientId;
}
public List<String> getRoles() {
return roles;
}
public String getContext() {
return context;
}
public ServiceMap getMap() {
return map;
}
public void setMap(ServiceMap map) {
this.map = map;
}
public List<CalledService> getBannedServices() {
return bannedServices;
}
public void setBannedServices(List<CalledService> bannedServices) {
this.bannedServices = bannedServices;
}
@Override
public String toString() {
return "AuthorizationEntry [clientId=" + clientId + ", roles=" + roles
+ ", context=" + context + ", map=" + map + ", bannedServices="
+ bannedServices + "]";
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result
+ ((bannedServices == null) ? 0 : bannedServices.hashCode());
result = prime * result
+ ((clientId == null) ? 0 : clientId.hashCode());
result = prime * result + ((context == null) ? 0 : context.hashCode());
result = prime * result + ((map == null) ? 0 : map.hashCode());
result = prime * result + ((roles == null) ? 0 : roles.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;
AuthorizationEntry other = (AuthorizationEntry) obj;
if (bannedServices == null) {
if (other.bannedServices != null)
return false;
} else if (!bannedServices.equals(other.bannedServices))
return false;
if (clientId == null) {
if (other.clientId != null)
return false;
} else if (!clientId.equals(other.clientId))
return false;
if (context == null) {
if (other.context != null)
return false;
} else if (!context.equals(other.context))
return false;
if (map == null) {
if (other.map != null)
return false;
} else if (!map.equals(other.map))
return false;
if (roles == null) {
if (other.roles != null)
return false;
} else if (!roles.equals(other.roles))
return false;
return true;
}
}