You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@shiro.apache.org by David Barron <db...@zencos.com> on 2014/01/30 18:41:47 UTC

PrincipleCollection

Is there a recommended way to add entries to a Subject's PrincipleCollection? 
I'd like to add things like first name and email so they can be called up in
the app.

Thanks



--
View this message in context: http://shiro-user.582556.n2.nabble.com/PrincipleCollection-tp7579605.html
Sent from the Shiro User mailing list archive at Nabble.com.

Re: PrincipleCollection

Posted by David Barron <db...@zencos.com>.
Yes, I'm beginning to think so too.  It seems odd that there's no better way
to do this, though, especially since the jsp tag gives you the option to
pull out something other that the primary principle.



--
View this message in context: http://shiro-user.582556.n2.nabble.com/PrincipleCollection-tp7579605p7579612.html
Sent from the Shiro User mailing list archive at Nabble.com.

Re: PrincipleCollection

Posted by Stuart Broad <st...@moogsoft.com>.
Maybe you should store this information in the session instead.  Just a
thought...
 On 30 Jan 2014 18:12, "David Barron" <db...@zencos.com> wrote:

> I'm not building the Session, I'm letting Shiro handle as much of it as
> possible.
>
> Everything I want to add is in the same users table that I'm authenticating
> against, so I thought there might be something internal that could be used
> but I guess not.
>
> I've extended the SecurityManager with a custom class, I can play with it
> in
> the onSuccessfulLogin method.
>
>
>
>
>
> --
> View this message in context:
> http://shiro-user.582556.n2.nabble.com/PrincipleCollection-tp7579605p7579610.html
> Sent from the Shiro User mailing list archive at Nabble.com.
>

Re: PrincipleCollection

Posted by David Barron <db...@zencos.com>.
I'm not building the Session, I'm letting Shiro handle as much of it as
possible.  

Everything I want to add is in the same users table that I'm authenticating
against, so I thought there might be something internal that could be used
but I guess not.  

I've extended the SecurityManager with a custom class, I can play with it in
the onSuccessfulLogin method.





--
View this message in context: http://shiro-user.582556.n2.nabble.com/PrincipleCollection-tp7579605p7579610.html
Sent from the Shiro User mailing list archive at Nabble.com.

Re: PrincipleCollection

Posted by Stuart Broad <st...@moogsoft.com>.
You might be able to hack it by casting the PricipalCollection returned
from the Subject to SimplePrinciapCollection and adding to that but I would
not advice it.


On Thu, Jan 30, 2014 at 6:00 PM, Stuart Broad <st...@moogsoft.com> wrote:

> When building the AuthenticationInfo in the realm you can use something
> like:
>
>         SimplePrincipalCollection principals = new
> SimplePrincipalCollection(userName, realmName);
>         ...
>         SimpleAuthenticationInfo authInfo = new
> SimpleAuthenticationInfo(principals, password);
>
> And similar logic when building the Session.
>
> Cheers,
>
> Stuart
>
>
> On Thu, Jan 30, 2014 at 5:53 PM, David Barron <db...@zencos.com> wrote:
>
>> Maybe I wasn't clear.  I know how to get the existing principles.  How do
>> I
>> add to them?  Is there anything in the API for doing it or does it require
>> something custom written?
>> In a web application, where in the authentication process would I do it?
>>
>>
>>
>>
>> --
>> View this message in context:
>> http://shiro-user.582556.n2.nabble.com/PrincipleCollection-tp7579605p7579607.html
>> Sent from the Shiro User mailing list archive at Nabble.com.
>>
>
>

Re: PrincipleCollection

Posted by Stuart Broad <st...@moogsoft.com>.
When building the AuthenticationInfo in the realm you can use something
like:

        SimplePrincipalCollection principals = new
SimplePrincipalCollection(userName, realmName);
        ...
        SimpleAuthenticationInfo authInfo = new
SimpleAuthenticationInfo(principals, password);

And similar logic when building the Session.

Cheers,

Stuart


On Thu, Jan 30, 2014 at 5:53 PM, David Barron <db...@zencos.com> wrote:

> Maybe I wasn't clear.  I know how to get the existing principles.  How do I
> add to them?  Is there anything in the API for doing it or does it require
> something custom written?
> In a web application, where in the authentication process would I do it?
>
>
>
>
> --
> View this message in context:
> http://shiro-user.582556.n2.nabble.com/PrincipleCollection-tp7579605p7579607.html
> Sent from the Shiro User mailing list archive at Nabble.com.
>

Re: PrincipleCollection

Posted by David Barron <db...@zencos.com>.
Thank you, that makes it much more clear.  I should be able to extend
JdbcRealm and add whatever I need.





--
View this message in context: http://shiro-user.582556.n2.nabble.com/PrincipleCollection-tp7579605p7579615.html
Sent from the Shiro User mailing list archive at Nabble.com.

Re: PrincipleCollection

Posted by Les Hazlewood <lh...@apache.org>.
P.S. The principals should be super lightweight - basically an ID or
username or email and nothing else.  It is expected that you will use this
id to then query your datastore of choice to obtain a User object (or
whatever other information you require).

You can store all of the attributes in the PrincipalCollection, (and will
be able to in Shiro 2.0), but the the < 2.0 design encourages only storing
'pointers' to your data and not the full data.

Best,

Les

On Thu, Jan 30, 2014 at 2:07 PM, Les Hazlewood <lh...@apache.org>wrote:

> Your realm populates the PrincipalCollection at the time the account is
> authenticated (or looked up).
>
> In your Realm's getAuthenticationInfo (or doGetAuthenticationInfo)
> implementation, you return an AuthenticationInfo instance from your realm,
> and info.getPrincipals() contains whatever you populate them with.  You
> shouldn't really need to populate the PrincipalCollection outside of the
> Realm - the rest of the app should basically just be able to read the
> principals and not need to modify them.
>
> On a side note: this will be much more intuitive in in Shiro 2.0: as
> things stand now, you'll likely be able to do things like
> subject.getAttributes().get("whatever"), instead of by the (much inferior)
> type-based lookup that is in place today.
>
> HTH!
>
> Les
>
> On Thu, Jan 30, 2014 at 9:53 AM, David Barron <db...@zencos.com> wrote:
>
>> Maybe I wasn't clear.  I know how to get the existing principles.  How do
>> I
>> add to them?  Is there anything in the API for doing it or does it require
>> something custom written?
>> In a web application, where in the authentication process would I do it?
>>
>>
>>
>>
>> --
>> View this message in context:
>> http://shiro-user.582556.n2.nabble.com/PrincipleCollection-tp7579605p7579607.html
>> Sent from the Shiro User mailing list archive at Nabble.com.
>>
>
>

Re: PrincipleCollection

Posted by Les Hazlewood <lh...@apache.org>.
Your realm populates the PrincipalCollection at the time the account is
authenticated (or looked up).

In your Realm's getAuthenticationInfo (or doGetAuthenticationInfo)
implementation, you return an AuthenticationInfo instance from your realm,
and info.getPrincipals() contains whatever you populate them with.  You
shouldn't really need to populate the PrincipalCollection outside of the
Realm - the rest of the app should basically just be able to read the
principals and not need to modify them.

On a side note: this will be much more intuitive in in Shiro 2.0: as things
stand now, you'll likely be able to do things like
subject.getAttributes().get("whatever"), instead of by the (much inferior)
type-based lookup that is in place today.

HTH!

Les

On Thu, Jan 30, 2014 at 9:53 AM, David Barron <db...@zencos.com> wrote:

> Maybe I wasn't clear.  I know how to get the existing principles.  How do I
> add to them?  Is there anything in the API for doing it or does it require
> something custom written?
> In a web application, where in the authentication process would I do it?
>
>
>
>
> --
> View this message in context:
> http://shiro-user.582556.n2.nabble.com/PrincipleCollection-tp7579605p7579607.html
> Sent from the Shiro User mailing list archive at Nabble.com.
>

Re: PrincipleCollection

Posted by David Barron <db...@zencos.com>.
Maybe I wasn't clear.  I know how to get the existing principles.  How do I
add to them?  Is there anything in the API for doing it or does it require
something custom written?
In a web application, where in the authentication process would I do it?




--
View this message in context: http://shiro-user.582556.n2.nabble.com/PrincipleCollection-tp7579605p7579607.html
Sent from the Shiro User mailing list archive at Nabble.com.

Re: PrincipleCollection

Posted by Stuart Broad <st...@moogsoft.com>.
Hi David,

>From the subject you can either call getPrincipal() or getPrincipals()
depending on your principals.  For me I simple call getPrincipal() in order
to get a username, but I call getPrincipals() to get access to other things
(note: you do need to know the order within the collection).

Cheers,

Stuart


On Thu, Jan 30, 2014 at 5:41 PM, David Barron <db...@zencos.com> wrote:

> Is there a recommended way to add entries to a Subject's
> PrincipleCollection?
> I'd like to add things like first name and email so they can be called up
> in
> the app.
>
> Thanks
>
>
>
> --
> View this message in context:
> http://shiro-user.582556.n2.nabble.com/PrincipleCollection-tp7579605.html
> Sent from the Shiro User mailing list archive at Nabble.com.
>