@Override public void init() { try { userService = UserService.getInstance(); } catch (ServiceException se) { log.error(se, "Unable to initialize User service!"); } }
public static Role getAdminRole() { if (ADMIN_ROLE == null) { // default to Administrator final String rolename = PropertyUtil.get("oskari.user.role.admin", DEFAULT_ADMIN_ROLE_NAME); try { final Role[] roles = UserService.getInstance().getRoles(); for (Role role : roles) { if (rolename.equals(role.getName())) { ADMIN_ROLE = role; break; } } } catch (ServiceException ex) { log.error(ex, "Error getting roles from user service"); } } return ADMIN_ROLE; }
private Resource getSourcePermission(final String layerId, final User user) { if (layerId == null) { return null; } if (layerId.startsWith(AnalysisParser.ANALYSIS_LAYER_PREFIX)) { final Resource resource = new Resource(); resource.setType(AnalysisLayer.TYPE); resource.setMapping( "analysis", Long.toString(AnalysisHelper.getAnalysisIdFromLayerId(layerId))); return permissionsService.findResource(resource); } else if (layerId.startsWith(AnalysisParser.MYPLACES_LAYER_PREFIX) || layerId.equals("-1") || layerId.startsWith(AnalysisParser.USERLAYER_PREFIX)) { final Resource resource = new Resource(); // permission to publish for self final Permission permPublish = new Permission(); permPublish.setExternalType(Permissions.EXTERNAL_TYPE_USER); permPublish.setExternalId("" + user.getId()); permPublish.setType(Permissions.PERMISSION_TYPE_PUBLISH); resource.addPermission(permPublish); try { // add VIEW_PUBLISHED for all roles currently in the system for (Role role : UserService.getInstance().getRoles()) { final Permission perm = new Permission(); perm.setExternalType(Permissions.EXTERNAL_TYPE_ROLE); perm.setExternalId("" + role.getId()); perm.setType(Permissions.PERMISSION_TYPE_VIEW_PUBLISHED); resource.addPermission(perm); } } catch (Exception e) { log.error( "Something went wrong when generating source permissions for myplaces layer or temporary or user data layer"); } return resource; } // default to usual layer final OskariLayer layer = mapLayerService.find(layerId); // copy permissions from source layer to new analysis return permissionsService.getResource( Permissions.RESOURCE_TYPE_MAP_LAYER, new OskariLayerResource(layer).getMapping()); }