You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Pedro Santos <pe...@gmail.com> on 2009/09/09 14:07:21 UTC

Re: Can't get attribute from AuthenticatedWebSession for no-role -needed page.

Please, what is "user id" that you refers?

On Wed, Sep 9, 2009 at 5:31 AM, Anders <in...@gmail.com> wrote:

> Hi,
>
> I can get the user id attribute from my authenticatedWebSession in a
> role-needed page.
> But I can't get user id when I go to no-role-needed page.
> Do I need to override newSession() method in WebApplication?
> Please help me~
>
> Belows are my classes:
>
> public class HelloWorldApplication extends AuthenticatedWebApplication
> {
>  @Override
>  protected Class<? extends AuthenticatedWebSession> getWebSessionClass()
>  {
>    return MyAuthenticatedWebSession.class;
>  }
>
>  @Override
>  protected Class<? extends WebPage> getSignInPageClass()
>  {
>    return MySignInPage.class;
>  }
> }
>
> public class MyAuthenticatedWebSession extends AuthenticatedWebSession
> {
>  public MyAuthenticatedWebSession(Request request)
>  {
>    super(request);
>  }
>
>  @Override
>  public boolean authenticate(String username, String password)
>  {
>    //do some authentication process
>    setAttribute("userId", username);
>    return true;
>  }
>
>  @Override
>  public Roles getRoles()
>  {
>    if(isSignedIn())
>    {
>      Roles roles = getUserRoles();
>      if(roles == null)
>      {
>        roles = new Roles();
>        roles.add("ROLE_USER");
>      }
>      return roles;
>    }
>    return null;
>  }
>
>  public static MyAuthenticatedWebSession get()
>  {
>    return (MyAuthenticatedWebSession) Session.get();
>  }
>
>  public String getUserId()
>  {
>    return (String) getAttribute("userId");
>  }
>
>  public Roles getUserRoles()
>  {
>    return (Roles) getAttribute("roles");
>  }
> }
>
> --
> ------------------
> ~Mia は 最高!~
> ------------------
>

Re: Can't get attribute from AuthenticatedWebSession for no-role -needed page.

Posted by "Juan Carlos Garcia M." <jc...@gmail.com>.
At any time, WebSession.get() will give you Wicket Session Object, but it
will not get persisted until you actually hit a page which requires state
full behavior. (Someone please correct me if im wrong.)



liny wrote:
> 
> Hi,
> 
> "user id" is the username. I want to set user id into session attribute.
> After I call WebSession.bind(), now the problem is solved.
> But why MyauthenticatedWebSession is temporary in default? (no session id)
> 
> 
> 
> Pedro Santos-6 wrote:
>> 
>> Please, what is "user id" that you refers?
>> 
>> On Wed, Sep 9, 2009 at 5:31 AM, Anders <in...@gmail.com> wrote:
>> 
>>> Hi,
>>>
>>> I can get the user id attribute from my authenticatedWebSession in a
>>> role-needed page.
>>> But I can't get user id when I go to no-role-needed page.
>>> Do I need to override newSession() method in WebApplication?
>>> Please help me~
>>>
>>> Belows are my classes:
>>>
>>> public class HelloWorldApplication extends AuthenticatedWebApplication
>>> {
>>>  @Override
>>>  protected Class<? extends AuthenticatedWebSession> getWebSessionClass()
>>>  {
>>>    return MyAuthenticatedWebSession.class;
>>>  }
>>>
>>>  @Override
>>>  protected Class<? extends WebPage> getSignInPageClass()
>>>  {
>>>    return MySignInPage.class;
>>>  }
>>> }
>>>
>>> public class MyAuthenticatedWebSession extends AuthenticatedWebSession
>>> {
>>>  public MyAuthenticatedWebSession(Request request)
>>>  {
>>>    super(request);
>>>  }
>>>
>>>  @Override
>>>  public boolean authenticate(String username, String password)
>>>  {
>>>    //do some authentication process
>>>    setAttribute("userId", username);
>>>    return true;
>>>  }
>>>
>>>  @Override
>>>  public Roles getRoles()
>>>  {
>>>    if(isSignedIn())
>>>    {
>>>      Roles roles = getUserRoles();
>>>      if(roles == null)
>>>      {
>>>        roles = new Roles();
>>>        roles.add("ROLE_USER");
>>>      }
>>>      return roles;
>>>    }
>>>    return null;
>>>  }
>>>
>>>  public static MyAuthenticatedWebSession get()
>>>  {
>>>    return (MyAuthenticatedWebSession) Session.get();
>>>  }
>>>
>>>  public String getUserId()
>>>  {
>>>    return (String) getAttribute("userId");
>>>  }
>>>
>>>  public Roles getUserRoles()
>>>  {
>>>    return (Roles) getAttribute("roles");
>>>  }
>>> }
>>>
>>> --
>>> ------------------
>>> ~Mia は 最高!~
>>> ------------------
>>>
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Can%27t-get-attribute-from-AuthenticatedWebSession-for-no-role--needed--page.-tp25360742p25364559.html
Sent from the Wicket - User mailing list archive at Nabble.com.


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


Re: Can't get attribute from AuthenticatedWebSession for no-role -needed page.

Posted by Pedro Santos <pe...@gmail.com>.
Hi,

I take a look at Page and WicketFilter code, it seems that an "actual
session" (typically an instance of {@link HttpSession}) are created only if
it is necessary. For example:


        if (!isPageStateless())
        {
            // trigger creation of the actual session in case it was
deferred

Session.get().getSessionStore().getSessionId(RequestCycle.get().getRequest(),
true);
            // Add/touch the response page in the session (its pagemap).
            getSession().touch(this);
        }

this is an fragment from renderPage() method of the Page. If your
application has only stateless pages, wicket will not dial with an actual
session. (take a look at ISessionStore.getSessionId javadoc -
http://wicketstuff.org/wicket13doc/org/apache/wicket/session/ISessionStore.html#getSessionId%28org.apache.wicket.Request,%20boolean%29
)

Another example are:

                // Try to see if there is a redirect stored
                // try get an existing session
                ISessionStore sessionStore =
webApplication.getSessionStore();
                String sessionId = sessionStore.getSessionId(request,
false);
                if (sessionId != null)
                {
in this fragment of WicketFilter, only try to get an existing "actual
session", if there are no one, it will only to be created if your
application are statefull.

On Wed, Sep 9, 2009 at 9:38 AM, liny <in...@gmail.com> wrote:

>
> Hi,
>
> "user id" is the username. I want to set user id into session attribute.
> After I call WebSession.bind(), now the problem is solved.
> But why MyauthenticatedWebSession is temporary in default? (no session id)
>
>
>
> Pedro Santos-6 wrote:
> >
> > Please, what is "user id" that you refers?
> >
> > On Wed, Sep 9, 2009 at 5:31 AM, Anders <in...@gmail.com> wrote:
> >
> >> Hi,
> >>
> >> I can get the user id attribute from my authenticatedWebSession in a
> >> role-needed page.
> >> But I can't get user id when I go to no-role-needed page.
> >> Do I need to override newSession() method in WebApplication?
> >> Please help me~
> >>
> >> Belows are my classes:
> >>
> >> public class HelloWorldApplication extends AuthenticatedWebApplication
> >> {
> >>  @Override
> >>  protected Class<? extends AuthenticatedWebSession> getWebSessionClass()
> >>  {
> >>    return MyAuthenticatedWebSession.class;
> >>  }
> >>
> >>  @Override
> >>  protected Class<? extends WebPage> getSignInPageClass()
> >>  {
> >>    return MySignInPage.class;
> >>  }
> >> }
> >>
> >> public class MyAuthenticatedWebSession extends AuthenticatedWebSession
> >> {
> >>  public MyAuthenticatedWebSession(Request request)
> >>  {
> >>    super(request);
> >>  }
> >>
> >>  @Override
> >>  public boolean authenticate(String username, String password)
> >>  {
> >>    //do some authentication process
> >>    setAttribute("userId", username);
> >>    return true;
> >>  }
> >>
> >>  @Override
> >>  public Roles getRoles()
> >>  {
> >>    if(isSignedIn())
> >>    {
> >>      Roles roles = getUserRoles();
> >>      if(roles == null)
> >>      {
> >>        roles = new Roles();
> >>        roles.add("ROLE_USER");
> >>      }
> >>      return roles;
> >>    }
> >>    return null;
> >>  }
> >>
> >>  public static MyAuthenticatedWebSession get()
> >>  {
> >>    return (MyAuthenticatedWebSession) Session.get();
> >>  }
> >>
> >>  public String getUserId()
> >>  {
> >>    return (String) getAttribute("userId");
> >>  }
> >>
> >>  public Roles getUserRoles()
> >>  {
> >>    return (Roles) getAttribute("roles");
> >>  }
> >> }
> >>
> >> --
> >> ------------------
> >> ~Mia は 最高!~
> >> ------------------
> >>
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/Can%27t-get-attribute-from-AuthenticatedWebSession-for-no-role--needed--page.-tp25360742p25364126.html
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: Can't get attribute from AuthenticatedWebSession for no-role -needed page.

Posted by liny <in...@gmail.com>.
Hi,

"user id" is the username. I want to set user id into session attribute.
After I call WebSession.bind(), now the problem is solved.
But why MyauthenticatedWebSession is temporary in default? (no session id)



Pedro Santos-6 wrote:
> 
> Please, what is "user id" that you refers?
> 
> On Wed, Sep 9, 2009 at 5:31 AM, Anders <in...@gmail.com> wrote:
> 
>> Hi,
>>
>> I can get the user id attribute from my authenticatedWebSession in a
>> role-needed page.
>> But I can't get user id when I go to no-role-needed page.
>> Do I need to override newSession() method in WebApplication?
>> Please help me~
>>
>> Belows are my classes:
>>
>> public class HelloWorldApplication extends AuthenticatedWebApplication
>> {
>>  @Override
>>  protected Class<? extends AuthenticatedWebSession> getWebSessionClass()
>>  {
>>    return MyAuthenticatedWebSession.class;
>>  }
>>
>>  @Override
>>  protected Class<? extends WebPage> getSignInPageClass()
>>  {
>>    return MySignInPage.class;
>>  }
>> }
>>
>> public class MyAuthenticatedWebSession extends AuthenticatedWebSession
>> {
>>  public MyAuthenticatedWebSession(Request request)
>>  {
>>    super(request);
>>  }
>>
>>  @Override
>>  public boolean authenticate(String username, String password)
>>  {
>>    //do some authentication process
>>    setAttribute("userId", username);
>>    return true;
>>  }
>>
>>  @Override
>>  public Roles getRoles()
>>  {
>>    if(isSignedIn())
>>    {
>>      Roles roles = getUserRoles();
>>      if(roles == null)
>>      {
>>        roles = new Roles();
>>        roles.add("ROLE_USER");
>>      }
>>      return roles;
>>    }
>>    return null;
>>  }
>>
>>  public static MyAuthenticatedWebSession get()
>>  {
>>    return (MyAuthenticatedWebSession) Session.get();
>>  }
>>
>>  public String getUserId()
>>  {
>>    return (String) getAttribute("userId");
>>  }
>>
>>  public Roles getUserRoles()
>>  {
>>    return (Roles) getAttribute("roles");
>>  }
>> }
>>
>> --
>> ------------------
>> ~Mia は 最高!~
>> ------------------
>>
> 
> 

-- 
View this message in context: http://www.nabble.com/Can%27t-get-attribute-from-AuthenticatedWebSession-for-no-role--needed--page.-tp25360742p25364126.html
Sent from the Wicket - User mailing list archive at Nabble.com.


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