### Question:
AuthorizationHelper { public static int getAuthenticatedId() { SecurityContext securityContext = SecurityContextHolder.getContext(); Authentication authentication = securityContext.getAuthentication(); Object principal = (authentication == null) ? null : authentication.getPrincipal(); if (principal instanceof AmbariUserDetails) { return ((AmbariUserDetails) principal).getUserId(); } return -1; }  static String getProxyUserName(Authentication authentication); static String getProxyUserName(); 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);  }### Answer:
@Test public void testAuthId() throws Exception { Integer userId = AuthorizationHelper.getAuthenticatedId(); Assert.assertEquals(Integer.valueOf(-1), userId); PrincipalEntity principalEntity = new PrincipalEntity(); UserEntity userEntity = new UserEntity(); userEntity.setUserId(1); userEntity.setPrincipal(principalEntity); User user = new User(userEntity); Authentication auth = new AmbariUserAuthentication(null, new AmbariUserDetailsImpl(user, null, null)); SecurityContextHolder.getContext().setAuthentication(auth); userId = AuthorizationHelper.getAuthenticatedId(); Assert.assertEquals(Integer.valueOf(1), userId); }
@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); }