Project

General

Profile

« Previous | Next » 

Revision 7075

Added by Chris Jones over 12 years ago

Only allow CNs to call MN.synchronizationFailed() by calling isAdminAuthorized(). The pid must also be valid.

View differences:

src/edu/ucsb/nceas/metacat/dataone/MNodeService.java
970 970
        throws NotImplemented, ServiceFailure, NotAuthorized {
971 971

  
972 972
        String localId;
973
        Identifier pid;
974
        if ( syncFailed.getPid() != null ) {
975
            pid = new Identifier();
976
            pid.setValue(syncFailed.getPid());
977
            boolean allowed;
978
            
979
            //are we allowed? only CNs
980
            try {
981
                allowed = isAdminAuthorized(session, pid, Permission.READ);
982
                if ( !allowed ){
983
                    throw new NotAuthorized("2162", 
984
                            "Not allowed to call synchronizationFailed() on this node.");
985
                }
986
            } catch (InvalidToken e) {
987
                throw new NotAuthorized("2162", 
988
                        "Not allowed to call synchronizationFailed() on this node.");
973 989

  
990
            } catch (NotFound e) {
991
                throw new ServiceFailure("2161", 
992
                        "The identifier specified by " + pid.getValue() + 
993
                        " was not found on this node.");
994

  
995
            }
996
            
997
        } else {
998
            throw new ServiceFailure("2161", "The identifier cannot be null.");
999

  
1000
        }
1001
        
974 1002
        try {
975
            localId = IdentifierManager.getInstance().getLocalId(syncFailed.getPid());
1003
            localId = IdentifierManager.getInstance().getLocalId(pid.getValue());
976 1004
        } catch (McdbDocNotFoundException e) {
977
            throw new ServiceFailure("2161", "The identifier specified by " + syncFailed.getPid() + " was not found on this node.");
1005
            throw new ServiceFailure("2161", "The identifier specified by " + 
1006
                    syncFailed.getPid() + " was not found on this node.");
978 1007

  
979 1008
        }
980 1009
        // TODO: update the CN URL below when the CNRead.SynchronizationFailed
981 1010
        // method is changed to include the URL as a parameter
982
        logMetacat.debug("Synchronization for the object identified by " + syncFailed.getPid() + " failed from " + syncFailed.getNodeId()
983
                + " Logging the event to the Metacat EventLog as a 'syncFailed' event.");
1011
        logMetacat.debug("Synchronization for the object identified by " + 
1012
                pid.getValue() + " failed from " + syncFailed.getNodeId() + 
1013
                " Logging the event to the Metacat EventLog as a 'syncFailed' event.");
984 1014
        // TODO: use the event type enum when the SYNCHRONIZATION_FAILED event is added
985 1015
        String principal = Constants.SUBJECT_PUBLIC;
986 1016
        if (session != null && session.getSubject() != null) {
......
989 1019
        try {
990 1020
          EventLog.getInstance().log(request.getRemoteAddr(), request.getHeader("User-Agent"), principal, localId, "synchronization_failed");
991 1021
        } catch (Exception e) {
992
            throw new ServiceFailure("2161", "Could not log the error for: " + syncFailed.getPid());
1022
            throw new ServiceFailure("2161", "Could not log the error for: " + pid.getValue());
993 1023
        }
994 1024
        //EventLog.getInstance().log("CN URL WILL GO HERE", 
995 1025
        //  session.getSubject().getValue(), localId, Event.SYNCHRONIZATION_FAILED);

Also available in: Unified diff