Package org.springframework.security

Examples of org.springframework.security.Authentication


  @Test
  public void testGetContext() throws Exception {
    final PentahoSecurityContextHolderStrategy strategy = new PentahoSecurityContextHolderStrategy();
    SecurityContext context = strategy.getContext();
    assertNotNull( context );
    final Authentication authentication = mock( Authentication.class );
    context.setAuthentication( authentication );

    assertSame( authentication, strategy.getContext().getAuthentication() );
    Thread thread = new Thread( new Runnable() {
      @Override public void run() {
        assertSame( authentication, strategy.getContext().getAuthentication() );
        Authentication authentication2 = mock( Authentication.class );
        strategy.getContext().setAuthentication( authentication2 );
        assertSame( authentication2, strategy.getContext().getAuthentication() );
        synchronized ( this ) {
          notify();
        }
View Full Code Here


   *
   * @param session The users' session
   * @return Users' roles as defined in the authentication object
   */
  protected String[] getPlatformRolesFromSession( IPentahoSession session ) {
    Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
    Assert.state( authentication != null );

    String[] rtn = null;
    // Get the authorities
    GrantedAuthority[] gAuths = authentication.getAuthorities();
    if ( ( gAuths != null ) && ( gAuths.length > 0 ) ) {
      // Copy role names out of the Authentication
      rtn = new String[gAuths.length];
      for ( int i = 0; i < gAuths.length; i++ ) {
        rtn[i] = gAuths[i].getAuthority();
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 );

    createUserHomeFolder( tenant, username );
View Full Code Here

    final GrantedAuthority[] repositoryAdminAuthorities =
        new GrantedAuthority[] { new GrantedAuthorityImpl( superAdminRoleName ) };
    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

    return principalName;
  }

  protected void createUserHomeFolder( final ITenant theTenant, final String theUsername ) {
    IPentahoSession origPentahoSession = PentahoSessionHolder.getSession();
    Authentication origAuthentication = SecurityContextHolder.getContext().getAuthentication();
    StandaloneSession pentahoSession = new StandaloneSession( repositoryAdminUsername );
    pentahoSession.setAuthenticated( null, repositoryAdminUsername );
    PentahoSessionHolder.setSession( pentahoSession );
    try {
      txnTemplate.execute( new TransactionCallbackWithoutResult() {
View Full Code Here

   */
  public void authenticate(HttpServletRequest req, String username, String password) {
    try {
      UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(username, password);
      token.setDetails(new WebAuthenticationDetails(req));
      Authentication authentication = this.authenticationManager.authenticate(token);
      log.debug("Logging in with [{}]", authentication.getPrincipal());
      SecurityContextHolder.getContext().setAuthentication(authentication);
    }
    catch (BadCredentialsException bd) {
      throw new RuntimeException("Authentication failed for: " + username, bd);
    }
View Full Code Here

   */
  public void authenticate(HttpServletRequest req, String username, String password) {
    try {
      UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(username, password);
      token.setDetails(new WebAuthenticationDetails(req));
      Authentication authentication = this.authenticationManager.authenticate(token);
      log.debug("Logging in with [{}]", authentication.getPrincipal());
      SecurityContextHolder.getContext().setAuthentication(authentication);
    }
    catch (BadCredentialsException bd) {
      throw new RuntimeException("Authentication failed for: " + username, bd);
    }
View Full Code Here

        if(!usingSSO) {
            log.info("SSO is not enabled. Skipping CustomUserRegistry functionality.");
            return null;
        }
       
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
       
        User ud = new User();
        // setting default
        ud.setId(null);
        ud.setLocale(Locale.getDefault().toString());
        ud.setTimeZone(TimeZone.getDefault().getID());
        ud.setDateCreated(new java.util.Date());

        String userName = null;
        String password = null;
        String fullName = null;
        String email = null;
        String screenName = null;
        String locale = null;
        String timezone = null;
        boolean enabled = false;

        if(authentication == null) {
            // Try to get SSO data from HttpServletRequest
            userName = getRequestAttribute(request, WebloggerConfig.getProperty(UID_LDAP_PROPERTY, DEFAULT_UID_LDAP_ATTRIBUTE));

            screenName = getRequestAttribute(request, WebloggerConfig.getProperty(SNAME_LDAP_PROPERTY, DEFAULT_SNAME_LDAP_ATTRIBUTE));

            fullName = getRequestAttribute(request, WebloggerConfig.getProperty(NAME_LDAP_PROPERTY, DEFAULT_NAME_LDAP_ATTRIBUTE));

            email = getRequestAttribute(request, WebloggerConfig.getProperty(EMAIL_LDAP_PROPERTY, DEFAULT_EMAIL_LDAP_ATTRIBUTE));

            locale = getRequestAttribute(request, WebloggerConfig.getProperty(LOCALE_LDAP_PROPERTY, DEFAULT_LOCALE_LDAP_ATTRIBUTE));

            timezone = getRequestAttribute(request, WebloggerConfig.getProperty(TIMEZONE_LDAP_PROPERTY, DEFAULT_TIMEZONE_LDAP_ATTRIBUTE));

            if (userName == null && fullName == null && screenName == null &&
                    email == null && locale == null && timezone == null) {

                log.warn("No Authentication found in SecurityContextHolder and HttpServletRequest.");
                return null;
            } else {
                enabled = true;
            }
        } else {
       
            Object oPrincipal = authentication.getPrincipal();
       
            if(oPrincipal == null) {
                log.warn("Principal is null. Skipping auto-registration.");
                return null;
            }
View Full Code Here

    List<GrantedAuthority> authList = new ArrayList<GrantedAuthority>();
    authList.add( new GrantedAuthorityImpl( "TenantAdmin" ) );
    authList.add( new GrantedAuthorityImpl( "Authenticated" ) );
    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

          "RequestParameterAuthenticationFilter.DEBUG_AUTH_USERID", username ) ); //$NON-NLS-1$
    }

    if ( ( username != null ) && ( password != null ) ) {
      // Only reauthenticate if username doesn't match SecurityContextHolder and user isn't authenticated (see SEC-53)
      Authentication existingAuth = SecurityContextHolder.getContext().getAuthentication();

      password = Encr.decryptPasswordOptionallyEncrypted( password );

      if ( ( existingAuth == null ) || !existingAuth.getName().equals( username ) || !existingAuth.isAuthenticated() ) {
        UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken( username, password );
        authRequest.setDetails( new WebAuthenticationDetails( httpRequest ) );

        Authentication authResult;

        try {
          authResult = authenticationManager.authenticate( authRequest );
        } catch ( AuthenticationException failed ) {
          // Authentication failed
          if ( RequestParameterAuthenticationFilter.logger.isDebugEnabled() ) {
            RequestParameterAuthenticationFilter.logger.debug( Messages.getInstance().getString(
                "RequestParameterAuthenticationFilter.DEBUG_AUTHENTICATION_REQUEST", username, failed.toString() ) ); //$NON-NLS-1$
          }

          SecurityContextHolder.getContext().setAuthentication( null );

          if ( ignoreFailure ) {
            chain.doFilter( wrapper, response );
          } else {
            authenticationEntryPoint.commence( wrapper, response, failed );
          }

          return;
        }

        // Authentication success
        if ( RequestParameterAuthenticationFilter.logger.isDebugEnabled() ) {
          RequestParameterAuthenticationFilter.logger.debug( Messages.getInstance().getString(
              "RequestParameterAuthenticationFilter.DEBUG_AUTH_SUCCESS", authResult.toString() ) ); //$NON-NLS-1$
        }

        SecurityContextHolder.getContext().setAuthentication( authResult );
      }
    }
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.