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.
16 package org.wamblee.photos.security;
18 import javax.persistence.DiscriminatorValue;
19 import javax.persistence.Entity;
21 import org.wamblee.photos.wicket.BasePage;
22 import org.wamblee.security.authorization.AllOperation;
23 import org.wamblee.security.authorization.AuthorizationResult;
24 import org.wamblee.security.authorization.IsaOperationCondition;
25 import org.wamblee.security.authorization.RegexpPathCondition;
26 import org.wamblee.security.authorization.UrlAuthorizationRule;
27 import org.wamblee.security.authorization.UserCondition;
30 * AUthorization rule for pages.
33 @DiscriminatorValue("PAGE")
34 public class PageAuthorizationRule extends UrlAuthorizationRule {
37 * Type-safe construction of page authorization rule.
39 * @param aResult Result.
40 * @param aUserCondition User condition.
41 * @param aPageList A list of page names.
43 public PageAuthorizationRule(AuthorizationResult aResult, UserCondition aUserCondition,
44 Class<? extends BasePage>... aPageList) {
45 super(aResult, aUserCondition, new RegexpPathCondition(getPageRegex(aPageList)), BasePage.class,
46 new IsaOperationCondition(AllOperation.class));
50 * Converts a list of page names into a regular expression for the pages.
52 * @param aPageList List of pages.
53 * @return Regexp matching any of the given pagenames.
55 private static String getPageRegex(Class<? extends BasePage>[] aPageList) {
57 for (int i = 0; i < aPageList.length; i++) {
58 if (result.length() == 0) {
59 result = "/" + aPageList[i].getSimpleName();
61 result = result + "|/" + aPageList[i].getSimpleName();
68 * Constructor for OR mapping.
70 protected PageAuthorizationRule() {
78 * org.wamblee.security.authorization.UrlAuthorizationRule#getResourcePath
82 protected String getResourcePath(Object aResource) {
83 BasePage page = (BasePage) aResource;
84 return "/" + page.getClass().getSimpleName();