/*
 * Copyright 2014 the original author or authors.
 *
 * 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 leap.web.security.logout;

import static leap.web.Renderable.FORWARD_PREFIX;
import static leap.web.Renderable.REDIRECT_PREFIX;
import static leap.web.Renderable.VIEW_PREFIX;
import leap.lang.Strings;
import leap.lang.http.Headers;
import leap.web.Request;
import leap.web.Response;

public class DefaultLogoutViewHandler implements LogoutViewHandler {
    
    @Override
    public void handleLogoutSuccess(Request request, Response response, LogoutContext context) throws Throwable {
        gotoLocation(request, response, getReturnUrl(context, request));        
    }
	
	protected void gotoLocation(Request request,Response response,String location) throws Throwable {
    	
    	// disable cache
		response.addHeader(Headers.CACHE_CONTROL,"no-cache");
		response.addHeader("Pragma","no-cache");
		if(location.startsWith(FORWARD_PREFIX)){
			request.forward(location.substring(FORWARD_PREFIX.length()));
			return;
		}
		
		if(location.startsWith(VIEW_PREFIX)){
			request.forwardToView(location.substring(VIEW_PREFIX.length()));
			return;
		}
		
		if(location.startsWith(REDIRECT_PREFIX)){
			response.sendRedirect(location.substring(REDIRECT_PREFIX.length()));
			return;
		}
		
		response.sendRedirect(location);
	}
	
	protected String getReturnUrl(LogoutContext context, Request request){
        String returnUrl = context.getReturnUrl() ;
        
        if(null == returnUrl){
        	returnUrl = request.getParameter(context.getSecurityConfig().getReturnUrlParameterName());
        }
        
        if(Strings.isEmpty(returnUrl)){
        	returnUrl = context.getSecurityConfig().getLogoutSuccessUrl();
        }
        
        if(Strings.isEmpty(returnUrl)){
        	returnUrl = Strings.isEmpty(request.getContextPath()) ? "/" : request.getContextPath();
        }
        
        return returnUrl;
	}
}
@@ -849,16 +849,43 @@
 eaders;%0A
+import leap.lang.net.Urls;%0A
 import l
@@ -1352,104 +1352,91 @@
 e%0A%09%09
-response.addHeader(Headers.CACHE_CONTROL,%22no-cache%22);%0A%09%09response.addHeader(%22Pragma%22,%22no-cache%22);
+location = Urls.appendQueryParams(location,%22_t_%22,System.currentTimeMillis()+%22%22);%0A%09%09
 %0A%09%09i

disable oauth2 web app redirect cache after logout