001package org.apache.archiva.redback.role;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 * http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import org.apache.archiva.redback.role.model.RedbackRoleModel;
023
024import java.net.URL;
025
026/**
027 * RoleProfileManager:
028 *
029 * @author: Jesse McConnell
030 *
031 */
032public interface RoleManager
033{
034
035    /**
036     * load the model and create/verify operations, resources, etc exist and make static roles
037     *
038     * @param resourceLocation
039     * @throws RoleManagerException
040     */
041    void loadRoleModel( URL resourceLocation )
042        throws RoleManagerException;
043
044    void loadRoleModel( RedbackRoleModel model )
045        throws RoleManagerException;
046
047    /**
048     * locate a role with the corresponding name and generate it with the given resource, ${resource}
049     * in the model will be replaced with this resource string, if this resource does not exist, it
050     * will be created.
051     *
052     * @param templateId
053     * @param resource
054     * @throws RoleManagerException
055     */
056    String createTemplatedRole( String templateId, String resource )
057        throws RoleManagerException;
058
059    /**
060     * removes a role corresponding to the role Id that was manufactured with the given resource
061     *
062     * it also removes any user assignments for that role
063     *
064     * @param templateId
065     * @param resource
066     * @throws RoleManagerException
067     */
068    void removeTemplatedRole( String templateId, String resource )
069        throws RoleManagerException;
070
071
072    /**
073     * Moves the instance of the templated role from the old resource to the new resource and updates the
074     * user assignments.
075     *
076     * @param templateId the name of the role template
077     * @param oldResource the old resource name
078     * @param newResource the new resource name
079     * @throws RoleManagerException
080     */
081    String moveTemplatedRole( String templateId, String oldResource, String newResource )
082        throws RoleManagerException;
083
084
085    /**
086     * Assigns the role indicated by the roleId to the given principal
087     *
088     * @param roleId
089     * @param principal
090     * @throws RoleManagerException
091     */
092    void assignRole( String roleId, String principal )
093        throws RoleManagerException;
094
095    /**
096     * Assigns the role indicated by the roleName to the given principal
097     *
098     * @param roleName
099     * @param principal
100     * @throws RoleManagerException
101     */
102    void assignRoleByName( String roleName, String principal )
103        throws RoleManagerException;
104
105    /**
106     * Assigns the templated role indicated by the templateId
107     *
108     * fails if the templated role has not been created
109     *
110     * @param templateId
111     * @param resource
112     * @param principal
113     */
114    void assignTemplatedRole( String templateId, String resource, String principal )
115        throws RoleManagerException;
116
117    /**
118     * Unassigns the role indicated by the role id from the given principal
119     *
120     * @param roleId
121     * @param principal
122     * @throws RoleManagerException
123     */
124    void unassignRole( String roleId, String principal )
125        throws RoleManagerException;
126
127    /**
128     * Unassigns the role indicated by the role name from the given principal
129     *
130     * @param roleName
131     * @param principal
132     * @throws RoleManagerException
133     */
134    void unassignRoleByName( String roleName, String principal )
135        throws RoleManagerException;
136
137    /**
138     * true of a role exists with the given roleId
139     *
140     * @param roleId
141     * @return
142     * @throws RoleManagerException
143     */
144    boolean roleExists( String roleId )
145        throws RoleManagerException;
146
147    /**
148     * true of a role exists with the given roleId
149     *
150     * @param templateId
151     * @param resource
152     * @return
153     * @throws RoleManagerException
154     */
155    boolean templatedRoleExists( String templateId, String resource )
156        throws RoleManagerException;
157
158    /**
159     * get the blessed model, the current operating instructions for all things role management
160     */
161    RedbackRoleModel getModel();
162
163    /**
164     * Check a role template is complete in the RBAC store.
165     *
166     * @param templateID the templated role
167     * @param resource   the resource to verify
168     * @throws RoleManagerException
169     */
170    void verifyTemplatedRole( String templateID, String resource )
171        throws RoleManagerException;
172
173    /**
174     * intialize the role manager
175     * @since 2.1
176     */
177    void initialize();
178}