Browse Source

Implement BookStoreAccessDeniedHandler

Signed-off-by: Pekka Helenius <fincer89@hotmail.com>
v0.0.3-alpha
Pekka Helenius 4 years ago
parent
commit
317a82b74f
1 changed files with 40 additions and 0 deletions
  1. +40
    -0
      bookstore/src/main/java/com/fjordtek/bookstore/service/session/BookStoreAccessDeniedHandler.java

+ 40
- 0
bookstore/src/main/java/com/fjordtek/bookstore/service/session/BookStoreAccessDeniedHandler.java View File

@ -0,0 +1,40 @@
package com.fjordtek.bookstore.service.session;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;
import com.fjordtek.bookstore.service.HttpServerLogger;
@Component
public class BookStoreAccessDeniedHandler implements AccessDeniedHandler {
private HttpServerLogger httpServerLogger = new HttpServerLogger();
@Override
public void handle(
HttpServletRequest requestData,
HttpServletResponse responseData,
AccessDeniedException accessDeniedException
) throws IOException, ServletException {
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
if (auth != null) {
responseData.setStatus(HttpServletResponse.SC_FORBIDDEN);
httpServerLogger.log(requestData, responseData);
}
responseData.setHeader("Location", "/");
responseData.setStatus(302);
}
}

Loading…
Cancel
Save