KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > him > authentication > HarmoniseAuthenticationStore


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.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.*;
31 import org.openharmonise.vfs.metadata.value.*;
32 import org.openharmonise.vfs.servers.*;
33
34
35 /**
36  * Provides authentication services against a Harmonise server.
37  *
38  * @author Matthew Large
39  * @version $Revision: 1.3 $
40  *
41  */

42 public class HarmoniseAuthenticationStore extends AbstractAuthenticationStore {
43
44     /**
45      * Authentication information for the currently logged in user.
46      */

47     private AuthInfo m_auth = null;
48     
49     /**
50      * true if the currently logged in user is a super user.
51      */

52     private static boolean m_bIsSuperUser = false;
53     
54     /**
55      * true if the super user status for the currently logged in user has been checked.
56      */

57     private static boolean m_bSuperUserStatusChecked = false;
58
59     /**
60      *
61      */

62     public HarmoniseAuthenticationStore() {
63         super();
64         this.setup();
65     }
66     
67     /**
68      * Configures this authentication store, runs the login sequence
69      * gathering details from the user and checking them with the
70      * Harmonise server.
71      *
72      */

73     private void setup() {
74         LoginSequence loginSeq = new LoginSequence();
75         boolean bWorked = loginSeq.runSequence(this);
76         if(bWorked) {
77             this.m_auth = loginSeq.getAuthInfo();
78         } else {
79             System.exit(1);
80         }
81         
82     }
83
84     /* (non-Javadoc)
85      * @see com.simulacramedia.vfs.authentication.AbstractAuthenticationStore#getUserDisplayName(java.lang.String)
86      */

87     public static String JavaDoc getUserDisplayName(String JavaDoc sPath) {
88         String JavaDoc sDisplayName = sPath;
89         VirtualFile vfPrincipal = ServerList.getInstance().getHarmoniseServer().getVFS().getVirtualFile(sPath).getResource();
90         
91         if(vfPrincipal!=null) {
92             if(vfPrincipal.getProperty(NamespaceType.OHRM.getURI(), "FNAME")!=null && vfPrincipal.getProperty(NamespaceType.OHRM.getURI(), "FNAME").getValues().size()>0) {
93                 sDisplayName = ((StringValue) vfPrincipal.getProperty(NamespaceType.OHRM.getURI(), "FNAME").getValues().get(0)).getValue();
94             }
95             if(vfPrincipal.getProperty(NamespaceType.OHRM.getURI(), "SNAME")!=null && vfPrincipal.getProperty(NamespaceType.OHRM.getURI(), "SNAME").getValues().size()>0) {
96                 sDisplayName = sDisplayName + " " + ((StringValue) vfPrincipal.getProperty(NamespaceType.OHRM.getURI(), "SNAME").getValues().get(0)).getValue();
97             }
98             if((vfPrincipal.getProperty(NamespaceType.OHRM.getURI(), "FNAME")==null || vfPrincipal.getProperty(NamespaceType.OHRM.getURI(), "FNAME").getValues().size()==0) && (vfPrincipal.getProperty(NamespaceType.OHRM.getURI(), "SNAME")==null || vfPrincipal.getProperty(NamespaceType.OHRM.getURI(), "SNAME").getValues().size()==0)) {
99                 sDisplayName = vfPrincipal.getFileName();
100             }
101
102         } else if(sPath.lastIndexOf("/")!=-1 && sPath.lastIndexOf("/")<sPath.length()) {
103             sDisplayName = sPath.substring(sPath.lastIndexOf("/")+1);
104         }
105         return sDisplayName;
106     }
107     
108
109
110     /* (non-Javadoc)
111      * @see com.simulacramedia.vfs.authentication.AbstractAuthenticationStore#addAuthentication(java.net.URI, com.simulacramedia.vfs.authentication.AuthInfo)
112      */

113     public void addAuthentication(URI uri, AuthInfo authInfo) {
114     }
115
116     /* (non-Javadoc)
117      * @see com.simulacramedia.vfs.authentication.AbstractAuthenticationStore#getAuthentication(java.lang.String)
118      */

119     protected AuthInfo getAuthentication(String JavaDoc sURI) {
120         return this.m_auth;
121     }
122
123     /* (non-Javadoc)
124      * @see com.simulacramedia.vfs.authentication.AbstractAuthenticationStore#getAuthentication(java.net.URI)
125      */

126     public AuthInfo getAuthentication(URI uri) {
127         return this.m_auth;
128     }
129     
130     /**
131      * Checks if the currently logged in user is a super
132      * user.
133      *
134      * @return true if the currently logged in user is a super user
135      */

136     public static boolean isSuperUser() {
137         boolean bRetn = false;
138         if(m_bSuperUserStatusChecked) {
139             bRetn = m_bIsSuperUser;
140         } else {
141             Server server = null;
142             server = ServerList.getInstance().getHarmoniseServer();
143             URI uri = server.getURI();
144         
145             String JavaDoc sURI = uri.getScheme() + "://" + uri.getHost() + ":" + uri.getPort() + "/webdav/services/HarmoniseService";
146             URL url = null;
147             try {
148                 url = new URL(sURI);
149             } catch (MalformedURLException e2) {
150                 e2.printStackTrace();
151                 System.exit(1);
152             }
153         
154             AuthInfo auth = server.getVFS().getAuthentication();
155         
156             try {
157                 m_bIsSuperUser = UserConfigClient.isSuperUser(url, auth.getUsername(), auth.getPassword());
158             } catch (RemoteException e) {
159                 e.printStackTrace();
160             } catch (ServiceException e) {
161                 e.printStackTrace();
162             }
163             bRetn = m_bIsSuperUser;
164             m_bSuperUserStatusChecked = true;
165         }
166         return bRetn;
167     }
168
169 }
170
Popular Tags