@Test public void testGetContextualAuthoritiesNonStaffSelf() { String token = "AQIC5wM2LY4SfczsoqTgHpfSEciO4J34Hc5ThvD0QaM2QUI.*AAJTSQACMDE.*"; Entity princEntity = new MongoEntity(null, "RegularTeacher3", new HashMap<String,Object>(), new HashMap<String,Object>()); SLIPrincipal principal = new SLIPrincipal(); principal.setEntity(princEntity); principal.setUserType(EntityNames.TEACHER); principal.setSelfRights(ADMIN_AUTHS); PreAuthenticatedAuthenticationToken authenticationToken = new PreAuthenticatedAuthenticationToken(principal, token, EDU_AUTHS); SecurityContextHolder.getContext().setAuthentication(authenticationToken); Entity entity = new MongoEntity("teacher", null, new HashMap<String,Object>(), new HashMap<String,Object>()); Collection<GrantedAuthority> auths = service.getContextualAuthorities(true, entity, SecurityUtil.UserContext.TEACHER_CONTEXT,false); Assert.assertEquals("Expected all rights", ALL_AUTHS, auths); }
public Collection<GrantedAuthority> getContextualAuthorities(boolean isSelf, Entity entity, SecurityUtil.UserContext context, boolean isRead){ Collection<GrantedAuthority> auths = new HashSet<GrantedAuthority>(); SLIPrincipal principal = SecurityUtil.getSLIPrincipal(); if (SecurityUtil.isStaffUser()) { if (entity == null) { LOG.trace("No authority for null"); } else { if ((entity.getMetaData() != null && SecurityUtil.principalId().equals(entity.getMetaData().get("createdBy")) && "true".equals(entity.getMetaData().get("isOrphaned"))) || (EntityNames.isPublic(entity.getType()) && !edOrgOwnershipArbiter.isEntityOwnedByEdOrg(entity.getType())) ) { auths.addAll(principal.getAllContextRights(isSelf)); } else if(EntityNames.isPublic(entity.getType()) && principal.getAllContextRights(isSelf).contains(Right.READ_PUBLIC) && isRead) { auths.add(Right.READ_PUBLIC); } else { auths.addAll(entityEdOrgRightBuilder.buildEntityEdOrgContextRights(principal.getEdOrgContextRights(), entity, context, isRead)); } if (isSelf) { auths.addAll(entityEdOrgRightBuilder.buildEntityEdOrgRights(principal.getEdOrgSelfRights(), entity, isRead)); } } } else { Authentication auth = SecurityContextHolder.getContext().getAuthentication(); auths.addAll(auth.getAuthorities()); if (isSelf) { auths.addAll(principal.getSelfRights()); } } return auths; }
RightAccessValidator { public Collection<GrantedAuthority> getContextualAuthorities(boolean isSelf, Entity entity, SecurityUtil.UserContext context, boolean isRead){ Collection<GrantedAuthority> auths = new HashSet<GrantedAuthority>(); SLIPrincipal principal = SecurityUtil.getSLIPrincipal(); if (SecurityUtil.isStaffUser()) { if (entity == null) { LOG.trace("No authority for null"); } else { if ((entity.getMetaData() != null && SecurityUtil.principalId().equals(entity.getMetaData().get("createdBy")) && "true".equals(entity.getMetaData().get("isOrphaned"))) || (EntityNames.isPublic(entity.getType()) && !edOrgOwnershipArbiter.isEntityOwnedByEdOrg(entity.getType())) ) { auths.addAll(principal.getAllContextRights(isSelf)); } else if(EntityNames.isPublic(entity.getType()) && principal.getAllContextRights(isSelf).contains(Right.READ_PUBLIC) && isRead) { auths.add(Right.READ_PUBLIC); } else { auths.addAll(entityEdOrgRightBuilder.buildEntityEdOrgContextRights(principal.getEdOrgContextRights(), entity, context, isRead)); } if (isSelf) { auths.addAll(entityEdOrgRightBuilder.buildEntityEdOrgRights(principal.getEdOrgSelfRights(), entity, isRead)); } } } else { Authentication auth = SecurityContextHolder.getContext().getAuthentication(); auths.addAll(auth.getAuthorities()); if (isSelf) { auths.addAll(principal.getSelfRights()); } } return auths; } }
RightAccessValidator { public Collection<GrantedAuthority> getContextualAuthorities(boolean isSelf, Entity entity, SecurityUtil.UserContext context, boolean isRead){ Collection<GrantedAuthority> auths = new HashSet<GrantedAuthority>(); SLIPrincipal principal = SecurityUtil.getSLIPrincipal(); if (SecurityUtil.isStaffUser()) { if (entity == null) { LOG.trace("No authority for null"); } else { if ((entity.getMetaData() != null && SecurityUtil.principalId().equals(entity.getMetaData().get("createdBy")) && "true".equals(entity.getMetaData().get("isOrphaned"))) || (EntityNames.isPublic(entity.getType()) && !edOrgOwnershipArbiter.isEntityOwnedByEdOrg(entity.getType())) ) { auths.addAll(principal.getAllContextRights(isSelf)); } else if(EntityNames.isPublic(entity.getType()) && principal.getAllContextRights(isSelf).contains(Right.READ_PUBLIC) && isRead) { auths.add(Right.READ_PUBLIC); } else { auths.addAll(entityEdOrgRightBuilder.buildEntityEdOrgContextRights(principal.getEdOrgContextRights(), entity, context, isRead)); } if (isSelf) { auths.addAll(entityEdOrgRightBuilder.buildEntityEdOrgRights(principal.getEdOrgSelfRights(), entity, isRead)); } } } else { Authentication auth = SecurityContextHolder.getContext().getAuthentication(); auths.addAll(auth.getAuthorities()); if (isSelf) { auths.addAll(principal.getSelfRights()); } } return auths; }  }
RightAccessValidator { public Collection<GrantedAuthority> getContextualAuthorities(boolean isSelf, Entity entity, SecurityUtil.UserContext context, boolean isRead){ Collection<GrantedAuthority> auths = new HashSet<GrantedAuthority>(); SLIPrincipal principal = SecurityUtil.getSLIPrincipal(); if (SecurityUtil.isStaffUser()) { if (entity == null) { LOG.trace("No authority for null"); } else { if ((entity.getMetaData() != null && SecurityUtil.principalId().equals(entity.getMetaData().get("createdBy")) && "true".equals(entity.getMetaData().get("isOrphaned"))) || (EntityNames.isPublic(entity.getType()) && !edOrgOwnershipArbiter.isEntityOwnedByEdOrg(entity.getType())) ) { auths.addAll(principal.getAllContextRights(isSelf)); } else if(EntityNames.isPublic(entity.getType()) && principal.getAllContextRights(isSelf).contains(Right.READ_PUBLIC) && isRead) { auths.add(Right.READ_PUBLIC); } else { auths.addAll(entityEdOrgRightBuilder.buildEntityEdOrgContextRights(principal.getEdOrgContextRights(), entity, context, isRead)); } if (isSelf) { auths.addAll(entityEdOrgRightBuilder.buildEntityEdOrgRights(principal.getEdOrgSelfRights(), entity, isRead)); } } } else { Authentication auth = SecurityContextHolder.getContext().getAuthentication(); auths.addAll(auth.getAuthorities()); if (isSelf) { auths.addAll(principal.getSelfRights()); } } return auths; }  void checkAccess(boolean isRead, boolean isSelf, Entity entity, String entityType, Collection<GrantedAuthority> auths); void checkAccess(boolean isRead, String entityId, EntityBody content, String entityType, String collectionName, Repository<Entity> repo, Collection<GrantedAuthority> auths); void checkAccess(boolean isRead, EntityBody entityBody, String entityType, Collection<GrantedAuthority> auths); void checkAccess(boolean isRead, EntityBody entityBody, String entityType, Collection<GrantedAuthority> auths, Entity entity); void checkFieldAccess(NeutralQuery query, Entity entity, String entityType, Collection<GrantedAuthority> auths); void checkFieldAccess(NeutralQuery query, String entityType, Collection<GrantedAuthority> auths); Collection<GrantedAuthority> getContextualAuthorities(boolean isSelf, Entity entity, SecurityUtil.UserContext context, boolean isRead); Set<Right> getNeededRights(String fieldPath, String entityType); boolean intersection(Collection<GrantedAuthority> authorities, Set<Right> neededRights); void checkSecurity(boolean isRead, String entityId, String entityType, String collectionName, Repository<Entity> repo); boolean isEntityAllowed(String entityId, String collectionName, String toType, Repository<Entity> repo); }
RightAccessValidator { public Collection<GrantedAuthority> getContextualAuthorities(boolean isSelf, Entity entity, SecurityUtil.UserContext context, boolean isRead){ Collection<GrantedAuthority> auths = new HashSet<GrantedAuthority>(); SLIPrincipal principal = SecurityUtil.getSLIPrincipal(); if (SecurityUtil.isStaffUser()) { if (entity == null) { LOG.trace("No authority for null"); } else { if ((entity.getMetaData() != null && SecurityUtil.principalId().equals(entity.getMetaData().get("createdBy")) && "true".equals(entity.getMetaData().get("isOrphaned"))) || (EntityNames.isPublic(entity.getType()) && !edOrgOwnershipArbiter.isEntityOwnedByEdOrg(entity.getType())) ) { auths.addAll(principal.getAllContextRights(isSelf)); } else if(EntityNames.isPublic(entity.getType()) && principal.getAllContextRights(isSelf).contains(Right.READ_PUBLIC) && isRead) { auths.add(Right.READ_PUBLIC); } else { auths.addAll(entityEdOrgRightBuilder.buildEntityEdOrgContextRights(principal.getEdOrgContextRights(), entity, context, isRead)); } if (isSelf) { auths.addAll(entityEdOrgRightBuilder.buildEntityEdOrgRights(principal.getEdOrgSelfRights(), entity, isRead)); } } } else { Authentication auth = SecurityContextHolder.getContext().getAuthentication(); auths.addAll(auth.getAuthorities()); if (isSelf) { auths.addAll(principal.getSelfRights()); } } return auths; }  void checkAccess(boolean isRead, boolean isSelf, Entity entity, String entityType, Collection<GrantedAuthority> auths); void checkAccess(boolean isRead, String entityId, EntityBody content, String entityType, String collectionName, Repository<Entity> repo, Collection<GrantedAuthority> auths); void checkAccess(boolean isRead, EntityBody entityBody, String entityType, Collection<GrantedAuthority> auths); void checkAccess(boolean isRead, EntityBody entityBody, String entityType, Collection<GrantedAuthority> auths, Entity entity); void checkFieldAccess(NeutralQuery query, Entity entity, String entityType, Collection<GrantedAuthority> auths); void checkFieldAccess(NeutralQuery query, String entityType, Collection<GrantedAuthority> auths); Collection<GrantedAuthority> getContextualAuthorities(boolean isSelf, Entity entity, SecurityUtil.UserContext context, boolean isRead); Set<Right> getNeededRights(String fieldPath, String entityType); boolean intersection(Collection<GrantedAuthority> authorities, Set<Right> neededRights); void checkSecurity(boolean isRead, String entityId, String entityType, String collectionName, Repository<Entity> repo); boolean isEntityAllowed(String entityId, String collectionName, String toType, Repository<Entity> repo);  }