-
Notifications
You must be signed in to change notification settings - Fork 11
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
1 parent
7b0bac9
commit 93e50fc
Showing
7 changed files
with
154 additions
and
18 deletions.
There are no files selected for viewing
46 changes: 43 additions & 3 deletions
46
src/main/kotlin/au/org/ala/cas/webflow/AlaCasWebflowConfiguration.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,24 +1,64 @@ | ||
package au.org.ala.cas.webflow | ||
|
||
import org.apereo.cas.ticket.registry.TicketRegistrySupport | ||
import org.apereo.cas.web.support.CookieRetrievingCookieGenerator | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.beans.factory.annotation.Qualifier | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean | ||
import org.springframework.boot.context.properties.EnableConfigurationProperties | ||
import org.springframework.cloud.context.config.annotation.RefreshScope | ||
import org.springframework.context.annotation.Bean | ||
import org.springframework.context.annotation.Configuration | ||
import org.springframework.webflow.definition.registry.FlowDefinitionRegistry | ||
import org.springframework.webflow.engine.builder.support.FlowBuilderServices | ||
|
||
@Configuration("alaCasWebflowConfiguration") | ||
@EnableConfigurationProperties(AuthCookieProperties::class) | ||
open class AlaCasWebflowConfiguration { | ||
|
||
@Autowired | ||
lateinit var authCookieProperties: AuthCookieProperties | ||
|
||
@Autowired | ||
@Qualifier("loginFlowRegistry") | ||
lateinit var loginFlowDefinitionRegistry: FlowDefinitionRegistry | ||
|
||
@Autowired | ||
@Qualifier("logoutFlowRegistry") | ||
lateinit var logoutFlowDefinitionRegistry: FlowDefinitionRegistry | ||
|
||
@Autowired | ||
lateinit var flowBuilderServices: FlowBuilderServices | ||
|
||
@ConditionalOnMissingBean(name = arrayOf("authCookeWebflowConfigurer")) | ||
@Bean("authCookeWebflowConfigurer") | ||
open fun authCookeWebflowConfigurer(): AuthCookieWebflowConfigurer = AuthCookieWebflowConfigurer(flowBuilderServices, loginFlowDefinitionRegistry) | ||
@Autowired | ||
@Qualifier("defaultTicketRegistrySupport") | ||
lateinit var ticketRegistrySupport: TicketRegistrySupport | ||
|
||
@Bean | ||
@RefreshScope | ||
@Qualifier("alaProxyAuthenticationCookieGenerator") | ||
open fun alaProxyAuthenticationCookieGenerator(): CookieRetrievingCookieGenerator = | ||
authCookieProperties.cookie.run { CookieRetrievingCookieGenerator(name, path, maxAge, isSecure, domain, isHttpOnly) } | ||
|
||
@Bean | ||
@RefreshScope | ||
open fun generateAuthCookieAction( | ||
@Qualifier("alaProxyAuthenticationCookieGenerator") alaProxyAuthenticationCookieGenerator: CookieRetrievingCookieGenerator | ||
): GenerateAuthCookieAction = | ||
GenerateAuthCookieAction(ticketRegistrySupport, alaProxyAuthenticationCookieGenerator) | ||
|
||
@Bean | ||
@RefreshScope | ||
open fun removeAuthCookieAction( | ||
@Qualifier("alaProxyAuthenticationCookieGenerator") alaProxyAuthenticationCookieGenerator: CookieRetrievingCookieGenerator | ||
): RemoveAuthCookieAction = | ||
RemoveAuthCookieAction(alaProxyAuthenticationCookieGenerator) | ||
|
||
@ConditionalOnMissingBean(name = arrayOf("authCookieWebflowConfigurer")) | ||
@Bean("authCookieWebflowConfigurer") | ||
open fun authCookieWebflowConfigurer( | ||
generateAuthCookieAction: GenerateAuthCookieAction, | ||
removeAuthCookieAction: RemoveAuthCookieAction | ||
): AuthCookieWebflowConfigurer = | ||
AuthCookieWebflowConfigurer(flowBuilderServices, loginFlowDefinitionRegistry, logoutFlowDefinitionRegistry, generateAuthCookieAction, removeAuthCookieAction) | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/kotlin/au/org/ala/cas/webflow/AuthCookieProperties.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,9 @@ | ||
package au.org.ala.cas.webflow | ||
|
||
import org.apereo.cas.configuration.model.support.cookie.CookieProperties | ||
import org.springframework.boot.context.properties.ConfigurationProperties | ||
|
||
@ConfigurationProperties(value = "auth") | ||
open class AuthCookieProperties( | ||
var cookie: CookieProperties = CookieProperties() | ||
) |
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
37 changes: 37 additions & 0 deletions
37
src/main/kotlin/au/org/ala/cas/webflow/GenerateAuthCookieAction.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,37 @@ | ||
package au.org.ala.cas.webflow | ||
|
||
import au.org.ala.utils.logger | ||
import org.apereo.cas.authentication.AuthenticationException | ||
import org.apereo.cas.ticket.InvalidTicketException | ||
import org.apereo.cas.ticket.registry.TicketRegistrySupport | ||
import org.apereo.cas.web.support.CookieRetrievingCookieGenerator | ||
import org.apereo.cas.web.support.WebUtils | ||
import org.springframework.webflow.action.AbstractAction | ||
import org.springframework.webflow.execution.Event | ||
import org.springframework.webflow.execution.RequestContext | ||
|
||
open class GenerateAuthCookieAction(val ticketRegistrySupport: TicketRegistrySupport, | ||
val alaProxyAuthenticationCookieGenerator: CookieRetrievingCookieGenerator) : AbstractAction() { | ||
|
||
companion object { | ||
val log = logger<GenerateAuthCookieAction>() | ||
} | ||
|
||
override fun doExecute(context: RequestContext): Event { | ||
|
||
log.error("GenerateAuthCookieAction running") | ||
// | ||
// Create ALA specific cookie that any ALA web application can read | ||
// | ||
val ticketGrantingTicket = WebUtils.getTicketGrantingTicketId(context) | ||
log.debug("Ticket-granting ticket found in the context is [{}]", ticketGrantingTicket) | ||
|
||
val authentication = this.ticketRegistrySupport.getAuthenticationFrom(ticketGrantingTicket) ?: throw InvalidTicketException(AuthenticationException("No authentication found for ticket " + ticketGrantingTicket), ticketGrantingTicket) | ||
val email = authentication.principal.id | ||
|
||
alaProxyAuthenticationCookieGenerator.addCookie(WebUtils.getHttpServletRequest(context), WebUtils.getHttpServletResponse(context), email) | ||
|
||
return success() | ||
} | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
src/main/kotlin/au/org/ala/cas/webflow/RemoveAuthCookieAction.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,25 @@ | ||
package au.org.ala.cas.webflow | ||
|
||
import au.org.ala.utils.logger | ||
import org.apereo.cas.web.support.CookieRetrievingCookieGenerator | ||
import org.apereo.cas.web.support.WebUtils | ||
import org.springframework.webflow.action.AbstractAction | ||
import org.springframework.webflow.execution.Event | ||
import org.springframework.webflow.execution.RequestContext | ||
|
||
open class RemoveAuthCookieAction( | ||
val alaProxyAuthenticationCookieGenerator: CookieRetrievingCookieGenerator | ||
) : AbstractAction() { | ||
|
||
companion object { | ||
val log = logger<RemoveAuthCookieAction>() | ||
} | ||
|
||
override fun doExecute(context: RequestContext?): Event { | ||
log.error("GenerateAuthCookieAction running") | ||
val response = WebUtils.getHttpServletResponse(context) | ||
alaProxyAuthenticationCookieGenerator.removeCookie(response) | ||
return success() // unnecessary? | ||
} | ||
|
||
} |
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 +1 @@ | ||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=au.org.ala.cas.ServletContextConfig | ||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=au.org.ala.cas.ServletContextConfig,au.org.ala.cas.webflow.AlaCasWebflowConfiguration |
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