I am presuming that the host is necessary as some identifying
information about the user?
You need to store the host information in the PrincipalCollection. So:
public class HostInfo {
String hostname;
}
Create this object in doGetAuthenticationInfo, and add it to the
PrincipalCollection in the returned AuthenticationInfo.
Then, in doGetAuthorizationInfo, you simply need to call:
principals.oneByType(HostInfo.class).hostname
Of course, make the HostInfo class prettier (constructors, getters, what
have you). It might take a little bit more effort to create the
AuthenticationInfo in the first place (I believe you will have to create
your own PrincipalCollection object) but without seeing your current
code I can't tell you much more than that.
Let me know if that makes sense.
On 09/15/2011 10:23 PM, mu wrote:
> Hello
>
> I have a class which extends from AuthrizingRealm, like the following
>
> public class UserRealm extends AuthorizingRealm {
>
>
> protected AuthenticationInfo
> doGetAuthenticationInfo(AuthenticationToken authcToken) throws
> AuthenticationException {
> ............
>
> UsernamePasswordToken token = (UsernamePasswordToken) authcToken;
>
> if(token.getHost().equals("www.abc.com")) {
> .................
>
> }
> ...................
> }
>
>
> protected AuthorizationInfo
> doGetAuthorizationInfo(PrincipalCollection principals) {
> String loginName = (String)
> principals.fromRealm(getName()).iterator().next();
> ......
> }
>
> }
>
> I want to get the host name in the doGetAuthorizationInfo method, just
> like what to do in the doGetAuthenticationInfo method
>
> What should i do?
>
> Thanks