Package org.springframework.security.web.authentication.preauth

Examples of org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken


        SimpleGrantedAuthority grantedAuthority = new SimpleGrantedAuthority("ROLE_IOS");
        grantedAuthorityList = new ArrayList<GrantedAuthority>();
        grantedAuthorityList.add(grantedAuthority);

        Authentication authentication = new PreAuthenticatedAuthenticationToken(tokenParam, tokenParam, grantedAuthorityList);
        authentication.setAuthenticated(authenticated);

        authenticationSuccessHandler.setDefaultTargetUrl((authenticated ? String.format("%s?token=%s", request.getServletPath(), tokenParam) : LOGIN_URL));
        this.setAuthenticationSuccessHandler(authenticationSuccessHandler);

        return authentication;
View Full Code Here


        Assert.notNull(authenticationManager);
        Assert.notNull(authenticationDetailsSource);

        String userName = wasHelper.getCurrentUserName();
        if (logger.isDebugEnabled()) { logger.debug("Creating authentication request for user "+userName); }
        PreAuthenticatedAuthenticationToken authRequest = new PreAuthenticatedAuthenticationToken(userName, "N/A");
        authRequest.setDetails(authenticationDetailsSource.buildDetails(null));
        if (logger.isDebugEnabled()) { logger.debug("Authentication request for user "+userName+": "+authRequest); }
        Authentication authResponse = authenticationManager.authenticate(authRequest);
        if (logger.isDebugEnabled()) { logger.debug("Authentication response for user "+userName+": "+authResponse); }
        SecurityContextHolder.getContext().setAuthentication(authResponse);
    }
View Full Code Here

      if (user != null)
      {
        String email = user.getEmail();

        PreAuthenticatedAuthenticationToken token = new PreAuthenticatedAuthenticationToken(email, null);
        token.setDetails(ads.buildDetails((HttpServletRequest) request));

        try
        {
          authentication = authenticationManager.authenticate(token);
          SecurityContextHolder.getContext().setAuthentication(authentication);
View Full Code Here

      log.info("Precaching. This may take a while.");
      try {
        RequestManager rm = (RequestManager)context.getBean("requestManager");

        User userdetails = new User("precacher", "none", true, true, true, true, AuthorityUtils.createAuthorityList("ROLE_ADMIN,ROLE_INTERNAL"));
        PreAuthenticatedAuthenticationToken newAuthentication = new PreAuthenticatedAuthenticationToken(userdetails, userdetails.getPassword(), userdetails.getAuthorities());
        newAuthentication.setAuthenticated(true);
        newAuthentication.setDetails(userdetails);

        try {
          SecurityContext sc = SecurityContextHolder.getContextHolderStrategy().getContext();
          sc.setAuthentication(newAuthentication);
          SecurityContextHolder.getContextHolderStrategy().setContext(sc);
View Full Code Here

    }

    logger.debug("REST KEY OK. Security!");

    if (userdetails != null) {
      PreAuthenticatedAuthenticationToken newAuthentication = new PreAuthenticatedAuthenticationToken(userdetails, userdetails.getPassword(), userdetails.getAuthorities());
      newAuthentication.setAuthenticated(true);
      newAuthentication.setDetails(userdetails);

      try {
        SecurityContext sc = SecurityContextHolder.getContextHolderStrategy().getContext();
        sc.setAuthentication(newAuthentication);
        SecurityContextHolder.getContextHolderStrategy().setContext(sc);
View Full Code Here

   *
   * @param userDetails 已初始化好的用户信息.
   * @param request 用于获取用户IP地址信息,可为Null.
   */
  public static void saveUserDetailsToContext(UserDetails userDetails, HttpServletRequest request) {
    PreAuthenticatedAuthenticationToken authentication = new PreAuthenticatedAuthenticationToken(userDetails,
        userDetails.getPassword(), userDetails.getAuthorities());

    if (request != null) {
      authentication.setDetails(new WebAuthenticationDetails(request));
    }

    SecurityContextHolder.getContext().setAuthentication(authentication);
  }
View Full Code Here

            if (tokenUtils.validate(token)) {
                // determine the user based on the (already validated) token
                UserDetails user = tokenUtils.getUserFromToken(token);

                // build an Authentication object with the user's info
                PreAuthenticatedAuthenticationToken authentication = new PreAuthenticatedAuthenticationToken(user, null);
                authentication.setDetails(ads.buildDetails(request));
                SecurityContextHolder.getContext().setAuthentication(authManager.authenticate(authentication));

                // Add token to HTTP header
                if (SecurityContextHolder.getContext().getAuthentication().isAuthenticated()) {
                    // Add token to HTTP header
                    HttpServletResponse httpResponse = (HttpServletResponse) response;
                    httpResponse.addHeader("X-Authentication-Token", token);
                }
            }
        } else {
        //    System.out.println("DONT HAVE TOKEN");
            // If there is not any token, check if there is a Google Accounts user
            User googleUser = UserServiceFactory.getUserService().getCurrentUser();
            // System.out.println(googleUser);
            if (googleUser != null) {
                UserDetails user = new org.springframework.security.core.userdetails.User(googleUser.getEmail(), "", new ArrayList<GrantedAuthority>());

                // build an Authentication object with the user's info
                PreAuthenticatedAuthenticationToken authentication = new PreAuthenticatedAuthenticationToken(user, null);
                authentication.setDetails(ads.buildDetails(request));
                SecurityContextHolder.getContext().setAuthentication(authManager.authenticate(authentication));

                if (SecurityContextHolder.getContext().getAuthentication().isAuthenticated()) {
                    // Add token to HTTP header
                    token = tokenUtils.getToken(user);
View Full Code Here

//        assertNotNull(redirectUrl);

        ctx = (SecurityContext) request.getSession(true).getAttribute(
                HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY);
        assertNotNull(ctx);
        PreAuthenticatedAuthenticationToken casAuth = (PreAuthenticatedAuthenticationToken) ctx.getAuthentication();
        assertNotNull(casAuth);
        assertNull(SecurityContextHolder.getContext().getAuthentication());
        checkForAuthenticatedRole(casAuth);
        assertEquals(username,  casAuth.getPrincipal());
        assertTrue(casAuth.getAuthorities().contains(new GeoServerRole(rootRole)));
        assertTrue(casAuth.getAuthorities().contains(new GeoServerRole(derivedRole)));
        Assertion  ass = (Assertion) request.getSession(true).getAttribute(GeoServerCasConstants.CAS_ASSERTION_KEY);
        assertNotNull(ass);
        String proxyTicket = ass.getPrincipal()
                .getProxyTicketFor("http://localhost/blabla");
        assertNotNull(proxyTicket);
View Full Code Here

            return;
        }
       
        LOGGER.log(Level.FINE,"preAuthenticatedPrincipal = " + principal + ", trying to authenticate");
       
        PreAuthenticatedAuthenticationToken result = null;
        if (GeoServerUser.ROOT_USERNAME.equals(principal)) {
            result = new PreAuthenticatedAuthenticationToken(principal, null, Collections.singleton(GeoServerRole.ADMIN_ROLE));           
        } else {
            Collection<GeoServerRole> roles=null;
            try {
                roles = getRoles(request, principal);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            if (roles.contains(GeoServerRole.AUTHENTICATED_ROLE)==false)
                roles.add(GeoServerRole.AUTHENTICATED_ROLE);
            result = new PreAuthenticatedAuthenticationToken(principal, null, roles);
           
        }
                                               
        result.setDetails(authenticationDetailsSource.buildDetails(request));
        SecurityContextHolder.getContext().setAuthentication(result);                       
    }
View Full Code Here

        return context.getAuthentication();
    }

    public static void saveUserDetailsToContext(UserDetails userDetails, HttpServletRequest request) {
        PreAuthenticatedAuthenticationToken authentication = new PreAuthenticatedAuthenticationToken(userDetails,
                userDetails.getPassword(), userDetails.getAuthorities());

        if (request != null) {
            authentication.setDetails(new WebAuthenticationDetails(request));
        }

        SecurityContextHolder.getContext().setAuthentication(authentication);
    }
View Full Code Here

TOP

Related Classes of org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken

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.