CoolioSo!

떵짜루의 개인 블로그

메뉴

컨텐츠로 건너뛰기
  • 홈
  • Home
  • SPRING SECURITY
  • SpringSecurity 강제로 로그인 시키기

SpringSecurity 강제로 로그인 시키기

정의되지 않은 로그인 폼을 통해서 로그인 할 경우에도 강제로 SpringSecurity의 로그인 세션을 생성하는 방법을 구현하였다.

1. 로그인으로 사용한 URL에 대한 세션체크 기능을 제외한다.

2. 컨트롤러에서 SpringSecurity에 세션 주입

@Resource(name="userDetailsService")
protected UserDetailsService userDetailsService;

@RequestMapping(value="login", method=RequestMethod.POST)
public String login(HttpServletRequest request) throws Exception{
    UserDetails ckUserDetails = userDetailsService.loadUserByUsername("USER_ID");
    Authentication authentication = new UsernamePasswordAuthenticationToken(ckUserDetails, "USER_PASSWORD", ckUserDetails.getAuthorities());

    SecurityContext securityContext = SecurityContextHolder.getContext();
    securityContext.setAuthentication(authentication);
    HttpSession session = request.getSession(true);
    session.setAttribute("SPRING_SECURITY_CONTEXT", securityContext);

    return "redirect:/login/success";
}

관련

이 글은 SPRING SECURITY 카테고리에 분류되었고 login, spring, springframework, springsecurity, 강제 로그인, 로그인 태그가 있으며 YOUNGMIN JUN님에 의해 2014년 5월 2일에 작성되었습니다.

글 네비게이션

← MS-SQL 테이블 컬럼 조작(추가,수정,삭제) HomeBrew 관리 →
YOUNGMIN JUN

YOUNGMIN JUN

Sony TT16, IBM X21, Mac Mini(2012 Late), MacBook Pro Retina 13(2012 Late), iMac 27(2011 Late) iPhone 5, New iPad, iPad Mini(2013), MS Surface2 RT, MS Surface2 Pro

확인된 서비스

전체 프로필 보기 →

[4월] 2021
월 목 수 목 금 토 토
 1234
567891011
12131415161718
19202122232425
2627282930  
« 7월    

카테고리

  • MAC_LIFE (9)
  • PHP (2)
  • 개발이야기 (66)
    • DevOPS (1)
    • ECLIPSE (1)
    • Git (3)
    • JAVA (3)
    • JAVASCRIPT (1)
    • LINUX (9)
    • MSSQL (3)
    • MYSQL (3)
    • ORACLE (5)
    • PostgreSQL (1)
    • PYTHON (1)
    • REDIS (2)
    • SPRING (3)
    • SPRING SECURITY (1)
    • ZEPPELIN (3)
  • 사랑이야기 (3)
  • 자격증 (3)
    • 정보보안기사 (3)
  • 자기관리 (9)
  • 프로젝트관리 (5)
    • Docker (1)
    • JENKINS (3)
    • Redmine (1)

최신 글

  • Spring Transactional
  • Git에서 CRLF 개행 문자 차이 해결법
  • Git 최초 설정
  • PostgreSQL
  • SpringQuartz 스케쥴링 시간지정 방법

태그

apache centos centos6 config console eclipse error git gmail homebrew html htmltopdf html to pdf install java jenkins linux mac mssql mysql network oracle osx pdf php pms redis redmine security server smtp spring ssh status su svn update window wkhtmltopdf yum zeppelin 시간관리 오라클 자기관리 정보보안
CoolioSo Modify By TwentyTwelve