001: /*
002: * Copyright 2005-2006 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.opensource.org/licenses/ecl1.php
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.kuali.core.datadictionary;
018:
019: import java.util.Collections;
020: import java.util.HashSet;
021: import java.util.Set;
022:
023: import org.apache.commons.lang.StringUtils;
024: import org.apache.commons.logging.Log;
025: import org.apache.commons.logging.LogFactory;
026: import org.kuali.core.datadictionary.exception.CompletionException;
027: import org.kuali.core.service.KualiGroupService;
028:
029: /**
030: * An authorization definition consists of an action (String) and a set of groups authorized to perform that action.
031: *
032: *
033: */
034: public class AuthorizationDefinition extends
035: DataDictionaryDefinitionBase {
036: // logger
037: private static Log LOG = LogFactory
038: .getLog(AuthorizationDefinition.class);
039:
040: private String action;
041:
042: private Set authorizedGroups;
043:
044: public AuthorizationDefinition() {
045: LOG.debug("creating new AuthorizationDefinition");
046:
047: authorizedGroups = new HashSet();
048: }
049:
050: /**
051: * @param action
052: */
053: public void setAction(String action) {
054: this .action = action;
055: }
056:
057: /**
058: * @return action to be associated with this authorizationDefinition
059: */
060: public String getAction() {
061: return action;
062: }
063:
064: /**
065: * Adds the given groupName to the set of authorized groupNames
066: *
067: * @param groupName
068: */
069: public void addGroupName(String groupName) {
070: if (StringUtils.isBlank(groupName)) {
071: throw new IllegalArgumentException(
072: "invalid (blank) groupName");
073: }
074:
075: authorizedGroups.add(groupName);
076: }
077:
078: /**
079: * @return current set of groupNames
080: */
081: public Set getGroupNames() {
082: return Collections.unmodifiableSet(authorizedGroups);
083: }
084:
085: /**
086: * Does nothing useful, since real validation is deferred until the validateWorkgroups method below
087: *
088: * @see org.kuali.core.datadictionary.DataDictionaryDefinition#completeValidation(java.lang.Class, java.lang.Class)
089: */
090: public void completeValidation(Class rootBusinessObjectClass,
091: Class otherBusinessObjectClass,
092: ValidationCompletionUtils validationCompletionUtils) {
093: // validate non-empty group list
094: if (authorizedGroups.isEmpty()) {
095: throw new CompletionException(
096: "empty workgroups list for action '" + action + "'");
097: }
098:
099: // validation of workgroup names deferred until later, since it requires access to a service which may not have been
100: // initialized yet
101: }
102:
103: public void validateWorkroups(KualiGroupService kualiGroupService) {
104: //
105: // commented out because it increase webapp startup time by 30 seconds or more
106:
107: // // validate existence of all specified groups
108: // for (Iterator i = authorizedGroups.iterator(); i.hasNext();) {
109: // String groupName = (String) i.next();
110: //
111: // if (!kualiGroupService.groupExists(groupName)) {
112: // throw new CompletionException("unable to retrieve group named '" + groupName + "'");
113: // }
114: // }
115: }
116:
117: /**
118: * @see java.lang.Object#toString()
119: */
120: public String toString() {
121: return "AuthorizationDefinition for action " + getAction();
122: }
123: }
|