-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: protect endpoints and conditional configuration
- Loading branch information
1 parent
924f57c
commit c11e9a2
Showing
14 changed files
with
209 additions
and
233 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...e/src/main/kotlin/com/aamdigital/aambackendservice/security/AamAuthenticationConverter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.aamdigital.aambackendservice.security | ||
|
||
import org.springframework.core.convert.converter.Converter | ||
import org.springframework.security.authentication.AbstractAuthenticationToken | ||
import org.springframework.security.core.GrantedAuthority | ||
import org.springframework.security.core.authority.SimpleGrantedAuthority | ||
import org.springframework.security.oauth2.jwt.Jwt | ||
import org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class AamAuthenticationConverter : Converter<Jwt, AbstractAuthenticationToken> { | ||
override fun convert(source: Jwt): AbstractAuthenticationToken { | ||
return JwtAuthenticationToken(source, getClientAuthorities(source)) | ||
} | ||
|
||
private fun getClientAuthorities(jwt: Jwt): Collection<GrantedAuthority> { | ||
val realmAccessClaim = jwt.getClaimAsMap("realm_access") ?: return emptyList() | ||
|
||
val roles: List<String> = if (realmAccessClaim.containsKey("roles")) { | ||
when (val rolesClaim = realmAccessClaim["roles"]) { | ||
is List<*> -> rolesClaim.filterIsInstance<String>() | ||
else -> emptyList() | ||
} | ||
} else { | ||
emptyList() | ||
} | ||
|
||
return roles | ||
.filter { it.startsWith("aam_") } | ||
.map { | ||
SimpleGrantedAuthority("ROLE_$it") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 0 additions & 15 deletions
15
...ckend-service/src/main/kotlin/com/aamdigital/aambackendservice/skill/core/SkillStorage.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.