Spring Security

   

         Security is the primary need of any web based application as it provided security from un-authorized access of your application. Spring Framework has API defined which can be configured and used in any Java web application.



   There are two of the terms widely used in Security world - PrincipleAuthentication and Authorization.
As these words itself are self explanatory;

Principle - it can be a user, device or system. Most of the time it is a User.
Authentication means checking the authentication, i.e. userid and password of a user.
Authorization means authorizing a user to decide whether she should be allowed to access a resource on web application.

Things we are going to learn here are:-
1. Designing a Login and Logout page which will ask for  userId/pwd
2. Storing encrypted pwd into database which will authenticate users.
3. Verifying authorization of any user before displaying a page.

Case: Let us imagine that our application will accept userId and password. If the login is succesfull she will be redirected to main page of application but if login fails, take her to the login page again with some error message.

1. Designing a Login and Logout page which will ask for  userId/pwd
  Form based Login:
      The form-based login service will render a web page that contains a login form for users to input their login details and process the login form submission. It's configured via the  element in web.xml file:


< http>
    ....
     login-page="/login.jsp" default-target-url="/employeeList"
              authentication-failure-url="/login.jsp?error=true"  />
< /http>


Explanation for above attributes:-
 login-page   is the login page which will be displayed to the user for login.
default-target-url  means, The user will be redirected to the target URL once the login succeeds. 
authentication-failure-url  if the login fails the user will be taken back to the login.jsp page with error parameter as true.


















Comments

Popular posts from this blog

Java

RTC - Repository : How to Revert Back the Changes