users@glassfish.java.net

Re: Pass username from custom realm to error page

From: Kumar Jayanti <Vbkumar.Jayanti_at_Sun.COM>
Date: Fri, 05 Jun 2009 14:38:15 +0530

Hi,

   
JasDA_at_web.de wrote:
> Hi,
>
> I know that I can access the username in my login module. This is what
> I already do in my authenticate method:
>
>
yes i knew you must be using the _username and _password, but i was just
trying to answer the last part of your original query :
> Perhaps it is possible to access the request from my custom realm that
> extends the IASRealm?
So i just wanted to tell you that even the Realm is accessible from the
LoginModule. And you can access the Realm Instance from the error page :

  Realm.getInstance(String name); //it would return the existing
instance from the underlying RealmsManager

Very round-about way and requires use of this internal Realm API that is
not exposed to users.

I vaguely remember someone else had filed an issue/rfe on the same
problem he had encountered, accessing username from the error page. But
i guess nothing has been done on this.


> protected void authenticate() throws LoginException
> {
>
> log("CustomRealm Auth
> Info:_username:"+_username+";_password:"+_password+";_currentrealm:"
> +_currentRealm);
>
> // Get the current realm and check whether it is instance of your realm
> if (!(_currentRealm instanceof IODS9Realm))
> {
> throw new LoginException("simplecustomrealm:badrealm");
> }
> IODS9Realm myCustomRealm = (IODS9Realm)_currentRealm;
>
> String[] grpList = myCustomRealm.authenticate(_username, _password);
>
> if (grpList == null) // JAAS behavior
> {
> throw new LoginException("customrealm:Login Failed with user
> " +_username);
> }
>
> log("login succeeded for " + _username);
>
> // Add the code related to authenticating to your user database.
> String[] groupListToForward = (String[])grpList.clone();
>
> /*
> * Call the commitAuthentication to populate grpList with the
> * set of groups to which _username belongs in this realm.
> */
>
> commitAuthentication(_username, _password, _currentRealm,
> groupListToForward);
> }
>
> If the login fails the LoginException will be thrown and the
> application will redirect to my error page defined in the web xml. In
> that error page (it's a Struts action) I need to know the username.
> And I don't know how to get it.
>
> 2009/6/5 Kumar Jayanti <Vbkumar.Jayanti_at_sun.com>:
>
>> JasDA_at_web.de wrote:
>>
>>> Hi,
>>>
>>> at the moment we are trying to get our old Tomcat 5 applications to work
>>> in Glassfish v2. I've implemented a custom realm for authentication and it
>>> works fine. But I have the following problem:
>>> If a user enters a wrong password the user will be redirected to an error
>>> page:
>>>
>>> <login-config>
>>> <auth-method>FORM</auth-method>
>>> <realm-name>iods9Realm</realm-name>
>>> <form-login-config>
>>> <form-login-page>/login.jsp</form-login-page>
>>> <form-error-page>/loginError.do</form-error-page>
>>> </form-login-config>
>>> </login-config>
>>>
>>> As you can see we're using Struts (I guess it's V1.x). My action looks
>>> like this:
>>>
>>> public void doExecute(ActionContext ctx) throws Exception
>>> {
>>> String text = "";
>>> if (ctx.request().getParameter("loginTimeout") != null)
>>> {
>>> .......
>>> }
>>> else
>>> {
>>> String userName = ctx.request().getParameter("j_username");
>>> .....
>>> }
>>> ctx.forwardByName("loginPage");
>>> }
>>>
>>> In our tomcat environment all parameters (j_username, ...) were available
>>> in this action. Now in our glassfish environment the parameters map is empty
>>> so I can't get the username. Is there any chance to geht the username?
>>> Perhaps it is possible to access the request from my custom realm that
>>> extends the IASRealm?
>>>
>>>
>> You can access username inside your Login Module, if your JAAS LoginModule
>> extends
>>
>> com.sun.appserv.security.AppservPasswordLoginModule
>>
>> then this class has protected members :
>>
>> protected String _username;
>> protected String _password;
>> protected Realm _currentRealm;
>>
>> Does that help you in any way.
>>
>> Thanks
>>
>>
>>> Regards,
>>> Jason
>>> __________________________________________________________
>>> WEB.DE FreeDSL mit DSL 6.000 Flatrate und Telefonanschluss
>>> für 17,95 Euro/mtl.!* http://produkte.web.de/go/02/
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
>>> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>>>
>>>
>>>
>>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
>> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>>
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
>
>