You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-user@jakarta.apache.org by Wong Kam Lai <kl...@onk.cintec.cuhk.edu.hk> on 2003/04/08 05:34:07 UTC

Get username and role

Hi,

I'm now mainly using WebdavResource to implement. I would like to know
how to get the username now accessing and his role.

Also, how to implement a application such that I can embed the windows
explorer in it? and also, I only need to login to the application and
don't need to login to the embeded windows explorer afterwards.


---------------------------------------------------------------------
To unsubscribe, e-mail: slide-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-user-help@jakarta.apache.org


Re: Get username and role

Posted by Wong Kam Lai <kl...@onk.cintec.cuhk.edu.hk>.
Hi, how to get the role of the user from the username? For example, give a
'root' username will return 'root' role?

I am now doing this ..
get the username from login page (jsp), init the Domain and get the
NamespaceToken, form a uri '/users/root' and use this uri to new a
SubjectNode, use this Object for using Security function getRoles to get
the Enumberation Object and I iterate the object to turn out the role, but
the result is 'nobody' -__- , here is the segment of my code ..


    private void setNamespaceToken(){
        try{
            if (domainConfigFile !=null){
                Domain.init(domainConfigFile);
                if (token == null){
                    token = Domain.accessNamespace(
                        new SecurityToken(this), namespaceName);
                }
            }
        } catch (Exception e){
            System.out.println("Cannot connect namespace");
        }
    }

    private String genUri(String username){
        NamespaceConfig nc = token.getNamespaceConfig();
        String striUri = nc.getUsersPath() +"/"+ username;
        return striUri;
    }

    public Enumeration getUserRole(String username){
        setNamespaceToken();
        String strUri = genUri(username);
        Security securityHelper = token.getSecurityHelper();
        SubjectNode subjectNode = new SubjectNode(strUri);
        Enumeration roleLists =
securityHelper.getRoles((ObjectNode) subjectNode);
        return roleLists;
    }



---------------------------------------------------------------------
To unsubscribe, e-mail: slide-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-user-help@jakarta.apache.org