Package org.springframework.security

Examples of org.springframework.security.Authentication


    if ( username != null && username.equals( "administrators" ) ) {
      return null;
    }
    // optimization for when running in pre-authenticated mode (i.e. Spring Security filters have setup holder with
    // current user meaning we don't have to hit the back-end again)
    Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    if ( auth != null ) {
      Object ssPrincipal = auth.getPrincipal();
      if ( ssPrincipal instanceof UserDetails ) {
        if ( username.equals( ( (UserDetails) ssPrincipal ).getUsername() ) ) {
          return (UserDetails) ssPrincipal;
        }
      }
    }

    UserDetails user = null;
    // user cache not available or user not in cache; do lookup
    GrantedAuthority[] auths = null;
    GrantedAuthority[] authorities = null;
    UserDetails newUser = null;
    if ( getUserDetailsService() != null ) {
      try {
        user = getUserDetailsService().loadUserByUsername( username );
        // We will use the authorities from the Authentication object of SecurityContextHolder.
        //Authentication object is null then we will get it from IUserRoleListService
        if ( auth == null || auth.getAuthorities() == null || auth.getAuthorities().length == 0 ) {
          if ( logger.isTraceEnabled() ) {
            logger.trace( "Authentication object from SecurityContextHolder is null,"
              + " so getting the roles for [ " + user.getUsername() + " ]  from IUserRoleListService " ); //$NON-NLS-1$
          }

          List<String> roles = getUserRoleListService().getRolesForUser( JcrTenantUtils.getCurrentTenant(), username );
          authorities = new GrantedAuthority[ roles.size() ];
          for ( int i = 0; i < roles.size(); i++ ) {
            authorities[ i ] = new GrantedAuthorityImpl( roles.get( i ) );
          }
        } else {
          authorities = auth.getAuthorities();
        }

        auths = new GrantedAuthority[ authorities.length ];
        // cache the roles while we're here
        for ( int i = 0; i < authorities.length; i++ ) {
View Full Code Here


      RepositoryFileAcl acl = repositoryFileAclDao.getAcl( tenantRootFolder.getId() );
      Builder aclBuilder =
          new RepositoryFileAcl.Builder( acl ).ace( tenantAdminRoleSid, EnumSet.of( RepositoryFilePermission.ALL ) );

      IPentahoSession origPentahoSession = PentahoSessionHolder.getSession();
      Authentication origAuthentication = SecurityContextHolder.getContext().getAuthentication();
      login( repositoryAdminUsername, tenantAdminRoleId );
      try {
        // Give all to Tenant Admin of all ancestors
        while ( !parentTenantFolder.equals( "/" ) ) {
          ITenant tenant = new Tenant( parentTenantFolder, true );
View Full Code Here

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

        if (threadUser != null && threadUser.trim().length() > 0) {
            return threadUser;
        }

        SecurityContext context = SecurityContextHolder.getContext();
        Authentication auth = context.getAuthentication();

        if (auth == null) {
            return ROLE_ANONYMOUS;
        }

        Object userObj = auth.getPrincipal();
        if (userObj instanceof String) {
            return (String) userObj;
        } else if (userObj instanceof UserDetails) {
            UserDetails userDetails = (UserDetails) userObj;
            return userDetails.getUsername();
View Full Code Here

    }

    public Collection<String> getCurrentRoles() {
        Collection<String> results = new HashSet<String>();
        SecurityContext context = SecurityContextHolder.getContext();
        Authentication auth = context.getAuthentication();

        if (auth != null) {
            Object userObj = auth.getPrincipal();
            if (userObj instanceof UserDetails) {
                GrantedAuthority[] authorities = ((UserDetails)userObj).getAuthorities();
                for (GrantedAuthority ga: authorities) {
                    results.add(ga.getAuthority());
                }
View Full Code Here

        if (p != null) {
            out.println("Principal: " + p.getName() + "<p>");
        }
       
        // Access Spring security context
        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
        if (auth instanceof FederationAuthenticationToken) {
            out.println("Roles of user:<p><ul>");
            FederationAuthenticationToken fedAuthToken = (FederationAuthenticationToken)auth;
            for (GrantedAuthority item : fedAuthToken.getAuthorities()) {
                out.println("<li>" + item.getAuthority() + "</li>");
View Full Code Here

            out.print(p.getName());
        }
        out.println("</p>");

        // Access Spring security context
        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
       
        if (auth instanceof FederationAuthenticationToken) {
            FederationAuthenticationToken fedToken = (FederationAuthenticationToken)auth;
            List<String> roleListToCheck = Arrays.asList("Admin", "Manager", "User", "Authenticated");
           
View Full Code Here

            if ((SecurityContextHolder.getContext() == null)
                    || (SecurityContextHolder.getContext().getAuthentication() == null)) {
                return;
            }

            Authentication auth = SecurityContextHolder.getContext().getAuthentication();

            if (auth.getPrincipal() == null) {
                return;
            }

            try {
                BeanWrapperImpl wrapper = new BeanWrapperImpl(auth);
View Full Code Here

        if ((SecurityContextHolder.getContext() == null)
                || (SecurityContextHolder.getContext().getAuthentication() == null)) {
            return null;
        }

        Authentication auth = SecurityContextHolder.getContext().getAuthentication();

        if (auth.getPrincipal() == null) {
            return null;
        }

        try {
            BeanWrapperImpl wrapper = new BeanWrapperImpl(auth);
View Full Code Here

//@TODO créer une gestion de debug pour les messages et le debug jsf.
        return false;
    }

    private static GrantedAuthority[] authorities() {
        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
        if (auth != null) {
            return auth.getAuthorities();
        } else {
            return null;
        }
    }
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.