-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
242 additions
and
81 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
38 changes: 38 additions & 0 deletions
38
backend/src/main/kotlin/hu/bme/sch/cmsch/component/app/ApplicationService.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,38 @@ | ||
package hu.bme.sch.cmsch.component.app | ||
|
||
import hu.bme.sch.cmsch.component.login.CmschUser | ||
import hu.bme.sch.cmsch.model.UserEntity | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class ApplicationService { | ||
|
||
fun getUserAuthInfo(jwtUser: CmschUser, actualUser: UserEntity?): UserAuthInfoView { | ||
if (actualUser == null || isAuthenticationExpired(jwtUser, actualUser)) | ||
return UserAuthInfoView(authState = AuthState.EXPIRED) | ||
|
||
return UserAuthInfoView( | ||
authState = AuthState.LOGGED_IN, | ||
id = actualUser.id, | ||
internalId = actualUser.internalId, | ||
role = actualUser.role, | ||
permissionsAsList = actualUser.permissionsAsList, | ||
userName = actualUser.userName, | ||
groupId = actualUser.groupId, | ||
groupName = actualUser.groupName, | ||
) | ||
} | ||
|
||
fun isAuthenticationExpired(jwtUser: CmschUser, actualUser: UserEntity): Boolean { | ||
if (jwtUser.id != actualUser.id) return true | ||
if (jwtUser.internalId != actualUser.internalId) return true | ||
if (jwtUser.role != actualUser.role) return true | ||
if (jwtUser.permissionsAsList != actualUser.permissionsAsList) return true | ||
if (jwtUser.userName != actualUser.userName) return true | ||
if (jwtUser.groupId != actualUser.groupId) return true | ||
if (jwtUser.groupName != actualUser.groupName) return true | ||
|
||
return false | ||
} | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
backend/src/main/kotlin/hu/bme/sch/cmsch/component/app/UserAuthInfoView.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,38 @@ | ||
package hu.bme.sch.cmsch.component.app | ||
|
||
import com.fasterxml.jackson.annotation.JsonView | ||
import hu.bme.sch.cmsch.dto.FullDetails | ||
import hu.bme.sch.cmsch.model.RoleType | ||
|
||
enum class AuthState { | ||
EXPIRED, | ||
LOGGED_IN, | ||
LOGGED_OUT | ||
} | ||
|
||
|
||
data class UserAuthInfoView( | ||
@field:JsonView(FullDetails::class) | ||
val authState: AuthState = AuthState.LOGGED_OUT, | ||
|
||
@field:JsonView(FullDetails::class) | ||
val id: Int? = null, | ||
|
||
@field:JsonView(FullDetails::class) | ||
val internalId: String? = null, | ||
|
||
@field:JsonView(FullDetails::class) | ||
val role: RoleType? = null, | ||
|
||
@field:JsonView(FullDetails::class) | ||
val permissionsAsList: List<String>? = null, | ||
|
||
@field:JsonView(FullDetails::class) | ||
val userName: String? = null, | ||
|
||
@field:JsonView(FullDetails::class) | ||
val groupId: Int? = null, | ||
|
||
@field:JsonView(FullDetails::class) | ||
val groupName: String? = null, | ||
) |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import axios from 'axios' | ||
import { useQuery } from 'react-query' | ||
import { QueryKeys } from '../queryKeys' | ||
import { ApiPaths } from '../../../util/paths' | ||
import { UserAuthInfoView } from '../../../util/views/authInfo.view.ts' | ||
|
||
export const useAuthInfo = () => { | ||
return useQuery<UserAuthInfoView, Error>(QueryKeys.WHO_AM_I, async () => { | ||
const response = await axios.get<UserAuthInfoView>(ApiPaths.WHO_AM_I) | ||
return response.data | ||
}) | ||
} |
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
Oops, something went wrong.