提交 2bf9fc21 编写于 作者: D Daniel Beck

[JENKINS-61905] Forward Groovy view permission errors to login

上级 653243a0
......@@ -51,7 +51,14 @@ public class UnwrapSecurityExceptionFilter implements Filter {
chain.doFilter(request,response);
} catch (ServletException e) {
Throwable t = e.getRootCause();
if (t instanceof JellyTagException) {
while (t != null && !(t instanceof JellyTagException)) {
if (t instanceof ServletException) {
t = ((ServletException) t).getRootCause();
} else {
t = t.getCause();
}
}
if (t != null) {
JellyTagException jte = (JellyTagException) t;
Throwable cause = jte.getCause();
if (cause instanceof AcegiSecurityException) {
......
......@@ -27,6 +27,10 @@ package hudson.security;
import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
import java.net.HttpURLConnection;
import static org.junit.Assert.*;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import jenkins.model.Jenkins;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.Issue;
......@@ -58,4 +62,21 @@ public class AccessDeniedException2Test {
}
}
@Test
@Issue("JENKINS-61905")
public void redirectPermissionErrorsToLogin() throws Exception {
JenkinsRule.DummySecurityRealm realm = r.createDummySecurityRealm();
r.jenkins.setSecurityRealm(realm);
r.jenkins.setAuthorizationStrategy(new MockAuthorizationStrategy().grant(Jenkins.READ).everywhere().toEveryone());
JenkinsRule.WebClient wc = r.createWebClient();
wc.setRedirectEnabled(true);
wc.setThrowExceptionOnFailingStatusCode(false);
final HtmlPage configure = wc.goTo("configure");
Assert.assertTrue(configure.getUrl().getPath().contains("login"));
Assert.assertTrue(configure.getUrl().getQuery().startsWith("from"));
final HtmlPage configureSecurity = wc.goTo("configureSecurity/");
Assert.assertTrue(configureSecurity.getUrl().getPath().contains("login"));
Assert.assertTrue(configureSecurity.getUrl().getQuery().startsWith("from"));
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册