シンプルなSpring Securityログインページを作成しようとしていますが、すべての構成が正しいようです(実際には何千もの異なる構成を試しましたが失敗しました)。Tomcat を起動すると、以下がスローされます。
java.lang.ClassNotFoundException: org.apache.jsp.WEB_002dINF.pages.welcome_jsp
アーティファクトを確認した後welcome.jsp
、ページの読み込みは成功したようですが、ログインして送信しようとすると、Tomcat がリダイレクトを試みて失敗します:
HTTP Status 404 - /j_spring_security_check
また、成功したログインに変更login-processing-url="/j_spring_security_check.action"
しますが、間違ったユーザー名パスを入力すると、エラーページのリダイレクトに失敗します (ブラウザーの URL は: と表示されます):login-processing-url="/j_spring_security_check"
http://localhost:8080/welcome?login_error=-1
HTTP Status 404 - /welcome
WEB-INF/pages
フォルダの下にページが存在し、と の 2 ページがindex.jsp
ありwelcome.jsp
ます。
spring-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:security="http://www.springframework.org/schema/security"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<security:debug />
<security:global-method-security jsr250-annotations="enabled" pre-post-annotations="enabled" secured-annotations="enabled" />
<security:http use-expressions="true" authentication-manager-ref="authManager">
<security:intercept-url pattern="/index" access="isAuthenticated"/>
<security:intercept-url pattern="/welcome" access="permitAll"/>
<security:form-login login-processing-url="/j_spring_security_check.action" login-page="/welcome" default-target-url="/index" authentication-failure-url="/welcome?login_error=-1" />
<security:logout logout-success-url="/" delete-cookies="JSESSIONID" invalidate-session="true"/>
<security:remember-me />
<security:session-management invalid-session-url="/">
<security:concurrency-control max-sessions="1" error-if-maximum-exceeded="false" />
</security:session-management>
</security:http>
<security:authentication-manager id="authManager">
<security:authentication-provider>
<security:jdbc-user-service data-source-ref="dataSource"
users-by-username-query="
select ..."
authorities-by-username-query="
select ... "
/>
</security:authentication-provider>
</security:authentication-manager>
<context:component-scan base-package="com.ch.core"/>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/pages/"/>
<property name="suffix" value=".jsp"/>
</bean>
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="..." />
<property name="username" value="..." />
<property name="password" value="..." />
</bean>
<mvc:annotation-driven />
<mvc:resources mapping="/css/**" location="/css/" cache-period="31556926"/>
<mvc:resources mapping="/js/**" location="/js/" cache-period="31556926"/>
<mvc:resources mapping="/img/**" location="/img/" cache-period="31556926"/>
<!-- Allows for mapping the DispatcherServlet to "/" by forwarding static resource
requests to the container's default Servlet -->
<mvc:default-servlet-handler/>
<mvc:view-controller path="/welcome" view-name="welcome"></mvc:view-controller>
</beans>
関連するwelcome.jspコード:
<form name='f' class="navbar-form pull-right" action='/j_spring_security_check' method='POST'>
<input type='text' name='j_username' value=''>
<input type='password' name='j_password'>
<button name="submit" type="submit" class="btn btn-small">Log in</button>
<label id="rememberMe">
<input type="checkbox" name='_spring_security_remember_me'> <h6">Remember me</h6>
</label>
</form>
<c:if test="${not empty param.login_error}">
<div class="error">
Your login attempt was not successful, try again.<br />
Reason: ${sessionScope.SPRING_SECURITY_LAST_EXCEPTION.message}
</div>
</c:if>
助けてくれてありがとう。
Spring Security 3.1.2、Spring WEBMVC 3.2.0、Tomcat 7.0.33。