/** * @return the {@link ISecurityHelper} used by this instance. If none has been specified, it will default to * using the {@link SecurityHelper} singleton. */ public ISecurityHelper getSecurityHelper() { return ( null != securityHelper ? securityHelper : SecurityHelper.getInstance() ); }
/** * Remove this method when data-access is JCR-branched * * @param ignoredSession * @param ignoredAllowAnonymous * @return */ @Override public Authentication getAuthentication( IPentahoSession ignoredSession, boolean ignoredAllowAnonymous ) { return getAuthentication(); }
protected UserDetails getUserDetailsWithDefaultRole( final UserDetails userDetails ) { if ( defaultRole != null ) { return new DefaultRoleUserDetailsProxy( userDetails, defaultRole, roleMapper ); } else { return userDetails; } }
private SecurityHelper getAuthorizedSecurityHelper() { SecurityHelper authorizedSecurityHelper = spy( new SecurityHelper() ); IUserRoleListService userRoleListServiceMock = getUserRoleListServiceMock( DEF_USERNAME, ALL_ROLES_ARRAY ); doReturn( userRoleListServiceMock ).when( authorizedSecurityHelper ).getUserRoleListService(); return authorizedSecurityHelper; }
/** * Utility method that allows you to run a block of code as the given user. Regardless of success or exception * situation, the original session and authentication will be restored once your block of code is finished executing, * i.e. the given user will apply only to your {@link Callable}, then the system environment will return to the user * present prior to you calling this method. * * @param <T> the return type of your operation, specify this type as <code>T</code> * @param principalName the user under whom you wish to run a section of code * @param callable {@link Callable#call()} contains the code you wish to run as the given user * @return the value returned by your implementation of {@link Callable#call()} * @throws Exception * @see {@link Callable} */ @Override public <T> T runAsUser( final String principalName, final Callable<T> callable ) throws Exception { return runAsUser( principalName, null, callable ); }
@Before public void init() { setSystemSettingsService( null ); PentahoSystemBoot boot = new PentahoSystemBoot(); boot.setFilePath( "test-src/solution" ); emptySecurityHelper = spy( new SecurityHelper() ); }
@Override public SecurityContext createEmptyContext() { return new PentahoSecurityContextImpl(); }
public String toString() { return "Authentication: " + this.getAuthentication(); } }
protected String getPrincipalName() { Authentication auth = getAuthentication(); if ( auth != null ) { return auth.getName(); } return null; }
public Map<IPermissionRecipient, IPermissionMask> getEffectivePermissions( Object domainInstance ) { IAclHolder aclHolder = (IAclHolder) domainInstance; List<IPentahoAclEntry> aclList = aclHolder.getEffectiveAccessControls(); return transformEntries( aclList ); }
/** * Hi-jacks the system for the named user. <p/> <p> This will essentially create a session for this user, make that * session the current session, and add the Authentication objects to the session and Spring context holder. WARNING: * this method is irreversible!!! If you want execute a block of code as a surrogate user and have the orignal user * resume after it is complete, you want {@link #runAsUser(String, Callable)}. </p> <p/> <p> This is for unit tests * only. </p> * * @param principalName the user to become in the system */ @Override public void becomeUser( final String principalName ) { becomeUser( principalName, null ); }
public boolean hasParameter( String name ) { return this.getParameter( name ) != null; } }
/** * Returns a string representation of the given object. This is useful when third-party objects do not have * <code>toString()</code> implementations that meet your needs. */ protected String toString( final Object object ) { /** * This impl uses reflection to print fields and it also skips sensitive fields. */ return ( new ReflectionToStringBuilder( object ) { @Override protected boolean accept( final Field f ) { return super.accept( f ) && !f.getName().equals( "password" ) && !f.getName().equals( "credentials" ); //$NON-NLS-1$ //$NON-NLS-2$ } } ).toString(); }
public DefaultRoleUserDetailsProxy( final UserDetails userDetails, final GrantedAuthority defaultRole, final IAuthenticationRoleMapper roleMapper ) { super(); Assert.notNull( userDetails ); Assert.notNull( defaultRole ); this.userDetails = userDetails; this.roleMapper = roleMapper; newRoles = getNewRoles( defaultRole ); }
@Override public Authentication getAuthentication( final IPentahoSession session ) { return SecurityHelper.getInstance().getAuthentication( session, true ); }
public SecurityContext getContext() { if ( context.get() == null ) { context.set( new PentahoSecurityContextImpl() ); } return context.get(); }
public int hashCode() { if ( getAuthentication() == null ) { return -1; } else { return getAuthentication().hashCode(); } }
protected String getPrincipalAuthenticated() { Authentication auth = getAuthentication(); if ( auth != null ) { return auth.isAuthenticated() ? "true" : "false"; //$NON-NLS-1$ //$NON-NLS-2$ } return "false"; //$NON-NLS-1$ }
public Map<IPermissionRecipient, IPermissionMask> getPermissions( final Object domainInstance ) { IAclHolder aclHolder = (IAclHolder) domainInstance; List<IPentahoAclEntry> aclList = aclHolder.getAccessControls(); return transformEntries( aclList ); }
public void testRunAsAnonymousWithAnonymousAuthenticationToken() throws Exception { Callable<Object> callableObject = new Callable<Object>() { public Object call() throws Exception { Authentication auth = SecurityContextHolder.getContext().getAuthentication(); // Assert.assertTrue( auth != null && auth instanceof AnonymousAuthenticationToken ); return null; } }; SecurityHelper.getInstance().runAsAnonymous( callableObject ); }