Package org.springframework.security

Examples of org.springframework.security.Authentication


  @Test
  public void testReadRolesInPlatform() throws Exception {
    SecurityHelper.getInstance().runAsUser( "admin", new Callable<Void>() {
      @Override
      public Void call() throws Exception {
        Authentication auth = SecurityHelper.getInstance().getAuthentication();
        Assert.assertNotNull( auth );
        GrantedAuthority[] gAuths = auth.getAuthorities();
        Assert.assertNotNull( gAuths );
        Assert.assertEquals( 3, gAuths.length );
        Assert.assertEquals( "ceo", gAuths[0].getAuthority() );
        Assert.assertEquals( "Admin", gAuths[1].getAuthority() );
        Assert.assertEquals( "Authenticated", gAuths[2].getAuthority() );
View Full Code Here


    final GrantedAuthority[] repositoryAdminAuthorities =
        new GrantedAuthority[]{new GrantedAuthorityImpl( sysAdminRoleName )};
    final String password = "ignored";
    UserDetails repositoryAdminUserDetails =
        new User( repositoryAdminUsername, password, true, true, true, true, repositoryAdminAuthorities );
    Authentication repositoryAdminAuthentication =
        new UsernamePasswordAuthenticationToken( repositoryAdminUserDetails, password, repositoryAdminAuthorities );
    PentahoSessionHolder.setSession( pentahoSession );
    // this line necessary for Spring Security's MethodSecurityInterceptor
    SecurityContextHolder.getContext().setAuthentication( repositoryAdminAuthentication );
  }
View Full Code Here

    for ( String roleName : roles ) {
      authList.add( new GrantedAuthorityImpl( roleName ) );
    }
    GrantedAuthority[] authorities = authList.toArray( new GrantedAuthority[0] );
    UserDetails userDetails = new User( username, password, true, true, true, true, authorities );
    Authentication auth = new UsernamePasswordAuthenticationToken( userDetails, password, authorities );
    PentahoSessionHolder.setSession( pentahoSession );
    // this line necessary for Spring Security's MethodSecurityInterceptor
    SecurityContextHolder.getContext().setAuthentication( auth );
  }
View Full Code Here

  public void onApplicationEvent( final ApplicationEvent event ) {
    if ( event instanceof AuthenticationSuccessEvent ) {
      logger.debug( "received " + event.getClass().getSimpleName() ); //$NON-NLS-1$
      logger.debug( "synchronizing current IPentahoSession with SecurityContext" ); //$NON-NLS-1$
      try {
        Authentication authentication = ( (AbstractAuthenticationEvent) event ).getAuthentication();
        IPentahoSession pentahoSession = PentahoSessionHolder.getSession();
        Assert.notNull( pentahoSession, "PentahoSessionHolder doesn't have a session" );
        pentahoSession.setAuthenticated( authentication.getName() );
        // audit session creation
        AuditHelper.audit( pentahoSession.getId(), pentahoSession.getName(), pentahoSession.getActionName(),
            pentahoSession.getObjectName(), "", MessageTypes.SESSION_START, "", "", 0, null ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
      } catch ( Exception e ) {
        logger.error( e.getLocalizedMessage(), e );
View Full Code Here

    return authorities;
  }

  @Override
  public Authentication authenticate( Authentication authentication ) throws AuthenticationException {
    final Authentication authenticate = super.authenticate( authentication );
    for ( GrantedAuthority authority : authenticate.getAuthorities() ) {
      if ( authority.getAuthority().equals( authenticatedRole ) ) {
        return authenticate;
      }
    }
    throw new AuthenticationServiceException( "The user doesn't have '" + authenticatedRole + "' role." );
View Full Code Here

  private Authentication getAuthentication() {
    return SecurityHelper.getInstance().getAuthentication();
  }

  protected String getPrincipalName() {
    Authentication auth = getAuthentication();
    if ( auth != null ) {
      return auth.getName();
    }
    return null;
  }
View Full Code Here

    }
    return null;
  }

  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$
  }
View Full Code Here

    return SecurityHelper.getInstance().isPentahoAdministrator( this.session ) ? "true" : "false"; //$NON-NLS-1$
    // //$NON-NLS-2$
  }

  protected Object getPrincipalRoles() {
    Authentication auth = getAuthentication();
    if ( auth != null ) {
      GrantedAuthority[] auths = auth.getAuthorities();
      if ( auths != null ) {
        List rtn = new ArrayList( auths.length );
        for ( GrantedAuthority element : auths ) {
          rtn.add( element.getAuthority() );
        }
View Full Code Here

    final GrantedAuthority[] repositoryAdminAuthorities =
        new GrantedAuthority[]{new GrantedAuthorityImpl( sysAdminRoleName )};
    final String password = "ignored";
    UserDetails repositoryAdminUserDetails =
        new User( repositoryAdminUsername, password, true, true, true, true, repositoryAdminAuthorities );
    Authentication repositoryAdminAuthentication =
        new UsernamePasswordAuthenticationToken( repositoryAdminUserDetails, password, repositoryAdminAuthorities );
    PentahoSessionHolder.setSession( pentahoSession );
    // this line necessary for Spring Security's MethodSecurityInterceptor
    SecurityContextHolder.getContext().setAuthentication( repositoryAdminAuthentication );
  }
View Full Code Here

    for ( String roleName : roles ) {
      authList.add( new GrantedAuthorityImpl( roleName ) );
    }
    GrantedAuthority[] authorities = authList.toArray( new GrantedAuthority[0] );
    UserDetails userDetails = new User( username, password, true, true, true, true, authorities );
    Authentication auth = new UsernamePasswordAuthenticationToken( userDetails, password, authorities );
    PentahoSessionHolder.setSession( pentahoSession );
    // this line necessary for Spring Security's MethodSecurityInterceptor
    SecurityContextHolder.getContext().setAuthentication( auth );
  }
View Full Code Here

TOP

Related Classes of org.springframework.security.Authentication

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.