Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4566510
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T18:47:57+00:00 2026-05-21T18:47:57+00:00

I’m trying to implement a redirect after login, which means I can’t use glassfish

  • 0

I’m trying to implement a redirect after login, which means I can’t use glassfish built-in form authentication settings anymore that handles such things automatically. So first thing’s first, I need to take control over redirecting to a login page when requesting a protected page. As I understand, this is done with a filter. Can this method be combined with security-constraints in web-xml? As it is, my filter is not called at all since glassfish just takes over and throws a basic loginbox at the user and ignores all filters even when no login configuration is set. Basicly, I have not managed to get a filter called before a user has logged in when security constraints are configured in glassfish.

Do I really need to take over security completly manually in a filter for this to work? If that’s the case, the implementation seems horrible.

Using glassfish 3.1 with JSF 2 and a custom loginpage logging in manually with request.login.

web.xml.

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value><!--Production-->Development</param-value>
    </context-param>
    <context-param>
        <param-name>com.sun.faces.expressionFactory</param-name>
        <param-value>de.odysseus.el.ExpressionFactoryImpl</param-value>
    </context-param>
    <filter-mapping>
        <filter-name>LoginFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.jsf</url-pattern>
    </servlet-mapping>
    <filter>
        <filter-name>LoginFilter</filter-name>
        <filter-class>com.xdin.competence.jsf.util.LoginFilter</filter-class>
    </filter>
    <session-config>
        <session-timeout>60</session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>index.jsf</welcome-file>
    </welcome-file-list>
    <!--<error-page>
        <exception-type>javax.faces.application.ViewExpiredException</exception-type>
        <location>/viewExpired.jsf</location>
    </error-page>-->
    <security-constraint>
        <display-name>ManagerArea</display-name>
        <web-resource-collection>
            <web-resource-name>ManagerArea</web-resource-name>
            <description/>
            <url-pattern>/manager/*</url-pattern>
        </web-resource-collection>
        <auth-constraint>
            <description/>
            <role-name>Manager-role</role-name>
            <role-name>Admin-role</role-name>
        </auth-constraint>
    </security-constraint>
    <security-constraint>
        <display-name>EmployeeArea</display-name>
        <web-resource-collection>
            <web-resource-name>EmployeeConstraint</web-resource-name>
            <description/>
            <url-pattern>/user/Overview.jsf</url-pattern>
            <url-pattern>/user/PrepareReport.jsf</url-pattern>
            <url-pattern>/user/Search.jsf</url-pattern>
        </web-resource-collection>
        <auth-constraint>
            <description/>
            <role-name>Employee-role</role-name>
            <role-name>Admin-role</role-name>
            <role-name>Manager-role</role-name>
            <role-name>OKIF-role</role-name>
        </auth-constraint>
    </security-constraint>
    <security-constraint>
        <display-name>AdminArea</display-name>
        <web-resource-collection>
            <web-resource-name>AdminCompetence</web-resource-name>
            <description/>
            <url-pattern>/admin/*</url-pattern>
        </web-resource-collection>
        <auth-constraint>
            <description/>
            <role-name>Admin-role</role-name>
        </auth-constraint>
    </security-constraint>
    <security-constraint>
        <display-name>UserArea</display-name>
        <web-resource-collection>
            <web-resource-name>UserConstraint</web-resource-name>
            <description/>
            <url-pattern>/index.jsf</url-pattern>
            <url-pattern>/template.jsf</url-pattern>
            <url-pattern>/user/UserDetail.jsf</url-pattern>
            <url-pattern>/user/UserInformation.jsf</url-pattern>
            <url-pattern>/print/*</url-pattern>
        </web-resource-collection>
        <auth-constraint>
            <description/>
            <role-name>Employee-role</role-name>
            <role-name>Admin-role</role-name>
            <role-name>Manager-role</role-name>
            <role-name>OKIF-role</role-name>
        </auth-constraint>
    </security-constraint>
    <!--<login-config>
        <auth-method>FORM</auth-method>
        <form-login-config>
            <form-login-page>/login.jsf</form-login-page>
            <form-error-page>/login.jsf</form-error-page>
        </form-login-config>
    </login-config>-->
    <security-role>
        <description/>
        <role-name>Employee-role</role-name>
    </security-role>
    <security-role>
        <description/>
        <role-name>Admin-role</role-name>
    </security-role>
    <security-role>
        <description/>
        <role-name>Manager-role</role-name>
    </security-role>
    <security-role>
        <description/>
        <role-name>OKIF-role</role-name>
    </security-role>
</web-app>

And my filter:

public class LoginFilter implements Filter {

    private FilterConfig filterConfig = null;

    public LoginFilter() {
    } 

    @Override
    public void doFilter(ServletRequest request, ServletResponse response,
                         FilterChain chain)
        throws IOException, ServletException {
        HttpServletRequest req = (HttpServletRequest)request;
        HttpServletResponse res = (HttpServletResponse)response;
        if (req.getUserPrincipal() == null) {
            req.getSession().setAttribute("from", req.getRequestURI());
            res.sendRedirect("/login.jsf");
        } else {
            chain.doFilter(request, response);
        }

    }

    @Override
    public void destroy() { 
    }

    @Override
    public void init(FilterConfig filterConfig) { 
        this.filterConfig = filterConfig;
    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T18:47:58+00:00Added an answer on May 21, 2026 at 6:47 pm

    In your customized login form, add the following hidden field:

    <input type="hidden" name="from" value="#{requestScope['javax.servlet.forward.request_uri']}" />
    

    which you set in JSF as follows

    @ManagedProperty(value="#{param.from}")
    private String from;
    

    and redirect as follows in login action method

    if (from != null) {
        externalContext.redirect(from);
    }
    

    No need for a Filter.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I have a text area in my form which accepts all possible characters from
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.