작성
·
723
0
spring mvc방식으로 구현해보고 있는데 권한 인증인 403에러는 잘뜹니다. 하지만 controller를 통해서 들어가면 404에러가 뜹니다. 관련되서 질문드립니다.
@RestController
public class AdminController {
@GetMapping("/admin")
public String admin() {
return "admin";
}
}
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:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:security="http://www.springframework.org/schema/security"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security.xsd
">
<security:http auto-config="true" use-expressions="false">
<security:intercept-url pattern="/**" access="ROLE_ADMIN"/>
<security:form-login/>
</security:http>
<security:authentication-manager>
<security:authentication-provider>
<security:user-service>
<security:user name="admin" password="{noop}1234" authorities="ROLE_ADMIN, ROLE_USER"/>
<security:user name="user" password="{noop}1234" authorities="ROLE_USER"/>
</security:user-service>
</security:authentication-provider>
</security:authentication-manager>
<mvc:resources mapping="/jsp/**" location="/jsp/"></mvc:resources>
<context:annotation-config/>
<context:component-scan base-package="com.test"/>
<mvc:annotation-driven />
<mvc:default-servlet-handler/>
<bean id="viewResolver" class = "org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:spring/context-spring.xml
</param-value>
</context-param>
<filter>
<filter-name>CharacterEncodingFilter</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>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>dispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/context-spring.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>dispatcherServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<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>
</web-app>
접속 404오류 로그
DEBUG [FilterChainProxy] - Securing GET /admin
DEBUG [HttpSessionSecurityContextRepository] - Retrieved SecurityContextImpl [Authentication=UsernamePasswordAuthenticationToken [Principal=org.springframework.security.core.userdetails.User [Username=admin, Password=[PROTECTED], Enabled=true, AccountNonExpired=true, credentialsNonExpired=true, AccountNonLocked=true, Granted Authorities=[ROLE_ADMIN, ROLE_USER]], Credentials=[PROTECTED], Authenticated=true, Details=WebAuthenticationDetails [RemoteIpAddress=0:0:0:0:0:0:0:1, SessionId=B6D437E830FDEBF274A77AF35C51A114], Granted Authorities=[ROLE_ADMIN, ROLE_USER]]]
DEBUG [SecurityContextPersistenceFilter] - Set SecurityContextHolder to SecurityContextImpl [Authentication=UsernamePasswordAuthenticationToken [Principal=org.springframework.security.core.userdetails.User [Username=admin, Password=[PROTECTED], Enabled=true, AccountNonExpired=true, credentialsNonExpired=true, AccountNonLocked=true, Granted Authorities=[ROLE_ADMIN, ROLE_USER]], Credentials=[PROTECTED], Authenticated=true, Details=WebAuthenticationDetails [RemoteIpAddress=0:0:0:0:0:0:0:1, SessionId=B6D437E830FDEBF274A77AF35C51A114], Granted Authorities=[ROLE_ADMIN, ROLE_USER]]]
DEBUG [FilterSecurityInterceptor] - Authorized filter invocation [GET /admin] with attributes [ROLE_ADMIN]
DEBUG [FilterChainProxy] - Secured GET /admin
DEBUG [DispatcherServlet] - GET "/admin", parameters={}
DEBUG [SimpleUrlHandlerMapping] - Mapped to org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler@8c32dc
DEBUG [DispatcherServlet] - Completed 404 NOT_FOUND
DEBUG [SecurityContextPersistenceFilter] - Cleared SecurityContextHolder to complete request
답변 2
0
음
해당 소스는 저의 강의 이전버전인 xml 방식으로 구성이 된 것이라 정확한 답변을 드리기가 어려울 것 같습니다.
주신 소스는 강의에서 설명하는 스프링 부트 기반이 아닌 점과 스프링 시큐리티 버전과의 호환성 등 여러 다양한 환경적인 요인이 있을 수 있기 때문에 강의의 주제와 좀 벗어나는 것 같습니다.
양해 부탁드립니다.
0