Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix for MID-4099 session timeout, ajax unresponsiveness and wrong aja…
…x response to login page redirect fix (cherry picked from commit b620bde)
- Loading branch information
Showing
3 changed files
with
121 additions
and
2 deletions.
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
.../main/java/com/evolveum/midpoint/web/security/WicketLoginUrlAuthenticationEntryPoint.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,66 @@ | ||
/* | ||
* Copyright (c) 2010-2017 Evolveum | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.evolveum.midpoint.web.security; | ||
|
||
import org.apache.wicket.request.http.WebRequest; | ||
import org.springframework.security.core.AuthenticationException; | ||
import org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint; | ||
|
||
import javax.servlet.ServletException; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import java.io.IOException; | ||
|
||
/** | ||
* Created by Viliam Repan (lazyman). | ||
*/ | ||
public class WicketLoginUrlAuthenticationEntryPoint extends LoginUrlAuthenticationEntryPoint { | ||
|
||
public WicketLoginUrlAuthenticationEntryPoint(String loginFormUrl) { | ||
super(loginFormUrl); | ||
} | ||
|
||
@Override | ||
public void commence(HttpServletRequest request, HttpServletResponse response, | ||
AuthenticationException authException) throws IOException, ServletException { | ||
|
||
if (!isWicketAjaxRequest(request)) { | ||
super.commence(request, response, authException); | ||
|
||
return; | ||
} | ||
|
||
String url = buildRedirectUrlToLoginPage(request, response, authException); | ||
|
||
WicketRedirectStrategy strategy = new WicketRedirectStrategy(); | ||
strategy.sendRedirect(request, response, url); | ||
} | ||
|
||
private boolean isWicketAjaxRequest(HttpServletRequest request) { | ||
String value = request.getParameter(WebRequest.PARAM_AJAX); | ||
if (value != null && "true".equals(value)) { | ||
return true; | ||
} | ||
|
||
value = request.getHeader(WebRequest.HEADER_AJAX); | ||
if (value != null && "true".equals(value)) { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
gui/admin-gui/src/main/java/com/evolveum/midpoint/web/security/WicketRedirectStrategy.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,48 @@ | ||
/* | ||
* Copyright (c) 2010-2017 Evolveum | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.evolveum.midpoint.web.security; | ||
|
||
import org.apache.wicket.util.time.Time; | ||
import org.springframework.security.web.DefaultRedirectStrategy; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import java.io.IOException; | ||
import java.io.Writer; | ||
|
||
/** | ||
* Created by Viliam Repan (lazyman). | ||
*/ | ||
public class WicketRedirectStrategy extends DefaultRedirectStrategy { | ||
|
||
@Override | ||
public void sendRedirect(HttpServletRequest request, HttpServletResponse response, String url) throws IOException { | ||
response.setStatus(HttpServletResponse.SC_OK); | ||
|
||
response.setContentType("text/xml"); | ||
|
||
response.setHeader("Ajax-Location", url); | ||
// disabled caching | ||
response.setHeader("Date", Long.toString(Time.now().getMilliseconds())); | ||
response.setHeader("Expires", Long.toString(Time.START_OF_UNIX_TIME.getMilliseconds())); | ||
response.setHeader("Pragma", "no-cache"); | ||
response.setHeader("Cache-Control", "no-cache, no-store"); | ||
|
||
Writer writer = response.getWriter(); | ||
writer.write("<ajax-response><redirect><![CDATA[" + url + "]]></redirect></ajax-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