기본 콘텐츠로 건너뛰기

11월, 2021의 게시물 표시

스프링 자바 JAVA 서버에서 URL 찾기

스프링 서버단에서 호출 URL 찾기 서버(spring)에서 호출 URL을 알아야 할때 유용할 듯 @Override      public   void  urlCheck(HttpServletRequest request, HttpServletResponse response) {          //이전 페이지의 정보를 알때 레퍼러를 활용(URL을 직접 치고 들어오는경우는 null)          String  referer  =  ( String ) request.getHeader( "REFEREER" );            //URL를 확인하는 방법         UrlPathHelper urlPathHelper  =   new  UrlPathHelper();          String  originalURL  =  urlPathHelper.getOriginatingRequestUri(request);            //스프링 시큐리티 로그인할떄 저장하는 캐시를 활용         RequestCache requestCache  =   new  HttpSessionRequestCache();         SavedRequest savedRequest  =  requestCache.getRequest(request, response);          String  redirectUrl  =  savedRequest.getRedirectUrl();             } Colored by Color Scripter cs 참고 감사합니다 https://blog.jiniworld.me/53 https://jang8584.tistory.com/86

스프링 시큐리티(Spring Security) 권한 없을때 여러 결과 페이지 설정하기

Spring Security의 인가 실패시 결과 커스텀하기 Java에서 config 설정 방법으로 남김 AccessDeniedHandler()를 커스텀 해야함 public   class  CustomAccessDeniedHandler  implements  AccessDeniedHandler {       @Override      public   void  handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException e)  throws  IOException, ServletException {          //스프링 시큐리티 로그인때 만든 객체         Authentication authentication  =  SecurityContextHolder.getContext().getAuthentication();          //현재 접속 url를 확인         UrlPathHelper urlPathHelper  =   new  UrlPathHelper();          String  originalURL  =  urlPathHelper.getOriginatingRequestUri(request);            //로직을 짜서 상황에 따라 보내줄 주소를 설정해주면 됨         response.sendRedirect( "/" );     } } Colored by Color Scripter cs config에 설정 @Override      protected   void  configure(HttpSecurity http)  throws  Exception {         http             .addFilterBefore(authenticationFilter(), UsernamePasswordSessionAuthenticationFilter. class )             .authorizeReque