Class OtpRuleHandler
java.lang.Object
es.kukenan.smartfi.common.security.web.otp.OtpRuleHandler
This class handles the
OtpProperties.OtpRule defined for a given request. That is:
- Check if the rule is fired for a given HTTP request. Under some circumstances (delegated) there is no way to know if the rule is fired because it depends on operation business logic.
- Create and exception that is translated into a response with all the required information to manage the OTP rule. This is done at the security-gateway and requires information about how to handle the OTP request.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classClass designed to hold all required information about the HTTP request. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final OtpRuleHandler.HttpRequestRequired HTTP request data.private final com.fasterxml.jackson.databind.ObjectMapperObject mapper.private final OtpPropertiesOTP configuration.private BooleanDelegated logic check result.private final OtpProperties.OtpRule -
Constructor Summary
ConstructorsConstructorDescriptionOtpRuleHandler(OtpProperties.OtpRule rule, com.fasterxml.jackson.databind.ObjectMapper objectMapper, OtpProperties otpProperties, OtpRuleHandler.HttpRequest httpRequest) Handler constructor. -
Method Summary
Modifier and TypeMethodDescriptionbooleanTest if an OTP is required for the given request.private StringextractUserIdBodyProp(String property) private StringextractUserIdFromUrl(String regEx) private OtpRequiredConfigurationRetrieve the innerOtpProperties.OtpRuleidentifier.protected StringRetrieves the user destination of the OTP if it is not the default one.booleanCheck if the rule logic is determines if the given request can not be executed because an OTP is required.voidThrows anOtpRequiredExceptionthat includes the OTP configuration for the given request andOtpProperties.OtpRule.voidthrowOtpRequiredException(Object operationalInfo) Test if an OTP is required for the given request.protected booleanCheck if the innerOtpProperties.OtpRuleapplies given the current authentication conServletOtpRuleHandlerFactorytext authorities (roles).
-
Field Details
-
rule
-
objectMapper
private final com.fasterxml.jackson.databind.ObjectMapper objectMapperObject mapper. -
otpProperties
OTP configuration. -
httpRequest
Required HTTP request data. -
otpRequiredByDelegatedLogicCheck
Delegated logic check result. This flag is used in delegated logic check to inform that the used is not authorized to perform the operation and that an OTP is required.
-
-
Constructor Details
-
OtpRuleHandler
public OtpRuleHandler(OtpProperties.OtpRule rule, com.fasterxml.jackson.databind.ObjectMapper objectMapper, OtpProperties otpProperties, OtpRuleHandler.HttpRequest httpRequest) Handler constructor.- Parameters:
rule- TheOtpProperties.OtpRule.objectMapper- Object mapper.otpProperties- OTP configuration.httpRequest- Required HTTP request data.
-
-
Method Details
-
getRuleId
Retrieve the innerOtpProperties.OtpRuleidentifier.- Returns:
- the inner
OtpProperties.OtpRuleidentifier.
-
doesNotApply
public boolean doesNotApply()Test if an OTP is required for the given request.- Returns:
- true if the rule does not apply to the given request.
-
ruleLogicCheck
public boolean ruleLogicCheck()Check if the rule logic is determines if the given request can not be executed because an OTP is required. This occurs in two cases:- There is no logic check: OTP is always required.
- Although the logic is delegated but a generateOtp has been received with value true.
- Returns:
- true if the given request can not be executed because an OTP is required.
-
throwOtpRequiredException
public void throwOtpRequiredException()Throws anOtpRequiredExceptionthat includes the OTP configuration for the given request andOtpProperties.OtpRule. -
throwOtpRequiredException
Test if an OTP is required for the given request.- Parameters:
operationalInfo- operationalInfo- Throws:
OtpRequiredException-OtpRequiredExceptionthat includes the OTP configuration for the given request andOtpProperties.OtpRule.
-
unrestrictedRole
protected boolean unrestrictedRole()Check if the innerOtpProperties.OtpRuleapplies given the current authentication conServletOtpRuleHandlerFactorytext authorities (roles).- Returns:
- true if the
OtpProperties.OtpRuleroles contain any of the current authentication context authorities (roles).
-
handleUserIdOverride
Retrieves the user destination of the OTP if it is not the default one.- Returns:
- the user destination of the OTP if it is overridden by configuration.
-
extractUserIdFromUrl
-
getOtpRequiredConfiguration
-
extractUserIdBodyProp
-