Obecnie pracuję na moim blogu w ramach Spring. Wdrażam Spring Security do celów logowania. Wszystko działa zgodnie z oczekiwaniami, dopóki nie prześlę loginów, które zawsze zwracają kod 404.Spring Security logowania zwraca 404
Oto mój dorsz web.xml e
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>avispring</display-name>
<error-page>
<error-code>404</error-code>
<location>/404.html</location>
</error-page>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-database.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>/admin/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<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>
Oto mój kod zabezpieczający wiosna:
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/avispring"/>
<property name="username" value="root"/>
<property name="password" value=""/>
</bean>
<security:debug/>
<security:http auto-config="true">
<security:intercept-url pattern="/admin/**" access="hasRole('ROLE_ADMIN')"/>
<security:intercept-url pattern="/j_spring_security_check" access="permitAll"/>
<security:form-login
login-page="/login.html"
authentication-failure-url="/login?login_error=1"
default-target-url="/admin/home.html"/>
</security:http>
<security:authentication-manager>
<security:authentication-provider>
<security:jdbc-user-service
data-source-ref="dataSource"
users-by-username-query="select USERNAME,PASSWORD,ENABLED from USER_AUTHENTICATION where USERNAME=?"
authorities-by-username-query="select u1.USERNAME,u2.ROLE from USER_AUTHENTICATION u1,USER_AUTHORIZATION u2 where u1.USER_ID=u2.USER_ID and u1.USERNAME=?"/>
</security:authentication-provider>
</security:authentication-manager>
część mojego kodu login.jsp jest
<form action="<c:url value="/login"/>" method="post">
<div class="form-group has-feedback">
<input type="email" class="form-control" placeholder="Email" name="username">
<span class="glyphicon glyphicon-envelope form-control-feedback"></span>
</div>
<div class="form-group has-feedback">
<input type="password" class="form-control" placeholder="Password" name="password">
<span class="glyphicon glyphicon-lock form-control-feedback"></span>
</div>
<div class="row">
<div class="col-xs-8">
<div class="checkbox icheck">
<label>
<input type="checkbox"> Remember Me
</label>
</div>
</div><!-- /.col -->
<div class="col-xs-4">
<button type="submit" class="btn btn-primary btn-block btn-flat" name="submit">Sign In</button>
</div><!-- /.col -->
</div>
</form>
a wyjście konsola jest
16 października 2015 01:06:03 org.springframework.web.servlet.DispatcherServlet noHandlerFound UWAGA:
012: Nie znaleziono żądania HTTP z URI [/ avispring/login] w DispatcherServlet o nazwie 'wiosnę'Uwaga mapowanie
- Używam Spring 4.2.1 i wiosną do bezpieczeństwa 4.0.2
- Większość forów są skierowane do ścieżki kontekstowego czyli [appname/login] lub [appname/j_spring_security_check] i myślę kopalnia jest ok, uważając go
Proszę o pomoc ...
UPDATE:
gdy użyłem log4j, wyjście debugowania w chwili złożenia formularza jest następujący:
debug: org.springframework.web.servlet.DispatcherServlet - Związany kontekst żądania wątku: org.apache.catalina. [email protected] DEBUG: org.springframework.web.servlet.DispatcherServlet - DispatcherServlet z nazwą 'spring' Przetwarzanie żądania POST dla [/ avispring/login] DEBUG: org.springframework.web.servlet.DispatcherServlet - Mapa programu testującego [org.springframework[email protected]16fffcf] w DispatcherServlet o nazwie 'spring' DEBUG: org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Lo oking up handler method for path/login DEBUG: org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Nie znaleziono metody obsługi dla [/ login] DEBUG: org.springframework.web.servlet.DispatcherServlet - Testowanie mapy obsługi [or[email protected]138f01b] w DispatcherServlet o nazwie "spring" DEBUG: org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping - Nie znaleziono mapowania obsługi dla [/ login] DEBUG: org.springframework.web.servlet.DispatcherServlet - Testowanie mapy obsługi [[email protected]1ff154c] w DispatcherServlet o nazwie 'spring' DEBUG: org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - Nie znaleziono mapowania obsługi dla [/ login ] WARN: org.springframework.web.servlet.PageNotFound - Nie znaleziono mapowania dla żądania HTTP z identyfikatorem URI [/ avispring/login] w DispatcherServlet o nazwie 'spring' DEBUG: org.springframework.web.servlet.DispatcherServlet - Wyczyść wątek kontekst żądania połączenia: [email protected] DEBUG: org.springframework.web.servlet.DispatcherServlet - Pomyślnie zakończono żądanie DEBUG: org.springframework.web.context.support.XmlWebApplicationContext - Publikowanie zdarzenia w WebApplicationContext for namespace 'spring-servlet': ServletRequestHandledEvent: url = [/avispring/login]; client = [0: 0: 0: 0: 0: 0: 0: 1]; method = [POST]; servlet = [wiosna]; session = [BC0FB7E62DC0AFABD8EF72B8BF1CED54]; user = [null]; czas = [3ms]; status = [OK] DEBUG: org.springframework.web.context.support.XmlWebApplicationContext - Publikowanie zdarzenia w katalogu głównym WebApplicationContext: ServletRequestHandledEvent: url = [/ avispring/login]; client = [0: 0: 0: 0: 0: 0: 0: 1]; method = [POST]; servlet = [wiosna]; session = [BC0FB7E62DC0AFABD8EF72B8BF1CED54]; user = [null]; czas = [3ms]; status = [OK] DEBUG: org.springframework.web.servlet.DispatcherServlet - Kontekst żądania powiązania z wątkiem: [email protected] DEBUG: org.springframework.web.servlet.DispatcherServlet - DispatcherServlet with przetwarzanie nazwy "wiosna" żądanie POST dla [/avispring/404.html] DEBUG: org.springframework.web.servlet.DispatcherServlet - Testowanie mapy handler [org.springframework[email protected]16fffcf ] w DispatcherServlet o nazwie 'spring' DEBUG: org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Wyszukiwanie metody obsługi dla ścieżki /404.html DEBUG: org.springframework.web.servlet.mvc. method.annotation.RequestMappingHandlerMapping - Znaleziono 1 pasujące mapowanie dla [/404.html]: [{[/404.html]}] DEBUG: org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Metoda zwracającego programu obsługi [public org.springframework.web.servlet.ModelAndView com.avispring.controllers.HelloController.errorPage()] DEBUG: org.springframework .web.servlet.DispatcherServlet - Testowanie adaptera obsługi [[email protected]1db5] DEBUG: org.springframework.web.servlet.DispatcherServlet - Testujący adapter obsługi [org.springframework.web.servlet. [email protected]] DEBUG: org.springframework.web.servlet.DispatcherServlet - Testowanie adaptera obsługi [org.springframework[email protected]c26a5f] DEBUG: org.springframework.web. servlet.mvc.method.annotation.ServletInvocableHandlerMethod - Wywoływanie metody [HelloController.errorPage] z argumentami [] DEBUG: org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod - Metoda [errorPage] zwróciła [ModelAndView: odwołanie do widoku o nazwie '/ 404'; model jest pusty] DEBUG: org.springframework.web.servlet.DispatcherServlet - Rendering view [org.springframework.web.servlet.view.JstlView: name '/ 404'; URL [/WEB-INF/jsp//404.jsp]] w DispatcherServlet o nazwie "spring" DEBUG: org.springframework.web.servlet.view.JstlView - Rendering widok o nazwie '/ 404' z modelem {} i Atrybuty statyczne {} DEBUG: org.springframework.web.servlet.view.JstlView - Przekazywanie do zasobu [/WEB-INF/jsp//404.jsp] w InternalResourceView '/ 404' DEBUG: org.springframework.web. servlet.DispatcherServlet - Skasowano kontekst żądania związanego z wątkami: [email protected] DEBUG: org.springframework.web.servlet.DispatcherServlet - Pomyślnie zakończono żądanie DEBUG: org.springframework.web.context.support .XmlWebApplicationContext - Publikowanie zdarzenia w WebApplicationContext dla "spring-servlet" przestrzeni nazw: ServletRequestHandledEvent: url = [/ avispring/404.html]; client = [0: 0: 0: 0: 0: 0: 0: 1]; method = [POST]; servlet = [wiosna]; session = [BC0FB7E62DC0AFABD8EF72B8BF1CED54]; user = [null]; czas = [1ms]; status = [OK] DEBUG: org.springframework.web.context.support.XmlWebApplicationContext - Publikowanie zdarzenia w głównym katalogu WebApplicationContext: ServletRequestHandledEvent: url = [/ avispring/404.html]; client = [0: 0: 0: 0: 0: 0: 0: 1]; method = [POST]; servlet = [wiosna]; session = [BC0FB7E62DC0AFABD8EF72B8BF1CED54]; user = [null]; czas = [1ms]; status = [OK]
wypróbowałeś j_spring_security_check zamiast/login? –
ya, już to wypróbowałem. Na początku użyłem ** j_spring_security_check **, ale to nie zadziałało, więc surfowałem w Internecie i odkryłem, że w późniejszych wersjach zostało zmienione na **/login ** –
@ Jesteśmy Borg: to nie pomogło –