After Spring Security authentication get HTTP Status 404 error

O.Kuz

while processing injection of spring security to my web app i get problem HTTP Status 404 error. When i try to get access for my pages first of all i get login page which is auto config, after typing login and password which is correct i get HTTP Status 404 error. Code below

web.xml

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xmlns="http://java.sun.com/xml/ns/javaee"
     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
     id="WebApp_ID" version="2.5">

<filter>
    <filter-name>encodingFilter</filter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
    <init-param>
        <param-name>encoding</param-name>
        <param-value>UTF-8</param-value>
    </init-param>
    <init-param>
        <param-name>forceEncoding</param-name>
        <param-value>true</param-value>
    </init-param>
</filter>
<filter-mapping>
    <filter-name>encodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>


<servlet>
    <servlet-name>spring</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>spring</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/application-context.xml, /WEB-INF/application-security.xml</param-value>
</context-param>

<filter>
    <filter-name>springSecurityFilterChain</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>

<filter-mapping>
    <filter-name>springSecurityFilterChain</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

application-security.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/security"
         xmlns:beans="http://www.springframework.org/schema/beans"   
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://www.springframework.org/schema/beans
                http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
                http://www.springframework.org/schema/security
                http://www.springframework.org/schema/security/spring-security-4.1.xsd">

<http auto-config="true" use-expressions="true">
    <intercept-url pattern="/main/**" access="hasRole('ROLE_USER')" />
</http>

<authentication-manager>
    <authentication-provider>
        <user-service>
            <user name="admin" password="adminpassword" authorities="ROLE_USER, ROLE_ADMIN" />
            <user name="user" password="userpassword" authorities="ROLE_USER" />
        </user-service>
    </authentication-provider>
</authentication-manager>

Controller

@Controller
@RequestMapping(value = "/main")
public class MainController {

@Autowired
DeputesAppealService deputesAppealService;

@Autowired
DeputesAppealDao deputesAppealDao;


@RequestMapping(value = "/mainFrame", method = RequestMethod.GET)
public String getMainPage(){
    return "mainPage";
}

@RequestMapping(value = "/resultOfSearching", method = RequestMethod.GET)
public String getSearchResult(Model model, @ModelAttribute("searchChar")String searchResult)  {
    List<DeputesAppeal> deputesAppeals = deputesAppealService.abstractSearch(searchResult);
    model.addAttribute("ListOfAppeals", deputesAppeals);
    return "searchingResultPage";
}

@RequestMapping(value = "/new", method = RequestMethod.GET)
public String getAddNewAppealPage(){
    return "addPage";
}


@RequestMapping(value = "/new", method = RequestMethod.POST)
public String addNewAppeal(@ModelAttribute("Appeal")DeputesAppeal deputesAppeal) {
    deputesAppealService.add(deputesAppeal);
    return "mainPage";
}


@RequestMapping(value = "/deleted", method = RequestMethod.GET)
public String deleteAppeal(@RequestParam(value = "id", required = true) Long id, Model model){
    deputesAppealService.delete(id);
    model.addAttribute("id", id);
    return "deletedPage";
}

@RequestMapping(value = "/editPage", method = RequestMethod.GET)
public String GetEdit(@RequestParam(value = "id", required = true) Long id, Model model){
    model.addAttribute("editedAppeal", deputesAppealService.getById(id));
    return "editPage";
}

@RequestMapping(value = "/editPage", method = RequestMethod.POST)
public String editCurrentAppeal(@ModelAttribute("userAttribute") DeputesAppeal deputesAppeal,
                                @RequestParam(value = "id", required = true)Integer id, Model model) {
    deputesAppeal.setNumber(id);
    deputesAppealService.edit(deputesAppeal);
    model.addAttribute("id", id);
    return "editedPage";
}
}
shankarsh15

Just see if you have springSecurityFilterChain defined in your web.xml

<filter>
    <filter-name>springSecurityFilterChain</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>

<filter-mapping>
    <filter-name>springSecurityFilterChain</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

You also need to change Login URL as well

<c:url value="/j_spring_security_check" var="loginUrl" />

and use this in your form action:

<form action="${loginUrl}" method="post">

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Spring security: save sessions status and get sessions after restart app

Spring security redirect to static resources after authentication

HTTP Server Status 404 Error in Spring MVC Project

spring security HTTP Status 403 - Access Denied

How to fix "HTTP Status 404" Spring MVC

Http basic authentication not working in Spring Security

Spring Security throwing 403 after basic authentication

Spring Security Authorize Tag - HTTP Status 500

HTTP Status 404 – Not Found tomcat spring

Http Status 404 after installing Tomcat 9

HTTP Status 404 – Not Found Spring Boot

Spring Security Login Error : HTTP Status 404 - /j_spring_security_check

spring security + 404 error

Spring MVC. HTTP Status 404

spring-security force "http" authentication

HTTP 404 Not Found after successful Spring Security authentication

After adding Spring Security to Spring MVC project, home page keeps returning 404 error

Node express 404 error HTTP status code

j_spring_security_check HTTP Status 404 (Custom Login)

Authentication based on http domain with spring-security

First application in Spring MVC - HTTP Status 404

HTTP Status [404] ? [Not Found] for /login in spring security

Spring Mvc get HTTP Status [404] – [Not Found] after the submission

Spring Mvc App get - HTTP Status [404] – [Not Found]

Spring Security Authentication issue: HTTP 401

Error in Spring Security with status code 404

Spring Security 404 error after log in standard form

Spring Security keeps giving Error 404 GET /login

It was authorized by Spring Security with error 404