1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.profiler.rules.impl;
18
19 import java.security.Principal;
20 import java.util.Iterator;
21
22 import javax.security.auth.Subject;
23
24 import org.apache.jetspeed.profiler.rules.RuleCriterion;
25 import org.apache.jetspeed.profiler.rules.RuleCriterionResolver;
26 import org.apache.jetspeed.request.RequestContext;
27 import org.apache.jetspeed.security.SecurityHelper;
28
29 /***
30 * Standard Jetspeed-1 style resolver for criterion.
31 * It first looks at the value in the request parameters.
32 * If it is null, it then falls back to the criterion record..
33 * If it is null it gives up and returns null allowing subclasses
34 * to continue processing.
35 *
36 * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
37 * @version $Id: StandardResolver.java 516448 2007-03-09 16:25:47Z ate $
38 */
39 public class StandardResolver implements RuleCriterionResolver
40 {
41 public static final String VALUE_DELIMITER = ",";
42 public static final String COMBO_DELIMITER = "-";
43
44
45
46
47 public String resolve(RequestContext context, RuleCriterion criterion)
48 {
49 String value = context.getRequestParameter(criterion.getName());
50 if (value == null)
51 {
52 value = criterion.getValue();
53 }
54 return value;
55 }
56
57
58
59
60 public boolean isControl(RuleCriterion criterion)
61 {
62 if (criterion.getName().equals(RuleCriterionResolver.PATH) ||
63 criterion.getName().equals(RuleCriterionResolver.PAGE))
64 {
65 return false;
66 }
67 return true;
68 }
69
70 public boolean isNavigation(RuleCriterion criterion)
71 {
72 return false;
73 }
74
75 protected String resolvePrincipals(RequestContext context, RuleCriterion criterion, Subject subject, Class classe)
76 {
77 StringBuffer result = new StringBuffer();
78 Iterator principals = SecurityHelper.getPrincipals(subject, classe).iterator();
79 int count = 0;
80 while (principals.hasNext())
81 {
82 Principal principal = (Principal)principals.next();
83 if (count > 0)
84 {
85 result.append(VALUE_DELIMITER);
86 }
87 result.append(principal.getName());
88 count++;
89 }
90 if (count == 0)
91 {
92 return null;
93 }
94 return result.toString();
95 }
96
97 protected String combinePrincipals(RequestContext context, RuleCriterion criterion, Subject subject, Class classe)
98 {
99 StringBuffer result = new StringBuffer();
100 Iterator principals = SecurityHelper.getPrincipals(subject, classe).iterator();
101 int count = 0;
102 while (principals.hasNext())
103 {
104 Principal principal = (Principal)principals.next();
105 if (count > 0)
106 {
107 result.append(COMBO_DELIMITER);
108 }
109 result.append(principal.getName());
110 count++;
111 }
112 if (count == 0)
113 {
114 return null;
115 }
116 return result.toString();
117 }
118
119 }