@Test public void testGetGrantedAuthoritiesAdmin() throws Exception { when(authorizeService.isAdmin(context, ePerson)).thenReturn(true); List<GrantedAuthority> authorities = ePersonRestAuthenticationProvider.getGrantedAuthorities(context, ePerson); assertThat(authorities.stream().map(a -> a.getAuthority()).collect(Collectors.toList()), containsInAnyOrder( WebSecurityConfiguration.ADMIN_GRANT, WebSecurityConfiguration.AUTHENTICATED_GRANT)); }
public List<GrantedAuthority> getGrantedAuthorities(Context context, EPerson eperson) { List<GrantedAuthority> authorities = new LinkedList<>(); if (eperson != null) { boolean isAdmin = false; boolean isCommunityAdmin = false; boolean isCollectionAdmin = false; try { isAdmin = authorizeService.isAdmin(context, eperson); isCommunityAdmin = authorizeService.isCommunityAdmin(context, eperson); isCollectionAdmin = authorizeService.isCollectionAdmin(context, eperson); } catch (SQLException e) { log.error("SQL error while checking for admin rights", e); } if (isAdmin) { authorities.add(new SimpleGrantedAuthority(ADMIN_GRANT)); } else if ((isCommunityAdmin && AuthorizeUtil.canCommunityAdminManageAccounts()) || (isCollectionAdmin && AuthorizeUtil.canCollectionAdminManageAccounts())) { authorities.add(new SimpleGrantedAuthority(MANAGE_ACCESS_GROUP)); } authorities.add(new SimpleGrantedAuthority(AUTHENTICATED_GRANT)); } return authorities; }
EPersonRestAuthenticationProvider implements AuthenticationProvider { public List<GrantedAuthority> getGrantedAuthorities(Context context, EPerson eperson) { List<GrantedAuthority> authorities = new LinkedList<>(); if (eperson != null) { boolean isAdmin = false; boolean isCommunityAdmin = false; boolean isCollectionAdmin = false; try { isAdmin = authorizeService.isAdmin(context, eperson); isCommunityAdmin = authorizeService.isCommunityAdmin(context, eperson); isCollectionAdmin = authorizeService.isCollectionAdmin(context, eperson); } catch (SQLException e) { log.error("SQL error while checking for admin rights", e); } if (isAdmin) { authorities.add(new SimpleGrantedAuthority(ADMIN_GRANT)); } else if ((isCommunityAdmin && AuthorizeUtil.canCommunityAdminManageAccounts()) || (isCollectionAdmin && AuthorizeUtil.canCollectionAdminManageAccounts())) { authorities.add(new SimpleGrantedAuthority(MANAGE_ACCESS_GROUP)); } authorities.add(new SimpleGrantedAuthority(AUTHENTICATED_GRANT)); } return authorities; } }
EPersonRestAuthenticationProvider implements AuthenticationProvider { public List<GrantedAuthority> getGrantedAuthorities(Context context, EPerson eperson) { List<GrantedAuthority> authorities = new LinkedList<>(); if (eperson != null) { boolean isAdmin = false; boolean isCommunityAdmin = false; boolean isCollectionAdmin = false; try { isAdmin = authorizeService.isAdmin(context, eperson); isCommunityAdmin = authorizeService.isCommunityAdmin(context, eperson); isCollectionAdmin = authorizeService.isCollectionAdmin(context, eperson); } catch (SQLException e) { log.error("SQL error while checking for admin rights", e); } if (isAdmin) { authorities.add(new SimpleGrantedAuthority(ADMIN_GRANT)); } else if ((isCommunityAdmin && AuthorizeUtil.canCommunityAdminManageAccounts()) || (isCollectionAdmin && AuthorizeUtil.canCollectionAdminManageAccounts())) { authorities.add(new SimpleGrantedAuthority(MANAGE_ACCESS_GROUP)); } authorities.add(new SimpleGrantedAuthority(AUTHENTICATED_GRANT)); } return authorities; }  }
EPersonRestAuthenticationProvider implements AuthenticationProvider { public List<GrantedAuthority> getGrantedAuthorities(Context context, EPerson eperson) { List<GrantedAuthority> authorities = new LinkedList<>(); if (eperson != null) { boolean isAdmin = false; boolean isCommunityAdmin = false; boolean isCollectionAdmin = false; try { isAdmin = authorizeService.isAdmin(context, eperson); isCommunityAdmin = authorizeService.isCommunityAdmin(context, eperson); isCollectionAdmin = authorizeService.isCollectionAdmin(context, eperson); } catch (SQLException e) { log.error("SQL error while checking for admin rights", e); } if (isAdmin) { authorities.add(new SimpleGrantedAuthority(ADMIN_GRANT)); } else if ((isCommunityAdmin && AuthorizeUtil.canCommunityAdminManageAccounts()) || (isCollectionAdmin && AuthorizeUtil.canCollectionAdminManageAccounts())) { authorities.add(new SimpleGrantedAuthority(MANAGE_ACCESS_GROUP)); } authorities.add(new SimpleGrantedAuthority(AUTHENTICATED_GRANT)); } return authorities; }  @Override Authentication authenticate(Authentication authentication); List<GrantedAuthority> getGrantedAuthorities(Context context, EPerson eperson); @Override boolean supports(Class<?> authentication); }
EPersonRestAuthenticationProvider implements AuthenticationProvider { public List<GrantedAuthority> getGrantedAuthorities(Context context, EPerson eperson) { List<GrantedAuthority> authorities = new LinkedList<>(); if (eperson != null) { boolean isAdmin = false; boolean isCommunityAdmin = false; boolean isCollectionAdmin = false; try { isAdmin = authorizeService.isAdmin(context, eperson); isCommunityAdmin = authorizeService.isCommunityAdmin(context, eperson); isCollectionAdmin = authorizeService.isCollectionAdmin(context, eperson); } catch (SQLException e) { log.error("SQL error while checking for admin rights", e); } if (isAdmin) { authorities.add(new SimpleGrantedAuthority(ADMIN_GRANT)); } else if ((isCommunityAdmin && AuthorizeUtil.canCommunityAdminManageAccounts()) || (isCollectionAdmin && AuthorizeUtil.canCollectionAdminManageAccounts())) { authorities.add(new SimpleGrantedAuthority(MANAGE_ACCESS_GROUP)); } authorities.add(new SimpleGrantedAuthority(AUTHENTICATED_GRANT)); } return authorities; }  @Override Authentication authenticate(Authentication authentication); List<GrantedAuthority> getGrantedAuthorities(Context context, EPerson eperson); @Override boolean supports(Class<?> authentication); static final String MANAGE_ACCESS_GROUP; }