%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.jetspeed.profiler.rules.impl.StandardResolver |
|
|
1 | /* |
|
2 | * Licensed to the Apache Software Foundation (ASF) under one or more |
|
3 | * contributor license agreements. See the NOTICE file distributed with |
|
4 | * this work for additional information regarding copyright ownership. |
|
5 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
|
6 | * (the "License"); you may not use this file except in compliance with |
|
7 | * the License. You may obtain a copy of the License at |
|
8 | * |
|
9 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
10 | * |
|
11 | * Unless required by applicable law or agreed to in writing, software |
|
12 | * distributed under the License is distributed on an "AS IS" BASIS, |
|
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
14 | * See the License for the specific language governing permissions and |
|
15 | * limitations under the License. |
|
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 | 0 | public class StandardResolver implements RuleCriterionResolver |
40 | { |
|
41 | public static final String VALUE_DELIMITER = ","; |
|
42 | public static final String COMBO_DELIMITER = "-"; |
|
43 | ||
44 | /* (non-Javadoc) |
|
45 | * @see org.apache.jetspeed.profiler.rules.RuleCriterionResolver#resolve(org.apache.jetspeed.request.RequestContext, org.apache.jetspeed.profiler.rules.RuleCriterion) |
|
46 | */ |
|
47 | public String resolve(RequestContext context, RuleCriterion criterion) |
|
48 | { |
|
49 | 0 | String value = context.getRequestParameter(criterion.getName()); |
50 | 0 | if (value == null) |
51 | { |
|
52 | 0 | value = criterion.getValue(); |
53 | } |
|
54 | 0 | return value; |
55 | } |
|
56 | ||
57 | /* (non-Javadoc) |
|
58 | * @see org.apache.jetspeed.profiler.rules.RuleCriterionResolver#isControl() |
|
59 | */ |
|
60 | public boolean isControl(RuleCriterion criterion) |
|
61 | { |
|
62 | 0 | if (criterion.getName().equals(RuleCriterionResolver.PATH) || |
63 | criterion.getName().equals(RuleCriterionResolver.PAGE)) |
|
64 | { |
|
65 | 0 | return false; |
66 | } |
|
67 | 0 | return true; |
68 | } |
|
69 | ||
70 | public boolean isNavigation(RuleCriterion criterion) |
|
71 | { |
|
72 | 0 | return false; |
73 | } |
|
74 | ||
75 | protected String resolvePrincipals(RequestContext context, RuleCriterion criterion, Subject subject, Class classe) |
|
76 | { |
|
77 | 0 | StringBuffer result = new StringBuffer(); |
78 | 0 | Iterator principals = SecurityHelper.getPrincipals(subject, classe).iterator(); |
79 | 0 | int count = 0; |
80 | 0 | while (principals.hasNext()) |
81 | { |
|
82 | 0 | Principal principal = (Principal)principals.next(); |
83 | 0 | if (count > 0) |
84 | { |
|
85 | 0 | result.append(VALUE_DELIMITER); |
86 | } |
|
87 | 0 | result.append(principal.getName()); |
88 | 0 | count++; |
89 | 0 | } |
90 | 0 | if (count == 0) |
91 | { |
|
92 | 0 | return null; |
93 | } |
|
94 | 0 | return result.toString(); |
95 | } |
|
96 | ||
97 | protected String combinePrincipals(RequestContext context, RuleCriterion criterion, Subject subject, Class classe) |
|
98 | { |
|
99 | 0 | StringBuffer result = new StringBuffer(); |
100 | 0 | Iterator principals = SecurityHelper.getPrincipals(subject, classe).iterator(); |
101 | 0 | int count = 0; |
102 | 0 | while (principals.hasNext()) |
103 | { |
|
104 | 0 | Principal principal = (Principal)principals.next(); |
105 | 0 | if (count > 0) |
106 | { |
|
107 | 0 | result.append(COMBO_DELIMITER); |
108 | } |
|
109 | 0 | result.append(principal.getName()); |
110 | 0 | count++; |
111 | 0 | } |
112 | 0 | if (count == 0) |
113 | { |
|
114 | 0 | return null; |
115 | } |
|
116 | 0 | return result.toString(); |
117 | } |
|
118 | ||
119 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |