You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Yucca Nel <yu...@live.co.za> on 2010/05/09 22:22:19 UTC

Almost figured out how to satisfy container and managed bean login.

I have a double login requirement because I need some finer detals that tomcst's container authentication does not seem to provide.
I need a way to atore username in business logic scope when logged in (mainly just  the username) my current solution is not working as follows:

I submit action to backing method which is coded in the jsf as follows in the login page:


<f:view>
    <body style="background-color:#7b68ee;margin:auto">
    <div align="center" id="header"><jsp:include page="/header.jsp"/></div>
    <div align="center">
        <div align="center" id="centred-content"style="border-width:3px; border-style: solid; border-color: #7fffd4;width:800px">
            <div id="h1" align="center">
                <h:outputText value="#{loginMsg.h1}..." style="color:white; font-family:fantasy;font-size:large;"/><br>
                <h:outputText value="#{loginMsg.h2}..." style="color:white; font-family:fantasy;font-size:large;"/></div>
            <div align="center">
                <h:form>
                    <h:panelGrid columns="2">

                        <h:outputText value="#{registerMsg.userName}:" style="color:yellow;"/>
                        <h:inputText id="j_username" value="#{loginForm.username}" title="#{registerMsg.userNameTitle}"required="true">

                            <f:validateLength maximum="20" minimum="6"/>
                        <h:outputText value="#{registerMsg.password}:" style="color:yellow;"/>
                        <h:inputSecret id="j_passwword" value="#{loginForm.password}" title="#{registerMsg.passwordTitle}"required="true" >

                        </h:inputSecret>

                    </h:panelGrid>

                    <h:commandButton action="#{loginForm.confirmCredentials}" value="#{loginMsg.login}"style="color:#20b2aa;" />
                    <br>
                </h:form>

then in loginForm.java I have the method coded as follows to set my managed bean and hopefuly dispatch on continer needed login credentials. 


public String confirmCredentials() throws IOException, ServletException {        UserSession userSession =
        (UserSession)FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("userSession");

        if (UserManagerBean.confirmLogin(username, password)) {
            
            UsersEntity user = UserManagerBean.findUser(username);
            userSession.setCurrentUser(user);
            return "home";
        }
        FacesMessage message = new FacesMessage();
        message.setSummary("Login Error");
        message.setDetail("Unable to log you in -"
           +  " username and password combination not found.");
        message.setSeverity(FacesMessage.SEVERITY_WARN);
        FacesContext.getCurrentInstance().addMessage(null,message);
        ExternalContext ectx =
FacesContext.getCurrentInstance().getExternalContext();
  HttpServletRequest request =
(HttpServletRequest)ectx.getRequest();
  HttpServletResponse response =
(HttpServletResponse)ectx.getResponse();
  RequestDispatcher dispatcher =
request.getRequestDispatcher("j_security_check");
  dispatcher.forward(request,response);
  return null;
    }

it never reaches the j_security check servlet

anyone know why?

The method works fine when called from outside containers security context defined around the  page request.



RE: Almost figured out how to satisfy container and managed bean login.

Posted by Leo Donahue - PLANDEVX <Le...@mail.maricopa.gov>.
>> anyone know why? 
Without seeing your web.xml, I have no idea.


>> it never reaches the j_security check servlet
However, are you trying to do FORM based authentication?  Then read this:  http://java.sun.com/javaee/5/docs/tutorial/doc/bncbe.html#bncbq

And here is an example: http://java.sun.com/javaee/5/docs/tutorial/doc/bncbx.html#bncca


>> I have a double login requirement...
If you are using container managed security, you can use "isUserInRole", no?

Leo

-----Original Message-----
From: Yucca Nel [mailto:yuccanel@live.co.za] 
Sent: Sunday, May 09, 2010 1:22 PM
To: Tomcat Users List
Subject: Almost figured out how to satisfy container and managed bean login.

I have a double login requirement because I need some finer detals that tomcst's container authentication does not seem to provide.
I need a way to atore username in business logic scope when logged in (mainly just  the username) my current solution is not working as follows:

I submit action to backing method which is coded in the jsf as follows in the login page:


<f:view>
    <body style="background-color:#7b68ee;margin:auto">
    <div align="center" id="header"><jsp:include page="/header.jsp"/></div>
    <div align="center">
        <div align="center" id="centred-content"style="border-width:3px; border-style: solid; border-color: #7fffd4;width:800px">
            <div id="h1" align="center">
                <h:outputText value="#{loginMsg.h1}..." style="color:white; font-family:fantasy;font-size:large;"/><br>
                <h:outputText value="#{loginMsg.h2}..." style="color:white; font-family:fantasy;font-size:large;"/></div>
            <div align="center">
                <h:form>
                    <h:panelGrid columns="2">

                        <h:outputText value="#{registerMsg.userName}:" style="color:yellow;"/>
                        <h:inputText id="j_username" value="#{loginForm.username}" title="#{registerMsg.userNameTitle}"required="true">

                            <f:validateLength maximum="20" minimum="6"/>
                        <h:outputText value="#{registerMsg.password}:" style="color:yellow;"/>
                        <h:inputSecret id="j_passwword" value="#{loginForm.password}" title="#{registerMsg.passwordTitle}"required="true" >

                        </h:inputSecret>

                    </h:panelGrid>

                    <h:commandButton action="#{loginForm.confirmCredentials}" value="#{loginMsg.login}"style="color:#20b2aa;" />
                    <br>
                </h:form>

then in loginForm.java I have the method coded as follows to set my managed bean and hopefuly dispatch on continer needed login credentials. 


public String confirmCredentials() throws IOException, ServletException {        UserSession userSession =
        (UserSession)FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("userSession");

        if (UserManagerBean.confirmLogin(username, password)) {
            
            UsersEntity user = UserManagerBean.findUser(username);
            userSession.setCurrentUser(user);
            return "home";
        }
        FacesMessage message = new FacesMessage();
        message.setSummary("Login Error");
        message.setDetail("Unable to log you in -"
           +  " username and password combination not found.");
        message.setSeverity(FacesMessage.SEVERITY_WARN);
        FacesContext.getCurrentInstance().addMessage(null,message);
        ExternalContext ectx =
FacesContext.getCurrentInstance().getExternalContext();
  HttpServletRequest request =
(HttpServletRequest)ectx.getRequest();
  HttpServletResponse response =
(HttpServletResponse)ectx.getResponse();
  RequestDispatcher dispatcher =
request.getRequestDispatcher("j_security_check");
  dispatcher.forward(request,response);
  return null;
    }

it never reaches the j_security check servlet

anyone know why?

The method works fine when called from outside containers security context defined around the  page request.



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Almost figured out how to satisfy container and managed bean login.

Posted by Pid <pi...@pidster.com>.
On 09/05/2010 21:22, Yucca Nel wrote:
> I have a double login requirement because I need some finer detals that tomcst's container authentication does not seem to provide.
> I need a way to atore username in business logic scope when logged in (mainly just  the username) my current solution is not working as follows:
> 
> I submit action to backing method which is coded in the jsf as follows in the login page:
> 
> 
> <f:view>
>     <body style="background-color:#7b68ee;margin:auto">
>     <div align="center" id="header"><jsp:include page="/header.jsp"/></div>
>     <div align="center">
>         <div align="center" id="centred-content"style="border-width:3px; border-style: solid; border-color: #7fffd4;width:800px">
>             <div id="h1" align="center">
>                 <h:outputText value="#{loginMsg.h1}..." style="color:white; font-family:fantasy;font-size:large;"/><br>
>                 <h:outputText value="#{loginMsg.h2}..." style="color:white; font-family:fantasy;font-size:large;"/></div>
>             <div align="center">
>                 <h:form>

How does the form defined here, know which method to submit the date
with (GET or POST) and to which URL (there's no action attribute)?


p

>                     <h:panelGrid columns="2">
> 
>                         <h:outputText value="#{registerMsg.userName}:" style="color:yellow;"/>
>                         <h:inputText id="j_username" value="#{loginForm.username}" title="#{registerMsg.userNameTitle}"required="true">
> 
>                             <f:validateLength maximum="20" minimum="6"/>
>                         <h:outputText value="#{registerMsg.password}:" style="color:yellow;"/>
>                         <h:inputSecret id="j_passwword" value="#{loginForm.password}" title="#{registerMsg.passwordTitle}"required="true" >
> 
>                         </h:inputSecret>
> 
>                     </h:panelGrid>
> 
>                     <h:commandButton action="#{loginForm.confirmCredentials}" value="#{loginMsg.login}"style="color:#20b2aa;" />
>                     <br>
>                 </h:form>
> 
> then in loginForm.java I have the method coded as follows to set my managed bean and hopefuly dispatch on continer needed login credentials. 
> 
> 
> public String confirmCredentials() throws IOException, ServletException {        UserSession userSession =
>         (UserSession)FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("userSession");
> 
>         if (UserManagerBean.confirmLogin(username, password)) {
>             
>             UsersEntity user = UserManagerBean.findUser(username);
>             userSession.setCurrentUser(user);
>             return "home";
>         }
>         FacesMessage message = new FacesMessage();
>         message.setSummary("Login Error");
>         message.setDetail("Unable to log you in -"
>            +  " username and password combination not found.");
>         message.setSeverity(FacesMessage.SEVERITY_WARN);
>         FacesContext.getCurrentInstance().addMessage(null,message);
>         ExternalContext ectx =
> FacesContext.getCurrentInstance().getExternalContext();
>   HttpServletRequest request =
> (HttpServletRequest)ectx.getRequest();
>   HttpServletResponse response =
> (HttpServletResponse)ectx.getResponse();
>   RequestDispatcher dispatcher =
> request.getRequestDispatcher("j_security_check");
>   dispatcher.forward(request,response);
>   return null;
>     }
> 
> it never reaches the j_security check servlet
> 
> anyone know why?
> 
> The method works fine when called from outside containers security context defined around the  page request.
> 
> 
> 



Re: Almost figured out how to satisfy container and managed bean login.

Posted by André Warnier <aw...@ice-sa.com>.
Yucca Nel wrote:
> I have a double login requirement because I need some finer detals that tomcst's container authentication does not seem to provide.
> I need a way to atore username in business logic scope when logged in (mainly just  the username) my current solution is not working as follows:
> 
> I submit action to backing method which is coded in the jsf as follows in the login page:
>
...

I know nothing of JSP.
But in the examples supplied with Tomcat, I see that the login form uses
<input type="text" name="j_username" ...
and not
<h:inputText id="j_username" ...


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org