geoportal-data-viewer-app/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/util/CheckAccessPolicyUtil.java

89 lines
1.8 KiB
Java
Raw Normal View History

2021-09-08 15:59:29 +02:00
package org.gcube.portlets.user.geoportaldataviewer.server.util;
2021-09-09 15:55:33 +02:00
2021-09-08 15:59:29 +02:00
/**
2021-09-09 15:55:33 +02:00
* The Class CheckAccessPolicyUtil.
2021-09-08 15:59:29 +02:00
*
2021-09-09 15:55:33 +02:00
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
2021-09-08 15:59:29 +02:00
*
2021-09-09 15:55:33 +02:00
* Sep 9, 2021
2021-09-08 15:59:29 +02:00
*/
2021-09-09 15:55:33 +02:00
public class CheckAccessPolicyUtil {
2021-09-08 15:59:29 +02:00
/**
* The Enum ACCESS_POLICY.
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
*
* Sep 8, 2021
*/
public static enum ACCESS_POLICY {
OPEN, RESTICTED
}
/**
* Checks if is open access.
*
* @param policy the policy
* @return true, if is open access
*/
private static boolean isOpenAccess(String policy) {
if (policy == null || policy.equalsIgnoreCase(ACCESS_POLICY.OPEN.name())) {
return true;
}
return false;
}
/**
* Checks if is restricted access.
*
* @param policy the policy
* @return true, if is restricted access
*/
private static boolean isRestrictedAccess(String policy) {
if (policy == null || policy.equalsIgnoreCase(ACCESS_POLICY.RESTICTED.name())) {
return true;
}
return false;
}
/**
2021-09-09 15:55:33 +02:00
* Checks if is accessible accoding to access policies
2021-09-08 15:59:29 +02:00
*
* @param policy the policy
* @param myLogin the my login
* @return true, if is accessible
*/
public static boolean isAccessible(String policy, String myLogin) {
boolean bool = isOpenAccess(policy);
if (bool) {
// is open access
return true;
}
if (myLogin == null || myLogin.isEmpty()) {
// is not open and the user is not authenticated
return false;
}
// Here the login is not null, so checking if the access to item is RESTICTED
bool = isRestrictedAccess(policy);
if (bool) {
// is restricted access
return true;
}
// Here the user is authenticated, but the policy is not managed, so returning
// true
return true;
}
}