001: /*
002: * The contents of this file are subject to the
003: * Mozilla Public License Version 1.1 (the "License");
004: * you may not use this file except in compliance with the License.
005: * You may obtain a copy of the License at http://www.mozilla.org/MPL/
006: *
007: * Software distributed under the License is distributed on an "AS IS"
008: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
009: * See the License for the specific language governing rights and
010: * limitations under the License.
011: *
012: * The Initial Developer of the Original Code is Simulacra Media Ltd.
013: * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
014: *
015: * All Rights Reserved.
016: *
017: * Contributor(s):
018: */
019: package org.openharmonise.him.authentication;
020:
021: import java.net.*;
022: import java.rmi.*;
023:
024: import javax.xml.rpc.*;
025:
026: import org.openharmonise.commons.xml.namespace.*;
027: import org.openharmonise.him.*;
028: import org.openharmonise.him.harmonise.*;
029: import org.openharmonise.vfs.*;
030: import org.openharmonise.vfs.authentication.*;
031: import org.openharmonise.vfs.metadata.value.*;
032: import org.openharmonise.vfs.servers.*;
033:
034: /**
035: * Provides authentication services against a Harmonise server.
036: *
037: * @author Matthew Large
038: * @version $Revision: 1.3 $
039: *
040: */
041: public class HarmoniseAuthenticationStore extends
042: AbstractAuthenticationStore {
043:
044: /**
045: * Authentication information for the currently logged in user.
046: */
047: private AuthInfo m_auth = null;
048:
049: /**
050: * true if the currently logged in user is a super user.
051: */
052: private static boolean m_bIsSuperUser = false;
053:
054: /**
055: * true if the super user status for the currently logged in user has been checked.
056: */
057: private static boolean m_bSuperUserStatusChecked = false;
058:
059: /**
060: *
061: */
062: public HarmoniseAuthenticationStore() {
063: super ();
064: this .setup();
065: }
066:
067: /**
068: * Configures this authentication store, runs the login sequence
069: * gathering details from the user and checking them with the
070: * Harmonise server.
071: *
072: */
073: private void setup() {
074: LoginSequence loginSeq = new LoginSequence();
075: boolean bWorked = loginSeq.runSequence(this );
076: if (bWorked) {
077: this .m_auth = loginSeq.getAuthInfo();
078: } else {
079: System.exit(1);
080: }
081:
082: }
083:
084: /* (non-Javadoc)
085: * @see com.simulacramedia.vfs.authentication.AbstractAuthenticationStore#getUserDisplayName(java.lang.String)
086: */
087: public static String getUserDisplayName(String sPath) {
088: String sDisplayName = sPath;
089: VirtualFile vfPrincipal = ServerList.getInstance()
090: .getHarmoniseServer().getVFS().getVirtualFile(sPath)
091: .getResource();
092:
093: if (vfPrincipal != null) {
094: if (vfPrincipal.getProperty(NamespaceType.OHRM.getURI(),
095: "FNAME") != null
096: && vfPrincipal.getProperty(
097: NamespaceType.OHRM.getURI(), "FNAME")
098: .getValues().size() > 0) {
099: sDisplayName = ((StringValue) vfPrincipal.getProperty(
100: NamespaceType.OHRM.getURI(), "FNAME")
101: .getValues().get(0)).getValue();
102: }
103: if (vfPrincipal.getProperty(NamespaceType.OHRM.getURI(),
104: "SNAME") != null
105: && vfPrincipal.getProperty(
106: NamespaceType.OHRM.getURI(), "SNAME")
107: .getValues().size() > 0) {
108: sDisplayName = sDisplayName
109: + " "
110: + ((StringValue) vfPrincipal.getProperty(
111: NamespaceType.OHRM.getURI(), "SNAME")
112: .getValues().get(0)).getValue();
113: }
114: if ((vfPrincipal.getProperty(NamespaceType.OHRM.getURI(),
115: "FNAME") == null || vfPrincipal.getProperty(
116: NamespaceType.OHRM.getURI(), "FNAME").getValues()
117: .size() == 0)
118: && (vfPrincipal.getProperty(NamespaceType.OHRM
119: .getURI(), "SNAME") == null || vfPrincipal
120: .getProperty(NamespaceType.OHRM.getURI(),
121: "SNAME").getValues().size() == 0)) {
122: sDisplayName = vfPrincipal.getFileName();
123: }
124:
125: } else if (sPath.lastIndexOf("/") != -1
126: && sPath.lastIndexOf("/") < sPath.length()) {
127: sDisplayName = sPath.substring(sPath.lastIndexOf("/") + 1);
128: }
129: return sDisplayName;
130: }
131:
132: /* (non-Javadoc)
133: * @see com.simulacramedia.vfs.authentication.AbstractAuthenticationStore#addAuthentication(java.net.URI, com.simulacramedia.vfs.authentication.AuthInfo)
134: */
135: public void addAuthentication(URI uri, AuthInfo authInfo) {
136: }
137:
138: /* (non-Javadoc)
139: * @see com.simulacramedia.vfs.authentication.AbstractAuthenticationStore#getAuthentication(java.lang.String)
140: */
141: protected AuthInfo getAuthentication(String sURI) {
142: return this .m_auth;
143: }
144:
145: /* (non-Javadoc)
146: * @see com.simulacramedia.vfs.authentication.AbstractAuthenticationStore#getAuthentication(java.net.URI)
147: */
148: public AuthInfo getAuthentication(URI uri) {
149: return this .m_auth;
150: }
151:
152: /**
153: * Checks if the currently logged in user is a super
154: * user.
155: *
156: * @return true if the currently logged in user is a super user
157: */
158: public static boolean isSuperUser() {
159: boolean bRetn = false;
160: if (m_bSuperUserStatusChecked) {
161: bRetn = m_bIsSuperUser;
162: } else {
163: Server server = null;
164: server = ServerList.getInstance().getHarmoniseServer();
165: URI uri = server.getURI();
166:
167: String sURI = uri.getScheme() + "://" + uri.getHost() + ":"
168: + uri.getPort()
169: + "/webdav/services/HarmoniseService";
170: URL url = null;
171: try {
172: url = new URL(sURI);
173: } catch (MalformedURLException e2) {
174: e2.printStackTrace();
175: System.exit(1);
176: }
177:
178: AuthInfo auth = server.getVFS().getAuthentication();
179:
180: try {
181: m_bIsSuperUser = UserConfigClient.isSuperUser(url, auth
182: .getUsername(), auth.getPassword());
183: } catch (RemoteException e) {
184: e.printStackTrace();
185: } catch (ServiceException e) {
186: e.printStackTrace();
187: }
188: bRetn = m_bIsSuperUser;
189: m_bSuperUserStatusChecked = true;
190: }
191: return bRetn;
192: }
193:
194: }
|