All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.addc.server.commons.struts12.actions.AccessDeniedAction Maven / Gradle / Ivy

package com.addc.server.commons.struts12.actions;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

import com.addc.server.commons.web.i18n.HtmlLabels;

/**
 * The AccessDeniedAction supplies the struts action for the access denied page
 */
@SuppressWarnings("PMD")
public class AccessDeniedAction extends DispatchAction {
    
    @SuppressWarnings("unused")
    public ActionForward preparePage(ActionMapping mapping, ActionForm form, HttpServletRequest request,
            HttpServletResponse response) {
        ActionForward forward= mapping.findForward(ActionConstants.SUCCESS_FORWARD);
        AccessDeniedActionForm actionForm= (AccessDeniedActionForm) form;
        Authentication auth= SecurityContextHolder.getContext().getAuthentication();
        if (auth != null) {
            actionForm.setUserName(auth.getName());
            actionForm.setPermissions(auth.getAuthorities().toString());
        } else {
            actionForm.setUserName(HtmlLabels.UNKNOWN);
            actionForm.setPermissions("[]");
        }
        return forward;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy