SecurityHelper implements ISecurityHelper { @Override public <T> T runAsAnonymous( final Callable<T> callable ) throws Exception { IPentahoSession origSession = PentahoSessionHolder.getSession(); Authentication origAuth = SecurityContextHolder.getContext().getAuthentication(); try { PentahoSessionHolder.setSession( new StandaloneSession() ); String user = PentahoSystem .getSystemSetting( "anonymous-authentication/anonymous-user", "anonymousUser" ); String role = PentahoSystem .getSystemSetting( "anonymous-authentication/anonymous-role", "Anonymous" ); List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>(); authorities.add( new SimpleGrantedAuthority( role ) ); Authentication auth = new AnonymousAuthenticationToken( "anonymousUser", new User( user, "ignored", true, true, true, true, authorities ), authorities ); SecurityContextHolder.clearContext(); SecurityContextHolder.getContext().setAuthentication( auth ); return callable.call(); } finally { PentahoSessionHolder.setSession( origSession ); SecurityContextHolder.getContext().setAuthentication( origAuth ); } } protected  SecurityHelper(); static ISecurityHelper getInstance(); static void setMockInstance( ISecurityHelper mockInstanceValue ); @Override void becomeUser( final String principalName ); @Override void becomeUser( final String principalName, final IParameterProvider paramProvider ); @Override T runAsUser( final String principalName, final Callable<T> callable ); @Override T runAsUser( final String principalName, final IParameterProvider paramProvider, final Callable<T> callable ); @Override T runAsAnonymous( final Callable<T> callable ); @Override @Deprecated boolean isPentahoAdministrator( final IPentahoSession session ); @Override boolean isGranted( final IPentahoSession session, final GrantedAuthority role ); @Deprecated boolean hasAccess( IAclHolder aHolder, int actionOperation, IPentahoSession session ); @Deprecated IAclVoter getAclVoter(); @Override Authentication createAuthentication( String principalName ); @Override Authentication getAuthentication(); @Override Authentication getAuthentication( IPentahoSession ignoredSession, boolean ignoredAllowAnonymous ); T runAsSystem( final Callable<T> callable ); IAuthorizationPolicy getAuthorizationPolicy(); ITenantedPrincipleNameResolver getTenantedUserNameUtils(); UserDetailsService getUserDetailsService(); IUserRoleListService getUserRoleListService();  }
@Test @SuppressWarnings( "unchecked" ) public void runAsAnonymousTest() throws Exception { Callable<String> callable = (Callable<String>) mock( Callable.class ); when( callable.call() ).thenReturn( CALLABLE_RETURNED_VALUE_OK ); String runningResult = emptySecurityHelper.runAsAnonymous( callable ); assertEquals( CALLABLE_RETURNED_VALUE_OK, runningResult ); }