-
Notifications
You must be signed in to change notification settings - Fork 181
Spring Lemon Commons Guide
spring-lemon-commons
is second in the Spring Lemon module hierarchy. It includes spring-lemon-exceptions and adds some common features that are useful in other modules, which are discussed below.
Spring Lemon comes with LemonJwsService
and LemonJweService
, which are used for creating and parsing JWS and JWE tokens respectively. They use Nimbus JOSE + JWT under the hood.
LemonJwsService and LemonJweService aren't used directly in Spring Lemon. Instead, BlueTokenService
and GreenTokenService
, two interfaces implemented by LemonJwsService and LemonJweService respectively, are used.
Spring Lemon uses BlueTokenService for creating/parsing authorization tokens, and GreenTokenService for creating/parsing other tokens (like forgot-password token). They are defined as beans in LemonCommonsAutoConfiguration
, as below:
@Bean
@ConditionalOnMissingBean(BlueTokenService.class)
public BlueTokenService blueTokenService(LemonProperties properties) throws JOSEException {
return new LemonJwsService(properties.getJwt().getSecret());
}
@Bean
@ConditionalOnMissingBean(GreenTokenService.class)
public GreenTokenService greenTokenService(LemonProperties properties) throws KeyLengthException {
return new LemonJweService(properties.getJwt().getSecret());
}
Noticed the @ConditionalOnMissingBean
annotation above? So, if you want to replace the implementations, just define your beans.