You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@shiro.apache.org by NabbleSometimesSucks <bi...@yahoo.com> on 2013/04/23 02:17:08 UTC

Is there a way to name Principals in Subject's collection

So right now I create a new MutablePrincipalCollection

MutablePrincipalCollection principalCollection = new
SimplePrincipalCollection();
principalCollection.add(accountSecurity.getUsername(), getName());
principalCollection.add(accountSecurity.getUuid().toString(), getName());
String fingerprint = accountSecurity.getFingerprint();
if (fingerprint != null) {
  principalCollection.add(accountSecurity.getFingerprint(), getName());
}

But in order to get a particular value (They are all Strings) I need to
first call asList, then get it by index number. It would be nice if we could
name them. Then we could do something like

subject.getNamedPrincipal("Uuid")

Thanks

Mark



--
View this message in context: http://shiro-user.582556.n2.nabble.com/Is-there-a-way-to-name-Principals-in-Subject-s-collection-tp7578647.html
Sent from the Shiro User mailing list archive at Nabble.com.

Re: Is there a way to name Principals in Subject's collection

Posted by NabbleSometimesSucks <bi...@yahoo.com>.

That last element might or might not be in the collection, which is why I
have to double check first.

Mark



--
View this message in context: http://shiro-user.582556.n2.nabble.com/Is-there-a-way-to-name-Principals-in-Subject-s-collection-tp7578647p7578651.html
Sent from the Shiro User mailing list archive at Nabble.com.

Re: Is there a way to name Principals in Subject's collection

Posted by NabbleSometimesSucks <bi...@yahoo.com>.
Thanks, I just created a Utility class with static methods that take a
Subject.

Thanks

Mark



--
View this message in context: http://shiro-user.582556.n2.nabble.com/Is-there-a-way-to-name-Principals-in-Subject-s-collection-tp7578647p7578650.html
Sent from the Shiro User mailing list archive at Nabble.com.

Re: Is there a way to name Principals in Subject's collection

Posted by Les Hazlewood <lh...@apache.org>.
Hi Mark,

Not at the moment, but this is a high priority change for Shiro 2.x.  The
PrincipalCollection will likely be a Map so you can do things like
subject.getPrincipals().get("id");

In the meantime a potential fix (although hacky) is to create a wrapper
value class for the attribute you need, e.g. UuidPrincipal that just has
one method getUuid();  Then you can do a principalCollection.oneByType
lookup and unwrap the value.  Not pretty, but it works.  The Map approach
will be much nicer for sure!

HTH,

--
Les Hazlewood | @lhazlewood
CTO, Stormpath | http://stormpath.com | @goStormpath | 888.391.5282


On Mon, Apr 22, 2013 at 5:17 PM, NabbleSometimesSucks <
bigtrashcaninthesky@yahoo.com> wrote:

> So right now I create a new MutablePrincipalCollection
>
> MutablePrincipalCollection principalCollection = new
> SimplePrincipalCollection();
> principalCollection.add(accountSecurity.getUsername(), getName());
> principalCollection.add(accountSecurity.getUuid().toString(), getName());
> String fingerprint = accountSecurity.getFingerprint();
> if (fingerprint != null) {
>   principalCollection.add(accountSecurity.getFingerprint(), getName());
> }
>
> But in order to get a particular value (They are all Strings) I need to
> first call asList, then get it by index number. It would be nice if we
> could
> name them. Then we could do something like
>
> subject.getNamedPrincipal("Uuid")
>
> Thanks
>
> Mark
>
>
>
> --
> View this message in context:
> http://shiro-user.582556.n2.nabble.com/Is-there-a-way-to-name-Principals-in-Subject-s-collection-tp7578647.html
> Sent from the Shiro User mailing list archive at Nabble.com.
>