Posts

Showing posts matching the search for spring

Spring Security Token Based Authentication | Code Factory

Image
Download code and jars :  Link. File : index.jsp <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> </head> <body> <center> <form action="sendData" method="post"> <table> <tr> <td>Username :</td> <td><input type="text" name="username"></td> </tr> <tr> <td>Username :</td> <td><input type="password" name="password"></td> </tr> <tr> <!-- TOCKEN --...

Spring Security Custom Login Form XML | Code Factory

Image
Download code and jars :  Link. File : hello.jsp <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@page session="false"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <meta name="_csrf" content="${_csrf.token}" /> <!-- default header name is X-CSRF-TOKEN --> <meta name="_csrf_header" content="${_csrf.headerName}" /> <title>Insert title here</title> <script src="https://code.jquery.com/jquery-1.10.2.js"></script> <script src="https://code.jquery.com/ui/1.10.4/jquery-ui.js"></script> <script type="text/javascript"> $(funct...

Spring MVC + jQuery | Code Factory

Image
Download code and jars :  Link. File : Country.java package com.codeFactory.bean; public class Country { private int countryId; private String countryName; // Getters and setters. } File : Action.java package com.codeFactory.controller; import java.util.ArrayList; import java.util.List; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; import com.codeFactory.bean.Country; @Controller public class Action { List<Country> allCountryList = new ArrayList<Country>(); public List<Country> getAllCountryList() { return allCountryList; } public void setAllCountryList(List<Country> allCountryList) { this.allCountryList = allCountryList; } @RequestMapping(value = "/getCountryList", method=RequestMethod....

Include the CSRF Token in Spring Security | Code Factory

Form Submissions To implement spring security you must include the CSRF token in all PATCH, POST, PUT, and DELETE methods. One way to approach this is to use the _csrf request attribute to obtain the current CsrfToken . An example of doing this with a JSP is shown below: <c:url var="logoutUrl" value="/logout"/> <form action="${logoutUrl}" method="post"> <input type="submit" value="Log out" /> <input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/> </form> *Note : If you are using Spring MVC <form:form> tag or Thymeleaf 2.1+ and are using @EnableWebSecurity , the CsrfToken is automatically included for you (using the CsrfRequestDataValueProcessor ). Ajax and JSON Requests If you are using JSON, then it is not possible to submit the CSRF token within an HTTP parameter. Instead you can submit the token within a H...