forked from benmccann/jenkins-saml-plugin
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[JENKINS-37311] make the logout button works (#19)
[FIX JENKINS-37311] make the logout button works
- Loading branch information
1 parent
0887ae3
commit d47d2c1
Showing
3 changed files
with
141 additions
and
0 deletions.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
src/main/java/org/jenkinsci/plugins/saml/SamlLogoutAction.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,71 @@ | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright (c) 2016 CloudBees, Inc., James Nord | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
package org.jenkinsci.plugins.saml; | ||
|
||
import org.kohsuke.accmod.Restricted; | ||
import org.kohsuke.accmod.restrictions.NoExternalUse; | ||
|
||
import hudson.Extension; | ||
import hudson.model.UnprotectedRootAction; | ||
import hudson.security.SecurityRealm; | ||
import jenkins.model.Jenkins; | ||
|
||
/** | ||
* A page that shows a simple message when the user logs out. | ||
* This prevents a logout - login loop when using this security realm and Anonymous does not have {@code Overall.READ} permission. | ||
*/ | ||
@Extension | ||
public class SamlLogoutAction implements UnprotectedRootAction { | ||
|
||
/** The URL of the action. */ | ||
static final String POST_LOGOUT_URL = "samlLogout"; | ||
|
||
@Override | ||
public String getDisplayName() { | ||
return "SAML Logout"; | ||
} | ||
|
||
@Override | ||
public String getIconFileName() { | ||
// hide it | ||
return null; | ||
} | ||
|
||
@Override | ||
public String getUrlName() { | ||
return POST_LOGOUT_URL; | ||
} | ||
|
||
@Restricted(NoExternalUse.class) // jelly only | ||
public String getSamlURL() { | ||
SecurityRealm r = Jenkins.getActiveInstance().getSecurityRealm(); | ||
if (r instanceof SamlSecurityRealm) { | ||
SamlSecurityRealm smlsr = (SamlSecurityRealm) r; | ||
return smlsr.getIdpMetadata(); | ||
} | ||
// only called from the Jelly if the SamlSecurityRealm is set... | ||
return ""; | ||
} | ||
|
||
} |
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
46 changes: 46 additions & 0 deletions
46
src/main/resources/org.jenkinsci.plugins.saml.SamlLogoutAction/index.jelly
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,46 @@ | ||
<!-- | ||
The MIT License | ||
Copyright (c) 2016 CloudBees, Inc., James Nord | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. | ||
*/ | ||
--> | ||
<?jelly escape-by-default='true'?> | ||
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" | ||
xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:i="jelly:fmt"> | ||
<l:layout norefresh="true"> | ||
<l:main-panel> | ||
<j:choose> | ||
<j:when test="${h.isAnonymous()}"> | ||
<p>You are now logged out of Jenkins, however this has not logged you out of | ||
<a href="${it.getSamlURL}">SAML</a> | ||
. | ||
</p> | ||
<p>Have a nice day</p> | ||
</j:when> | ||
<j:otherwise> | ||
<h2>Woo There....</h2> | ||
<p>You are not logged out - don't run away!</p> | ||
<p>Whilst you should been logged out you are not actually logged out...</p> | ||
</j:otherwise> | ||
</j:choose> | ||
</l:main-panel> | ||
</l:layout> | ||
</j:jelly> |