Skip to content

Commit

Permalink
feat: return existing user ID when trying to add a user twice
Browse files Browse the repository at this point in the history
  • Loading branch information
atennert committed Apr 27, 2023
1 parent 8e74524 commit 47dcc9e
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/main/kotlin/com/qupaya/sha1/Sha1ImportResource.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ class Sha1ImportResource(private val session: KeycloakSession) {
fun importUser(userData: Sha1User): Response {
checkRealmAdmin()

val existingUser = session.users().getUserByEmail(session.context.realm, userData.email)
if (existingUser != null) {
return Response.ok("{\"id\": \"${existingUser.id}\"}")
.build()
}

val user = session.users().addUser(session.context.realm, userData.username)
user.firstName = userData.firstName
user.lastName = userData.lastName
Expand All @@ -44,7 +50,6 @@ class Sha1ImportResource(private val session: KeycloakSession) {
if (auth == null) {
throw NotAuthorizedException("Bearer")
} else if (auth.token.realmAccess == null || !auth.token.realmAccess.isUserInRole("sha1-import")) {
println(auth.token.realmAccess?.roles)
throw ForbiddenException("Does not have the required import role")
}
}
Expand Down

0 comments on commit 47dcc9e

Please sign in to comment.