[SPRING] 스프링 보안 로그인 페이지
SPRING스프링 보안 로그인 페이지
Spring Security의 기본 로그인 페이지를 사용하는 응용 프로그램을 개발했습니다. 그러나 나는 내 자신의 로그인 페이지를 구현하고 싶다. jsp 페이지 대신 login.html을 넣을 것입니다. 나는 그것을 위해 JQuery를 사용하고 싶다. 나는 많은 예를 살펴 보았지만 성취 할 수 없었다. Spring과 Spring Security가 처음인데 Spring Security 3을 사용합니다. 내가 따라야 할 단계는 무엇입니까?
해결법
-
==============================
1.Spring Security의 커스텀 로그인 페이지에는 네 가지 요구 사항이 있습니다 :
Spring Security의 커스텀 로그인 페이지에는 네 가지 요구 사항이 있습니다 :
Login.html
<body> <form action="/j_spring_security_check" method="POST"> <label for="username">User Name:</label> <input id="username" name="j_username" type="text"/> <label for="password">Password:</label> <input id="password" name="j_password" type="password"/> <input type="submit" value="Log In"/> </form> </body>
스프링 보안 설정 파일
<http use-expressions="true"> <intercept-url pattern="/login*" access="isAnonymous()"/> <intercept-url pattern="/**" access="isFullyAuthenticated()"/> <form-login login-page="/login.html" login-processing-url="/j_spring_security_check.action" authentication-failure-url="/login_error.html" default-target-url="/home.html" always-use-default-target="true"/> </http>
-
==============================
2.나는 내 프로젝트에서 스프링 보안을 구현하는 데 며칠 동안 일해 왔으며 마지막으로 다음과 같은 구성을 수행했다.
나는 내 프로젝트에서 스프링 보안을 구현하는 데 며칠 동안 일해 왔으며 마지막으로 다음과 같은 구성을 수행했다.
spring-security.xml
<security:http auto-config="true" disable-url-rewriting="true" use-expressions="true"> <security:form-login login-page="/login.html" login-processing-url="/j_spring_security_check.action" default-target-url="/index.html" always-use-default-target="true" authentication-failure-url="/login.html?error=true" /> <security:intercept-url pattern="/login*" access="isAnonymous()" /> <security:intercept-url pattern="/**" access="hasRole('ROLE_USER')" /> </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 smartcaldb.users where username=?" authorities-by-username-query="select u.username, r.authority from smartcaldb.users u, smartcaldb.roles r where u.userid = r.userid and u.username =?" /> </security:authentication-provider> </security:authentication-manager>
spring-config.xml
<mvc:annotation-driven /> <context:component-scan base-package="com.smartcal.**" /> <!-- setup database connectivity bean --> <bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="${jdbc.driverClassName}" /> <property name="url" value="${jdbc.url}" /> <property name="username" value="${jdbc.username}" /> <property name="password" value="${jdbc.password}" /> </bean> <context:property-placeholder location="/WEB-INF/jdbc.properties" /> <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"> <constructor-arg ref="dataSource"/> </bean>
을 포함한다.
<welcome-file-list> <welcome-file>index.html</welcome-file> </welcome-file-list> <context-param> <param-name>contextConfigLocation</param-name> <param-value> /WEB-INF/spring-config.xml /WEB-INF/spring-security.xml </param-value> </context-param> <listener> <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class> </listener> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <servlet> <servlet-name>dispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>dispatcher</servlet-name> <url-pattern>/login</url-pattern> <url-pattern>/</url-pattern> </servlet-mapping> <filter> <filter-name>springSecurityFilterChain</filter-name> <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> <init-param> <param-name>contextAttribute</param-name> <param-value>org.springframework.web.context.WebApplicationContext.ROOT</param-value> </init-param> </filter> <filter-mapping> <filter-name>springSecurityFilterChain</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <error-page> <error-code>403</error-code> <location>/403</location> </error-page>
login.html
<body> <form action="/smartcal/j_spring_security_check.action" method="POST"> <label for="username">User Name:</label> <input id="username" name="j_username" type="text" /> <label for="password">Password:</label> <input id="password" name="j_password" type="password" /> <input type="submit" value="Log In" /> </form> </body>
로그 아웃 사용 url - "/ {yourAppPathInTheContainer} / j_spring_security_logout"
from https://stackoverflow.com/questions/7361513/spring-security-login-page by cc-by-sa and MIT license
'SPRING' 카테고리의 다른 글
[SPRING] 스프링 MVC 컨트롤러는 싱글 톤입니까? (0) | 2018.12.17 |
---|---|
[SPRING] 봄 보안으로 사용자를 수동으로 로그 아웃하는 방법은 무엇입니까? (0) | 2018.12.17 |
[SPRING] JBoss의 서블릿에서 Spring 빈에 접근하기 (0) | 2018.12.17 |
[SPRING] 주석으로 봄 mvc 3 헤더 없음 캐시를 설정하는 방법 (0) | 2018.12.17 |
[SPRING] Spring 3.1, Hibernate 4, SessionFactory (0) | 2018.12.17 |