01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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:
21: import javax.security.auth.Subject;
22:
23: import org.apache.commons.logging.Log;
24: import org.apache.commons.logging.LogFactory;
25: import org.apache.jetspeed.profiler.rules.RuleCriterion;
26: import org.apache.jetspeed.profiler.rules.RuleCriterionResolver;
27: import org.apache.jetspeed.request.RequestContext;
28: import org.apache.jetspeed.security.SecurityHelper;
29: import org.apache.jetspeed.security.UserPrincipal;
30:
31: /**
32: * Standard Jetspeed-1 User resolver.
33: * It first looks at the value in the criterion record.
34: * If it is null, it then falls back to a request parameter.
35: * If it is null it gives up and returns null allowing subclasses
36: * to continue processing.
37: *
38: * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
39: * @version $Id: UserCriterionResolver.java 516448 2007-03-09 16:25:47Z ate $
40: */
41: public class UserCriterionResolver extends StandardResolver implements
42: RuleCriterionResolver {
43: protected final static Log log = LogFactory
44: .getLog(UserCriterionResolver.class);
45:
46: /* (non-Javadoc)
47: * @see org.apache.jetspeed.profiler.rules.RuleCriterionResolver#resolve(org.apache.jetspeed.request.RequestContext, org.apache.jetspeed.profiler.rules.RuleCriterion)
48: */
49: public String resolve(RequestContext context,
50: RuleCriterion criterion) {
51: String value = super .resolve(context, criterion);
52: if (value != null) {
53: return value;
54: }
55:
56: Subject subject = context.getSubject();
57: if (subject == null) {
58: String msg = "Invalid (null) Subject in request pipeline";
59: log.error(msg);
60: return null;
61: }
62:
63: Principal principal = SecurityHelper.getPrincipal(subject,
64: UserPrincipal.class);
65: if (principal != null) {
66: return principal.getName();
67: }
68: return null;
69: }
70:
71: /* (non-Javadoc)
72: * @see org.apache.jetspeed.profiler.rules.RuleCriterionResolver#isControl()
73: */
74: public boolean isControl(RuleCriterion criterion) {
75: return true;
76: }
77:
78: }
|