Interface Resource

All Known Subinterfaces:
AccessControlledResource, AddressBookDirectoryResource, AddressBookResource, AddressResource, BufferingControlResource, CalDavPrincipal, CalendarCollection, CalendarResource, CardDavPrincipal, CollectionResource, CopyableResource, DeletableCollectionResource, DeletableResource, DigestResource, DirectoryGatewayCardDavPrincipal, DiscretePrincipal, DisplayNameResource, ExtMakeCalendarResource, FileResource, FolderResource, GetableResource, ICalResource, LdapContact, LockableResource, LockingCollectionResource, LockNullResource, MakeCalendarResource, MakeCollectionableResource, MoveableResource, MultiNamespaceCustomPropertyResource, OAuth2Resource, PostableResource, PropFindableResource, PutableResource, QuotaResource, RemovedResource, ReplaceableResource, ReportableResource, SyncCollectionResource

public interface Resource
Implementations should implement compareTo as an alphabetic comparison on the name property
  • Method Summary

    Modifier and Type
    Method
    Description
    authenticate(String user, String password)
    Check the given credentials, and return a relevant object if accepted.
    boolean
    authorise(Request request, Request.Method method, Auth auth)
    Return true if the current user is permitted to access this resource using the specified method.
    Determine if a redirect is required for this request, and if so return the URL to redirect to.
    The date and time that this resource, or any part of this resource, was last modified.
    Note that this name MUST be consistent with URL resolution in your ResourceFactory
    Return the security realm for this resource.
    Returning a null value is allowed, and disables the ETag field.
  • Method Details

    • getUniqueId

      String getUniqueId()
      Returning a null value is allowed, and disables the ETag field.

      If a unique id is returned it will be combined with the modified date (if available) to produce an ETag which identifies this version of this resource. Note that this behaviour can be changed by injecting an alternative EtagGenerator instance into the HttpManagerBuilder

      Returns:
      - a string which uniquely identifies this resource. This will be used in the ETag header field, and affects caching of resources.
    • getName

      String getName()
      Note that this name MUST be consistent with URL resolution in your ResourceFactory

      If they aren't consistent Milton will generate a different href in PropFind responses then what clients have request and this will cause either an error or no resources to be displayed

      Returns:
      - the name of this resource. Ie just the local name, within its folder
    • authenticate

      Object authenticate(String user, String password)
      Check the given credentials, and return a relevant object if accepted.

      Returning null indicates credentials were not accepted

      Parameters:
      user - - the user name provided by the user's agent
      password - - the password provided by the user's agent
      Returns:
      - if credentials are accepted, some object to attach to the Auth object. otherwise null
    • authorise

      boolean authorise(Request request, Request.Method method, Auth auth)
      Return true if the current user is permitted to access this resource using the specified method.

      Note that the current user may be determined by the Auth associated with the request, or by a separate, application specific, login mechanism such as a session variable or cookie based system. This method should correctly interpret all such mechanisms

      The auth given as a parameter will be null if authentication failed. The auth associated with the request will still exist

      Parameters:
      request -
      method -
      auth -
      Returns:
      - true to permit the request
    • getRealm

      String getRealm()
      Return the security realm for this resource. Just any string identifier.

      This will be used to construct authorization challenges and will be used on Digest authentication to construct the expected response.

      Returns:
      - the security realm, for HTTP authentication
    • getModifiedDate

      Date getModifiedDate()
      The date and time that this resource, or any part of this resource, was last modified. For dynamic rendered resources this should consider everything which will influence its output.

      Resources for which no such date can be calculated should return null.

      This field, if not null, is used to reply to conditional GETs (ie GET with if-modified-since). If the modified-since argument is later then the modified date then we return a 304 - Not Modified.

      Although nulls are explicitly allowed by milton, certain client applications might require modified dates for file browsing. For example, the command line client on Vista doesn't work properly if this is null.

      Returns:
      - null if not known, else the last date the resource was modified
    • checkRedirect

      String checkRedirect(Request request) throws io.milton.http.exceptions.NotAuthorizedException, io.milton.http.exceptions.BadRequestException
      Determine if a redirect is required for this request, and if so return the URL to redirect to. May be absolute or relative.

      Called after authorization check but before any method specific processing

      Return null for no redirect

      Parameters:
      request -
      Returns:
      - null for no redirect, else the path to redirect to
      Throws:
      io.milton.http.exceptions.NotAuthorizedException
      io.milton.http.exceptions.BadRequestException