added scope validator method

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portal/portal-auth-library@142253 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Massimiliano Assante 2017-02-06 13:32:04 +00:00
parent 64c211a8aa
commit 7c864237c6
1 changed files with 21 additions and 1 deletions

View File

@ -1,8 +1,8 @@
package org.gcube.portal.auth;
import static org.gcube.common.authorization.client.Constants.authorizationService;
import static org.gcube.resources.discovery.icclient.ICFactory.client;
import static org.gcube.resources.discovery.icclient.ICFactory.clientFor;
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
import static org.gcube.resources.discovery.icclient.ICFactory.client;
import java.io.IOException;
import java.io.InputStream;
@ -27,6 +27,10 @@ import org.gcube.common.resources.gcore.utils.Group;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.resources.discovery.client.api.DiscoveryClient;
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
import org.gcube.vomanagement.usermanagement.GroupManager;
import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault;
import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException;
import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -217,5 +221,21 @@ public class AuthUtil {
else
return null;
}
/**
* check if the context exists
* @param context
* @return <code>true</code> if the scope is valid and exists or <code>false</code> otherwise
*/
public boolean isValidContext(String context) {
GroupManager gm = new LiferayGroupManager();
try {
long groupId = gm.getGroupIdFromInfrastructureScope(context);
return (groupId > 0);
} catch (IllegalArgumentException | UserManagementSystemException | GroupRetrievalFault e) {
_log.error("Something wrong in the Context parameter: " + context + " -> " +e.getMessage());
return false;
}
}
}