Search in sources :

Example 1 with SRMInternalErrorException

use of org.dcache.srm.SRMInternalErrorException in project dcache by dCache.

the class SrmHandler method handleRequest.

public Object handleRequest(String requestName, Object request) throws RemoteException {
    long startTimeStamp = System.currentTimeMillis();
    // requestName values all start "srm".  This is redundant, so may
    // be removed when creating the session id.  The initial character is
    // converted to lowercase, so "srmPrepareToPut" becomes "prepareToPut".
    String session = "srm2:" + Character.toLowerCase(requestName.charAt(3)) + requestName.substring(4);
    try (JDC ignored = JDC.createSession(session)) {
        for (RequestLogger logger : loggers) {
            logger.request(requestName, request);
        }
        Subject user = Subject.getSubject(AccessController.getContext());
        Object response;
        if (requestName.equals("srmPing")) {
            // Ping is special as it isn't authenticated and unable to return a failure
            response = new SrmPingResponse("v2.2", pingExtraInfo);
        } else {
            try {
                response = dispatch(user, requestName, request);
            } catch (SRMInternalErrorException e) {
                LOGGER.error(e.getMessage());
                response = getFailedResponse(requestName, e.getStatusCode(), "Authentication failed (server log contains additional information).");
            } catch (SRMAuthorizationException e) {
                LOGGER.info(e.getMessage());
                response = getFailedResponse(requestName, e.getStatusCode(), "Permission denied.");
            } catch (SRMAuthenticationException e) {
                LOGGER.warn(e.getMessage());
                response = getFailedResponse(requestName, e.getStatusCode(), "Authentication failed (server log contains additional information).");
            } catch (SRMException e) {
                response = getFailedResponse(requestName, e.getStatusCode(), e.getMessage());
            } catch (PermissionDeniedCacheException e) {
                response = getFailedResponse(requestName, TStatusCode.SRM_AUTHORIZATION_FAILURE, e.getMessage());
            } catch (CacheException e) {
                response = getFailedResponse(requestName, TStatusCode.SRM_INTERNAL_ERROR, e.getMessage());
            } catch (InterruptedException e) {
                response = getFailedResponse(requestName, TStatusCode.SRM_FATAL_INTERNAL_ERROR, "Server shutdown.");
            } catch (NoRouteToCellException e) {
                LOGGER.error(e.getMessage());
                response = getFailedResponse(requestName, TStatusCode.SRM_INTERNAL_ERROR, "SRM backend serving this request is currently offline.");
            }
        }
        long time = System.currentTimeMillis() - startTimeStamp;
        for (RequestLogger logger : loggers) {
            logger.response(requestName, request, response, user, time);
        }
        return response;
    }
}
Also used : SRMAuthorizationException(org.dcache.srm.SRMAuthorizationException) CacheException(diskCacheV111.util.CacheException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) JDC(org.dcache.srm.util.JDC) ArrayOfString(org.dcache.srm.v2_2.ArrayOfString) SrmPingResponse(org.dcache.srm.v2_2.SrmPingResponse) Subject(javax.security.auth.Subject) SRMInternalErrorException(org.dcache.srm.SRMInternalErrorException) SRMAuthenticationException(org.dcache.srm.SRMAuthenticationException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) SRMException(org.dcache.srm.SRMException) NoRouteToCellException(dmg.cells.nucleus.NoRouteToCellException)

Example 2 with SRMInternalErrorException

use of org.dcache.srm.SRMInternalErrorException in project dcache by dCache.

the class SrmService method messageArrived.

public SrmResponse messageArrived(SrmRequest request) throws SRMException {
    try {
        CertPath certPath = getFirst(request.getSubject().getPublicCredentials(CertPath.class), null);
        LoginReply login = new LoginReply(request.getSubject(), request.getLoginAttributes());
        SRMUser user = userManager.persist(certPath, login);
        String requestName = request.getRequestName();
        Class<?> requestClass = request.getRequest().getClass();
        String capitalizedRequestName = Character.toUpperCase(requestName.charAt(0)) + requestName.substring(1);
        LOGGER.debug("About to call {} handler", requestName);
        Constructor<?> handlerConstructor;
        Object handler;
        Method handleGetResponseMethod;
        try {
            Class<?> handlerClass = Class.forName("org.dcache.srm.handler." + capitalizedRequestName);
            handlerConstructor = handlerClass.getConstructor(SRMUser.class, requestClass, AbstractStorageElement.class, SRM.class, String.class);
            handler = handlerConstructor.newInstance(user, request.getRequest(), storage, srm, request.getRemoteHost());
            if (handler instanceof CredentialAwareHandler) {
                CredentialAwareHandler credentialAware = (CredentialAwareHandler) handler;
                RequestCredential requestCredential = saveRequestCredential(request.getSubject(), request.getCredential());
                credentialAware.setCredential(requestCredential);
            }
            handleGetResponseMethod = handlerClass.getMethod("getResponse");
        } catch (ClassNotFoundException e) {
            if (LOGGER.isDebugEnabled()) {
                LOGGER.info("handler discovery and dynamic loading failed", e);
            } else {
                LOGGER.info("handler discovery and dynamic loading failed");
            }
            throw new SRMNotSupportedException(requestName + " is unsupported");
        }
        Object result = handleGetResponseMethod.invoke(handler);
        return new SrmResponse(id, result);
    } catch (CertificateEncodingException | KeyStoreException e) {
        throw new SRMInternalErrorException("Failed to process certificate chain.", e);
    } catch (InvocationTargetException | NoSuchMethodException | InstantiationException | IllegalAccessException | RuntimeException e) {
        LOGGER.error("Please report this failure to support@dcache.org", e);
        throw new SRMInternalErrorException("Internal error (server log contains additional information)");
    }
}
Also used : SRMUser(org.dcache.srm.SRMUser) SRMNotSupportedException(org.dcache.srm.SRMNotSupportedException) RequestCredential(org.dcache.srm.request.RequestCredential) LoginReply(org.dcache.auth.LoginReply) SRM(org.dcache.srm.SRM) SRMInternalErrorException(org.dcache.srm.SRMInternalErrorException) CertPath(java.security.cert.CertPath) SrmResponse(org.dcache.srm.SrmResponse) AbstractStorageElement(org.dcache.srm.AbstractStorageElement) CredentialAwareHandler(org.dcache.srm.handler.CredentialAwareHandler) CertificateEncodingException(java.security.cert.CertificateEncodingException) Method(java.lang.reflect.Method) KeyStoreException(java.security.KeyStoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 3 with SRMInternalErrorException

use of org.dcache.srm.SRMInternalErrorException in project dcache by dCache.

the class PinCompanion method fail.

private void fail(int rc, String error) {
    switch(rc) {
        case FILE_NOT_FOUND:
            setException(new SRMInvalidPathException("No such file."));
            break;
        case FILE_NOT_IN_REPOSITORY:
            _log.warn("Pinning failed for {} ({})", _path, error);
            setException(new SRMFileUnvailableException(error));
            break;
        case PERMISSION_DENIED:
            _log.warn("Pinning failed for {} ({})", _path, error);
            setException(new SRMAuthorizationException(error));
            break;
        case TIMEOUT:
            _log.info("Pinning failed: {}", error);
            setException(new SRMInternalErrorException("Pin operation timed out"));
            break;
        default:
            _log.error("Pinning failed for {} [rc={},msg={}].", _path, rc, error);
            String reason = String.format("Failed to pin file [rc=%d,msg=%s].", rc, error);
            setException(new SRMException(reason));
            break;
    }
    _state = new FailedState();
}
Also used : SRMInternalErrorException(org.dcache.srm.SRMInternalErrorException) SRMAuthorizationException(org.dcache.srm.SRMAuthorizationException) SRMException(org.dcache.srm.SRMException) SRMFileUnvailableException(org.dcache.srm.SRMFileUnvailableException) SRMInvalidPathException(org.dcache.srm.SRMInvalidPathException)

Example 4 with SRMInternalErrorException

use of org.dcache.srm.SRMInternalErrorException in project dcache by dCache.

the class Storage method putDone.

@Override
public void putDone(SRMUser user, String localTransferPath, URI surl, boolean overwrite) throws SRMException {
    try {
        Subject subject = asDcacheUser(user).getSubject();
        Restriction restriction = asDcacheUser(user).getRestriction();
        FsPath fullPath = getPath(surl);
        checkNonBrokenUpload(localTransferPath);
        EnumSet<CreateOption> options = EnumSet.noneOf(CreateOption.class);
        if (overwrite) {
            options.add(CreateOption.OVERWRITE_EXISTING);
        }
        PnfsCommitUpload msg = new PnfsCommitUpload(subject, restriction, FsPath.create(localTransferPath), fullPath, options, EnumSet.of(PNFSID, SIZE, STORAGEINFO));
        msg = _pnfsStub.sendAndWait(msg);
        DoorRequestInfoMessage infoMsg = new DoorRequestInfoMessage(getCellAddress());
        infoMsg.setSubject(subject);
        infoMsg.setBillingPath(fullPath.toString());
        infoMsg.setTransferPath(localTransferPath);
        infoMsg.setTransaction(CDC.getSession());
        infoMsg.setPnfsId(msg.getFileAttributes().getPnfsId());
        infoMsg.setResult(0, "");
        infoMsg.setFileSize(msg.getFileAttributes().getSizeIfPresent().orElse(0L));
        infoMsg.setStorageInfo(msg.getFileAttributes().getStorageInfo());
        Origin origin = Subjects.getOrigin(subject);
        if (origin != null) {
            infoMsg.setClient(origin.getAddress().getHostAddress());
        }
        _billingStub.notify(infoMsg);
    } catch (FileNotFoundCacheException e) {
        throw new SRMInvalidPathException(e.getMessage(), e);
    } catch (FileIsNewCacheException | FileCorruptedCacheException e) {
        throw new SRMException(e.getMessage(), e);
    } catch (PermissionDeniedCacheException e) {
        throw new SRMAuthorizationException("Permission denied.", e);
    } catch (FileExistsCacheException e) {
        throw new SRMDuplicationException(surl + " exists.", e);
    } catch (CacheException e) {
        throw new SRMInternalErrorException(e.getMessage(), e);
    } catch (InterruptedException e) {
        throw new SRMInternalErrorException("Operation interrupted", e);
    } catch (NoRouteToCellException e) {
        throw new SRMInternalErrorException("Internal communication failure", e);
    }
}
Also used : DoorRequestInfoMessage(diskCacheV111.vehicles.DoorRequestInfoMessage) Origin(org.dcache.auth.Origin) SRMAuthorizationException(org.dcache.srm.SRMAuthorizationException) FileIsNewCacheException(diskCacheV111.util.FileIsNewCacheException) FileExistsCacheException(diskCacheV111.util.FileExistsCacheException) NotDirCacheException(diskCacheV111.util.NotDirCacheException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException) CacheException(diskCacheV111.util.CacheException) FileCorruptedCacheException(diskCacheV111.util.FileCorruptedCacheException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) SRMInvalidPathException(org.dcache.srm.SRMInvalidPathException) Subject(javax.security.auth.Subject) SRMInternalErrorException(org.dcache.srm.SRMInternalErrorException) Restriction(org.dcache.auth.attributes.Restriction) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) SRMException(org.dcache.srm.SRMException) NoRouteToCellException(dmg.cells.nucleus.NoRouteToCellException) FileCorruptedCacheException(diskCacheV111.util.FileCorruptedCacheException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) FileIsNewCacheException(diskCacheV111.util.FileIsNewCacheException) CreateOption(org.dcache.namespace.CreateOption) PnfsCommitUpload(diskCacheV111.vehicles.PnfsCommitUpload) FileExistsCacheException(diskCacheV111.util.FileExistsCacheException) SRMDuplicationException(org.dcache.srm.SRMDuplicationException) FsPath(diskCacheV111.util.FsPath)

Example 5 with SRMInternalErrorException

use of org.dcache.srm.SRMInternalErrorException in project dcache by dCache.

the class Storage method moveEntry.

@Override
public void moveEntry(SRMUser abstractUser, URI from, URI to) throws SRMException {
    DcacheUser user = asDcacheUser(abstractUser);
    PnfsHandler handler = new PnfsHandler(_pnfs, user.getSubject(), user.getRestriction());
    FsPath fromPath = getPath(from);
    FsPath toPath = getPath(to);
    try {
        try {
            FileAttributes attr = handler.getFileAttributes(toPath.toString(), EnumSet.of(TYPE));
            /* We now know the destination exists. In case the
                 * source and destination names are identical, we
                 * silently ignore the request.
                 */
            if (fromPath.equals(toPath)) {
                return;
            }
            if (attr.getFileType() != FileType.DIR) {
                throw new SRMDuplicationException("Destination exists");
            }
            toPath = toPath.child(fromPath.name());
        } catch (FileNotFoundCacheException e) {
        /* Destination name does not exist; not a problem.
                 */
        }
        handler.renameEntry(fromPath.toString(), toPath.toString(), false);
    } catch (FileNotFoundCacheException e) {
        throw new SRMInvalidPathException("No such file or directory", e);
    } catch (FileExistsCacheException e) {
        throw new SRMDuplicationException("Destination exists", e);
    } catch (NotDirCacheException e) {
        /* The parent of the target name did not exist or was not
             * a directory.
             */
        FsPath parent = toPath.parent();
        throw new SRMInvalidPathException("No such directory: " + parent, e);
    } catch (PermissionDeniedCacheException e) {
        throw new SRMAuthorizationException("Permission denied");
    } catch (TimeoutCacheException e) {
        _log.error("Failed to rename {} due to timeout", fromPath);
        throw new SRMInternalErrorException("Internal name space timeout");
    } catch (CacheException e) {
        _log.error("Failed to rename {}: {}", fromPath, e.getMessage());
        throw new SRMException(String.format("Rename failed [rc=%d,msg=%s]", e.getRc(), e.getMessage()));
    }
}
Also used : SRMAuthorizationException(org.dcache.srm.SRMAuthorizationException) FileIsNewCacheException(diskCacheV111.util.FileIsNewCacheException) FileExistsCacheException(diskCacheV111.util.FileExistsCacheException) NotDirCacheException(diskCacheV111.util.NotDirCacheException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException) CacheException(diskCacheV111.util.CacheException) FileCorruptedCacheException(diskCacheV111.util.FileCorruptedCacheException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) SRMInvalidPathException(org.dcache.srm.SRMInvalidPathException) PnfsHandler(diskCacheV111.util.PnfsHandler) SRMInternalErrorException(org.dcache.srm.SRMInternalErrorException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) SRMException(org.dcache.srm.SRMException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) FileAttributes(org.dcache.vehicles.FileAttributes) NotDirCacheException(diskCacheV111.util.NotDirCacheException) SRMDuplicationException(org.dcache.srm.SRMDuplicationException) FileExistsCacheException(diskCacheV111.util.FileExistsCacheException) FsPath(diskCacheV111.util.FsPath) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException)

Aggregations

SRMInternalErrorException (org.dcache.srm.SRMInternalErrorException)46 SRMException (org.dcache.srm.SRMException)34 SRMAuthorizationException (org.dcache.srm.SRMAuthorizationException)26 SRMInvalidPathException (org.dcache.srm.SRMInvalidPathException)21 CacheException (diskCacheV111.util.CacheException)20 PermissionDeniedCacheException (diskCacheV111.util.PermissionDeniedCacheException)19 TimeoutCacheException (diskCacheV111.util.TimeoutCacheException)18 FileCorruptedCacheException (diskCacheV111.util.FileCorruptedCacheException)17 FileExistsCacheException (diskCacheV111.util.FileExistsCacheException)17 FileIsNewCacheException (diskCacheV111.util.FileIsNewCacheException)17 FileNotFoundCacheException (diskCacheV111.util.FileNotFoundCacheException)17 NotDirCacheException (diskCacheV111.util.NotDirCacheException)17 FsPath (diskCacheV111.util.FsPath)13 TReturnStatus (org.dcache.srm.v2_2.TReturnStatus)13 NoRouteToCellException (dmg.cells.nucleus.NoRouteToCellException)10 Subject (javax.security.auth.Subject)10 URI (java.net.URI)9 PnfsHandler (diskCacheV111.util.PnfsHandler)8 SRMInvalidRequestException (org.dcache.srm.SRMInvalidRequestException)7 SRMDuplicationException (org.dcache.srm.SRMDuplicationException)6