0
저는 스프링 - mvc와 함께 아파치 속도로 작업 중이며 이제는 스프링 보안 통합을 고수했습니다. 내가 mkyong에서 제공하는 문서와 예제를 통해 갔다 : http://www.mkyong.com/tutorials/spring-security-tutorials/스프링 보안 사용자 정의 폼이로드되지 않음 (페이지를 찾을 수 없음)
문제 :은 다른 모든 요청이 컨트롤러 것입니다하지만 콘솔은 모델 객체의 쇼 SYSOUT 값을 doesnot로 "/ 로그인"컨트롤러에 도달하지 않습니다. 여기
내 스프링 security.xml이다<http auto-config="true" use-expressions="true">
<form-login login-page="/login" default-target-url="/sample.html" authentication-failure-url="/login?error" username-parameter="userName" password-parameter="password" />
<intercept-url pattern="/login*" access="isAnonymous()" />
<logout invalidate-session="true" logout-success-url="/login?success" />
<csrf />
</http>
컨트롤러 :
@RequestMapping(value = "/login", method = RequestMethod.GET)
public ModelAndView login(@RequestParam(value = "error", required = false) String error,
@RequestParam(value = "logout", required = false) String logout) {
logger.info("Login Page Redirect..");
ModelAndView model = new ModelAndView();
if (error != null) {
model.addObject("error", "Invalid username and password!");
}
if (logout != null) {
model.addObject("msg", "You've been logged out successfully.");
}
model.setViewName("loginPage");
System.out.println("Print Model:"+model);
return model;
}
봄-servlet.xml에
<beans xmlns="http://www......>
<mvc:annotation-driven />
<context:component-scan base-package="com.anksys.bgms"></context:component-scan>
<mvc:default-servlet-handler />
<!-- This bean sets up the Velocity environment for us based on a root path
for templates. Optionally, a properties file can be specified for more control
over the Velocity environment, but the defaults are pretty same for file
based template loading. -->
<bean id="velocityConfig"
class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
<property name="resourceLoaderPath" value="/WEB-INF/views/velocity/" />
</bean>
<!-- Velocity template resolver -->
<bean
class="org.springframework.web.servlet.view.velocity.VelocityLayoutViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.velocity.VelocityLayoutView" />
<property name="layoutUrl" value="base_template.vm"></property>
<property name="cache" value="true" />
<property name="prefix" value="" />
<property name="suffix" value=".vm" />
<property name="order" value="1" />
<property name="attributesMap">
<map>
<entry key="authz"><bean class="com.anksys.bgms.security.VelocityUserDetails"></bean></entry>
</map>
</property>
</bean>
<!-- JSP resolver -->
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".jsp" />
<property name="order" value="2" />
</bean>
loginPage.jsp 경로 :
웹 애플리케이션/WEB-INF/뷰/
loginPage.jsp
는 로그의 라인은 주변에 어떤 일 .. 다음 사전에감사합니다 ..
을 제안하십시오.
2015-01-28 10:02:25 DEBUG DefaultRedirectStrategy:36 - Redirecting to 'http://localhost:8081/BGMS/login'
2015-01-28 10:02:25 DEBUG HttpSessionSecurityContextRepository:300 - SecurityContext is empty or contents are anonymous - context will not be stored in HttpSession.
2015-01-28 10:02:25 DEBUG SecurityContextPersistenceFilter:97 - SecurityContextHolder now cleared, as request processing completed
2015-01-28 10:02:25 DEBUG FilterChainProxy:337 - /login at position 1 of 12 in additional filter chain; firing Filter: 'SecurityContextPersistenceFilter'
2015-01-28 10:02:25 DEBUG HttpSessionSecurityContextRepository:148 - HttpSession returned null object for SPRING_SECURITY_CONTEXT
2015-01-28 10:02:25 DEBUG HttpSessionSecurityContextRepository:90 - No SecurityContext was available from the HttpSession: [email protected] A new one will be created.
2015-01-28 10:02:25 DEBUG FilterChainProxy:337 - /login at position 2 of 12 in additional filter chain; firing Filter: 'WebAsyncManagerIntegrationFilter'
2015-01-28 10:02:25 DEBUG FilterChainProxy:337 - /login at position 3 of 12 in additional filter chain; firing Filter: 'CsrfFilter'
2015-01-28 10:02:25 DEBUG FilterChainProxy:337 - /login at position 4 of 12 in additional filter chain; firing Filter: 'LogoutFilter'
2015-01-28 10:02:25 DEBUG AntPathRequestMatcher:127 - Request 'GET /login' doesn't match 'POST /j_spring_security_logout
2015-01-28 10:02:25 DEBUG FilterChainProxy:337 - /login at position 5 of 12 in additional filter chain; firing Filter: 'UsernamePasswordAuthenticationFilter'
2015-01-28 10:02:25 DEBUG FilterChainProxy:337 - /login at position 6 of 12 in additional filter chain; firing Filter: 'BasicAuthenticationFilter'
2015-01-28 10:02:25 DEBUG FilterChainProxy:337 - /login at position 7 of 12 in additional filter chain; firing Filter: 'RequestCacheAwareFilter'
2015-01-28 10:02:25 DEBUG DefaultSavedRequest:309 - pathInfo: both null (property equals)
2015-01-28 10:02:25 DEBUG DefaultSavedRequest:309 - queryString: both null (property equals)
2015-01-28 10:02:25 DEBUG DefaultSavedRequest:331 - requestURI: arg1=/BGMS/user/sample.html; arg2=/BGMS/login (property not equals)
2015-01-28 10:02:25 DEBUG HttpSessionRequestCache:75 - saved request doesn't match
2015-01-28 10:02:25 DEBUG FilterChainProxy:337 - /login at position 8 of 12 in additional filter chain; firing Filter: 'SecurityContextHolderAwareRequestFilter'
2015-01-28 10:02:25 DEBUG FilterChainProxy:337 - /login at position 9 of 12 in additional filter chain; firing Filter: 'AnonymousAuthenticationFilter'
2015-01-28 10:02:25 DEBUG AnonymousAuthenticationFilter:102 - Populated SecurityContextHolder with anonymous token: 'org.sprin[email protected]6faa1b5a: Principal: anonymousUser; Credentials: [PROTECTED]; Authenticated: true; Details: org.sprin[email protected]ffff6a82: RemoteIpAddress: 127.0.0.1; SessionId: 8373E425131980C1C5DF87CB932C8AB0; Granted Authorities: ROLE_ANONYMOUS'
2015-01-28 10:02:25 DEBUG FilterChainProxy:337 - /login at position 10 of 12 in additional filter chain; firing Filter: 'SessionManagementFilter'
2015-01-28 10:02:25 DEBUG FilterChainProxy:337 - /login at position 11 of 12 in additional filter chain; firing Filter: 'ExceptionTranslationFilter'
2015-01-28 10:02:25 DEBUG FilterChainProxy:337 - /login at position 12 of 12 in additional filter chain; firing Filter: 'FilterSecurityInterceptor'
2015-01-28 10:02:25 DEBUG AntPathRequestMatcher:145 - Checking match of request : '/login'; against '/user/**'
2015-01-28 10:02:25 DEBUG FilterSecurityInterceptor:185 - Public object - authentication not attempted
2015-01-28 10:02:25 DEBUG FilterChainProxy:323 - /login reached end of additional filter chain; proceeding with original chain
2015-01-28 10:02:25 DEBUG HttpSessionSecurityContextRepository:300 - SecurityContext is empty or contents are anonymous - context will not be stored in HttpSession.
2015-01-28 10:02:25 DEBUG ExceptionTranslationFilter:115 - Chain processed normally
2015-01-28 10:02:25 DEBUG SecurityContextPersistenceFilter:97 - SecurityContextHolder now cleared, as request processing completed
isAnonymouse()에서 permitAll로 액세스 제어 표현식을 변경하십시오. 여전히 로그인 양식에 액세스 할 수없는 경우 자세한 정보를 공유하십시오. 같은 봄 보안 로그 (디버그 수준) 또는 더 나은 간단한 응용 프로그램과 같은 문제. – Babl
짝수 로그가 비어 있습니다 ...... 사용자에 대한 액세스가 거부 된 것을 제외하고는 아무런 오류가 없습니다/** – Harsh
다음은 로그의 마지막 줄입니다. 이해합니다 ... 요청이 매핑이있는 컨트롤러에 올바르게 전달되지 않았습니다. " /로그인" – Harsh