SecurityHelper implements ISecurityHelper { @Override public Authentication createAuthentication( String principalName ) { String anonymousUser = PentahoSystem .getSystemSetting( "anonymous-authentication/anonymous-user", "anonymousUser" ); userDetailsService = getUserDetailsService(); userRoleListService = getUserRoleListService(); List<String> roles = new ArrayList<String>(); if ( anonymousUser.equals( principalName ) ) { String anonymousRole = PentahoSystem .getSystemSetting( "anonymous-authentication/anonymous-role", "Anonymous" ); roles.add( anonymousRole ); } else { roles = userRoleListService.getRolesForUser( null, principalName ); } if ( SecurityHelper.logger.isDebugEnabled() ) { SecurityHelper.logger.debug( "rolesForUser:" + roles ); } List<GrantedAuthority> grantedAuthorities = new ArrayList<GrantedAuthority>(); if ( roles != null ) { grantedAuthorities = new ArrayList<GrantedAuthority>( roles.size() ); for ( String role : roles ) { grantedAuthorities.add( new SimpleGrantedAuthority( role ) ); } } User user = new User( principalName, "", true, true, true, true, grantedAuthorities ); Authentication auth = new UsernamePasswordAuthenticationToken( user, null, grantedAuthorities ); return auth; } 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 public void createAuthentificationTest() { Authentication authentication = getAuthorizedSecurityHelper().createAuthentication( DEF_USERNAME ); Collection<? extends GrantedAuthority> autorities = authentication.getAuthorities(); for ( String sourceRole : ALL_ROLES_ARRAY ) { boolean roleWasFound = false; for ( GrantedAuthority authRole : autorities ) { if ( sourceRole.equals( authRole.getAuthority() ) ) { roleWasFound = true; break; } } if ( !roleWasFound ) { fail( "not whole of required roles are present in created authentication authorities" ); return; } } }
@Test public void createAnonimousAuthentificationTest() { Authentication auth = getAuthorizedSecurityHelper().createAuthentication( ANONIMOUS_USER ); boolean roleWasFound = false; for ( GrantedAuthority authElem : auth.getAuthorities() ) { if ( authElem != null && ANONIMOUS_ROLE.equals( authElem.getAuthority() ) ) { roleWasFound = true; break; } } assertTrue( "not granted access for anonimous user", roleWasFound ); }