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.harmonise.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.AuthInfo;
031: import org.openharmonise.vfs.authentication.VFSUser;
032: import org.openharmonise.vfs.metadata.*;
033: import org.openharmonise.vfs.metadata.value.*;
034: import org.openharmonise.vfs.servers.*;
035:
036: /**
037: * Wraps up the information and methods for a user on a Harmonise server.
038: *
039: * @author Matthew Large
040: * @version $Revision: 1.4 $
041: *
042: */
043: public class HarmoniseUser implements VFSUser {
044:
045: /**
046: * Full path to the virtual file for the principal representing the user.
047: */
048: private String m_sUserPath = null;
049:
050: /**
051: * The virtual file system for the Harmonise server.
052: */
053: private AbstractVirtualFileSystem m_vfs = null;
054:
055: /**
056: * true if the super user information has already been checked.
057: */
058: private boolean m_bSuperUserStatusChecked = false;
059:
060: /**
061: * true if the user is a super user.
062: */
063: private boolean m_bIsSuperUser = false;
064:
065: /**
066: * Contructs a user object.
067: *
068: * @param vfs Virtual file system for the Harmonise server
069: * @param sUserPath Full path to the virtual file for the principal representing the user
070: */
071: public HarmoniseUser(AbstractVirtualFileSystem vfs, String sUserPath) {
072: super ();
073: this .m_vfs = vfs;
074: this .m_sUserPath = sUserPath;
075: }
076:
077: /**
078: * Returns the full path for the user's role.
079: *
080: * @return Full path
081: */
082: public String getRolePath() {
083: String sRolePath = null;
084:
085: VirtualFile vfUser = this .m_vfs.getVirtualFile(m_sUserPath)
086: .getResource();
087:
088: PropertyInstance rbsPropInst = vfUser.getProperty(
089: NamespaceType.OHRM_RBS.getURI(), "ROLE");
090: if (rbsPropInst.getValues().size() > 0) {
091: ValueValue value = (ValueValue) rbsPropInst.getValues()
092: .get(0);
093: sRolePath = value.getValue();
094: }
095:
096: return sRolePath;
097: }
098:
099: /**
100: * Checks if the user is a super user.
101: *
102: * @return true if the user is a super user
103: */
104: public boolean isSuperUser() {
105: if (!this .m_bSuperUserStatusChecked) {
106: Server server = null;
107: server = ServerList.getInstance().getHarmoniseServer();
108: URI uri = server.getURI();
109:
110: String sURI = uri.getScheme() + "://" + uri.getHost() + ":"
111: + uri.getPort()
112: + "/webdav/services/HarmoniseService";
113: URL url = null;
114: try {
115: url = new URL(sURI);
116: } catch (MalformedURLException e2) {
117: e2.printStackTrace();
118: }
119:
120: AuthInfo auth = server.getVFS().getAuthentication();
121:
122: try {
123: if (UserConfigClient.isSuperUser(url, auth
124: .getUsername(), auth.getPassword())) {
125: this .m_bIsSuperUser = true;
126: }
127: } catch (RemoteException e) {
128: e.printStackTrace();
129: } catch (ServiceException e) {
130: e.printStackTrace();
131: }
132: this .m_bSuperUserStatusChecked = true;
133: return this.m_bIsSuperUser;
134: } else {
135: return this.m_bIsSuperUser;
136: }
137: }
138:
139: }
|