Spring Security Processor

Source: Internet
Author: User

In spring security we can define our own handler to help us perform some functions, such as putting user information into session after successful login, changing the direction of execution flow, etc. Here are two Handler:authenticationsuccesshandler (login successful processors), Accessdeniedhandler (Deny access to the processor), and then customize these two processors respectively.

public class Loginsuccesshandler implements Authenticationsuccesshandler {

public void Onauthenticationsuccess (HttpServletRequest req,
HttpServletResponse resp, authentication auth) throws IOException,
servletexception {


HttpSession session=req.getsession ();

Myuserdetails is a custom implementation Userdetails class

Myuserdetials user= (myuserdetials) Auth.getprincipal ();

Session.setattribute ("User", User.getu ());

Resp.sendredirect ("Home");

}
}



public class Myaccessdeniedhandler implements Accessdeniedhandler {


public void handle (HttpServletRequest req, HttpServletResponse resp,
Accessdeniedexception arg2) throws IOException, Servletexception {


String Uri=req.getrequesturi ();

Meet Requirements Change Workflow

if (Uri.equals ("/shop/publish.jsp"))
{
Resp.sendredirect ("applicant.jsp");
}
}
}

Of course, don't forget that you also need to configure it in the configuration file:

<access-denied-handler ref= "Myaccessdeniedhandler"/>

<form-login login-page= "/login.jsp"
Authentication-failure-url= "/403.jsp"
Login-processing-url= "/j_login"
Default-target-url= "/Home"
Always-use-default-target= "true" authentication-success-handler-ref= "Loginsuccesshanlder"
/>

<beans:bean id= "Loginsuccesshanlder" class= "Com.duangshopping.handler.LoginSuccessHandler" >

<beans:bean id= "Myaccessdeniedhandler" class= "Com.duangshopping.handler.MyAccessDeniedHandler"/>
</beans:bean>


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Spring Security Processor

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.