Search in sources :

Example 21 with NotAuthorizedException

use of io.milton.http.exceptions.NotAuthorizedException in project lobcder by skoulouzis.

the class PropPatchHandler method processExistingResource.

@Override
public void processExistingResource(HttpManager manager, Request request, Response response, Resource resource) throws NotAuthorizedException, BadRequestException, ConflictException {
    // todo: check if token header
    try {
        PropFindResponse resp = doPropPatch(request, resource);
        manager.getEventManager().fireEvent(new PropPatchEvent(resource, resp));
        List<PropFindResponse> responses = new ArrayList<PropFindResponse>();
        responses.add(resp);
        responseHandler.respondPropFind(responses, response, request, resource);
    } catch (NotAuthorizedException e) {
        responseHandler.respondUnauthorised(resource, response, request);
    } catch (WritingException ex) {
        throw new RuntimeException(ex);
    } catch (ReadingException ex) {
        throw new RuntimeException(ex);
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    }
}
Also used : ReadingException(io.milton.common.ReadingException) ArrayList(java.util.ArrayList) NotAuthorizedException(io.milton.http.exceptions.NotAuthorizedException) IOException(java.io.IOException) WritingException(io.milton.common.WritingException) PropPatchEvent(io.milton.event.PropPatchEvent)

Example 22 with NotAuthorizedException

use of io.milton.http.exceptions.NotAuthorizedException in project lobcder by skoulouzis.

the class AnnoPrincipalResource method getCalendarHomeSet.

@Override
public HrefList getCalendarHomeSet() {
    try {
        HrefList list = new HrefList();
        for (Resource r : getChildren()) {
            if (r instanceof AnnoCollectionResource) {
                AnnoCollectionResource col = (AnnoCollectionResource) r;
                if (annoFactory.calendarsAnnotationHandler.hasCalendars(col.getSource())) {
                    list.add(col.getHref());
                }
            }
        }
        if (list.isEmpty()) {
            ResourceList topDirs = getChildren().getDirs();
            if (topDirs.isEmpty()) {
                log.warn("Could not find any calendar home directories for user type: " + getSource().getClass() + ". In fact there are no child diretories at all!");
            } else {
                log.warn("Could not find any calendar home directories for user type: " + getSource().getClass() + " You should have a @" + Calendars.class + " annotation on one of the following methods");
                for (Resource r : topDirs) {
                    if (r instanceof AnnoCollectionResource) {
                        AnnoCollectionResource col = (AnnoCollectionResource) r;
                        List<ControllerMethod> candMethods = annoFactory.calendarsAnnotationHandler.getMethods(col.getSource().getClass());
                        if (candMethods.isEmpty()) {
                            log.info("	- inspecting: " + col.getName() + " for source: " + col.getSource().getClass() + " - has NO child methods");
                        } else {
                            log.info("	- inspecting: " + col.getName() + " for source: " + col.getSource().getClass());
                            for (ControllerMethod cm : candMethods) {
                                log.warn("	- candidate method: " + cm.controller.getClass() + "::" + cm.method.getName());
                            }
                        }
                    } else {
                        log.warn("	- found a directory which is not a AnnoCollectionResource: " + r.getClass() + " which cannot be inspected");
                    }
                }
            }
        }
        return list;
    } catch (NotAuthorizedException e) {
        throw new RuntimeException(e);
    } catch (BadRequestException e) {
        throw new RuntimeException(e);
    }
}
Also used : Resource(io.milton.resource.Resource) BadRequestException(io.milton.http.exceptions.BadRequestException) NotAuthorizedException(io.milton.http.exceptions.NotAuthorizedException) HrefList(io.milton.http.values.HrefList)

Example 23 with NotAuthorizedException

use of io.milton.http.exceptions.NotAuthorizedException in project lobcder by skoulouzis.

the class MiltonFtpFile method isWritable.

/**
 * Check file write permission.
 */
@Override
public boolean isWritable() {
    try {
        log.debug("isWritable: " + getAbsolutePath());
        if (path.isRoot())
            return false;
        Auth auth = new Auth(user.getName(), user.getUser());
        FtpRequest request = new FtpRequest(Method.DELETE, auth, path.toString());
        if (r != null) {
            if (r instanceof ReplaceableResource) {
                return r.authorise(request, Method.PUT, auth);
            }
        }
        if (getParent() instanceof PutableResource) {
            return getParent().authorise(request, Method.PUT, auth);
        } else {
            return false;
        }
    } catch (NotAuthorizedException ex) {
        throw new RuntimeException(ex);
    } catch (BadRequestException ex) {
        throw new RuntimeException(ex);
    }
}
Also used : Auth(io.milton.http.Auth) BadRequestException(io.milton.http.exceptions.BadRequestException) NotAuthorizedException(io.milton.http.exceptions.NotAuthorizedException) ReplaceableResource(io.milton.resource.ReplaceableResource)

Example 24 with NotAuthorizedException

use of io.milton.http.exceptions.NotAuthorizedException in project lobcder by skoulouzis.

the class MiltonFtpFile method createOutputStream.

@Override
public OutputStream createOutputStream(long offset) throws IOException {
    log.debug("createOutputStream: " + offset);
    final BufferingOutputStream out = new BufferingOutputStream(50000);
    if (r instanceof ReplaceableResource) {
        log.debug("resource is replaceable");
        final ReplaceableResource rr = (ReplaceableResource) r;
        Runnable runnable = new Runnable() {

            @Override
            public void run() {
                try {
                    rr.replaceContent(out.getInputStream(), out.getSize());
                } catch (BadRequestException ex) {
                    throw new RuntimeException(ex);
                } catch (ConflictException ex) {
                    throw new RuntimeException(ex);
                } catch (NotAuthorizedException ex) {
                    throw new RuntimeException(ex);
                }
            }
        };
        out.setOnClose(runnable);
        return out;
    } else {
        CollectionResource col;
        try {
            col = getParent();
        } catch (NotAuthorizedException ex) {
            throw new RuntimeException(ex);
        } catch (BadRequestException ex) {
            throw new RuntimeException(ex);
        }
        if (col == null) {
            throw new IOException("parent not found");
        } else if (col instanceof PutableResource) {
            final PutableResource putableResource = (PutableResource) col;
            final String newName = path.getName();
            Runnable runnable = new Runnable() {

                @Override
                public void run() {
                    try {
                        putableResource.createNew(newName, out.getInputStream(), out.getSize(), null);
                    } catch (BadRequestException ex) {
                        throw new RuntimeException(ex);
                    } catch (NotAuthorizedException ex) {
                        throw new RuntimeException(ex);
                    } catch (ConflictException ex) {
                        throw new RuntimeException(ex);
                    } catch (IOException ex) {
                        throw new RuntimeException(ex);
                    }
                }
            };
            out.setOnClose(runnable);
            return out;
        } else {
            throw new IOException("folder doesnt support PUT, and the resource is not replaceable");
        }
    }
}
Also used : ConflictException(io.milton.http.exceptions.ConflictException) BufferingOutputStream(io.milton.common.BufferingOutputStream) BadRequestException(io.milton.http.exceptions.BadRequestException) NotAuthorizedException(io.milton.http.exceptions.NotAuthorizedException) IOException(java.io.IOException) ReplaceableResource(io.milton.resource.ReplaceableResource)

Example 25 with NotAuthorizedException

use of io.milton.http.exceptions.NotAuthorizedException in project lobcder by skoulouzis.

the class MiltonFtpFile method createInputStream.

@Override
public InputStream createInputStream(long offset) throws IOException {
    if (r instanceof GetableResource) {
        GetableResource gr = (GetableResource) r;
        String ct = gr.getContentType(null);
        BufferingOutputStream out = new BufferingOutputStream(50000);
        try {
            gr.sendContent(out, null, null, ct);
            out.close();
            return out.getInputStream();
        } catch (NotFoundException ex) {
            log.warn("Not found exception", ex);
            return null;
        } catch (BadRequestException ex) {
            log.warn("bad request", ex);
            return null;
        } catch (NotAuthorizedException ex) {
            log.warn("not authorising", ex);
            return null;
        }
    } else {
        return null;
    }
}
Also used : BufferingOutputStream(io.milton.common.BufferingOutputStream) NotFoundException(io.milton.http.exceptions.NotFoundException) BadRequestException(io.milton.http.exceptions.BadRequestException) NotAuthorizedException(io.milton.http.exceptions.NotAuthorizedException)

Aggregations

NotAuthorizedException (io.milton.http.exceptions.NotAuthorizedException)40 BadRequestException (io.milton.http.exceptions.BadRequestException)29 IOException (java.io.IOException)12 Resource (io.milton.resource.Resource)10 URISyntaxException (java.net.URISyntaxException)9 Connection (java.sql.Connection)9 SQLException (java.sql.SQLException)9 ConflictException (io.milton.http.exceptions.ConflictException)7 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)7 PreConditionFailedException (io.milton.http.exceptions.PreConditionFailedException)6 UnsupportedEncodingException (java.io.UnsupportedEncodingException)6 Permissions (nl.uva.cs.lobcder.auth.Permissions)6 NotFoundException (io.milton.http.exceptions.NotFoundException)5 CollectionResource (io.milton.resource.CollectionResource)5 ReplaceableResource (io.milton.resource.ReplaceableResource)5 QName (javax.xml.namespace.QName)5 Path (io.milton.common.Path)4 LockedException (io.milton.http.exceptions.LockedException)4 ValueAndType (io.milton.http.values.ValueAndType)4 LogicalData (nl.uva.cs.lobcder.resources.LogicalData)4