@Test public void testAuthWithoutId() throws Exception { Authentication auth = new UsernamePasswordAuthenticationToken("admin", null); SecurityContextHolder.getContext().setAuthentication(auth); Integer userId = AuthorizationHelper.getAuthenticatedId(); Assert.assertEquals(Integer.valueOf(-1), userId); }
public static int getAuthenticatedId() { SecurityContext securityContext = SecurityContextHolder.getContext(); Authentication authentication = securityContext.getAuthentication(); UserIdAuthentication auth; if (authentication instanceof UserIdAuthentication) { auth = (UserIdAuthentication) authentication; } else { return -1; } return auth.getUserId(); }
AuthorizationHelper { public static int getAuthenticatedId() { SecurityContext securityContext = SecurityContextHolder.getContext(); Authentication authentication = securityContext.getAuthentication(); UserIdAuthentication auth; if (authentication instanceof UserIdAuthentication) { auth = (UserIdAuthentication) authentication; } else { return -1; } return auth.getUserId(); } }
AuthorizationHelper { public static int getAuthenticatedId() { SecurityContext securityContext = SecurityContextHolder.getContext(); Authentication authentication = securityContext.getAuthentication(); UserIdAuthentication auth; if (authentication instanceof UserIdAuthentication) { auth = (UserIdAuthentication) authentication; } else { return -1; } return auth.getUserId(); }  }
AuthorizationHelper { public static int getAuthenticatedId() { SecurityContext securityContext = SecurityContextHolder.getContext(); Authentication authentication = securityContext.getAuthentication(); UserIdAuthentication auth; if (authentication instanceof UserIdAuthentication) { auth = (UserIdAuthentication) authentication; } else { return -1; } return auth.getUserId(); }  Collection<GrantedAuthority> convertPrivilegesToAuthorities(Collection<PrivilegeEntity> privilegeEntities); static String getAuthenticatedName(); static String getAuthenticatedName(String defaultUsername); static int getAuthenticatedId(); static boolean isAuthorized(ResourceType resourceType, Long resourceId, 
                                     RoleAuthorization requiredAuthorization); static boolean isAuthorized(ResourceType resourceType, Long resourceId, 
                                     Set<RoleAuthorization> requiredAuthorizations); static boolean isAuthorized(Authentication authentication, ResourceType resourceType,
                                     Long resourceId, RoleAuthorization requiredAuthorization); static boolean isAuthorized(Authentication authentication, ResourceType resourceType,
                                     Long resourceId, Set<RoleAuthorization> requiredAuthorizations); static void verifyAuthorization(ResourceType resourceType,
                                         Long resourceId,
                                         Set<RoleAuthorization> requiredAuthorizations); static void verifyAuthorization(Authentication authentication,
                                         ResourceType resourceType,
                                         Long resourceId,
                                         Set<RoleAuthorization> requiredAuthorizations); static Authentication getAuthentication(); static void addLoginNameAlias(String ambariUserName, String loginAlias); static String resolveLoginAliasToUserName(String loginAlias); static List<String> getAuthorizationNames(Authentication authentication); }
AuthorizationHelper { public static int getAuthenticatedId() { SecurityContext securityContext = SecurityContextHolder.getContext(); Authentication authentication = securityContext.getAuthentication(); UserIdAuthentication auth; if (authentication instanceof UserIdAuthentication) { auth = (UserIdAuthentication) authentication; } else { return -1; } return auth.getUserId(); }  Collection<GrantedAuthority> convertPrivilegesToAuthorities(Collection<PrivilegeEntity> privilegeEntities); static String getAuthenticatedName(); static String getAuthenticatedName(String defaultUsername); static int getAuthenticatedId(); static boolean isAuthorized(ResourceType resourceType, Long resourceId, 
                                     RoleAuthorization requiredAuthorization); static boolean isAuthorized(ResourceType resourceType, Long resourceId, 
                                     Set<RoleAuthorization> requiredAuthorizations); static boolean isAuthorized(Authentication authentication, ResourceType resourceType,
                                     Long resourceId, RoleAuthorization requiredAuthorization); static boolean isAuthorized(Authentication authentication, ResourceType resourceType,
                                     Long resourceId, Set<RoleAuthorization> requiredAuthorizations); static void verifyAuthorization(ResourceType resourceType,
                                         Long resourceId,
                                         Set<RoleAuthorization> requiredAuthorizations); static void verifyAuthorization(Authentication authentication,
                                         ResourceType resourceType,
                                         Long resourceId,
                                         Set<RoleAuthorization> requiredAuthorizations); static Authentication getAuthentication(); static void addLoginNameAlias(String ambariUserName, String loginAlias); static String resolveLoginAliasToUserName(String loginAlias); static List<String> getAuthorizationNames(Authentication authentication);  }