Newer
Older
Patrick Dowler
committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package org.astrogrid.security.delegation;
/**
* A minimal parser for the path of a URI in the delgations service.
* The constructor must be fed the "path info" string from the HTTP request:
* i.e. the part of the path following the servlet path (refer to the
* documentation for javax.http.HttpServletRequest for details).
*
* @author Guy Rixon
*/
public class DelegationUri {
private String[] pathElements;
public final static int UNKNOWN = 0;
public final static int LIST = 1;
public final static int IDENTITY = 2;
public final static int CSR = 3;
public final static int CERTIFICATE = 4;
/**
* Constructs a DelegationUri.
*/
public DelegationUri(String path) {
if (path == null) {
path = "/";
}
this.pathElements = path.split("/");
}
public boolean isValid() {
return (getResourceCode() != UNKNOWN);
}
public String getUser() {
return (pathElements.length > 1)? pathElements[1] : null;
}
public int getResourceCode() {
switch (this.pathElements.length) {
case 0:
case 1:
return LIST;
case 2:
return IDENTITY;
case 3:
if (this.pathElements[2].equals("CSR")) {
return CSR;
}
else if (this.pathElements[2].equals("certificate")) {
return CERTIFICATE;
}
else {
return UNKNOWN;
}
default:
return UNKNOWN;
}
}
}