-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Arthur Gregorio
committed
Nov 13, 2018
1 parent
16f400b
commit 12c52f5
Showing
4 changed files
with
79 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
.../java/br/eti/arthurgregorio/library/infrastructure/soteria/auth/AuthenticationFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package br.eti.arthurgregorio.library.infrastructure.soteria.auth; | ||
|
||
import org.omnifaces.filter.HttpFilter; | ||
import org.omnifaces.util.Servlets; | ||
import org.slf4j.Logger; | ||
|
||
import javax.inject.Inject; | ||
import javax.servlet.FilterChain; | ||
import javax.servlet.ServletException; | ||
import javax.servlet.annotation.WebFilter; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import javax.servlet.http.HttpSession; | ||
import java.io.IOException; | ||
|
||
import static org.apache.commons.lang3.StringUtils.isBlank; | ||
|
||
/** | ||
* @author Arthur Gregorio | ||
* | ||
* @version 1.0.0 | ||
* @since 1.0.0, 13/11/2018 | ||
*/ | ||
@WebFilter(urlPatterns = "/secured/*") | ||
public class AuthenticationFilter extends HttpFilter { | ||
|
||
@Inject | ||
private Logger logger; | ||
|
||
/** | ||
* | ||
* @param request | ||
* @param response | ||
* @param session | ||
* @param chain | ||
* @throws ServletException | ||
* @throws IOException | ||
*/ | ||
@Override | ||
public void doFilter(HttpServletRequest request, HttpServletResponse response, HttpSession session, FilterChain chain) | ||
throws ServletException, IOException { | ||
|
||
final String requestedPath = request.getRequestURI().substring(request.getContextPath().length()) | ||
.replaceAll("[/]+$", ""); | ||
|
||
final String user = request.getRemoteUser(); | ||
|
||
if (isBlank(user)) { | ||
this.logger.info(String.format("The user must be authenticated to access this [%s]", requestedPath)); | ||
Servlets.facesRedirect(request, response, "/index.xhtml"); | ||
} | ||
chain.doFilter(request, response); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters