-
Notifications
You must be signed in to change notification settings - Fork 706
feat(OAuth2): Migrated OAuth2 configuration to align with Spring Security 5 Java DSL standards #2216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
rahul-chekuri
wants to merge
14
commits into
spinnaker:master
Choose a base branch
from
rahul-chekuri:oauth2-spring-scrty-5-properties
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
feat(OAuth2): Migrated OAuth2 configuration to align with Spring Security 5 Java DSL standards #2216
Changes from 12 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
b958cf4
feat(OAuth2): Migrated OAuth2 configuration to align with Spring Secu…
rahul-chekuri 2063e0d
feat(OAuth2): Add new GateBoot667ProfileFactory that emits the new ga…
rahul-chekuri 29d76dd
Tests: Add GateServiceTest and GateBoot667ProfileFactoryTest. Also ad…
rahul-chekuri 47ec3c8
feat(OAuth2): Add javadocs and comments.
rahul-chekuri 9796027
feat(OAuth2): Migrated OAuth2 configuration to align with Spring Secu…
rahul-chekuri b05f42e
feat(OAuth2): Add new GateBoot667ProfileFactory that emits the new ga…
rahul-chekuri e04687b
Tests: Add GateServiceTest and GateBoot667ProfileFactoryTest. Also ad…
rahul-chekuri 326bd1e
feat(OAuth2): Add javadocs and comments.
rahul-chekuri 1899c53
Merge remote-tracking branch 'origin/oauth2-spring-scrty-5-properties…
rahul-chekuri 38caab9
tests(OAuth2): Add license and some more tests around different provi…
rahul-chekuri 9c61acd
feat(OAuth2): Update gate version.
rahul-chekuri 1bf3023
feat(OAuth2): Rename classes, properties. Add comments.
rahul-chekuri 19944c1
feat(OAuth2): Update tests/comments with gate version 6.68.0
rahul-chekuri 9e0b2f5
Merge branch 'spinnaker:master' into oauth2-spring-scrty-5-properties
rahul-chekuri File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
69 changes: 69 additions & 0 deletions
69
...pinnaker/halyard/deploy/spinnaker/v1/profile/GateSpringSecurity5OAuth2ProfileFactory.java
This file contains hidden or 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,69 @@ | ||
/* | ||
* Copyright 2025 OpsMx, 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.halyard.deploy.spinnaker.v1.profile; | ||
|
||
import com.netflix.spinnaker.halyard.config.model.v1.security.Security; | ||
import com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceSettings; | ||
import org.springframework.stereotype.Component; | ||
|
||
/** | ||
* Factory class for creating Gate configuration profiles for versions 6.67.0 and above. | ||
* | ||
* <p>This class extends {@link GateProfileFactory} and provides specific configurations required | ||
* for Gate versions 6.67.0 and later. In these versions, a different set of properties is needed to | ||
* enable OAuth2 authentication. | ||
* | ||
* <p>The factory determines the appropriate security configuration (OAuth2, SAML, LDAP, IAP, X509) | ||
* based on the provided {@link Security} settings and constructs the {@link GateConfig} | ||
* accordingly. | ||
*/ | ||
@Component | ||
public class GateSpringSecurity5OAuth2ProfileFactory extends GateProfileFactory { | ||
|
||
/** | ||
* Creates a {@link GateConfig} instance based on the provided security settings. | ||
* | ||
* <p>If OAuth2 authentication is enabled, a {@link SpringConfig} is set up. If SAML | ||
* authentication is enabled, a {@link SamlConfig} is set. If LDAP authentication is enabled, a | ||
* {@link LdapConfig} is set. If IAP authentication is enabled, a {@link IAPConfig} is set under | ||
* Google authentication. If X509 authentication is enabled, a {@link X509Config} is set. | ||
* | ||
* @param gate The service settings for Gate. | ||
* @param security The security configuration settings. | ||
* @return A configured {@link GateConfig} instance. | ||
*/ | ||
@Override | ||
protected GateConfig getGateConfig(ServiceSettings gate, Security security) { | ||
GateConfig config = new GateConfig(gate, security); | ||
|
||
if (security.getAuthn().getOauth2().isEnabled()) { | ||
config.setSpring(new SpringConfig(security.getAuthn().getOauth2())); | ||
} else if (security.getAuthn().getSaml().isEnabled()) { | ||
config.saml = new SamlConfig(security); | ||
} else if (security.getAuthn().getLdap().isEnabled()) { | ||
config.ldap = new LdapConfig(security); | ||
} else if (security.getAuthn().getIap().isEnabled()) { | ||
config.google.iap = new IAPConfig(security); | ||
} | ||
|
||
if (security.getAuthn().getX509().isEnabled()) { | ||
config.x509 = new X509Config(security); | ||
} | ||
|
||
return config; | ||
} | ||
} |
This file contains hidden or 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 hidden or 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
89 changes: 89 additions & 0 deletions
89
...est/groovy/com/netflix/spinnaker/halyard/deploy/spinnaker/v1/service/GateServiceTest.java
This file contains hidden or 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,89 @@ | ||
/* | ||
* Copyright 2025 OpsMx, 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.halyard.deploy.spinnaker.v1.service; | ||
dbyron-sf marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.mockito.Mockito.CALLS_REAL_METHODS; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
import com.netflix.spinnaker.halyard.deploy.services.v1.ArtifactService; | ||
import com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerArtifact; | ||
import com.netflix.spinnaker.halyard.deploy.spinnaker.v1.profile.GateBoot128ProfileFactory; | ||
import com.netflix.spinnaker.halyard.deploy.spinnaker.v1.profile.GateBoot154ProfileFactory; | ||
import com.netflix.spinnaker.halyard.deploy.spinnaker.v1.profile.GateProfileFactory; | ||
import com.netflix.spinnaker.halyard.deploy.spinnaker.v1.profile.GateSpringSecurity5OAuth2ProfileFactory; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class GateServiceTest { | ||
|
||
private GateService gateService; | ||
private GateBoot128ProfileFactory mockBoot128ProfileFactory; | ||
private GateBoot154ProfileFactory mockBoot154ProfileFactory; | ||
private GateSpringSecurity5OAuth2ProfileFactory mockBoot667ProfileFactory; | ||
private ArtifactService mockArtifactService; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
gateService = mock(GateService.class, CALLS_REAL_METHODS); | ||
mockBoot128ProfileFactory = mock(GateBoot128ProfileFactory.class); | ||
mockBoot154ProfileFactory = mock(GateBoot154ProfileFactory.class); | ||
mockBoot667ProfileFactory = mock(GateSpringSecurity5OAuth2ProfileFactory.class); | ||
mockArtifactService = mock(ArtifactService.class); | ||
|
||
gateService.setBoot128ProfileFactory(mockBoot128ProfileFactory); | ||
gateService.setBoot154ProfileFactory(mockBoot154ProfileFactory); | ||
gateService.setSpringSecurity5OAuth2ProfileFactory(mockBoot667ProfileFactory); | ||
when(gateService.getArtifactService()).thenReturn(mockArtifactService); | ||
} | ||
|
||
@Test | ||
void testGetGateProfileFactoryVersionLessThan070() { | ||
when(mockArtifactService.getArtifactVersion("test-deployment", SpinnakerArtifact.GATE)) | ||
.thenReturn("0.6.9"); | ||
|
||
GateProfileFactory result = gateService.getGateProfileFactory("test-deployment"); | ||
assertEquals(mockBoot128ProfileFactory, result); | ||
} | ||
|
||
@Test | ||
void testGetGateProfileFactoryVersionBetween070And667() { | ||
when(mockArtifactService.getArtifactVersion("test-deployment", SpinnakerArtifact.GATE)) | ||
.thenReturn("6.66.0"); | ||
|
||
GateProfileFactory result = gateService.getGateProfileFactory("test-deployment"); | ||
assertEquals(mockBoot154ProfileFactory, result); | ||
} | ||
|
||
@Test | ||
void testGetGateProfileFactoryVersionGreaterThan667() { | ||
when(mockArtifactService.getArtifactVersion("test-deployment", SpinnakerArtifact.GATE)) | ||
.thenReturn("6.67.1"); | ||
|
||
GateProfileFactory result = gateService.getGateProfileFactory("test-deployment"); | ||
assertEquals(mockBoot667ProfileFactory, result); | ||
} | ||
|
||
@Test | ||
void testGetGateProfileFactoryInvalidVersionUsesDefault() { | ||
when(mockArtifactService.getArtifactVersion("test-deployment", SpinnakerArtifact.GATE)) | ||
.thenReturn("invalid-version"); | ||
|
||
GateProfileFactory result = gateService.getGateProfileFactory("test-deployment"); | ||
assertEquals(mockBoot667ProfileFactory, result); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.