You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Giulio Quaresima <gi...@gmail.com> on 2013/02/20 14:58:56 UTC

GenericPrincipal . catalina 6.0.24

Hi all, this is my first post in this list.

I have a little doubt about the default Realm implementations which comes
with Tomcat. In particular, I refer to JAASRealm.

I developed a JAAS LoginModule which populate the Subject with a user
principal called MyUserPrincipal. This Principal implementation expose some
information which are useful to recognize the user (myUserCode in this
example). JAASRealm incapsulate my principal in a GenericPrincipal
instance, which in turn refers to my principal through the
getUserPrincipal() method.

The problem is that, respecting the low-copuling principle, I don't want to
expose the Container API (catalina) to my webapps, because I want my
webapps virtually deployable in any environment, without any modification.

As a workaround, I develeloped a static method
MyUserPrincipal.getInstance() which return my Principal, as you can see in
the example code pasted below, but, IMHO, I think it would be better if the
principal returned by request.getUserPrincipal() would be the same instance
I set in the Subject given to my LoginModule.

Thanks to all, and sorry for my poor english.

public class MyUserPrincipal implements Principal
{
 private static final long serialVersionUID = 581169071825028084L;

private String name;
private int myUserCode;
 public static MyUserPrincipal getInstance(Principal principal)
{
if (principal instanceof GenericPrincipal)
{
GenericPrincipal genericPrincipal = (GenericPrincipal) principal;
Principal userPrincipal = genericPrincipal.getUserPrincipal();
if (userPrincipal != null && userPrincipal instanceof MyUserPrincipal)
{
return (MyUserPrincipal) userPrincipal;
}
}
else if (principal instanceof MyUserPrincipal)
{
return (MyUserPrincipal) principal;
}
return null;
}

public int getName()
{
      return name;
}

public int getMyUserCode()
{
      return myUserCode;
}

...

}

Re: GenericPrincipal . catalina 6.0.24

Posted by Giulio Quaresima <gi...@gmail.com>.
I simply made an error in the XML configuration of JAASRealm. Sorry for the
waste of time.


On Wed, Feb 20, 2013 at 10:04 PM, Christopher Schultz <
chris@christopherschultz.net> wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA256
>
> Giulio,
>
> On 2/20/13 8:58 AM, Giulio Quaresima wrote:
> > I have a little [question] about the default Realm implementations
> > which comes with Tomcat. In particular, I refer to JAASRealm.
> >
> > I developed a JAAS LoginModule which populate the Subject with a
> > user principal called MyUserPrincipal. This Principal
> > implementation expose some information which are useful to
> > recognize the user (myUserCode in this example). JAASRealm
> > incapsulate my principal in a GenericPrincipal instance, which in
> > turn refers to my principal through the getUserPrincipal() method.
>
> Why are you using GenericPrincipal at all?
>
> > The problem is that, respecting the low-copuling principle, I don't
> > want to expose the Container API (catalina) to my webapps, because
> > I want my webapps virtually deployable in any environment, without
> > any modification.
>
> That sounds like a reasonable goal.
>
> > public class MyUserPrincipal implements Principal { private String
> > name; private int myUserCode; public static MyUserPrincipal
> > getInstance(Principal principal) { if (principal instanceof
> > GenericPrincipal)
>
> Why do you have any of this at all? You should just have the
> "implements Principal" in your class and that should be it.
>
> - -chris
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
> Comment: GPGTools - http://gpgtools.org
> Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/
>
> iEYEAREIAAYFAlElOkIACgkQ9CaO5/Lv0PDEkgCfXvtKu35C51P5KZnkaS/F/Fs3
> NlcAn1JN0DwbnE65So2w7ZeSRRFQnYCe
> =sV0v
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

Re: GenericPrincipal . catalina 6.0.24

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Giulio,

On 2/20/13 8:58 AM, Giulio Quaresima wrote:
> I have a little [question] about the default Realm implementations 
> which comes with Tomcat. In particular, I refer to JAASRealm.
> 
> I developed a JAAS LoginModule which populate the Subject with a
> user principal called MyUserPrincipal. This Principal
> implementation expose some information which are useful to
> recognize the user (myUserCode in this example). JAASRealm
> incapsulate my principal in a GenericPrincipal instance, which in
> turn refers to my principal through the getUserPrincipal() method.

Why are you using GenericPrincipal at all?

> The problem is that, respecting the low-copuling principle, I don't
> want to expose the Container API (catalina) to my webapps, because
> I want my webapps virtually deployable in any environment, without
> any modification.

That sounds like a reasonable goal.

> public class MyUserPrincipal implements Principal { private String
> name; private int myUserCode; public static MyUserPrincipal
> getInstance(Principal principal) { if (principal instanceof
> GenericPrincipal)

Why do you have any of this at all? You should just have the
"implements Principal" in your class and that should be it.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iEYEAREIAAYFAlElOkIACgkQ9CaO5/Lv0PDEkgCfXvtKu35C51P5KZnkaS/F/Fs3
NlcAn1JN0DwbnE65So2w7ZeSRRFQnYCe
=sV0v
-----END PGP SIGNATURE-----

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