private boolean checkPrivileges(Resource resource, List<Privilege> privileges) { if (privileges == null || privileges.isEmpty()) { return Boolean.FALSE; } Resource currentResource = resource; // QueryService queryService = (QueryService) SpringContextUtil // .getBean(ServiceNames.QUERY_SERVICE); Resource checkResource = resource; if (isIncludeList(checkResource.getId(), privileges)) { currentResource.setPrivilege(Boolean.TRUE); return Boolean.TRUE; } else { if (checkResource.getParentId() == null) { currentResource.setPrivilege(Boolean.FALSE); return Boolean.FALSE; } do { checkResource = queryService.getResource(checkResource.getParentId()); if (isIncludeList(checkResource.getId(), privileges)) { currentResource.setPrivilege(Boolean.TRUE); return Boolean.TRUE; } } while (checkResource.getParentId() != null); } currentResource.setPrivilege(Boolean.FALSE); return Boolean.FALSE; }
@Override public boolean checkReadPermission(Resource resource, Session cs) { if (cs.getPrivileges() != null) { if (checkPrivileges(resource, cs.getPrivileges())) { return true; } } Map<Long, Resource> groupMap = new HashMap<Long, Resource>(); for (Iterator<Resource> it = cs.getGroups().iterator(); it.hasNext(); ) { Resource currGroup = it.next(); groupMap.put(currGroup.getId(), currGroup); } if (resource.getOwnResourceId().equals(cs.getAccount().getResource().getId())) { Byte permission = resource.getCurrentAccountPermission(); if (permission.equals(CommonConstants.PERMISSION.ALL) || permission.equals(CommonConstants.PERMISSION.RW) || permission.equals(CommonConstants.PERMISSION.RX) || permission.equals(CommonConstants.PERMISSION.READ)) { return true; } } if (groupMap.get(resource.getOwnGroupResourceId()) != null) { Byte permission = resource.getCurrentGroupPermission(); if (permission.equals(CommonConstants.PERMISSION.ALL) || permission.equals(CommonConstants.PERMISSION.RW) || permission.equals(CommonConstants.PERMISSION.RX) || permission.equals(CommonConstants.PERMISSION.READ)) { return true; } } Byte permission = resource.getOthersPermission(); if (permission.equals(CommonConstants.PERMISSION.ALL) || permission.equals(CommonConstants.PERMISSION.RW) || permission.equals(CommonConstants.PERMISSION.RX) || permission.equals(CommonConstants.PERMISSION.READ)) { return true; } return false; }