-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set up an error page when the token could not be validated. (#344)
- Loading branch information
Showing
4 changed files
with
134 additions
and
18 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
src/main/java/org/jenkinsci/plugins/oic/FailedCheckOfTokenException.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,33 @@ | ||
package org.jenkinsci.plugins.oic; | ||
|
||
import edu.umd.cs.findbugs.annotations.CheckForNull; | ||
import java.io.IOException; | ||
import javax.servlet.ServletException; | ||
import org.kohsuke.stapler.HttpResponse; | ||
import org.kohsuke.stapler.StaplerRequest; | ||
import org.kohsuke.stapler.StaplerResponse; | ||
|
||
/** | ||
* Exception to be thrown when the received ID Token did not pass the expected check. | ||
* It offers a link to log out from the OpenID Connect provider. | ||
*/ | ||
public class FailedCheckOfTokenException extends RuntimeException implements HttpResponse { | ||
@CheckForNull | ||
private final String idpLogoutUrl; | ||
|
||
public FailedCheckOfTokenException(@CheckForNull String idpLogoutUrl) { | ||
this.idpLogoutUrl = idpLogoutUrl; | ||
} | ||
|
||
@CheckForNull | ||
@SuppressWarnings("unused") // stapler/jelly | ||
public String getIdpLogoutUrl() { | ||
return idpLogoutUrl; | ||
} | ||
|
||
@Override | ||
public void generateResponse(StaplerRequest req, StaplerResponse rsp, Object node) | ||
throws IOException, ServletException { | ||
req.getView(this, "error").forward(req, rsp); | ||
} | ||
} |
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
38 changes: 38 additions & 0 deletions
38
src/main/resources/org/jenkinsci/plugins/oic/FailedCheckOfTokenException/error.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,38 @@ | ||
<!-- | ||
The MIT License | ||
Copyright (c) 2024, CloudBees, Inc. | ||
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"> | ||
<st:statusCode value="401"/> | ||
<l:layout title="${%Unauthorized}"> | ||
<l:main-panel> | ||
<div class="error"> | ||
<h1>${%Unauthorized}</h1> | ||
<p>${%You do not have permission to access this instance.}</p> | ||
<j:if test="${it.idpLogoutUrl != null}"> | ||
<p><a href="${it.idpLogoutUrl}">${%Log out from OpenID Connect Provider}</a></p> | ||
</j:if> | ||
</div> | ||
</l:main-panel> | ||
</l:layout> | ||
</j: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