-
Notifications
You must be signed in to change notification settings - Fork 100
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
Add support for Microsoft AD FS #368
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 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,26 @@ | ||
# ADFS Provider | ||
|
||
[ADFS][1] can be used as as an OpenID Connect identity provider. | ||
|
||
## Provider configuration | ||
|
||
[This][2] stack overflow step though is a great resource, followed by [This IBM resource][3] for granting the correct permissions. | ||
|
||
Where the IBM resource adds 2 individual permissions, 3 are needed and can be performed in one command - e.g. | ||
`Set-AdfsApplicationPermission -TargetIdentifier fe56f061-c689-45e8-af8d-b8fdf5d1e60f -AddScope 'openid','aza','allatclaims'` | ||
|
||
Extra claims (for example users display name) can be added using a similar approach to the groups. | ||
|
||
## Plugin configuration | ||
|
||
ADFS provides a well known configuration endpoint which can be used for automating endpoint configuration. | ||
It also supports PKCE verification for additional security. | ||
|
||
### User information | ||
|
||
Without any extra claims, the user field should be set to `upn` | ||
|
||
|
||
[1]: https://learn.microsoft.com/en-us/windows-server/identity/ad-fs/ad-fs-overview | ||
[2]: https://stackoverflow.com/questions/55494354/user-groups-as-claims-through-openid-connect-over-adfs/55570286#55570286 | ||
[3]: https://community.ibm.com/community/user/security/blogs/laurent-lapiquionne1/2020/07/21/how-to-configure-igi-service-center-to-authent |
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
34 changes: 34 additions & 0 deletions
34
src/main/java/org/jenkinsci/plugins/oic/OicCrumbExclusion.java
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,34 @@ | ||
package org.jenkinsci.plugins.oic; | ||
|
||
import hudson.Extension; | ||
import hudson.security.SecurityRealm; | ||
import hudson.security.csrf.CrumbExclusion; | ||
import java.io.IOException; | ||
import javax.servlet.FilterChain; | ||
import javax.servlet.ServletException; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import jenkins.model.Jenkins; | ||
|
||
/** | ||
* Crumb exclusion to allow POSTing to {@link OicSecurityRealm#doFinishLogin(org.kohsuke.stapler.StaplerRequest)} | ||
*/ | ||
@Extension | ||
public class OicCrumbExclusion extends CrumbExclusion { | ||
|
||
@Override | ||
public boolean process(HttpServletRequest request, HttpServletResponse response, FilterChain chain) | ||
throws IOException, ServletException { | ||
Jenkins j = Jenkins.getInstanceOrNull(); | ||
if (j != null) { | ||
SecurityRealm sr = j.getSecurityRealm(); | ||
if (sr instanceof OicSecurityRealm) { | ||
if ("/securityRealm/finishLogin".equals(request.getPathInfo())) { | ||
chain.doFilter(request, response); | ||
return true; | ||
} | ||
} | ||
} | ||
return false; | ||
} | ||
} |
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
101 changes: 101 additions & 0 deletions
101
src/test/java/org/jenkinsci/plugins/oic/OicCrumbExclusionTest.java
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,101 @@ | ||
package org.jenkinsci.plugins.oic; | ||
|
||
import javax.servlet.FilterChain; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import jenkins.model.Jenkins; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.Mock; | ||
import org.mockito.MockedStatic; | ||
import org.mockito.Mockito; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
import static org.mockito.Mockito.lenient; | ||
import static org.mockito.Mockito.times; | ||
import static org.mockito.Mockito.when; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class OicCrumbExclusionTest { | ||
|
||
@Mock | ||
Jenkins jenkins; | ||
|
||
@Mock | ||
MockedStatic<Jenkins> staticJenkins; | ||
|
||
@Mock | ||
OicSecurityRealm oicSecurityRealm; | ||
|
||
@Mock | ||
FilterChain chain; | ||
|
||
@Mock | ||
HttpServletRequest request; | ||
|
||
@Mock | ||
HttpServletResponse response; | ||
|
||
private void withJenkins() { | ||
staticJenkins.when(Jenkins::getInstanceOrNull).thenReturn(jenkins); | ||
} | ||
|
||
private void withRequestPath(String path) { | ||
lenient().when(request.getPathInfo()).thenReturn(path); | ||
} | ||
|
||
private void withOicSecurityRealm() { | ||
when(jenkins.getSecurityRealm()).thenReturn(oicSecurityRealm); | ||
} | ||
|
||
@Test | ||
void exclusion_applies_when_realm_is_OIC_and_path_is_finishLogin() throws Exception { | ||
withJenkins(); | ||
withRequestPath("/securityRealm/finishLogin"); | ||
withOicSecurityRealm(); | ||
|
||
OicCrumbExclusion oicCrumbExclusion = new OicCrumbExclusion(); | ||
assertTrue("path should be excluded", oicCrumbExclusion.process(request, response, chain)); | ||
Mockito.verify(chain, times(1)).doFilter(request, response); | ||
} | ||
|
||
@Test | ||
void exclusion_does_not_apply_when_realm_is_OIC_and_path_is_not_finishLogin() throws Exception { | ||
withJenkins(); | ||
withRequestPath("/securityRealm/anything"); | ||
withOicSecurityRealm(); | ||
|
||
OicCrumbExclusion oicCrumbExclusion = new OicCrumbExclusion(); | ||
assertFalse("path should not be excluded", oicCrumbExclusion.process(request, response, chain)); | ||
Mockito.verify(chain, times(0)).doFilter(request, response); | ||
} | ||
|
||
@Test | ||
void exclusion_does_not_apply_when_realm_is_not_OIC_and_path_is_finishLogin() throws Exception { | ||
withJenkins(); | ||
withRequestPath("/securityRealm/finishLogin"); | ||
|
||
OicCrumbExclusion oicCrumbExclusion = new OicCrumbExclusion(); | ||
assertFalse("path should not be excluded", oicCrumbExclusion.process(request, response, chain)); | ||
Mockito.verify(chain, times(0)).doFilter(request, response); | ||
} | ||
|
||
@Test | ||
void exclusion_does_not_apply_when_realm_is_not_OIC_and_path_is_not_finishLogin() throws Exception { | ||
withJenkins(); | ||
withRequestPath("/securityRealm/anything"); | ||
|
||
OicCrumbExclusion oicCrumbExclusion = new OicCrumbExclusion(); | ||
assertFalse("path should not be excluded", oicCrumbExclusion.process(request, response, chain)); | ||
Mockito.verify(chain, times(0)).doFilter(request, response); | ||
} | ||
|
||
@Test | ||
void exclusion_does_not_apply_when_jenkins_is_not_set() throws Exception { | ||
OicCrumbExclusion oicCrumbExclusion = new OicCrumbExclusion(); | ||
assertFalse("path should not be excluded", oicCrumbExclusion.process(request, response, chain)); | ||
Mockito.verify(chain, times(0)).doFilter(request, response); | ||
} | ||
} |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unrelated to the change, but due to eclipse-m2e/m2e-core/issues/1291 would cause an error in the project in eclipse.