001: /*
002: * Copyright 2005-2007 The Kuali Foundation.
003: *
004: *
005: * Licensed under the Educational Community License, Version 1.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.opensource.org/licenses/ecl1.php
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package edu.iu.uis.eden.actionrequests;
018:
019: import java.util.ArrayList;
020: import java.util.HashMap;
021: import java.util.Iterator;
022: import java.util.List;
023: import java.util.Map;
024:
025: import edu.iu.uis.eden.engine.RouteContext;
026: import edu.iu.uis.eden.exception.EdenUserNotFoundException;
027: import edu.iu.uis.eden.routeheader.DocumentContent;
028: import edu.iu.uis.eden.routetemplate.AbstractRoleAttribute;
029: import edu.iu.uis.eden.routetemplate.ResolvedQualifiedRole;
030: import edu.iu.uis.eden.routetemplate.Role;
031: import edu.iu.uis.eden.user.AuthenticationUserId;
032:
033: public class RoleToRoleDelegationRole extends AbstractRoleAttribute {
034:
035: private static final long serialVersionUID = 3881730393316239780L;
036: public static final String MAIN_ROLE = "MAIN";
037: public static final String PRIMARY_DELEGATE_ROLE = "PRIMARY_DELEGATE";
038: public static final String SECONDARY_DELEGATE_ROLE = "SECONDARY_DELEGATE";
039:
040: private static final List ROLE_NAMES = new ArrayList();
041: static {
042: ROLE_NAMES.add(new Role(RoleToRoleDelegationRole.class,
043: MAIN_ROLE, MAIN_ROLE));
044: ROLE_NAMES.add(new Role(RoleToRoleDelegationRole.class,
045: PRIMARY_DELEGATE_ROLE, PRIMARY_DELEGATE_ROLE));
046: ROLE_NAMES.add(new Role(RoleToRoleDelegationRole.class,
047: SECONDARY_DELEGATE_ROLE, SECONDARY_DELEGATE_ROLE));
048: }
049:
050: public static List MAIN_USERS = new ArrayList();
051: static {
052: MAIN_USERS.add("ewestfal");
053: }
054:
055: public static Map PRIMARY_DELEGATES = new HashMap();
056: static {
057: List primDelegates1 = new ArrayList();
058: primDelegates1.add("jhopf");
059: PRIMARY_DELEGATES.put("ewestfal", primDelegates1);
060: PRIMARY_DELEGATES.put("rkirkend", new ArrayList());
061: }
062:
063: public static Map SECONDARY_DELEGATES = new HashMap();
064: static {
065: List secondaryDelegates1 = new ArrayList();
066: secondaryDelegates1.add("jitrue");
067: secondaryDelegates1.add("xqi");
068: List secondaryDelegates2 = new ArrayList();
069: secondaryDelegates2.add("jhopf");
070: secondaryDelegates2.add("bmcgough");
071: secondaryDelegates2.add("natjohns");
072: SECONDARY_DELEGATES.put("ewestfal", secondaryDelegates1);
073: SECONDARY_DELEGATES.put("rkirkend", secondaryDelegates2);
074: }
075:
076: public List getRoleNames() {
077: return ROLE_NAMES;
078: }
079:
080: public List getQualifiedRoleNames(String roleName,
081: DocumentContent documentContent)
082: throws EdenUserNotFoundException {
083: List names = new ArrayList();
084: if (MAIN_ROLE.equals(roleName)) {
085: names = new ArrayList(MAIN_USERS);
086: } else {
087: throw new IllegalArgumentException(
088: "Can't get qualified role names for role '"
089: + roleName + "'");
090: }
091: return names;
092: }
093:
094: public ResolvedQualifiedRole resolveQualifiedRole(
095: RouteContext routeContext, String roleName,
096: String qualifiedRole) throws EdenUserNotFoundException {
097: List userIds = new ArrayList();
098: if (MAIN_ROLE.equals(roleName)) {
099: userIds = MAIN_USERS;
100: } else if (PRIMARY_DELEGATE_ROLE.equals(roleName)) {
101: userIds = new ArrayList((List) PRIMARY_DELEGATES
102: .get(qualifiedRole));
103: } else if (SECONDARY_DELEGATE_ROLE.equals(roleName)) {
104: userIds = new ArrayList((List) SECONDARY_DELEGATES
105: .get(qualifiedRole));
106: } else {
107: throw new IllegalArgumentException(
108: "Can't resolve qualified role for role '"
109: + roleName + "'");
110: }
111: List recipients = new ArrayList();
112: for (Iterator iterator = userIds.iterator(); iterator.hasNext();) {
113: String networkId = (String) iterator.next();
114: recipients.add(new AuthenticationUserId(networkId));
115: }
116: return new ResolvedQualifiedRole(roleName, recipients);
117: }
118:
119: }
|