Package tech.corefinance.common.service
Class JwtServiceImpl
java.lang.Object
tech.corefinance.common.service.JwtServiceImpl
- All Implemented Interfaces:
JwtService
@Service
@ConditionalOnProperty(prefix="tech.corefinance.security.jwt.enabled",
name="common",
matchIfMissing=true,
havingValue="true")
public class JwtServiceImpl
extends Object
implements JwtService
-
Constructor Summary
ConstructorsConstructorDescriptionJwtServiceImpl(String publicKey, String privateKey, org.springframework.core.io.ResourceLoader resourceLoader) -
Method Summary
Modifier and TypeMethodDescriptionprotected tech.corefinance.common.dto.JwtTokenDtoadditionalJwtVerifyStep(tech.corefinance.common.dto.JwtTokenDto jwtTokenDto, String token, String deviceId, String ipaddress) buildLoginDataMap(tech.corefinance.common.dto.JwtTokenDto jwtTokenDto) buildRefreshTokenDataMap(tech.corefinance.common.dto.JwtTokenDto jwtTokenDto, String token) extractIpAddress(jakarta.servlet.http.HttpServletRequest httpServletRequest) Extract client IP Address from request.retreiveTokenFromRequest(jakarta.servlet.http.HttpServletRequest httpServletRequest, jakarta.servlet.http.HttpServletResponse httpServletResponse) Retreive JWT data from request.tech.corefinance.common.dto.BasicUserDtoretrieveUserAsAttribute(tech.corefinance.common.dto.JwtTokenDto jwtTokenDto) Retrieve user info from login token.sign(Map<String, Serializable> data) Signing data.com.auth0.jwt.interfaces.DecodedJWTVerify JWT token.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface tech.corefinance.common.service.JwtService
buildLoginToken, buildLoginVerifyKey, buildRefreshToken
-
Constructor Details
-
JwtServiceImpl
public JwtServiceImpl(@Value("${tech.corefinance.security.public-key}") String publicKey, @Value("${tech.corefinance.security.private-key:}") String privateKey, @Autowired org.springframework.core.io.ResourceLoader resourceLoader) throws GeneralSecurityException, IOException - Throws:
GeneralSecurityExceptionIOException
-
-
Method Details
-
getJwtConfiguration
- Specified by:
getJwtConfigurationin interfaceJwtService
-
sign
Description copied from interface:JwtServiceSigning data.- Specified by:
signin interfaceJwtService- Parameters:
data- Data to sign.- Returns:
- JWT token
-
verfiy
Description copied from interface:JwtServiceVerify JWT token.- Specified by:
verfiyin interfaceJwtService- Parameters:
token- JWT tokendeviceId- Login device IDipaddress- Client IP Address- Returns:
- True if token active
-
extractIpAddress
public String extractIpAddress(jakarta.servlet.http.HttpServletRequest httpServletRequest) throws UnknownHostException Description copied from interface:JwtServiceExtract client IP Address from request.- Specified by:
extractIpAddressin interfaceJwtService- Parameters:
httpServletRequest- Request- Returns:
- Client IP Address
- Throws:
UnknownHostException- When cannot read ip address
-
retreiveTokenFromRequest
public Map<String,tech.corefinance.common.dto.JwtTokenDto> retreiveTokenFromRequest(jakarta.servlet.http.HttpServletRequest httpServletRequest, jakarta.servlet.http.HttpServletResponse httpServletResponse) throws IOException Description copied from interface:JwtServiceRetreive JWT data from request.- Specified by:
retreiveTokenFromRequestin interfaceJwtService- Parameters:
httpServletRequest- HttpServletRequesthttpServletResponse- HttpServletResponse- Returns:
- JwtTokenDto Object
- Throws:
IOException- When read fail
-
buildLoginDataMap
public Map<String,Serializable> buildLoginDataMap(tech.corefinance.common.dto.JwtTokenDto jwtTokenDto) throws com.fasterxml.jackson.core.JsonProcessingException - Specified by:
buildLoginDataMapin interfaceJwtService- Throws:
com.fasterxml.jackson.core.JsonProcessingException
-
buildRefreshTokenDataMap
public Map<String,Serializable> buildRefreshTokenDataMap(tech.corefinance.common.dto.JwtTokenDto jwtTokenDto, String token) throws com.fasterxml.jackson.core.JsonProcessingException - Specified by:
buildRefreshTokenDataMapin interfaceJwtService- Throws:
com.fasterxml.jackson.core.JsonProcessingException
-
additionalJwtVerifyStep
-
retrieveUserAsAttribute
public tech.corefinance.common.dto.BasicUserDto retrieveUserAsAttribute(tech.corefinance.common.dto.JwtTokenDto jwtTokenDto) Description copied from interface:JwtServiceRetrieve user info from login token.- Specified by:
retrieveUserAsAttributein interfaceJwtService- Parameters:
jwtTokenDto- Login token.- Returns:
- User from token
-