提交 6c6f34cd 编写于 作者: I Ing. Pavel Janousek

[JENKINS-31618] Fixed NoSuchMethodException in loginLink.jelly

The logic is moved from template back to Java and modified to fix the issue.
The argorithm is rewritten for better legibility.
上级 d3b61b9c
......@@ -62,6 +62,7 @@ import javax.servlet.ServletException;
import javax.servlet.http.HttpSession;
import javax.servlet.http.Cookie;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
......@@ -484,6 +485,44 @@ public abstract class SecurityRealm extends AbstractDescribableImpl<SecurityReal
*/
public static final SecurityRealm NO_AUTHENTICATION = new None();
/**
* Perform a calculation where we should go back after sucessfull login
*
* @return Encoded URI where we should go back after sucessfull login or "/" if no way back
*
* @since TODO
*/
public static String getFrom() {
String from = null;
final StaplerRequest request = Stapler.getCurrentRequest();
if (request.getSession(false) != null) {
from = (String) request.getSession().getAttribute("from");
}
if (from == null) {
from = request.getParameter("from");
}
final String requestURI = request.getRequestURI();
if (from == null && requestURI != null
&& requestURI.compareTo("/loginError") != 0 && requestURI.compareTo("/login") != 0) {
from = requestURI;
}
if (from == null || from.trim().isEmpty()) {
from = "/";
}
try {
from = java.net.URLEncoder.encode(from, "UTF-8");
} catch (UnsupportedEncodingException e) {
from = "/";
}
return from;
}
private static class None extends SecurityRealm {
public SecurityComponents createSecurityComponents() {
return new SecurityComponents(new AuthenticationManager() {
......
......@@ -25,9 +25,5 @@ THE SOFTWARE.
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler">
<j:invokeStatic var="from" className="java.net.URLEncoder" method="encode">
<j:arg value="${if (request.session.attribute('from')!=null) request.session.getAttribute('from'); else if (request.getParameter('from')!=null) request.getParameter('from'); else if (request.requestURI=='/loginError' || request.requestURI=='/login') '/'; else request.requestURI;}"/>
<j:arg value="UTF-8"/>
</j:invokeStatic>
<a href="${rootURL}/${app.securityRealm.loginUrl}?from=${from}"><b>${%login}</b></a>
</j:jelly>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册