Class BaseIDAFilter
- java.lang.Object
-
- io.mosip.authentication.common.service.filter.BaseIDAFilter
-
- All Implemented Interfaces:
javax.servlet.Filter
- Direct Known Subclasses:
BaseAuthFilter
public abstract class BaseIDAFilter extends Object implements javax.servlet.Filter
The Class BaseIDAFilter - The Base IDA Filter that does all necessary authentication/authorization before allowing the request to the respective controllers.- Author:
- Sanjay Murali
-
-
Field Summary
Fields Modifier and Type Field Description protected EnvUtilenvThe env.protected KeyManagerkeyManagerThe key manager.protected com.fasterxml.jackson.databind.ObjectMappermapperThe mapper.
-
Constructor Summary
Constructors Constructor Description BaseIDAFilter()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract voidauthenticateRequest(ResettableStreamHttpServletRequest requestWrapper)authenticateRequest method used to validate the JSON signature pay load and the certificateprotected abstract voidcheckAllowedAMRForKBT(Map<String,Object> requestBody, Set<String> allowedAMRs)protected abstract voidcheckMispPolicyAllowed(MispPolicyDTO mispPolicy)protected voidconsumeRequest(ResettableStreamHttpServletRequest requestWrapper, Map<String,Object> requestBody)consumeRequest method is used to manipulate the request where the request is first reached and along this all validation are done further after successful decipher.protected StringconsumeResponse(ResettableStreamHttpServletRequest requestWrapper, io.mosip.authentication.common.service.filter.CharResponseWrapper responseWrapper, String responseAsString, Temporal actualRequestTime, Map<String,Object> requestBody)mapResponse method is used to construct the response for the successful authentication.voiddestroy()voiddoFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain)protected abstract StringfetchId(ResettableStreamHttpServletRequest requestWrapper, String attribute)fetchId used to fetch and determine the id of requestprotected Map<String,Object>getRequestBody(InputStream requestBody)getRequestBody used to get the request body from the raw input streamvoidinit(javax.servlet.FilterConfig filterConfig)protected abstract booleanisAMRValidationRequired()protected abstract booleanisCertificateValidationRequired()protected booleanisDate(String date)To validate a string whether its a date or not.protected abstract booleanisMispPolicyValidationRequired()protected abstract booleanisSignatureVerificationRequired()protected abstract booleanisSigningRequired()protected abstract booleanisThumbprintValidationRequired()protected abstract booleanisTrustValidationRequired()protected booleanneedStoreAnonymousProfile()protected booleanneedStoreAuthTransaction()protected Map<String,Object>removeNullOrEmptyFieldsInResponse(Map<String,Object> responseMap)removeNullOrEmptyFieldsInResponse method is used to remove all the empty and null values present in the responseprotected voidvalidateId(Map<String,Object> requestBody, String id)validateId is used to validate the id present in the requestprotected voidvalidateRequest(ResettableStreamHttpServletRequest requestWrapper, Map<String,Object> requestBody)validateRequest method is used to validate the version and the ID passed for the each request
-
-
-
Field Detail
-
env
protected EnvUtil env
The env.
-
mapper
protected com.fasterxml.jackson.databind.ObjectMapper mapper
The mapper.
-
keyManager
protected KeyManager keyManager
The key manager.
-
-
Method Detail
-
init
public void init(javax.servlet.FilterConfig filterConfig) throws javax.servlet.ServletException- Specified by:
initin interfacejavax.servlet.Filter- Throws:
javax.servlet.ServletException
-
doFilter
public void doFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain) throws IOException, javax.servlet.ServletException- Specified by:
doFilterin interfacejavax.servlet.Filter- Throws:
IOExceptionjavax.servlet.ServletException
-
removeNullOrEmptyFieldsInResponse
protected Map<String,Object> removeNullOrEmptyFieldsInResponse(Map<String,Object> responseMap)
removeNullOrEmptyFieldsInResponse method is used to remove all the empty and null values present in the response- Parameters:
responseMap- the response got after the authentication- Returns:
- the map consists of filter response without null or empty
-
needStoreAuthTransaction
protected boolean needStoreAuthTransaction()
-
needStoreAnonymousProfile
protected boolean needStoreAnonymousProfile()
-
consumeRequest
protected void consumeRequest(ResettableStreamHttpServletRequest requestWrapper, Map<String,Object> requestBody) throws IdAuthenticationAppException
consumeRequest method is used to manipulate the request where the request is first reached and along this all validation are done further after successful decipher.- Parameters:
requestWrapper-ResettableStreamHttpServletRequestrequestBody- the request body- Throws:
IdAuthenticationAppException- the id authentication app exceptionIdAuthenticationBusinessException
-
validateRequest
protected void validateRequest(ResettableStreamHttpServletRequest requestWrapper, Map<String,Object> requestBody) throws IdAuthenticationAppException
validateRequest method is used to validate the version and the ID passed for the each request- Parameters:
requestWrapper-ResettableStreamHttpServletRequestrequestBody- the request body is the request body fetched from input stream- Throws:
IdAuthenticationAppException- the id authentication app exception
-
fetchId
protected abstract String fetchId(ResettableStreamHttpServletRequest requestWrapper, String attribute)
fetchId used to fetch and determine the id of request- Parameters:
requestWrapper- theResettableStreamHttpServletRequest- Returns:
- the string
-
validateId
protected void validateId(Map<String,Object> requestBody, String id) throws IdAuthenticationAppException
validateId is used to validate the id present in the request- Parameters:
requestBody- the request bodyid- the id- Throws:
IdAuthenticationAppException- the id authentication app exception
-
consumeResponse
protected String consumeResponse(ResettableStreamHttpServletRequest requestWrapper, io.mosip.authentication.common.service.filter.CharResponseWrapper responseWrapper, String responseAsString, Temporal actualRequestTime, Map<String,Object> requestBody) throws IdAuthenticationAppException
mapResponse method is used to construct the response for the successful authentication.- Parameters:
requestWrapper-ResettableStreamHttpServletRequestresponseWrapper-CharResponseWrapperactualRequestTime- the request timerequestBody-- Returns:
- the string response finally built
- Throws:
IdAuthenticationAppException- the id authentication app exception
-
getRequestBody
protected Map<String,Object> getRequestBody(InputStream requestBody) throws IdAuthenticationAppException
getRequestBody used to get the request body from the raw input stream- Parameters:
requestBody-ResettableStreamHttpServletRequestget request as input stream- Returns:
- the request body
- Throws:
IdAuthenticationAppException- the id authentication app exception
-
isDate
protected boolean isDate(String date)
To validate a string whether its a date or not.- Parameters:
date- the date- Returns:
- true, if is date
-
authenticateRequest
protected abstract void authenticateRequest(ResettableStreamHttpServletRequest requestWrapper) throws IdAuthenticationAppException
authenticateRequest method used to validate the JSON signature pay load and the certificate- Parameters:
requestWrapper-ResettableStreamHttpServletRequest- Throws:
IdAuthenticationAppException- the id authentication app exception
-
isSigningRequired
protected abstract boolean isSigningRequired()
-
isSignatureVerificationRequired
protected abstract boolean isSignatureVerificationRequired()
-
isThumbprintValidationRequired
protected abstract boolean isThumbprintValidationRequired()
-
isTrustValidationRequired
protected abstract boolean isTrustValidationRequired()
-
isMispPolicyValidationRequired
protected abstract boolean isMispPolicyValidationRequired()
-
isCertificateValidationRequired
protected abstract boolean isCertificateValidationRequired()
-
isAMRValidationRequired
protected abstract boolean isAMRValidationRequired()
-
checkAllowedAMRForKBT
protected abstract void checkAllowedAMRForKBT(Map<String,Object> requestBody, Set<String> allowedAMRs) throws IdAuthenticationAppException
- Throws:
IdAuthenticationAppException
-
checkMispPolicyAllowed
protected abstract void checkMispPolicyAllowed(MispPolicyDTO mispPolicy) throws IdAuthenticationAppException
- Throws:
IdAuthenticationAppException
-
destroy
public void destroy()
- Specified by:
destroyin interfacejavax.servlet.Filter
-
-