Package org.springframework.security.context

Examples of org.springframework.security.context.SecurityContext


                username,
                new GrantedAuthority[] {
                        new GrantedAuthorityImpl("ROLE_TELLER"),
                        new GrantedAuthorityImpl("ROLE_PERMISSION_LIST") });

        SecurityContext secureContext = new SecurityContextImpl();
        secureContext.setAuthentication(auth);
        SecurityContextHolder.setContext(secureContext);

    }
View Full Code Here


                username,
                new GrantedAuthority[] {
                        new GrantedAuthorityImpl("ROLE_TELLER"),
                        new GrantedAuthorityImpl("ROLE_PERMISSION_LIST") });

        SecurityContext secureContext = new SecurityContextImpl();
        secureContext.setAuthentication(auth);
        SecurityContextHolder.setContext(secureContext);

    }
View Full Code Here

            user = userService.createUser(fullName, email, username, password1);

            Authentication token = new UsernamePasswordAuthenticationToken(username, password1);
            Authentication result = authenticationManager.authenticate(token);
            SecurityContext securityContext = new SecurityContextImpl();
            securityContext.setAuthentication(result);
            SecurityContextHolder.setContext(securityContext);

            String path = redirectField.getValue();
            if (StringUtils.isNotBlank(path)) {
                setRedirect(path);
View Full Code Here

    /*
     * @see vn.pyco.tinycms.services.SecurityService#getCurrentUsername()
     */
    @Override
    public String getCurrentUsername() {
        SecurityContext securityContext = SecurityContextHolder.getContext();
        if (securityContext.getAuthentication() == null) {
            return null;
        }
       
        Object userDetails = securityContext.getAuthentication().getPrincipal();
       
        if (userDetails instanceof String) {
            return (String) userDetails;
        }
       
View Full Code Here

      // we want this
    }
  }

  private void configureSecurityContext() {
    SecurityContext sc = new SecurityContextImpl();
    sc.setAuthentication(getAuthentication());
    SecurityContextHolder.setContext(sc);
  }
View Full Code Here

    Authentication authentication = new UsernamePasswordAuthenticationToken(userName, password);
    try {
      authentication = authenticationManager.authenticate(authentication);
      if (authentication.isAuthenticated()) {
        // Set the security context
        SecurityContext securityContext = new SecurityContextImpl();
        securityContext.setAuthentication(authentication);
        SecurityContextHolder.setContext(securityContext);
      } else {
        throw new RuntimeException("Invalid credentials."); //$NON-NLS-1$
      }
    } catch (AuthenticationException e) {
View Full Code Here

@Test
public class AnonymousProcessingFilterTest {

  @SuppressWarnings("serial")
  public void test() throws Exception {
    SecurityContextHolder.setContext(new SecurityContext() {

      @Override
      public void setAuthentication(Authentication authentication) {
      }
View Full Code Here

  }

  private final void updateSecurityContextIfNecessary(final String originalUsername, final String newUsername,
      final String newPassword, final boolean justRemove) {

    final SecurityContext securityContext = SecurityContextHolder.getContext();
    if(securityContext == null) return;

    final Authentication authentication = securityContext.getAuthentication();
    if(authentication == null) return;

    final Object principal = authentication.getPrincipal();
    if(principal instanceof User == false) return;
    final User user = (User) authentication.getPrincipal();
View Full Code Here

            user = userService.createUser(fullName, email, username, password1);

            Authentication token = new UsernamePasswordAuthenticationToken(username, password1);
            Authentication result = authenticationManager.authenticate(token);
            SecurityContext securityContext = new SecurityContextImpl();
            securityContext.setAuthentication(result);
            SecurityContextHolder.setContext(securityContext);

            String path = redirectField.getValue();
            if (StringUtils.isNotBlank(path)) {
                setRedirect(path);
View Full Code Here

                httpSession.setAttribute( PentahoSystem.PENTAHO_SESSION_KEY, PentahoSessionHolder.getSession() );

                /**
                 * definition of anonymous inner class
                 */
                SecurityContext authWrapper = new SecurityContext() {
                  /**
                     *
                     */
                  private static final long serialVersionUID = 1L;
                  private Authentication authentication;

                  public Authentication getAuthentication() {
                    return authentication;
                  };

                  public void setAuthentication( Authentication authentication ) {
                    this.authentication = authentication;
                  };
                }; // end anonymous inner class

                authWrapper.setAuthentication( SecurityContextHolder.getContext().getAuthentication() );
                httpSession.setAttribute( HttpSessionContextIntegrationFilter.SPRING_SECURITY_CONTEXT_KEY,
                  authWrapper );
                return null;
              }

View Full Code Here

TOP

Related Classes of org.springframework.security.context.SecurityContext

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.