Skip to content

Commit

Permalink
code tidy up
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmaLRussell committed Mar 4, 2024
1 parent 2f436ee commit 93b158c
Show file tree
Hide file tree
Showing 8 changed files with 4 additions and 50 deletions.
3 changes: 3 additions & 0 deletions api/app/src/main/kotlin/packit/controllers/LoginController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ class LoginController(
@ResponseBody
fun authConfig(): ResponseEntity<Map<String, Any>>
{
// TODO: 'appRoute' is needed by the front end to prepend routes, which may be needed if Packit is to be deployed
// under a route within the domain (e.g. /packit in the case of Montagu deploy). It isn't *really* auth config
// as such (though related), so consider if this is the right place to return it
val authConfig = mapOf(
"enableGithubLogin" to config.authEnableGithubLogin,
"enableBasicLogin" to config.authEnableBasicLogin,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,6 @@ class OAuth2UserService(private val githubUserClient: GithubUserClient) : Defaul

// TODO check if user exists, if not, save user email to database

/*val user = User(
githubInfo.userName(),
githubInfo.displayName(),
listOf(Role.USER)
)*/

//return PackitOAuth2User.create(user, oAuth2User.attributes)

val principal = UserPrincipal(
githubInfo.userName(),
githubInfo.displayName(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,6 @@ class BasicUserDetails(
private val password: String
) : UserDetails
{
/*companion object
{
fun create(user: User, attributes: MutableMap<String, Any>): BasicUserDetails
{
val authorities = AuthorityUtils.createAuthorityList(user.role.toString())
return BasicUserDetails(
UserPrincipal(user.userName, user.displayName, authorities, attributes),
user.password
)
}
}*/

/*override fun getName(): String
{
return principal.displayName
}*/

/*override fun getAttributes(): MutableMap<String, Any>
{
return principal.attributes
}*/

override fun getAuthorities(): MutableCollection<out GrantedAuthority>
{
return principal.authorities
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,6 @@ class PackitOAuth2User(
val principal: UserPrincipal
) : OAuth2User
{
/*companion object
{
fun create(user: User, attributes: MutableMap<String, Any>): PackitOAuth2User
{
val authorities = AuthorityUtils.createAuthorityList(user.role.toString())
return PackitOAuth2User(
UserPrincipal(user.userName, user.displayName, authorities, attributes)
)
}
}*/

override fun getAttributes(): MutableMap<String, Any>
{
return principal.attributes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ class TokenProvider(val config: AppConfig) : JwtIssuer

override fun issue(user: UserPrincipal): String
{
//val user = authentication.principal as UserPrincipal

val roles = user.authorities.map { it.authority }

val createdDate = Instant.now()
Expand Down
3 changes: 0 additions & 3 deletions api/app/src/main/kotlin/packit/service/BasePacketService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ class BasePacketService(
{
override fun importPackets()
{
// TODO: remove debug
println("importing packets")
val mostRecent = packetRepository.findTopByOrderByImportTimeDesc()?.importTime
val now = Instant.now().epochSecond.toDouble()
val packets = outpackServerClient.getMetadata(mostRecent)
Expand All @@ -54,7 +52,6 @@ class BasePacketService(
it.time.start, it.time.end
)
}
println("found packets: " + packets.count())
packetRepository.saveAll(packets)
}

Expand Down
3 changes: 0 additions & 3 deletions api/app/src/main/kotlin/packit/service/BasicLoginService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ class BasicLoginService(
)
)

// I don't think we need this
//SecurityContextHolder.getContext().authentication = authentication

val userDetails = (authentication.principal as BasicUserDetails)
val token = jwtIssuer.issue(userDetails.principal)

Expand Down
2 changes: 1 addition & 1 deletion api/app/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ spring.task.scheduling.pool.size=5
spring.security.oauth2.client.registration.github.client-id=${GITHUB_CLIENT_ID}
spring.security.oauth2.client.registration.github.client-secret=${GITHUB_CLIENT_SECRET}
spring.security.oauth2.client.registration.github.scope=read:org
spring.security.oauth2.client.registration.github.redirect-uri=http://localhost:8080/login/oauth2/code/github
spring.security.oauth2.client.registration.github.redirect-uri=${PACKIT_API_ROOT}/login/oauth2/code/github

0 comments on commit 93b158c

Please sign in to comment.