Skip to content

Commit

Permalink
Revert "fix(oauth): remove circular dependency on ExternalAuthTokenFi…
Browse files Browse the repository at this point in the history
…lter bean in OAuth2SsoConfig when oauth2 is enabled (spinnaker#1492)"

This reverts commit 1407c05.
  • Loading branch information
rahul-chekuri committed Apr 5, 2022
1 parent 1407c05 commit 937a6f3
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import org.springframework.security.core.Authentication
import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken
import org.springframework.security.oauth2.common.OAuth2AccessToken
import org.springframework.security.oauth2.provider.authentication.BearerTokenExtractor
import org.springframework.stereotype.Component

import javax.servlet.Filter
import javax.servlet.FilterChain
Expand All @@ -38,12 +37,9 @@ import javax.servlet.http.HttpServletRequest
* Github-issued personal access token.
*/
@Slf4j
@Component
class ExternalAuthTokenFilter implements Filter {

// UserInfoRestTemplateFactory can't be Autowired if no oauth2 configurations are set.
// In this case, userInfoRestTemplateFactory will be null
@Autowired(required = false)
@Autowired
UserInfoRestTemplateFactory userInfoRestTemplateFactory

BearerTokenExtractor extractor = new BearerTokenExtractor()
Expand All @@ -57,10 +53,9 @@ class ExternalAuthTokenFilter implements Filter {
// Reassign token type to be capitalized "Bearer",
// see https://github.com/spinnaker/spinnaker/issues/2074
token.tokenType = OAuth2AccessToken.BEARER_TYPE
if (userInfoRestTemplateFactory != null) {
def ctx = userInfoRestTemplateFactory.getUserInfoRestTemplate().getOAuth2ClientContext()
ctx.accessToken = token
}

def ctx = userInfoRestTemplateFactory.getUserInfoRestTemplate().getOAuth2ClientContext()
ctx.accessToken = token
}
chain.doFilter(request, response)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ class OAuth2SsoConfig extends WebSecurityConfigurerAdapter {
new SpinnakerUserInfoTokenServices()
}

@Bean
ExternalAuthTokenFilter externalAuthTokenFilter() {
new ExternalAuthTokenFilter()
}

@Override
void configure(HttpSecurity http) throws Exception {
defaultCookieSerializer.setSameSite(null)
Expand Down
1 change: 0 additions & 1 deletion gate-web/gate-web.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ dependencies {

testImplementation project(":gate-ldap") // TODO: Move system tests to own module
testImplementation project(":gate-basic")
testImplementation project(":gate-oauth2")
testImplementation "com.squareup.okhttp:mockwebserver"

testImplementation "com.squareup.retrofit:retrofit-mock"
Expand Down

This file was deleted.

0 comments on commit 937a6f3

Please sign in to comment.