2 * Copyright 2005 the original author or authors.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.wamblee.photos.security;
19 import javax.persistence.DiscriminatorValue;
20 import javax.persistence.Entity;
22 import org.wamblee.photos.wicket.BasePage;
23 import org.wamblee.security.authorization.AllOperation;
24 import org.wamblee.security.authorization.AuthorizationResult;
25 import org.wamblee.security.authorization.IsaOperationCondition;
26 import org.wamblee.security.authorization.RegexpPathCondition;
27 import org.wamblee.security.authorization.UrlAuthorizationRule;
28 import org.wamblee.security.authorization.UserCondition;
31 * AUthorization rule for pages.
34 @DiscriminatorValue("PAGE")
35 public class PageAuthorizationRule extends UrlAuthorizationRule {
38 * Type-safe construction of page authorization rule.
42 * @param aUserCondition
45 * A list of page names.
47 public PageAuthorizationRule(AuthorizationResult aResult,
48 UserCondition aUserCondition, Class<? extends BasePage>... aPageList) {
49 super(aResult, aUserCondition, new RegexpPathCondition(
50 getPageRegex(aPageList)), BasePage.class,
51 new IsaOperationCondition(AllOperation.class));
55 * Converts a list of page names into a regular expression for the pages.
59 * @return Regexp matching any of the given pagenames.
61 private static String getPageRegex(Class<? extends BasePage>[] aPageList) {
63 for (int i = 0; i < aPageList.length; i++) {
64 if (result.length() == 0) {
65 result = "/" + aPageList[i].getSimpleName();
67 result = result + "|/" + aPageList[i].getSimpleName();
74 * Constructor for OR mapping.
76 protected PageAuthorizationRule() {
81 * @see org.wamblee.security.authorization.UrlAuthorizationRule#getResourcePath(java.lang.Object)
84 protected String getResourcePath(Object aResource) {
85 BasePage page = (BasePage) aResource;
86 return "/" + page.getClass().getSimpleName();