-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
change password use case still to be implemented now we have a stubbed step just to try the workflow engine
- Loading branch information
Showing
13 changed files
with
225 additions
and
120 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import React from 'react'; | ||
import Template from "../component/Template"; | ||
import {Divider, Grid, Paper, ThemeProvider, Typography} from "@mui/material"; | ||
import {VpnKey} from "@mui/icons-material"; | ||
import theme from "../component/styles"; | ||
import getDataFromDomUtils from "../utils/getDataFromDomUtils"; | ||
import ComponentInitializer from "../utils/ComponentInitializer"; | ||
|
||
interface ChangePasswordPageProps { | ||
metadata: string | ||
} | ||
|
||
const ResetChangePasswordPage: React.FC<ChangePasswordPageProps> = ({metadata}) => { | ||
|
||
return ( | ||
<ThemeProvider theme={theme}> | ||
<Template maxWidth="sm"> | ||
<Typography variant="h3" component="h3"> | ||
<VpnKey fontSize="large"/> Reset your password | ||
</Typography> | ||
|
||
<Grid style={{marginTop: '10px'}}> | ||
<Divider/> | ||
</Grid> | ||
|
||
<Paper> | ||
<form action="/change-password" method="post"> | ||
|
||
<button type="submit">Submit</button> | ||
</form> | ||
</Paper> | ||
</Template> | ||
</ThemeProvider> | ||
) | ||
} | ||
|
||
let metadata = getDataFromDomUtils('metadata') | ||
let page = <ResetChangePasswordPage metadata={metadata}/>; | ||
|
||
ComponentInitializer(page) |
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
85 changes: 85 additions & 0 deletions
85
src/main/kotlin/com/vauthenticator/server/login/LoginWorkflowHandler.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,85 @@ | ||
package com.vauthenticator.server.login | ||
|
||
import jakarta.servlet.http.HttpServletRequest | ||
import jakarta.servlet.http.HttpServletResponse | ||
import jakarta.servlet.http.HttpSession | ||
import org.springframework.security.core.Authentication | ||
import org.springframework.security.core.context.SecurityContextHolder | ||
import org.springframework.security.web.DefaultRedirectStrategy | ||
import org.springframework.security.web.RedirectStrategy | ||
import org.springframework.security.web.authentication.AuthenticationSuccessHandler | ||
import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler | ||
import org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler | ||
import org.springframework.stereotype.Controller | ||
import org.springframework.web.bind.annotation.GetMapping | ||
import org.springframework.web.servlet.ModelAndView | ||
import java.util.Optional.* | ||
import kotlin.jvm.optionals.getOrElse | ||
|
||
class CompositeLoginWorkflowEngine( | ||
val url: String, | ||
private val handlers: List<LoginWorkflowHandler> | ||
) : | ||
LoginWorkflowEngine, AuthenticationSuccessHandler { | ||
private val defaultSuccessHandler: AuthenticationSuccessHandler | ||
|
||
init { | ||
this.defaultSuccessHandler = SimpleUrlAuthenticationSuccessHandler(url) | ||
this.defaultSuccessHandler.setAlwaysUseDefaultTargetUrl(true) | ||
} | ||
|
||
override fun onAuthenticationSuccess( | ||
request: HttpServletRequest, | ||
response: HttpServletResponse, | ||
authentication: Authentication | ||
) { | ||
println("authentication on engine: $authentication") | ||
SecurityContextHolder.getContext().authentication = authentication | ||
this.defaultSuccessHandler.onAuthenticationSuccess(request, response, authentication) | ||
} | ||
|
||
override fun workflowsNextHop(session: HttpSession): LoginWorkflowHandler { | ||
val index = ofNullable(session.getAttribute("CompositeLoginWorkflowEngine_index")).getOrElse { 0 } as Int | ||
val nextHandler = index + 1 | ||
session.setAttribute("CompositeLoginWorkflowEngine_index", nextHandler) | ||
return handlers[index] | ||
} | ||
|
||
} | ||
|
||
interface LoginWorkflowEngine { | ||
fun workflowsNextHop(session: HttpSession): LoginWorkflowHandler | ||
} | ||
|
||
interface LoginWorkflowHandler { | ||
fun view(): String | ||
|
||
fun canHandle(request: HttpServletRequest, response: HttpServletResponse): Boolean | ||
|
||
} | ||
|
||
@Controller | ||
class LoginWorkflowEngineController(private val engine: LoginWorkflowEngine) { | ||
|
||
val defaultNextHope = SavedRequestAwareAuthenticationSuccessHandler() | ||
private val redirectStrategy: RedirectStrategy = DefaultRedirectStrategy() | ||
|
||
@GetMapping("/login-workflow") | ||
fun view( | ||
modelAndView: ModelAndView, | ||
session: HttpSession, | ||
authentication: Authentication?, | ||
request: HttpServletRequest, | ||
response: HttpServletResponse | ||
) { | ||
val workflowsNextHop = engine.workflowsNextHop(session) | ||
println("workflowsNextHop: ${workflowsNextHop}") | ||
|
||
if (workflowsNextHop.canHandle(request, response)) { | ||
println("go to redirect on ${workflowsNextHop.view()}") | ||
redirectStrategy.sendRedirect(request, response, workflowsNextHop.view()) | ||
} else { | ||
defaultNextHope.onAuthenticationSuccess(request, response, authentication) | ||
} | ||
} | ||
} |
27 changes: 0 additions & 27 deletions
27
src/main/kotlin/com/vauthenticator/server/mfa/MfaAuthentication.kt
This file was deleted.
Oops, something went wrong.
41 changes: 12 additions & 29 deletions
41
src/main/kotlin/com/vauthenticator/server/mfa/MfaAuthenticationHandler.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 |
---|---|---|
@@ -1,45 +1,28 @@ | ||
package com.vauthenticator.server.mfa | ||
|
||
import com.vauthenticator.server.extentions.hasEnoughScopes | ||
import com.vauthenticator.server.login.LoginWorkflowHandler | ||
import com.vauthenticator.server.oauth2.clientapp.ClientAppId | ||
import com.vauthenticator.server.oauth2.clientapp.ClientApplicationRepository | ||
import com.vauthenticator.server.oauth2.clientapp.Scope | ||
import jakarta.servlet.http.HttpServletRequest | ||
import jakarta.servlet.http.HttpServletResponse | ||
import org.springframework.security.core.Authentication | ||
import org.springframework.security.core.context.SecurityContextHolder | ||
import org.springframework.security.web.authentication.AuthenticationSuccessHandler | ||
import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler | ||
import org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler | ||
|
||
class MfaAuthenticationHandler(private val clientApplicationRepository: ClientApplicationRepository, url: String) : | ||
AuthenticationSuccessHandler { | ||
private val withMfaSuccessHandler: AuthenticationSuccessHandler | ||
private val withoutMfaSuccessHandler: AuthenticationSuccessHandler | ||
class MfaAuthenticationHandler( | ||
private val clientApplicationRepository: ClientApplicationRepository, | ||
private val url: String | ||
) : LoginWorkflowHandler { | ||
|
||
init { | ||
val withMfaSuccessHandler = SimpleUrlAuthenticationSuccessHandler(url) | ||
withMfaSuccessHandler.setAlwaysUseDefaultTargetUrl(true) | ||
this.withMfaSuccessHandler = withMfaSuccessHandler | ||
this.withoutMfaSuccessHandler = SavedRequestAwareAuthenticationSuccessHandler() | ||
} | ||
|
||
override fun onAuthenticationSuccess( | ||
request: HttpServletRequest, response: HttpServletResponse, | ||
authentication: Authentication | ||
) { | ||
override fun view(): String = this.url | ||
|
||
override fun canHandle( | ||
request: HttpServletRequest, | ||
response: HttpServletResponse, | ||
): Boolean { | ||
val clientId = request.session.getAttribute("clientId") as String | ||
val isMfaRequired = clientApplicationRepository.findOne(ClientAppId(clientId)) | ||
return clientApplicationRepository.findOne(ClientAppId(clientId)) | ||
.filter { it.hasEnoughScopes(Scope.MFA_ALWAYS) } | ||
.isPresent | ||
|
||
if (isMfaRequired) { | ||
SecurityContextHolder.getContext().authentication = MfaAuthentication(authentication) | ||
withMfaSuccessHandler.onAuthenticationSuccess(request, response, authentication) | ||
} else { | ||
withoutMfaSuccessHandler.onAuthenticationSuccess(request, response, authentication) | ||
} | ||
} | ||
|
||
} | ||
} |
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
16 changes: 0 additions & 16 deletions
16
src/main/kotlin/com/vauthenticator/server/mfa/MfaTrustResolver.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.