1 package com.bradmcevoy.http;
2
3 import java.util.Date;
4
5
6 /**
7 *
8 * Implementations should implement compareTo as an alphabetic comparison
9 * on the name property
10 *
11 * @author Alienware1
12 */
13 public interface Resource {
14
15 /**
16 * Returning a null value is allowed, and disables the ETag field.
17 * <P/>
18 * If a unique id is returned it will be combined with the modified date (if available)
19 * to produce an ETag which identifies this version of this resource.
20 *
21 * @return - a string which uniquely identifies this resource. This will be
22 * used in the ETag header field, and affects caching of resources.
23 *
24 */
25 String getUniqueId();
26
27 /**
28 * Note that this name MUST be consistent with URL resolution in your ResourceFactory
29 * <P/>
30 * If they aren't consistent Milton will generate a different href in PropFind
31 * responses then what clients have request and this will cause either an
32 * error or no resources to be displayed
33 *
34 * @return - the name of this resource. Ie just the local name, within its folder
35 */
36 String getName();
37
38
39 /**
40 * Check the given credentials, and return a relevant object if accepted.
41 * <P/>
42 * Returning null indicates credentials were not accepted
43 *
44 * @param user - the user name provided by the user's agent
45 * @param password - the password provided by the user's agent
46 * @return - if credentials are accepted, some object to attach to the Auth object.
47 * otherwise null
48 */
49 Object authenticate(String user, String password);
50
51 /** Return true if the current user is permitted to access this resource using
52 * the specified method.
53 * <P/>
54 * Note that the current user may be determined by the Auth associated with
55 * the request, or by a separate, application specific, login mechanism such
56 * as a session variable or cookie based system. This method should correctly
57 * interpret all such mechanisms
58 * <P/>
59 * The auth given as a parameter will be null if authentication failed. The
60 * auth associated with the request will still exist
61 */
62 boolean authorise(Request request, Request.Method method, Auth auth);
63
64 /** Return the security realm for this resource. Just any string identifier.
65 * <P/>
66 * This will be used to construct authorization challenges and will be used
67 * on Digest authentication to construct the expected response.
68 */
69 String getRealm();
70
71 /** The date and time that this resource, or any part of this resource, was last
72 * modified. For dynamic rendered resources this should consider everything
73 * which will influence its output.
74 *<P/>
75 * Resources for which no such date can be calculated should return null.
76 *<P/>
77 * This field, if not null, is used to reply to conditional GETs (ie GET with
78 * if-modified-since). If the modified-since argument is later then the modified
79 * date then we return a 304 - Not Modified.
80 *<P/>
81 * Although nulls are explicitly allowed by milton, certain client applications
82 * might require modified dates for file browsing. For example, the command line
83 * client on Vista doesn't work properly if this is null.
84 *
85 */
86 Date getModifiedDate();
87
88
89
90
91 /** Determine if a redirect is required for this request, and if so return
92 * the URL to redirect to. May be absolute or relative.
93 *<P/>
94 * Called after authorization check but before any method specific processing
95 *<P/>
96 * Return null for no redirect
97 */
98 abstract String checkRedirect(Request request);
99
100
101 }