Package filter
Class AuthenticationFilter
java.lang.Object
filter.AuthenticationFilter
- All Implemented Interfaces:
javax.servlet.Filter
Filter that checks Authentication and Authorization
Redirects unauthenticated users to login page
Enforces role based access control
- Author:
- TAMIL MUGHILAN
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
destroy()
Cleans up resources when filter is destroyed.void
doFilter
(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain) Processes requests to check Authentication and Authorization.void
init
(javax.servlet.FilterConfig fConfig) Initializes the filter when application starts.private boolean
isStaticResource
(String path) Checks if the requested path is a static resource.private void
redirectBasedOnRole
(String role, javax.servlet.http.HttpServletResponse response, String contextPath) Redirects user to appropriate page based on their role.private void
sendAccessDenied
(javax.servlet.http.HttpServletResponse response, String message)
-
Field Details
-
openPaths
-
-
Constructor Details
-
AuthenticationFilter
public AuthenticationFilter()
-
-
Method Details
-
doFilter
public void doFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain) throws IOException, javax.servlet.ServletException Processes requests to check Authentication and Authorization. Allows access based on user role and user requests.- Specified by:
doFilter
in interfacejavax.servlet.Filter
- Parameters:
request
- the servlet requestresponse
- the servlet responsechain
- the filter chain- Throws:
IOException
- if an I/O error occursjavax.servlet.ServletException
- if a servlet error occurs
-
isStaticResource
Checks if the requested path is a static resource.- Parameters:
path
- the request path to check- Returns:
- true if it's a static resource, false otherwise
-
redirectBasedOnRole
private void redirectBasedOnRole(String role, javax.servlet.http.HttpServletResponse response, String contextPath) throws IOException Redirects user to appropriate page based on their role.- Parameters:
role
- the user's roleresponse
- the HTTP responsecontextPath
- the application context path- Throws:
IOException
- if redirection fails
-
sendAccessDenied
private void sendAccessDenied(javax.servlet.http.HttpServletResponse response, String message) throws IOException - Throws:
IOException
-
init
public void init(javax.servlet.FilterConfig fConfig) Initializes the filter when application starts.- Specified by:
init
in interfacejavax.servlet.Filter
- Parameters:
fConfig
- the filter configuration
-
destroy
public void destroy()Cleans up resources when filter is destroyed.- Specified by:
destroy
in interfacejavax.servlet.Filter
-