기본 콘텐츠로 건너뛰기

라벨이 Spring인 게시물 표시

Spring security @PreAuthorize @PostAuthorize 사용하기

이번에 프로젝트 하면서 따로따로 java에서 requestmapping에 권한을 줘야하는 일이 발생하였다 권한 주는법은 밑에와같다 하지만 Spring security가 있다고해서 바로 되는것이아니다. 1 2 3 4 5 @RequestMapping(value= "/preAuthorize" ) @PreAuthorize( "isAuthenticated()" )      public   String  preAuthorize() {            ................     } 우선 자기의 web.xml을 확인해보자 거기에서 디스펙처를 어디로 정한지 확인을한 후 ( org.springframework.web.servlet.DispatcherServlet) 그곳에다가  < security:global-method-security pre-post-annotations = "enabled" /> 해당 global method security를 추가해주도록 하자 이걸 몰라서 한참 뒤저보았다....

Spring 로컬 마음데로 변경하기

Interceptor.java public class Interceptors extends HandlerInterceptorAdapter { @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { //메소드는 컨트롤러가 호출되기 전에 실행된다. Locale locale = extractLocale(request, "ko" ); LocaleResolver localeResolver = RequestContextUtils.getLocaleResolver(request); localeResolver.setLocale(request, response, locale); return true ; } private Locale extractLocale(HttpServletRequest request,String local) { if (StringUtils.hasText(local)) { return StringUtils.parseLocaleString(local); } return request.getLocale(); } } web-interceptor.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 = "ht...