-
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.
Moves request claim processing to processor and adds support for simp…
…le claims
- Loading branch information
1 parent
dcb1710
commit daddfa6
Showing
4 changed files
with
93 additions
and
19 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
43 changes: 43 additions & 0 deletions
43
src/main/kotlin/de/solugo/oauthmock/token/processor/RequestClaimsProcessor.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,43 @@ | ||
package de.solugo.oauthmock.token.processor | ||
|
||
import de.solugo.oauthmock.token.* | ||
import de.solugo.oauthmock.util.put | ||
import de.solugo.oauthmock.util.removePrefixOrNull | ||
import org.jose4j.jwt.JwtClaims | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class RequestClaimsProcessor : TokenProcessor { | ||
|
||
override val step = TokenProcessor.Step.CLAIMS | ||
|
||
override suspend fun process(context: TokenContext) { | ||
context.parameters["claims"]?.forEach { | ||
context.commonClaims.put(JwtClaims.parse(it)) | ||
} | ||
context.parameters["idClaims"]?.forEach { | ||
context.idClaims.put(JwtClaims.parse(it)) | ||
} | ||
context.parameters["accessClaims"]?.forEach { | ||
context.accessClaims.put(JwtClaims.parse(it)) | ||
} | ||
context.parameters["refreshClaims"]?.forEach { | ||
context.refreshClaims.put(JwtClaims.parse(it)) | ||
} | ||
context.parameters.entries.forEach { (key, values) -> | ||
key.removePrefixOrNull("claim_")?.also { | ||
context.commonClaims.setClaim(it, values.last()) | ||
} | ||
key.removePrefixOrNull("accessClaim_")?.also { | ||
context.accessClaims.setClaim(it, values.last()) | ||
} | ||
key.removePrefixOrNull("idClaim_")?.also { | ||
context.idClaims.setClaim(it, values.last()) | ||
} | ||
key.removePrefixOrNull("refreshClaim_")?.also { | ||
context.refreshClaims.setClaim(it, values.last()) | ||
} | ||
} | ||
} | ||
|
||
} |
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