DocumentrPermissionEvaluator implements PermissionEvaluator { public boolean isAdmin(String loginName) { try { UserDetails user = userDetailsService.loadUserByUsername(loginName); return hasApplicationPermission(user.getAuthorities(), Permission.ADMIN); } catch (UsernameNotFoundException e) { } return false; }  @Override boolean hasPermission(Authentication authentication, Object targetDomainObject, Object permission); @Override boolean hasPermission(Authentication authentication, Serializable targetId, String targetType,
			Object permission); boolean hasApplicationPermission(Authentication authentication, Permission permission); boolean hasProjectPermission(Authentication authentication, String projectName, Permission permission); boolean hasAnyProjectPermission(Authentication authentication, Permission permission); boolean hasBranchPermission(Authentication authentication, String projectName, String branchName,
			Permission permission); boolean hasAnyBranchPermission(Authentication authentication, String projectName, Permission permission); boolean hasPagePermission(Authentication authentication, String projectName, String branchName,
			String path, Permission permission); boolean hasPagePermissionInOtherBranches(Authentication authentication, String projectName,
			String branchName, String path, Permission permission); Set<String> getBranchesForPermission(Authentication authentication, Permission permission); boolean isAdmin(String loginName); boolean isLastAdminRole(String roleName);  }
@Test public void isAdmin() { when(userDetailsService.loadUserByUsername(USER)).thenReturn(userDetails); GrantedAuthority authority = new PermissionGrantedAuthority(GrantedAuthorityTarget.APPLICATION, Permission.ADMIN); doReturn(Sets.newHashSet(authority)).when(userDetails).getAuthorities(); assertTrue(permissionEvaluator.isAdmin(USER)); GrantedAuthorityTarget target = new GrantedAuthorityTarget("project", GrantedAuthorityTarget.Type.PROJECT); authority = new PermissionGrantedAuthority(target, Permission.ADMIN); doReturn(Sets.newHashSet(authority)).when(userDetails).getAuthorities(); assertFalse(permissionEvaluator.isAdmin(USER)); target = new GrantedAuthorityTarget("project", GrantedAuthorityTarget.Type.PROJECT); authority = new PermissionGrantedAuthority(target, Permission.VIEW); doReturn(Sets.newHashSet(authority)).when(userDetails).getAuthorities(); assertFalse(permissionEvaluator.isAdmin(USER)); }