Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #25216 Redirection does not work after session timeout in Admin Console #25217

Merged
merged 2 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright (c) 2024 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
package org.glassfish.admingui.common;

import jakarta.faces.FacesException;
import jakarta.faces.application.ViewExpiredException;
import jakarta.faces.context.ExceptionHandler;
import jakarta.faces.context.ExceptionHandlerWrapper;
import jakarta.faces.context.ExternalContext;
import jakarta.faces.context.FacesContext;
import jakarta.faces.event.ExceptionQueuedEvent;
import jakarta.faces.event.ExceptionQueuedEventContext;

import java.io.IOException;
import java.util.Iterator;

public class AdminGuiExceptionHandler extends ExceptionHandlerWrapper {

public AdminGuiExceptionHandler(ExceptionHandler wrapped) {
super(wrapped);
}

@Override
public void handle() throws FacesException {
for (Iterator<ExceptionQueuedEvent> i = getUnhandledExceptionQueuedEvents().iterator(); i.hasNext();) {
ExceptionQueuedEvent event = i.next();
ExceptionQueuedEventContext eventContext = event.getContext();
if (eventContext.getException() instanceof ViewExpiredException) {
try {
FacesContext facesContext = FacesContext.getCurrentInstance();
if (facesContext == null) {
continue;
}
ExternalContext externalContext = facesContext.getExternalContext();
if (facesContext.getPartialViewContext().isAjaxRequest()) {
externalContext.getResponseOutputWriter().write(
"<script type='text/javascript'>"
+ "window.location.href = '" + externalContext.getRequestContextPath() + "/';"
+ "</script>");
facesContext.responseComplete();
} else {
externalContext.redirect(externalContext.getRequestContextPath() + "/");
}
} catch (IOException e) {
throw new FacesException(e);
} finally {
i.remove();
}
}
}
getWrapped().handle();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (c) 2024 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
package org.glassfish.admingui.common;

import jakarta.faces.context.ExceptionHandler;
import jakarta.faces.context.ExceptionHandlerFactory;

public class AdminGuiExceptionHandlerFactory extends ExceptionHandlerFactory {

public AdminGuiExceptionHandlerFactory(ExceptionHandlerFactory wrapped) {
super(wrapped);
}

@Override
public ExceptionHandler getExceptionHandler() {
return new AdminGuiExceptionHandler(getWrapped().getExceptionHandler());
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2022 Contributors to the Eclipse Foundation. All rights reserved.
Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation. All rights reserved.
Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.

This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -43,5 +43,6 @@
</application>
<factory>
<application-factory>org.glassfish.admingui.common.AdminGuiApplicationFactory</application-factory>
<exception-handler-factory>org.glassfish.admingui.common.AdminGuiExceptionHandlerFactory</exception-handler-factory>
</factory>
</faces-config>