Skip to content

Commit

Permalink
Fixing SEAMFACES-126
Browse files Browse the repository at this point in the history
Logging a warning instead of an exception. This is really a
configuration issue. A 401 is actually the correct thing to do if there
is no configured page.

Also wrapping any output in an if statement to make sure we don't send
any of our output if the users have already pushed things out to the
output stream.
  • Loading branch information
LightGuard committed Aug 25, 2011
1 parent 1277f99 commit c09fe7e
Showing 1 changed file with 14 additions and 11 deletions.
Expand Up @@ -327,18 +327,21 @@ private void redirectToLoginPage(FacesContext context, UIViewRoot viewRoot) {
* @param viewRoot
*/
private void redirectToAccessDeniedView(FacesContext context, UIViewRoot viewRoot) {
AccessDeniedView accessDeniedView = viewConfigStore.getAnnotationData(viewRoot.getViewId(), AccessDeniedView.class);
if (accessDeniedView == null || accessDeniedView.value() == null || accessDeniedView.value().isEmpty()) {
log.debug("Returning 401 response (access denied)");
context.getExternalContext().setResponseStatus(401);
context.responseComplete();
return;
// If a user has already done a redirect and rendered the response (possibly in an observer) we cannot do this output
if (!(context.getResponseComplete() || context.getRenderResponse())) {
AccessDeniedView accessDeniedView = viewConfigStore.getAnnotationData(viewRoot.getViewId(), AccessDeniedView.class);
if (accessDeniedView == null || accessDeniedView.value() == null || accessDeniedView.value().isEmpty()) {
log.warn("No AccessDeniedView is configured, returning 401 response (access denied). Please configure an AccessDeniedView in the ViewConfig.");
context.getExternalContext().setResponseStatus(401);
context.responseComplete();
return;
}
String accessDeniedViewId = accessDeniedView.value();
log.debugf("Redirecting to configured AccessDenied %s", accessDeniedViewId);
NavigationHandler navHandler = context.getApplication().getNavigationHandler();
navHandler.handleNavigation(context, "", accessDeniedViewId);
context.renderResponse();
}
String accessDeniedViewId = accessDeniedView.value();
log.debugf("Redirecting to configured AccessDenied %s", accessDeniedViewId);
NavigationHandler navHandler = context.getApplication().getNavigationHandler();
navHandler.handleNavigation(context, "", accessDeniedViewId);
context.renderResponse();
}

/**
Expand Down

0 comments on commit c09fe7e

Please sign in to comment.