Project

General

Profile

« Previous | Next » 

Revision 6334

consistently construct username/groups for MetacatHandler calls - also consistently call isAuthorized

View differences:

src/edu/ucsb/nceas/metacat/dataone/MNodeService.java
27 27
import java.io.InputStream;
28 28
import java.security.NoSuchAlgorithmException;
29 29
import java.sql.SQLException;
30
import java.util.ArrayList;
31 30
import java.util.Date;
32 31
import java.util.List;
33 32

  
......
35 34
import org.apache.log4j.Logger;
36 35
import org.dataone.client.D1Client;
37 36
import org.dataone.client.MNode;
37
import org.dataone.service.Constants;
38 38
import org.dataone.service.exceptions.IdentifierNotUnique;
39 39
import org.dataone.service.exceptions.InsufficientResources;
40 40
import org.dataone.service.exceptions.InvalidRequest;
......
168 168

  
169 169
    String localId = null;
170 170
    boolean allowed = false;
171
    Subject subject = session.getSubject();
172
    List<Group> groupList = new ArrayList<Group>();
173
    String[] groups = new String[0];
174
    if ( session.getSubjectList() != null ) {
175
      groupList = session.getSubjectList().getGroupList();
176
      groups = new String[groupList.size()];
177
    	
171
    String username = Constants.PUBLIC_SUBJECT;
172
    String[] groupnames = null;
173
    if (session != null ) {
174
    	username = session.getSubject().getValue();
175
    	if (session.getSubjectList() != null) {
176
    		List<Group> groupList = session.getSubjectList().getGroupList();
177
    		if (groupList != null) {
178
    			groupnames = new String[groupList.size()];
179
    			for (int i = 0; i > groupList.size(); i++ ) {
180
    				groupnames[i] = groupList.get(i).getGroupName();
181
    			}
182
    		}
183
    	}
178 184
    }
179
    IdentifierManager im = IdentifierManager.getInstance();
180 185
    
181
    // put the group names into a string array
182
    if( session != null ) {
183
      for ( int i = 0; i > groupList.size(); i++ ) {
184
        groups[i] = groupList.get(i).getGroupName();
185
        
186
      }
187
    }
188

  
189
    // be sure the user is authenticated for delete()
190
    if (subject.getValue() == null || 
191
        subject.getValue().toLowerCase().equals("public") ) {
192
      throw new NotAuthorized("1320", "The provided identity does not have " +
193
        "permission to DELETE objects on the Member Node.");
194
      
195
    }
196
    
197 186
    // do we have a valid pid?
198 187
    if ( pid == null || pid.getValue().trim().equals("") ) {
199 188
      throw new InvalidRequest("1322", "The provided identifier was invalid.");
200

  
201 189
    }
202 190

  
203 191
    // check for the existing identifier
204 192
    try {
205
      localId = im.getLocalId(pid.getValue());
193
      localId = IdentifierManager.getInstance().getLocalId(pid.getValue());
206 194
    
207 195
    } catch (McdbDocNotFoundException e) {
208 196
      throw new InvalidRequest("1322", "The object with the provided " +
......
216 204
    if ( allowed ) {
217 205
      try {
218 206
        // delete the document
219
        DocumentImpl.delete(localId, subject.getValue(), groups, null);
220
        EventLog.getInstance().log(metacatUrl, subject.getValue(), localId, "delete");
207
        DocumentImpl.delete(localId, username, groupnames, null);
208
        EventLog.getInstance().log(metacatUrl, username, localId, Event.DELETE.toString());
221 209

  
222 210
      } catch (McdbDocNotFoundException e) {
223 211
        throw new InvalidRequest("1322", "The provided identifier was invalid.");
......
280 268
    String localId = null;
281 269
    boolean allowed = false;
282 270
    boolean isScienceMetadata = false;
283
    List<Group> groupList = new ArrayList<Group>();
284
    String[] groups = new String[0];
285 271
    Subject subject = session.getSubject();
286
    if ( session.getSubjectList() != null ) {
287
      groupList = session.getSubjectList().getGroupList();
288
      groups = new String[groupList.size()];
289
    	
290
    }
291
    IdentifierManager im = IdentifierManager.getInstance();
292

  
293
    // put the group names into a string array
294
    if( session != null ) {
295
      for ( int i = 0; i > groupList.size(); i++ ) {
296
        groups[i] = groupList.get(i).getGroupName();
297
        
298
      }
299
    }
300

  
301
    // be sure the user is authenticated for update()
302
    if (subject.getValue() == null || 
303
        subject.getValue().toLowerCase().equals("public") ) {
304
      throw new NotAuthorized("1200", "The provided identity does not have " +
305
        "permission to UPDATE objects on the Member Node.");
306
      
307
    }
308

  
272
    
309 273
    // do we have a valid pid?
310 274
    if ( pid == null || pid.getValue().trim().equals("") ) {
311 275
      throw new InvalidRequest("1202", "The provided identifier was invalid.");
......
314 278

  
315 279
    // check for the existing identifier
316 280
    try {
317
      localId = im.getLocalId(pid.getValue());
281
      localId = IdentifierManager.getInstance().getLocalId(pid.getValue());
318 282

  
319 283
    } catch (McdbDocNotFoundException e) {
320 284
      throw new InvalidRequest("1202", "The object with the provided " +
......
358 322
          localId = insertOrUpdateDocument(objectAsXML, newPid, session, "update");
359 323
          // register the newPid and the generated localId
360 324
          if ( newPid != null ) {
361
            im.createMapping(newPid.getValue(), localId);
325
        	  IdentifierManager.getInstance().createMapping(newPid.getValue(), localId);
362 326
            
363 327
          }
364 328
          
......
376 340
        localId = insertDataObject(object, newPid, session);
377 341
        // register the newPid and the generated localId
378 342
        if ( newPid != null ) {
379
          im.createMapping(newPid.getValue(), localId);
343
        	IdentifierManager.getInstance().createMapping(newPid.getValue(), localId);
380 344
          
381 345
        }
382 346
       

Also available in: Unified diff