KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > him > harmonise > authentication > HarmoniseUser


1 /*
2  * The contents of this file are subject to the
3  * Mozilla Public License Version 1.1 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
6  *
7  * Software distributed under the License is distributed on an "AS IS"
8  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
9  * See the License for the specific language governing rights and
10  * limitations under the License.
11  *
12  * The Initial Developer of the Original Code is Simulacra Media Ltd.
13  * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
14  *
15  * All Rights Reserved.
16  *
17  * Contributor(s):
18  */

19 package org.openharmonise.him.harmonise.authentication;
20
21 import java.net.*;
22 import java.rmi.*;
23
24 import javax.xml.rpc.*;
25
26 import org.openharmonise.commons.xml.namespace.*;
27 import org.openharmonise.him.*;
28 import org.openharmonise.him.harmonise.*;
29 import org.openharmonise.vfs.*;
30 import org.openharmonise.vfs.authentication.AuthInfo;
31 import org.openharmonise.vfs.authentication.VFSUser;
32 import org.openharmonise.vfs.metadata.*;
33 import org.openharmonise.vfs.metadata.value.*;
34 import org.openharmonise.vfs.servers.*;
35
36
37 /**
38  * Wraps up the information and methods for a user on a Harmonise server.
39  *
40  * @author Matthew Large
41  * @version $Revision: 1.4 $
42  *
43  */

44 public class HarmoniseUser implements VFSUser {
45
46     /**
47      * Full path to the virtual file for the principal representing the user.
48      */

49     private String JavaDoc m_sUserPath = null;
50
51     /**
52      * The virtual file system for the Harmonise server.
53      */

54     private AbstractVirtualFileSystem m_vfs = null;
55     
56     /**
57      * true if the super user information has already been checked.
58      */

59     private boolean m_bSuperUserStatusChecked = false;
60     
61     /**
62      * true if the user is a super user.
63      */

64     private boolean m_bIsSuperUser = false;
65
66     /**
67      * Contructs a user object.
68      *
69      * @param vfs Virtual file system for the Harmonise server
70      * @param sUserPath Full path to the virtual file for the principal representing the user
71      */

72     public HarmoniseUser(AbstractVirtualFileSystem vfs, String JavaDoc sUserPath) {
73         super();
74         this.m_vfs = vfs;
75         this.m_sUserPath = sUserPath;
76     }
77     
78     /**
79      * Returns the full path for the user's role.
80      *
81      * @return Full path
82      */

83     public String JavaDoc getRolePath() {
84         String JavaDoc sRolePath = null;
85         
86         VirtualFile vfUser = this.m_vfs.getVirtualFile(m_sUserPath).getResource();
87         
88         PropertyInstance rbsPropInst = vfUser.getProperty(NamespaceType.OHRM_RBS.getURI(), "ROLE");
89         if(rbsPropInst.getValues().size()>0) {
90             ValueValue value = (ValueValue) rbsPropInst.getValues().get(0);
91             sRolePath = value.getValue();
92         }
93         
94         return sRolePath;
95     }
96     
97     /**
98      * Checks if the user is a super user.
99      *
100      * @return true if the user is a super user
101      */

102     public boolean isSuperUser() {
103         if(!this.m_bSuperUserStatusChecked) {
104             Server server = null;
105             server = ServerList.getInstance().getHarmoniseServer();
106             URI uri = server.getURI();
107         
108             String JavaDoc sURI = uri.getScheme() + "://" + uri.getHost() + ":" + uri.getPort() + "/webdav/services/HarmoniseService";
109             URL url = null;
110             try {
111                 url = new URL(sURI);
112             } catch (MalformedURLException e2) {
113                 e2.printStackTrace();
114             }
115         
116             AuthInfo auth = server.getVFS().getAuthentication();
117         
118             try {
119                 if( UserConfigClient.isSuperUser(url, auth.getUsername(), auth.getPassword()) ) {
120                     this.m_bIsSuperUser=true;
121                 }
122             } catch (RemoteException e) {
123                 e.printStackTrace();
124             } catch (ServiceException e) {
125                 e.printStackTrace();
126             }
127             this.m_bSuperUserStatusChecked = true;
128             return this.m_bIsSuperUser;
129         } else {
130             return this.m_bIsSuperUser;
131         }
132     }
133
134 }
135
Popular Tags