Skip to content

Commit

Permalink
Refactor CoSecJwtAutoConfiguration (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahoo-Wang authored Dec 31, 2022
1 parent 9289510 commit bb1c0b0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import me.ahoo.cosec.jwt.JwtTokenConverter
import me.ahoo.cosec.jwt.JwtTokenVerifier
import me.ahoo.cosec.spring.boot.starter.ConditionalOnCoSecEnabled
import me.ahoo.cosec.spring.boot.starter.authentication.ConditionalOnAuthenticationEnabled
import me.ahoo.cosec.spring.boot.starter.authorization.ConditionalOnAuthorizationEnabled
import me.ahoo.cosec.token.TokenCompositeAuthentication
import me.ahoo.cosec.token.TokenConverter
import me.ahoo.cosec.token.TokenVerifier
Expand Down Expand Up @@ -63,25 +62,33 @@ class CoSecJwtAutoConfiguration {
}
}

@Bean
@ConditionalOnMissingBean
fun cosecJwtTokenVerifier(
algorithm: Algorithm
): TokenVerifier {
return JwtTokenVerifier(algorithm)
}

@Bean
@ConditionalOnMissingBean
fun cosecTokenConverter(
idGenerator: IdGenerator,
algorithm: Algorithm,
jwtProperties: JwtProperties
): TokenConverter {
return JwtTokenConverter(
idGenerator,
algorithm,
jwtProperties.tokenValidity.access,
jwtProperties.tokenValidity.refresh
)
}

@Configuration
@ConditionalOnAuthenticationEnabled
class OnAuthentication {

@Bean
@ConditionalOnMissingBean
fun cosecTokenConverter(
idGenerator: IdGenerator,
algorithm: Algorithm,
jwtProperties: JwtProperties
): TokenConverter {
return JwtTokenConverter(
idGenerator,
algorithm,
jwtProperties.tokenValidity.access,
jwtProperties.tokenValidity.refresh
)
}

@Bean
@ConditionalOnBean(CompositeAuthentication::class)
fun tokenCompositeAuthentication(
Expand All @@ -91,16 +98,4 @@ class CoSecJwtAutoConfiguration {
return TokenCompositeAuthentication(compositeAuthentication, tokenConverter)
}
}

@Configuration
@ConditionalOnAuthorizationEnabled
class OnAuthorization {
@Bean
@ConditionalOnMissingBean
fun cosecJwtTokenVerifier(
algorithm: Algorithm
): TokenVerifier {
return JwtTokenVerifier(algorithm)
}
}
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# limitations under the License.
#
group=me.ahoo.cosec
version=1.6.5
version=1.6.6
description=RBAC-based And Policy-based Multi-Tenant Reactive Security Framework
website=https://github.com/Ahoo-Wang/CoSec
issues=https://github.com/Ahoo-Wang/CoSec/issues
Expand Down

0 comments on commit bb1c0b0

Please sign in to comment.