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:
18: package org.apache.jetspeed.security.impl;
19:
20: import java.security.CodeSource;
21: import java.security.Permission;
22: import java.security.PermissionCollection;
23: import java.security.Policy;
24: import java.security.ProtectionDomain;
25:
26: /**
27: * <p>
28: * Provide coordination between the default policy and Jetspeed custom policy.
29: * </p>
30: */
31: public class JaasPolicyCoordinator extends Policy {
32: private final Policy defaultPolicy;
33:
34: private final Policy j2Policy;
35:
36: /**
37: * <p>
38: * Constructor for coordinating the policies.
39: * </p>
40: *
41: * @param defaultPolicy The default policy.
42: * @param j2Policy Jetspeed policy.
43: */
44: public JaasPolicyCoordinator(Policy defaultPolicy, Policy j2Policy) {
45: this .defaultPolicy = defaultPolicy;
46: this .j2Policy = j2Policy;
47: }
48:
49: /**
50: * @see java.security.Policy#getPermissions(java.security.CodeSource)
51: */
52: public PermissionCollection getPermissions(CodeSource codeSource) {
53: return defaultPolicy.getPermissions(codeSource);
54: }
55:
56: /**
57: * @see java.security.Policy#refresh()
58: */
59: public void refresh() {
60: defaultPolicy.refresh();
61: j2Policy.refresh();
62: }
63:
64: /**
65: * @see java.security.Policy#implies(java.security.ProtectionDomain, java.security.Permission)
66: */
67: public boolean implies(ProtectionDomain domain,
68: Permission permission) {
69: if (permission.getClass().getName().startsWith("java")) {
70: return defaultPolicy.implies(domain, permission);
71: } else {
72: return j2Policy.implies(domain, permission);
73: }
74: }
75: }
|