-
Notifications
You must be signed in to change notification settings - Fork 740
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(oauth): remove circular dependency on ExternalAuthTokenFilter bea…
…n in OAuth2SsoConfig when oauth2 is enabled Previously in spring 2.2.5, if oauth2 is enabled there is no circular dependency on ExternalAuthTokenFilter bean in OAuth2SsoConfig. In spring 2.2.13, if oauth2 is enabled there is a circular dependency error on ExternalAuthTokenFilter bean. This circular dependency results in an error when the gate application tries to start up. The application fails with error: BeanCurrentlyInCreationException: Error creating bean with name 'OAuth2SsoConfig': Bean with name 'OAuth2SsoConfig' has been injected into other beans [externalAuthTokenFilter] in its raw version as part of a circular reference, but has eventually been wrapped. To fix this error, add the Component annotation to ExternalAuthTokenFilter and remove the ExternalAuthTokenFilter bean from OAuth2SsoConfig.
- Loading branch information
Showing
4 changed files
with
66 additions
and
9 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
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
56 changes: 56 additions & 0 deletions
56
gate-web/src/test/groovy/com/netflix/spinnaker/gate/security/oauth2/OAuth2Spec.groovy
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,56 @@ | ||
/* | ||
* Copyright 2021 Salesforce.com, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.netflix.spinnaker.gate.security.oauth2 | ||
|
||
|
||
import groovy.util.logging.Slf4j | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc | ||
import org.springframework.boot.test.context.SpringBootTest | ||
import org.springframework.http.HttpHeaders | ||
import org.springframework.test.context.TestPropertySource | ||
import org.springframework.test.web.servlet.MockMvc | ||
import spock.lang.Specification | ||
|
||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get | ||
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print | ||
|
||
@Slf4j | ||
// AutoConfigureMockMvc is needed here because requests made by MockMvc will need to go through the OAuth2 filter | ||
@AutoConfigureMockMvc | ||
@SpringBootTest(properties = [ | ||
"retrofit.enabled=true", | ||
"security.oauth2.client.clientId=Spinnaker-Client", | ||
"security.oauth2.resource.userInfoUri=http://localhost/userinfo" | ||
]) | ||
@TestPropertySource(properties = ["spring.config.location=classpath:gate-test.yml"]) | ||
class OAuth2Spec extends Specification { | ||
|
||
@Autowired | ||
MockMvc mockMvc | ||
|
||
def "should redirect on oauth2 authentication"() { | ||
when: | ||
def result = mockMvc.perform(get("/credentials") | ||
.header(HttpHeaders.AUTHORIZATION, "Bearer access_token")) | ||
.andDo(print()) | ||
.andReturn() | ||
|
||
then: | ||
result.response.getStatus() == 302 | ||
} | ||
} |