@ -2,7 +2,9 @@ package org.gcube.portlets.widgets.wsthreddssync.server;
import java.util.ArrayList ;
import java.util.Collections ;
import java.util.HashMap ;
import java.util.List ;
import java.util.Map ;
import java.util.Set ;
import org.gcube.common.portal.PortalContext ;
@ -73,7 +75,7 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
return true ;
}
catch ( Exception ex ) {
logger . trace ( "Development Mode ON" ) ;
logger . warn ( "Development Mode ON" ) ;
return false ;
}
}
@ -148,6 +150,44 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
return listCtlgs ;
}
/ * *
* Gets the list of Scopes ( Root - VO , VOs and VREs ) for user and the Thredds roles that user has in them .
*
* @param user the user
* @return the VREs and Thredds roles for a given user
* @throws Exception
* /
@Override
public Map < String , GatewayRolesThredds > getScopesWithThreddsRolesForLoggedUser ( ) throws Exception {
logger . info ( "called getScopesWithThreddsRolesForLoggedUser" ) ;
GCubeUser user = null ;
Map < String , GatewayRolesThredds > mapScopesRoles = null ;
//DEV MODE
if ( ! isWithinPortal ( ) ) {
mapScopesRoles = new HashMap < String , GatewayRolesThredds > ( ) ;
// mapScopesRoles.put( "/gcube/devsec/devVRE", GatewayRolesThredds.THREDDS_PUBLISHER);
// mapScopesRoles.put( "/gcube", GatewayRolesThredds.THREDDS_PUBLISHER);
// mapScopesRoles.put( "/gcube/devNext/NextNext", GatewayRolesThredds.THREDDS_PUBLISHER);
return mapScopesRoles ;
}
try {
user = PortalContext . getConfiguration ( ) . getCurrentUser ( this . getThreadLocalRequest ( ) ) ;
mapScopesRoles = WsUtil . getScopesWithThreddsRolesForUser ( user ) ;
logger . info ( "returning Map(scopes,roles): " + mapScopesRoles ) ;
return mapScopesRoles ;
} catch ( Exception e ) {
String errorMsg = "An error occurred on checking user roles. Refresh the page and try again." ;
logger . error ( "An error occurred on checking user roles for user: " + user , e ) ;
throw new Exception ( errorMsg ) ;
}
}
/ * *
@ -165,7 +205,8 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
// Instanciate the manager
GroupManager groupManager = new LiferayGroupManager ( ) ;
List < GcubeScope > listOfScopes = new ArrayList < GcubeScope > ( ) ;
//DEV MODE
if ( ! isWithinPortal ( ) ) {
listOfScopes . add ( new GcubeScope ( "devVRE" , "/gcube/devsec/devVRE" , GcubeScopeType . VRE ) ) ;
listOfScopes . add ( new GcubeScope ( "NextNext" , "/gcube/devNext/NextNext" , GcubeScopeType . VRE ) ) ;
@ -197,15 +238,9 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
// }
if ( scopeType ! = null ) {
List < GatewayRolesThredds > roles = WsUtil . getThreddsRoleFor ( user , gCubeGroup ) ;
//Adding only the scope where the user has the (GatewayRolesThredds.THREDDS_ADMIN role
/ * if ( roles ! = null & & roles . size ( ) > 0 & & roles . contains ( GatewayRolesThredds . THREDDS_ADMIN ) ) {
GcubeScope gcubeScope = new GcubeScope ( gCubeGroup . getGroupName ( ) , groupManager . getInfrastructureScope ( gCubeGroup . getGroupId ( ) ) , scopeType ) ;
listOfScopes . add ( gcubeScope ) ;
} * /
GatewayRolesThredds roles = WsUtil . getThreddsRoleFor ( user , gCubeGroup ) ;
//Adding only the scope where the user has the THREDDS_ADMIN role
GcubeScope gcubeScope = availableScopeForRole ( roles , gCubeGroup , groupManager , scopeType ) ;
GcubeScope gcubeScope = availableScopeForRoleAndCatalogue ( roles , gCubeGroup , groupManager , scopeType ) ;
if ( gcubeScope ! = null ) {
listOfScopes . add ( gcubeScope ) ;
}
@ -213,15 +248,9 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
}
GCubeGroup theRootVO = groupManager . getRootVO ( ) ;
List < GatewayRolesThredds > roles = WsUtil . getThreddsRoleFor ( user , theRootVO ) ;
//ADDING THE ROOT SCOPE
/ * if ( roles ! = null & & roles . size ( ) > 0 & & roles . contains ( GatewayRolesThredds . THREDDS_ADMIN ) ) {
GcubeScope gcubeScope = new GcubeScope ( theRootVO . getGroupName ( ) , groupManager . getInfrastructureScope ( theRootVO . getGroupId ( ) ) , GcubeScopeType . ROOT ) ;
listOfScopes . add ( gcubeScope ) ;
} * /
///ADDING THE ROOT SCOPE if the user has the THREDDS_ADMIN role in the scope
GcubeScope gcubeScope = availableScopeForRole ( roles , theRootVO , groupManager , GcubeScopeType . ROOT ) ;
GatewayRolesThredds roles = WsUtil . getThreddsRoleFor ( user , theRootVO ) ;
///ADDING THE ROOT SCOPE if the user has the THREDDS_ADMIN role in the ROOT-VO
GcubeScope gcubeScope = availableScopeForRoleAndCatalogue ( roles , theRootVO , groupManager , GcubeScopeType . ROOT ) ;
if ( gcubeScope ! = null ) {
listOfScopes . add ( gcubeScope ) ;
}
@ -244,29 +273,29 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
}
Collections . sort ( listOfScopes ) ;
logger . info ( "Returning list of VRE s: "+ listOfScopes ) ;
logger . info ( "Returning list of allowed scope/s with: "+ GatewayRolesThredds . THREDDS_ADMIN + " role/ s: "+ listOfScopes ) ;
return listOfScopes ;
}
/ * *
* Available scope for role and catalogue , checks if for the input scope :
* - the user has the role { @link GatewayRolesThredds . # THREDDS_ADMIN } alid catalogue configured for thredds
* - the scope has an available thredds catalogue configured ( by calling the service )
*
* @param role s the role s
* - the user has the role { @link GatewayRolesThredds . # THREDDS_ADMIN }
* - the scope has an available thredds catalogue configured
*
* @param role the role
* @param scope the scope
* @param groupManager the group manager
* @param scopeType the scope type
* @return the gcube scope { @link GcubeScope } if the two conditions ( see description ) are satisfied , null otherwise
* @throws Exception the exception
* /
private GcubeScope availableScopeForRoleAndCatalogue ( List< GatewayRolesThredds> role s , GCubeGroup scope , GroupManager groupManager , GcubeScopeType scopeType ) throws Exception {
private GcubeScope availableScopeForRoleAndCatalogue ( GatewayRolesThredds role , GCubeGroup scope , GroupManager groupManager , GcubeScopeType scopeType ) throws Exception {
if ( role s ! = null & & role s. size ( ) > 0 & & roles . contain s( GatewayRolesThredds . THREDDS_ADMIN ) ) {
if ( role ! = null & & role . equal s( GatewayRolesThredds . THREDDS_ADMIN ) ) {
try {
List < ThCatalogueBean > list = getAvailableCataloguesForScope ( scope . getGroupName ( ) ) ;
if ( list ! = null & & list . size ( ) > 0 ) {
if ( list ! = null ) {
return new GcubeScope ( scope . getGroupName ( ) , groupManager . getInfrastructureScope ( scope . getGroupId ( ) ) , scopeType ) ;
}
} catch ( Exception e ) {
@ -279,17 +308,17 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
/ * *
* Available scope for role , checks if for the input scope the user has the role of { @link GatewayRolesThredds . # THREDDS_ADMIN }
*
* @param role s the role s
*
* @param role the role
* @param scope the scope
* @param groupManager the group manager
* @param scopeType the scope type
* @return the gcube scope { @link GcubeScope } if the user has the role of { @link GatewayRolesThredds . # THREDDS_ADMIN } , null otherwise
* @throws Exception the exception
* /
private GcubeScope availableScopeForRole ( List< GatewayRolesThredds> role s , GCubeGroup scope , GroupManager groupManager , GcubeScopeType scopeType ) throws Exception {
private GcubeScope availableScopeForRole ( GatewayRolesThredds role , GCubeGroup scope , GroupManager groupManager , GcubeScopeType scopeType ) throws Exception {
if ( role s ! = null & & role s. size ( ) > 0 & & roles . contain s( GatewayRolesThredds . THREDDS_ADMIN ) ) {
if ( role ! = null & & role . equal s( GatewayRolesThredds . THREDDS_ADMIN ) ) {
return new GcubeScope ( scope . getGroupName ( ) , groupManager . getInfrastructureScope ( scope . getGroupId ( ) ) , scopeType ) ;
}
return null ;