001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.jetspeed.profiler.rules.impl;
018:
019: import java.security.Principal;
020: import java.util.Iterator;
021:
022: import javax.security.auth.Subject;
023:
024: import org.apache.jetspeed.profiler.rules.RuleCriterion;
025: import org.apache.jetspeed.profiler.rules.RuleCriterionResolver;
026: import org.apache.jetspeed.request.RequestContext;
027: import org.apache.jetspeed.security.SecurityHelper;
028:
029: /**
030: * Standard Jetspeed-1 style resolver for criterion.
031: * It first looks at the value in the request parameters.
032: * If it is null, it then falls back to the criterion record..
033: * If it is null it gives up and returns null allowing subclasses
034: * to continue processing.
035: *
036: * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
037: * @version $Id: StandardResolver.java 516448 2007-03-09 16:25:47Z ate $
038: */
039: public class StandardResolver implements RuleCriterionResolver {
040: public static final String VALUE_DELIMITER = ",";
041: public static final String COMBO_DELIMITER = "-";
042:
043: /* (non-Javadoc)
044: * @see org.apache.jetspeed.profiler.rules.RuleCriterionResolver#resolve(org.apache.jetspeed.request.RequestContext, org.apache.jetspeed.profiler.rules.RuleCriterion)
045: */
046: public String resolve(RequestContext context,
047: RuleCriterion criterion) {
048: String value = context.getRequestParameter(criterion.getName());
049: if (value == null) {
050: value = criterion.getValue();
051: }
052: return value;
053: }
054:
055: /* (non-Javadoc)
056: * @see org.apache.jetspeed.profiler.rules.RuleCriterionResolver#isControl()
057: */
058: public boolean isControl(RuleCriterion criterion) {
059: if (criterion.getName().equals(RuleCriterionResolver.PATH)
060: || criterion.getName().equals(
061: RuleCriterionResolver.PAGE)) {
062: return false;
063: }
064: return true;
065: }
066:
067: public boolean isNavigation(RuleCriterion criterion) {
068: return false;
069: }
070:
071: protected String resolvePrincipals(RequestContext context,
072: RuleCriterion criterion, Subject subject, Class classe) {
073: StringBuffer result = new StringBuffer();
074: Iterator principals = SecurityHelper.getPrincipals(subject,
075: classe).iterator();
076: int count = 0;
077: while (principals.hasNext()) {
078: Principal principal = (Principal) principals.next();
079: if (count > 0) {
080: result.append(VALUE_DELIMITER);
081: }
082: result.append(principal.getName());
083: count++;
084: }
085: if (count == 0) {
086: return null;
087: }
088: return result.toString();
089: }
090:
091: protected String combinePrincipals(RequestContext context,
092: RuleCriterion criterion, Subject subject, Class classe) {
093: StringBuffer result = new StringBuffer();
094: Iterator principals = SecurityHelper.getPrincipals(subject,
095: classe).iterator();
096: int count = 0;
097: while (principals.hasNext()) {
098: Principal principal = (Principal) principals.next();
099: if (count > 0) {
100: result.append(COMBO_DELIMITER);
101: }
102: result.append(principal.getName());
103: count++;
104: }
105: if (count == 0) {
106: return null;
107: }
108: return result.toString();
109: }
110:
111: }
|