Repository navigation
Use new oidc authsch endpoint #1078
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| package hu.bme.sch.cmsch.component.login | ||
|
|
||
| import hu.bme.sch.cmsch.component.login.authsch.ProfileResponse | ||
| import hu.bme.sch.cmsch.component.login.authsch.AuthschProfile | ||
| import hu.bme.sch.cmsch.component.login.google.GoogleUserInfoResponse | ||
| import hu.bme.sch.cmsch.component.login.keycloak.KeycloakUserInfoResponse | ||
| import hu.bme.sch.cmsch.component.team.TeamService | ||
|
|
@@ -43,7 +43,7 @@ | |
| private val log = LoggerFactory.getLogger(javaClass) | ||
| private val userLocks = InternalIdLocks() | ||
|
|
||
| fun fetchUserEntity(profile: ProfileResponse): UserEntity { | ||
| fun fetchUserEntity(profile: AuthschProfile): UserEntity { | ||
| val lock = userLocks.lockForKey(profile.internalId) | ||
| try { | ||
| var user: UserEntity | ||
|
|
@@ -53,7 +53,7 @@ | |
| log.info("Logging in with existing user ${user.fullName} as authsch user") | ||
| } else { | ||
| val existingByEmail = | ||
| if (!profile.email.isNullOrBlank()) users.findByEmailIgnoreCase(profile.email!!) else Optional.empty() | ||
|
Check warning on line 56 in backend/src/main/kotlin/hu/bme/sch/cmsch/component/login/LoginService.kt
|
||
| if (existingByEmail.isPresent) { | ||
| user = existingByEmail.get() | ||
| log.info("Logging in with existing user ${user.fullName} (found by email) as authsch user, internalId updated from ${user.internalId} to ${profile.internalId}") | ||
|
|
@@ -64,10 +64,11 @@ | |
| profile.internalId, | ||
| profile.neptun ?: "N/A", | ||
| "", | ||
| (profile.surname ?: "") + " " + (profile.givenName ?: ""), | ||
| profile.fullName, | ||
| "", | ||
| profile.email ?: "", | ||
| RoleType.BASIC, | ||
| profile.email, | ||
| role = RoleType.BASIC, | ||
| secondaryEmail = profile.secondaryEmail, | ||
| groupName = "", group = null, | ||
| guild = GuildType.UNKNOWN, major = MajorType.UNKNOWN, | ||
| provider = AUTHSCH | ||
|
|
@@ -115,8 +116,8 @@ | |
| "", | ||
| "${profile.familyName} ${profile.givenName}".take(254), | ||
| "", | ||
| profile.email.take(254), | ||
| RoleType.BASIC, | ||
| profile.email.take(254).ifBlank { null }, | ||
| role = RoleType.BASIC, | ||
| groupName = "", group = null, | ||
| guild = GuildType.UNKNOWN, major = MajorType.UNKNOWN, | ||
| provider = GOOGLE, | ||
|
|
@@ -164,7 +165,7 @@ | |
| user.groupName = user.group?.name ?: "" | ||
| } | ||
|
|
||
| private fun updateFieldsForAuthsch(user: UserEntity, profile: ProfileResponse) { | ||
| private fun updateFieldsForAuthsch(user: UserEntity, profile: AuthschProfile) { | ||
|
Check failure on line 168 in backend/src/main/kotlin/hu/bme/sch/cmsch/component/login/LoginService.kt
|
||
| // Generate CMSch id if not present | ||
| if (user.cmschId.isBlank()) { | ||
| profileService.generateProfileIdForUser(user) | ||
|
|
@@ -172,12 +173,24 @@ | |
|
|
||
| // Update user profile values | ||
| if (profile.neptun != null) { | ||
| user.neptun = profile.neptun ?: user.neptun | ||
|
Check warning on line 176 in backend/src/main/kotlin/hu/bme/sch/cmsch/component/login/LoginService.kt
|
||
| } | ||
| if (profile.email != null && profile.email?.isNotBlank() == true) { | ||
| if (profile.email != null && profile.email.isNotBlank() == true) { | ||
| user.email = profile.email ?: user.email | ||
|
Check warning on line 179 in backend/src/main/kotlin/hu/bme/sch/cmsch/component/login/LoginService.kt
|
||
| } | ||
|
|
||
| if (!profile.secondaryEmail.isNullOrBlank()) { | ||
| user.secondaryEmail = profile.secondaryEmail | ||
| } | ||
|
|
||
| // Grant admin by BME directory address | ||
| val authschAdminAddresses = loginComponent.authschAdminAddresses.split(Regex(", *")).filter { it.isNotBlank() } | ||
| if (profile.email != null && authschAdminAddresses.any { it.equals(profile.email, ignoreCase = true) }) { | ||
|
Comment on lines
+187
to
+188
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win Trim each configured AuthSCH admin address before matching. If an address has leading whitespace or whitespace before a comma, 🤖 Prompt for AI Agents |
||
| log.info("Granting ADMIN for ${user.fullName}") | ||
| user.role = RoleType.ADMIN | ||
| user.detailsImported = true | ||
| } | ||
|
|
||
| grantGuildAndGroup(user) | ||
| grantRole(user) | ||
|
|
||
|
|
@@ -206,7 +219,7 @@ | |
| } | ||
|
|
||
| // Assign groups and roles | ||
| if (profile.eduPersonEntitlement != null && user.role.value < RoleType.ADMIN.value) { | ||
| if (profile.activeMemberships.isNotEmpty() && user.role.value < RoleType.ADMIN.value) { | ||
| assignStaffRole(profile, user) | ||
| assignAdminRole(profile, user) | ||
| assignOrganizerGroup(profile, user) | ||
|
|
@@ -219,8 +232,8 @@ | |
| } | ||
|
|
||
| // Assign using unit-scope | ||
| val bmeUnitScopes = profile.bmeunitscope | ||
| if (unitScopeComponent.unitScopeGrantsEnabled && bmeUnitScopes != null) { | ||
| val bmeUnitScopes = profile.unitScopes | ||
| if (unitScopeComponent.unitScopeGrantsEnabled && !bmeUnitScopes.isNullOrEmpty()) { | ||
| if (bmeUnitScopes.any { it.bme }) { | ||
| processUnitScopeStatus(user, | ||
| unitScopeComponent.bmeGrantRoleAttendee, | ||
|
|
@@ -264,6 +277,7 @@ | |
| unitScopeComponent.vbkNewbieGrantGroupName) | ||
| } | ||
| } | ||
| // Assigned only when the claim is actually present | ||
| if (bmeUnitScopes != null) { | ||
| user.unitScopes = bmeUnitScopes.joinToString(", ") | ||
| } | ||
|
|
@@ -293,8 +307,8 @@ | |
| } | ||
| } | ||
|
|
||
| if (user.email.isNotBlank() && !alreadySetGroupAndGuild) { | ||
| groupToUserMapping.findByEmailIgnoreCase(user.email).ifPresent { | ||
| if (!user.email.isNullOrBlank() && !alreadySetGroupAndGuild) { | ||
| groupToUserMapping.findByEmailIgnoreCase(user.email!!).ifPresent { | ||
| user.major = it.major | ||
| addUserToGroup(user, it) | ||
| user.detailsImported = true | ||
|
|
@@ -311,8 +325,8 @@ | |
| applied = true | ||
| } | ||
| } | ||
| if (!applied && user.email.isNotBlank()) { | ||
| roleToUserMapping.findByEmailIgnoreCase(user.email).ifPresent { | ||
| if (!applied && !user.email.isNullOrBlank()) { | ||
| roleToUserMapping.findByEmailIgnoreCase(user.email!!).ifPresent { | ||
| user.role = it.role | ||
| } | ||
| } | ||
|
|
@@ -347,7 +361,7 @@ | |
| } | ||
|
|
||
| private fun assignStaffRole( | ||
| profile: ProfileResponse, | ||
| profile: AuthschProfile, | ||
| user: UserEntity | ||
| ) { | ||
| val staffGroups = loginComponent.staffGroups | ||
|
|
@@ -357,10 +371,7 @@ | |
| if (staffGroups.isEmpty()) | ||
| return | ||
|
|
||
| val grantStaffRole = profile.eduPersonEntitlement | ||
| ?.filter { it.end == null } | ||
| ?.any { staffGroups.contains(it.id) } | ||
| ?: false | ||
| val grantStaffRole = profile.activeMemberships.any { staffGroups.contains(it.id) } | ||
|
|
||
| if (grantStaffRole) { | ||
| log.info("Granting STAFF for ${user.fullName}") | ||
|
|
@@ -376,7 +387,7 @@ | |
| } | ||
|
|
||
| private fun assignAdminRole( | ||
| profile: ProfileResponse, | ||
| profile: AuthschProfile, | ||
| user: UserEntity | ||
| ) { | ||
| val adminGroups = loginComponent.adminGroups | ||
|
|
@@ -386,10 +397,7 @@ | |
| if (adminGroups.isEmpty()) | ||
| return | ||
|
|
||
| val grantAdminRole = profile.eduPersonEntitlement | ||
| ?.filter { it.end == null } | ||
| ?.any { adminGroups.contains(it.id) } | ||
| ?: false | ||
| val grantAdminRole = profile.activeMemberships.any { adminGroups.contains(it.id) } | ||
|
|
||
| if (grantAdminRole) { | ||
| log.info("Granting ADMIN for ${user.fullName}") | ||
|
|
@@ -398,7 +406,7 @@ | |
| } | ||
|
|
||
| private fun assignOrganizerGroup( | ||
| profile: ProfileResponse, | ||
| profile: AuthschProfile, | ||
| user: UserEntity | ||
| ) { | ||
| val organizerGroups = loginComponent.organizerGroups | ||
|
|
@@ -408,10 +416,7 @@ | |
| if (organizerGroups.isEmpty()) | ||
| return | ||
|
|
||
| val memberOfAnyOrganizerGroups = profile.eduPersonEntitlement | ||
| ?.filter { it.end == null } | ||
| ?.any { organizerGroups.contains(it.id) } | ||
| ?: false | ||
| val memberOfAnyOrganizerGroups = profile.activeMemberships.any { organizerGroups.contains(it.id) } | ||
|
|
||
| if (memberOfAnyOrganizerGroups && user.role.value < RoleType.STAFF.value) { | ||
| groups.findByName(loginComponent.organizerGroupName).ifPresent { | ||
|
|
@@ -453,8 +458,8 @@ | |
| "", | ||
| "${profile.familyName} ${profile.givenName}", | ||
| profile.preferredUsername, | ||
| profile.email, | ||
| RoleType.BASIC, | ||
| profile.email.ifBlank { null }, | ||
| role = RoleType.BASIC, | ||
| groupName = "", group = null, | ||
| guild = GuildType.UNKNOWN, major = MajorType.UNKNOWN, | ||
| provider = KEYCLOAK, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package hu.bme.sch.cmsch.component.login.authsch | ||
|
|
||
| data class ActiveMembership( | ||
| val id: Long = 0, | ||
| val name: String = "", | ||
| val title: List<String> = listOf() | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renaming this is intentional, we don't want to break live websites, currently all live sites use the default config, so we don't lose scopes