Lucio Lelii 2015-07-21 10:39:27 +00:00
parent cb25f11f3d
commit 11d10673d7
5 changed files with 71 additions and 92 deletions

View File

@ -7,8 +7,6 @@ import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import org.gcube.common.authorization.library.provider.Service;
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class AuthorizationEntry {
@ -16,7 +14,7 @@ public class AuthorizationEntry {
private String userName;
private List<String> roles;
private String scope;
private List<Service> bannedServices = new ArrayList<Service>();
private List<BannedService> bannedServices = new ArrayList<BannedService>();
protected AuthorizationEntry(){}
@ -27,7 +25,7 @@ public class AuthorizationEntry {
this.scope = scope;
}
public AuthorizationEntry(String userName, List<String> roles, String scope, List<Service> bannedServices) {
public AuthorizationEntry(String userName, List<String> roles, String scope, List<BannedService> bannedServices) {
this(userName, roles, scope);
this.bannedServices = bannedServices;
}
@ -44,18 +42,18 @@ public class AuthorizationEntry {
return scope;
}
public List<Service> getBannedServices() {
public List<BannedService> getBannedServices() {
return bannedServices;
}
public void setBannedServices(List<Service> bannedServices) {
public void setBannedServices(List<BannedService> bannedServices) {
this.bannedServices = bannedServices;
}
@Override
public String toString() {
return "AuthorizationEntry [userName=" + userName + ", roles=" + roles
+ ", scope=" + scope + "]";
+ ", scope=" + scope + " bannedServices "+ bannedServices+"]";
}

View File

@ -8,7 +8,6 @@ import java.util.List;
import org.gcube.common.authorization.library.annotations.IsAllowedFor;
import org.gcube.common.authorization.library.annotations.SubjectToQuota;
import org.gcube.common.authorization.library.provider.AuthorizationProvider;
import org.gcube.common.authorization.library.provider.Service;
import org.gcube.common.authorization.library.provider.UserInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -47,7 +46,7 @@ public class AuthorizationInvocationHandler<T, I extends T> implements Invocatio
private void checkSubjectToQuota(UserInfo info, Method method){
if(method.isAnnotationPresent(SubjectToQuota.class)){
Service service = new Service(resourceAuthorizationProxy.getServiceClass(), resourceAuthorizationProxy.getServiceName());
BannedService service = new BannedService(resourceAuthorizationProxy.getServiceClass(), resourceAuthorizationProxy.getServiceName());
log.debug("subjectToQuota annotation present, checking for service {} in bannedServices {}",service, info.getBannedServices());
if (info.getBannedServices().contains(service)){
String message = "blocking method "+method.getName()+" for user "+info.getUserName()+": overquota reached";

View File

@ -6,31 +6,81 @@ import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import org.gcube.common.authorization.library.provider.Service;
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class BannedService {
private Service service;
private String serviceClass;
private String serviceName;
private Calendar banTime;
protected BannedService() {
super();
}
public BannedService(Service service, Calendar banTime) {
public BannedService(String serviceClass, String serviceName, Calendar banTime) {
super();
this.service = service;
this.serviceClass = serviceClass;
this.serviceName = serviceName;
this.banTime = banTime;
}
public Service getService() {
return service;
public BannedService(String serviceClass, String serviceName) {
super();
this.serviceClass = serviceClass;
this.serviceName = serviceName;
this.banTime = Calendar.getInstance();
}
public String getServiceClass() {
return serviceClass;
}
public String getServiceName() {
return serviceName;
}
public Calendar getCreationTime() {
return banTime;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result
+ ((serviceClass == null) ? 0 : serviceClass.hashCode());
result = prime * result
+ ((serviceName == null) ? 0 : serviceName.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;
BannedService other = (BannedService) obj;
if (serviceClass == null) {
if (other.serviceClass != null)
return false;
} else if (!serviceClass.equals(other.serviceClass))
return false;
if (serviceName == null) {
if (other.serviceName != null)
return false;
} else if (!serviceName.equals(other.serviceName))
return false;
return true;
}
@Override
public String toString() {
return "BannedService [serviceClass=" + serviceClass + ", serviceName="
+ serviceName + ", banTime=" + banTime.getTimeInMillis() + "]";
}
}

View File

@ -1,70 +0,0 @@
package org.gcube.common.authorization.library.provider;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class Service {
private String serviceClass;
private String serviceName;
protected Service(){}
public Service(String serviceClass, String serviceName) {
super();
this.serviceClass = serviceClass;
this.serviceName = serviceName;
}
public String getServiceClass() {
return serviceClass;
}
public String getServiceName() {
return serviceName;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result
+ ((serviceClass == null) ? 0 : serviceClass.hashCode());
result = prime * result
+ ((serviceName == null) ? 0 : serviceName.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;
Service other = (Service) obj;
if (serviceClass == null) {
if (other.serviceClass != null)
return false;
} else if (!serviceClass.equals(other.serviceClass))
return false;
if (serviceName == null) {
if (other.serviceName != null)
return false;
} else if (!serviceName.equals(other.serviceName))
return false;
return true;
}
@Override
public String toString() {
return "Service [serviceClass=" + serviceClass + ", serviceName="
+ serviceName + "]";
}
}

View File

@ -6,6 +6,8 @@ import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import org.gcube.common.authorization.library.BannedService;
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
@ -13,11 +15,11 @@ public class UserInfo {
private String userName;
private List<String> roles;
private List<Service> bannedServices;
private List<BannedService> bannedServices;
protected UserInfo(){}
public UserInfo(String userName, List<String> roles, List<Service> bannedServices) {
public UserInfo(String userName, List<String> roles, List<BannedService> bannedServices) {
super();
this.userName = userName;
this.roles = roles;
@ -31,11 +33,11 @@ public class UserInfo {
return roles;
}
public List<Service> getBannedServices() {
public List<BannedService> getBannedServices() {
return bannedServices;
}
public boolean isTokenBannedForService(Service service){
public boolean isTokenBannedForService(BannedService service){
return (bannedServices.contains(service));
}