pom.xml 하기 dependency 추가...
<properties> |
<!-- spring security --> |
spring/security-context.xml 생성... 일단 생성 -_-
web.xml – filter 추가
<!-- The definition of the Root Spring Container shared by all Servlets and Filters --> *** 일단은 기존 root-context 에서 security-context.xml 을 추가했기때문에 위와 같이 변경;; <!-- spring security --> |
Configuration 상세 – 생성한 spring/sercurity-context.xml 정리;;
<?xml version="1.0" encoding="UTF-8"?> *** 이후부터 /views-people 폴더내의 파일들에 대한 접근은 위의 두 권한으로 제한한다 *** 로그인 페이지 커스텀 처리, 만약 설정하지않는다면 스프링 자체적으로 지원하는 로그인 페이지로 이동하게 된다. 로그인 각각의 성공 / 실패시 핸들러 처리 추가; <security:logout logout-success-url="/" /> |
class 처리 - PredeUserService.java
package com.spring.service; *** UserDetailsService 를 implement 했다면 기본 셋팅되는 메소드.. 실제 org.springframework.security.core.userdetails.UserDetailsService 이 jar 를 열어보면 이 메소드밖에 없다
if(prede == null ) throw new UsernameNotFoundException(username); *** db table 에 authority 칼럼을 만들어놓은 상태, default 는 ROLE_USER 로;;; |
class 처리 - LoginSuccessHandler.java
package com.spring.handler; |
class 처리 - LoginFailureHandler.java
package com.spring.handler; import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.security.core.AuthenticationException; import org.springframework.security.web.authentication.AuthenticationFailureHandler; public class LoginFailureHandler implements AuthenticationFailureHandler { private static final Logger logger = LoggerFactory.getLogger(LoginFailureHandler.class); @Override public void onAuthenticationFailure(HttpServletRequest req, HttpServletResponse res, AuthenticationException auth) throws IOException, ServletException { // TODO Auto-generated method stub logger.info(auth.getLocalizedMessage()); logger.info(auth.getMessage()); for(StackTraceElement s : auth.getStackTrace()){ logger.info(s.getClassName()); logger.info(s.getFileName()); logger.info(s.getMethodName()); logger.info(s.getLineNumber()+""); logger.info(s.isNativeMethod()+""); } req.setAttribute("errMsg",auth.getMessage()); req.getRequestDispatcher("/signin.do").forward(req, res); } //public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException auth) throws IOException, ServletException //{ // response.sendRedirect(request.getContextPath() + "/"); //} } |
jsp 파일 -_- signin.jsp
. . <form method="post" class="signin" action="j_spring_security_check"> *** sigin 부분에서 해당 action 을 j_spring_security_check 로 변경 . . |
security 에서의 session 처리에 대한 해당 값 받아오기
jsp 파일 -_- answer.jsp
<%@ page language="java" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%> . . . <div style="width:800; height:400" align=center> |
------------
음.. 뭐 별개로... spring security 상에서의 세션(?;) 으로 값을 받아올수도 있겠지만..
간단하게 -_-
컨트롤러에서 그냥 세션으로 집어넣어봤다;;
package com.spring.prede; |
테스트야 뭐 간단하다 -_- answer.jsp 에서 세션스콥으로 받아와봄 -_-
<div style="width:800; height:400" align=center> |
'spring' 카테고리의 다른 글
spring framewrok MVC - 6-1 ( 부제 : 개인적으로 쉬어가는 페이지 ) (0) | 2014.11.03 |
---|---|
spring framewrok MVC - 5 ( 부제 : 게시판만들기 -_- ) (0) | 2014.10.28 |
spring framewrok MVC - 4 ( 부제 : sign-up & sign-in & session ) (0) | 2014.10.28 |
spring framewrok MVC - 3 ( 부제 : mysql & mybatis ) (0) | 2014.10.28 |
spring framewrok MVC - 2 ( 부제 : 타일즈( tiles ) 적용 ) (0) | 2014.10.28 |
댓글