Revision 802
Added by bojilova almost 23 years ago
DocumentImpl.java | ||
---|---|---|
100 | 100 |
* @param docid the identifier of the document to be created |
101 | 101 |
* @param readNodes flag indicating whether the xmlnodes should be read |
102 | 102 |
*/ |
103 |
public DocumentImpl(Connection conn, String docid, boolean readNodes) throws McdbException |
|
103 |
public DocumentImpl(Connection conn, String docid, boolean readNodes) |
|
104 |
throws McdbException |
|
104 | 105 |
{ |
105 | 106 |
try { |
106 | 107 |
this.conn = conn; |
... | ... | |
825 | 826 |
* @param action the action to be performed (INSERT OR UPDATE) |
826 | 827 |
* @param docid the docid to use for the INSERT OR UPDATE |
827 | 828 |
* @param user the user that owns the document |
828 |
* @param group the group to which user belongs
|
|
829 |
* @param groups the groups to which user belongs
|
|
829 | 830 |
*/ |
830 | 831 |
public static String write(Connection conn,String filename, |
831 | 832 |
String pub, String dtdfilename, |
832 | 833 |
String action, String docid, String user, |
833 |
String group )
|
|
834 |
String[] groups )
|
|
834 | 835 |
throws Exception { |
835 | 836 |
|
836 | 837 |
Reader dtd = null; |
... | ... | |
838 | 839 |
dtd = new FileReader(new File(dtdfilename).toString()); |
839 | 840 |
} |
840 | 841 |
return write ( conn, new FileReader(new File(filename).toString()), |
841 |
pub, dtd, action, docid, user, group, false); |
|
842 |
pub, dtd, action, docid, user, groups, false);
|
|
842 | 843 |
} |
843 | 844 |
|
844 | 845 |
public static String write(Connection conn,Reader xml,String pub,Reader dtd, |
845 | 846 |
String action, String docid, String user, |
846 |
String group, boolean validate)
|
|
847 |
String[] groups, boolean validate)
|
|
847 | 848 |
throws Exception { |
848 |
return write(conn,xml,pub,dtd,action,docid,user,group,1,false,validate); |
|
849 |
return write(conn,xml,pub,dtd,action,docid,user,groups,1,false,validate);
|
|
849 | 850 |
} |
850 | 851 |
|
851 | 852 |
public static String write(Connection conn, Reader xml, String pub, |
852 | 853 |
String action, String docid, String user, |
853 |
String group )
|
|
854 |
String[] groups )
|
|
854 | 855 |
throws Exception { |
855 | 856 |
if(action.equals("UPDATE")) |
856 | 857 |
{//if the document is being updated then use the servercode from the |
857 | 858 |
//originally inserted document. |
858 | 859 |
DocumentImpl doc = new DocumentImpl(conn, docid); |
859 | 860 |
int servercode = doc.getServerlocation(); |
860 |
return write(conn, xml, pub, action, docid, user, group, servercode); |
|
861 |
return write(conn, xml, pub, action, docid, user, groups, servercode);
|
|
861 | 862 |
} |
862 | 863 |
else |
863 | 864 |
{//if the file is being inserted then the servercode is always 1 |
864 |
return write(conn, xml, pub, action, docid, user, group, 1); |
|
865 |
return write(conn, xml, pub, action, docid, user, groups, 1);
|
|
865 | 866 |
} |
866 | 867 |
} |
867 | 868 |
|
868 | 869 |
public static String write( Connection conn, Reader xml, |
869 | 870 |
String action, String docid, String user, |
870 |
String group, int serverCode )
|
|
871 |
String[] groups, int serverCode )
|
|
871 | 872 |
throws Exception |
872 | 873 |
{ |
873 |
return write(conn,xml,null,action,docid,user,group,serverCode); |
|
874 |
return write(conn,xml,null,action,docid,user,groups,serverCode);
|
|
874 | 875 |
} |
875 | 876 |
|
876 | 877 |
public static String write( Connection conn, Reader xml, String pub, |
877 | 878 |
String action, String docid, String user, |
878 |
String group, int serverCode)
|
|
879 |
String[] groups, int serverCode)
|
|
879 | 880 |
throws Exception |
880 | 881 |
{ |
881 |
return write(conn,xml,pub,null,action,docid,user,group, |
|
882 |
return write(conn,xml,pub,null,action,docid,user,groups,
|
|
882 | 883 |
serverCode,false,false); |
883 | 884 |
} |
884 | 885 |
|
885 | 886 |
public static String write( Connection conn, Reader xml, String pub, |
886 | 887 |
String action, String docid, String user, |
887 |
String group, int serverCode, boolean override)
|
|
888 |
String[] groups, int serverCode, boolean override)
|
|
888 | 889 |
throws Exception |
889 | 890 |
{ |
890 |
return write(conn,xml,pub,null,action,docid,user,group, |
|
891 |
return write(conn,xml,pub,null,action,docid,user,groups,
|
|
891 | 892 |
serverCode,override,false); |
892 | 893 |
} |
893 | 894 |
|
... | ... | |
901 | 902 |
* @param action the action to be performed (INSERT or UPDATE) |
902 | 903 |
* @param accnum the docid + rev# to use on INSERT or UPDATE |
903 | 904 |
* @param user the user that owns the document |
904 |
* @param group the group to which user belongs
|
|
905 |
* @param groups the groups to which user belongs
|
|
905 | 906 |
* @param serverCode the serverid from xml_replication on which this document |
906 | 907 |
* resides. |
907 | 908 |
* @param override flag to stop insert replication checking. |
... | ... | |
913 | 914 |
|
914 | 915 |
public static String write( Connection conn,Reader xml,String pub,Reader dtd, |
915 | 916 |
String action, String accnum, String user, |
916 |
String group, int serverCode, boolean override,
|
|
917 |
String[] groups, int serverCode, boolean override,
|
|
917 | 918 |
boolean validate) |
918 | 919 |
throws Exception |
919 | 920 |
{ |
... | ... | |
972 | 973 |
MetacatReplication.replLog("lock granted for " + accnum + " from " + |
973 | 974 |
server); |
974 | 975 |
XMLReader parser = initializeParser(conn, action, docid, validate, |
975 |
user, group, pub, serverCode, dtd); |
|
976 |
user, groups, pub, serverCode, dtd);
|
|
976 | 977 |
conn.setAutoCommit(false); |
977 | 978 |
parser.parse(new InputSource(xml)); |
978 | 979 |
conn.commit(); |
... | ... | |
1022 | 1023 |
if ( action.equals("UPDATE") ) { |
1023 | 1024 |
// check for 'write' permission for 'user' to update this document |
1024 | 1025 |
|
1025 |
if ( !hasPermission(conn, user, group, docid) ) { |
|
1026 |
if ( !hasPermission(conn, user, groups, docid) ) {
|
|
1026 | 1027 |
throw new Exception("User " + user + |
1027 | 1028 |
" does not have permission to update XML Document #" + accnum); |
1028 | 1029 |
} |
... | ... | |
1032 | 1033 |
try |
1033 | 1034 |
{ |
1034 | 1035 |
XMLReader parser = initializeParser(conn, action, docid, validate, |
1035 |
user, group, pub, serverCode, dtd); |
|
1036 |
user, groups, pub, serverCode, dtd);
|
|
1036 | 1037 |
conn.setAutoCommit(false); |
1037 | 1038 |
parser.parse(new InputSource(xml)); |
1038 | 1039 |
conn.commit(); |
... | ... | |
1062 | 1063 |
* @param docid the ID of the document to be deleted from the database |
1063 | 1064 |
*/ |
1064 | 1065 |
public static void delete( Connection conn, String accnum, |
1065 |
String user, String group )
|
|
1066 |
String user, String[] groups )
|
|
1066 | 1067 |
throws Exception |
1067 | 1068 |
{ |
1068 | 1069 |
// OLD |
... | ... | |
1082 | 1083 |
|
1083 | 1084 |
|
1084 | 1085 |
// check for 'write' permission for 'user' to delete this document |
1085 |
if ( !hasPermission(conn, user, group, docid) ) { |
|
1086 |
if ( !hasPermission(conn, user, groups, docid) ) {
|
|
1086 | 1087 |
throw new Exception("User " + user + |
1087 | 1088 |
" does not have permission to delete XML Document #" + accnum); |
1088 | 1089 |
} |
... | ... | |
1110 | 1111 |
} |
1111 | 1112 |
|
1112 | 1113 |
/** |
1113 |
* Check for "WRITE" permission on @docid for @user and/or @group |
|
1114 |
* Check for "WRITE" permission on @docid for @user and/or @groups
|
|
1114 | 1115 |
* from DB connection |
1115 | 1116 |
*/ |
1116 |
private static boolean hasPermission( Connection conn, String user, |
|
1117 |
String group, String docid)
|
|
1118 |
throws SQLException
|
|
1117 |
private static boolean hasPermission ( Connection conn, String user,
|
|
1118 |
String[] groups, String docid )
|
|
1119 |
throws SQLException
|
|
1119 | 1120 |
{ |
1120 |
// b' of the command line invocation |
|
1121 |
if ( (user == null) && (group == null) ) { |
|
1122 |
return true; |
|
1123 |
} |
|
1124 |
|
|
1125 |
// Check for WRITE permission on @docid for @user and/or @group |
|
1121 |
// Check for WRITE permission on @docid for @user and/or @groups |
|
1126 | 1122 |
AccessControlList aclobj = new AccessControlList(conn); |
1127 |
boolean hasPermission = aclobj.hasPermission("WRITE",user,docid); |
|
1128 |
if ( !hasPermission && group != null ) { |
|
1129 |
hasPermission = aclobj.hasPermission("WRITE",group,docid); |
|
1130 |
} |
|
1131 |
|
|
1132 |
return hasPermission; |
|
1123 |
return aclobj.hasPermission("WRITE", user, groups, docid); |
|
1133 | 1124 |
} |
1134 | 1125 |
|
1135 | 1126 |
/** |
... | ... | |
1137 | 1128 |
*/ |
1138 | 1129 |
private static XMLReader initializeParser(Connection conn, String action, |
1139 | 1130 |
String docid, boolean validate, |
1140 |
String user, String group, String pub,
|
|
1131 |
String user, String[] groups, String pub,
|
|
1141 | 1132 |
int serverCode, Reader dtd) |
1142 | 1133 |
throws Exception |
1143 | 1134 |
{ |
... | ... | |
1147 | 1138 |
// |
1148 | 1139 |
try { |
1149 | 1140 |
ContentHandler chandler = new DBSAXHandler(conn, action, docid, |
1150 |
user, group, pub, serverCode); |
|
1141 |
user, groups, pub, serverCode);
|
|
1151 | 1142 |
EntityResolver eresolver= new DBEntityResolver(conn, |
1152 | 1143 |
(DBSAXHandler)chandler, dtd); |
1153 | 1144 |
DTDHandler dtdhandler = new DBDTDHandler(conn); |
1154 | 1145 |
|
1155 | 1146 |
// Get an instance of the parser |
1156 |
MetaCatUtil util = new MetaCatUtil(); |
|
1157 |
String parserName = util.getOption("saxparser"); |
|
1147 |
String parserName = MetaCatUtil.getOption("saxparser"); |
|
1158 | 1148 |
parser = XMLReaderFactory.createXMLReader(parserName); |
1159 | 1149 |
|
1160 | 1150 |
// Turn on validation |
Also available in: Unified diff
added support for multiple group membership