SHARE
TWEET

Untitled

a guest Sep 3rd, 2018 106 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Spring Auto Login Intercept URL issue
  2. @Named
  3.     @Scope("request")
  4.     public class SignUpDetail extends BaseAction{
  5.         @Inject
  6.         private SignUpDetailBean signUpDetailBean;
  7.         @Inject
  8.         private UserManager userManager;
  9.         @Inject @Named("am")
  10.         protected AuthenticationManager authenticationManager;
  11.  
  12.         public String login(){
  13.             if(signUpDetailBean.getEmail() != null){
  14.                 Users currentUser = userManager.getUser(signUpDetailBean.getEmail());
  15.                 authenticateUserAndSetSession(currentUser, (HttpServletRequest) FacesUtils.getExternalContext().getRequest());
  16.  
  17.                 return "/registered/home.html";
  18.             }else{
  19.  
  20.                 return "/auth/login.html";
  21.             }
  22.  
  23.         }
  24.  
  25.      private void authenticateUserAndSetSession(Users user,
  26.                     HttpServletRequest request)
  27.                 {
  28.              UserDetails details = userManager.loadUserByUsername(user.getUsername());
  29.              UsernamePasswordAuthenticationToken usernameAndPassword =
  30.                  new UsernamePasswordAuthenticationToken(
  31.                      user.getUsername(), "pwd", details.getAuthorities());
  32.  
  33.              // Authenticate, just to be sure
  34.              Authentication auth = authenticationManager.authenticate(usernameAndPassword);
  35.  
  36.              // Place the new Authentication object in the security context.
  37.              SecurityContextHolder.getContext().setAuthentication(auth);
  38.         }
  39.  
  40. <context:annotation-config />
  41.     <context:component-scan base-package="dc" />
  42.     <global-method-security />
  43.     <http security="none" pattern="/javax.faces.resource/**" />
  44.     <http security="none" pattern="/services/rest-api/1.0/**" />
  45.     <http security="none" pattern="/preregistered/*" />
  46.     <http access-denied-page="/auth/denied.html">
  47.         <intercept-url
  48.             pattern="/**/*.xhtml"
  49.             access="ROLE_NONE_GETS_ACCESS" />
  50.         <intercept-url
  51.             pattern="/auth/**"
  52.             access="ROLE_ANONYMOUS,ROLE_USER" />
  53.          <intercept-url
  54.             pattern="/auth/*"
  55.             access="ROLE_ANONYMOUS" />
  56.          <intercept-url
  57.             pattern="/registered/*"
  58.             access="ROLE_USER" />
  59.           <intercept-url
  60.             pattern="/*"
  61.            access="ROLE_ANONYMOUS" />
  62.         <form-login
  63.             login-processing-url="/j_spring_security_check.html"
  64.             login-page="/auth/login.html"
  65.             default-target-url="/registered/home.html"
  66.             authentication-failure-url="/auth/login.html" />
  67.          <logout invalidate-session="true"
  68.               logout-success-url="/"
  69.               logout-url="/auth/logout.html"/>
  70.         <anonymous username="guest" granted-authority="ROLE_ANONYMOUS"/>
  71.         <remember-me user-service-ref="userManager" key="dfdf"/>
  72.     </http>
  73.     <!-- Configure the authentication provider -->
  74.     <authentication-manager alias="am">
  75.         <authentication-provider user-service-ref="userManager">
  76.                 <password-encoder ref="passwordEncoder" />
  77.         </authentication-provider>
  78.     </authentication-manager>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top