View Javadoc
1   /*
2    * Copyright (c) 2002-2022, City of Paris
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions
7    * are met:
8    *
9    *  1. Redistributions of source code must retain the above copyright notice
10   *     and the following disclaimer.
11   *
12   *  2. Redistributions in binary form must reproduce the above copyright notice
13   *     and the following disclaimer in the documentation and/or other materials
14   *     provided with the distribution.
15   *
16   *  3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
17   *     contributors may be used to endorse or promote products derived from
18   *     this software without specific prior written permission.
19   *
20   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23   * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30   * POSSIBILITY OF SUCH DAMAGE.
31   *
32   * License 1.0
33   */
34  package fr.paris.lutece.plugins.profiles.service;
35  
36  import fr.paris.lutece.plugins.profiles.business.Profile;
37  import fr.paris.lutece.plugins.profiles.business.ProfileHome;
38  import fr.paris.lutece.portal.service.plugin.Plugin;
39  import fr.paris.lutece.portal.service.plugin.PluginService;
40  import fr.paris.lutece.portal.service.rbac.Permission;
41  import fr.paris.lutece.portal.service.rbac.ResourceIdService;
42  import fr.paris.lutece.portal.service.rbac.ResourceType;
43  import fr.paris.lutece.portal.service.rbac.ResourceTypeManager;
44  import fr.paris.lutece.util.ReferenceList;
45  
46  import java.util.Locale;
47  
48  /**
49   *
50   * Class ProfileResourceIdService
51   *
52   */
53  public class ProfilesResourceIdService extends ResourceIdService
54  {
55      public static final String PERMISSION_CREATE_PROFILE = "CREATE_PROFILE";
56      public static final String PERMISSION_MODIFY_PROFILE = "MODIFY_PROFILE";
57      public static final String PERMISSION_DELETE_PROFILE = "DELETE_PROFILE";
58      public static final String PERMISSION_MANAGE_USERS_ASSIGNMENT = "MANAGE_USERS_ASSIGNMENT";
59      public static final String PERMISSION_MANAGE_RIGHTS_ASSIGNMENT = "MANAGE_RIGHTS_ASSIGNMENT";
60      public static final String PERMISSION_MANAGE_ROLES_ASSIGNMENT = "MANAGE_ROLES_ASSIGNMENT";
61      public static final String PERMISSION_MANAGE_WORKGROUPS_ASSIGNMENT = "MANAGE_WORKGROUPS_ASSIGNMENT";
62      public static final String PERMISSION_MANAGE_VIEW_ASSIGNMENT = "MANAGE_VIEW_ASSIGNMENT";
63      private static final String PROPERTY_LABEL_RESOURCE_TYPE = "profiles.permission.label.resource_type_profile";
64      private static final String PROPERTY_LABEL_CREATE_PROFILE = "profiles.permission.label.create_profile";
65      private static final String PROPERTY_LABEL_MODIFY_PROFILE = "profiles.permission.label.modify_profile";
66      private static final String PROPERTY_LABEL_DELETE_PROFILE = "profiles.permission.label.delete_profile";
67      private static final String PROPERTY_LABEL_MANAGE_USERS_ASSIGNMENT = "profiles.permission.label.manage_users_assignment";
68      private static final String PROPERTY_LABEL_MANAGE_RIGHTS_ASSIGNMENT = "profiles.permission.label.manage_rights_assignment";
69      private static final String PROPERTY_LABEL_MANAGE_ROLES_ASSIGNMENT = "profiles.permission.label.manage_roles_assignment";
70      private static final String PROPERTY_LABEL_MANAGE_WORKGROUPS_ASSIGNMENT = "profiles.permission.label.manage_workgroups_assignment";
71      private static final String PROPERTY_LABEL_MANAGE_VIEW_ASSIGNMENT = "profiles.permission.label.manage_view_assignment";
72  
73      /**
74       * Create a new instance of ProfilesResourceIdService
75       */
76      public ProfilesResourceIdService( )
77      {
78          setPluginName( ProfilesPlugin.PLUGIN_NAME );
79      }
80  
81      /**
82       * Initializes the service
83       */
84      public void register( )
85      {
86          ResourceType rt = new ResourceType( );
87          rt.setResourceIdServiceClass( ProfilesResourceIdService.class.getName( ) );
88          rt.setResourceTypeKey( Profile.RESOURCE_TYPE );
89          rt.setResourceTypeLabelKey( PROPERTY_LABEL_RESOURCE_TYPE );
90  
91          Permission p = new Permission( );
92          p.setPermissionKey( PERMISSION_CREATE_PROFILE );
93          p.setPermissionTitleKey( PROPERTY_LABEL_CREATE_PROFILE );
94          rt.registerPermission( p );
95  
96          p = new Permission( );
97          p.setPermissionKey( PERMISSION_MODIFY_PROFILE );
98          p.setPermissionTitleKey( PROPERTY_LABEL_MODIFY_PROFILE );
99          rt.registerPermission( p );
100 
101         p = new Permission( );
102         p.setPermissionKey( PERMISSION_DELETE_PROFILE );
103         p.setPermissionTitleKey( PROPERTY_LABEL_DELETE_PROFILE );
104         rt.registerPermission( p );
105 
106         p = new Permission( );
107         p.setPermissionKey( PERMISSION_MANAGE_USERS_ASSIGNMENT );
108         p.setPermissionTitleKey( PROPERTY_LABEL_MANAGE_USERS_ASSIGNMENT );
109         rt.registerPermission( p );
110 
111         p = new Permission( );
112         p.setPermissionKey( PERMISSION_MANAGE_RIGHTS_ASSIGNMENT );
113         p.setPermissionTitleKey( PROPERTY_LABEL_MANAGE_RIGHTS_ASSIGNMENT );
114         rt.registerPermission( p );
115 
116         p = new Permission( );
117         p.setPermissionKey( PERMISSION_MANAGE_ROLES_ASSIGNMENT );
118         p.setPermissionTitleKey( PROPERTY_LABEL_MANAGE_ROLES_ASSIGNMENT );
119         rt.registerPermission( p );
120 
121         p = new Permission( );
122         p.setPermissionKey( PERMISSION_MANAGE_WORKGROUPS_ASSIGNMENT );
123         p.setPermissionTitleKey( PROPERTY_LABEL_MANAGE_WORKGROUPS_ASSIGNMENT );
124         rt.registerPermission( p );
125 
126         p = new Permission( );
127         p.setPermissionKey( PERMISSION_MANAGE_VIEW_ASSIGNMENT );
128         p.setPermissionTitleKey( PROPERTY_LABEL_MANAGE_VIEW_ASSIGNMENT );
129         rt.registerPermission( p );
130 
131         ResourceTypeManager.registerResourceType( rt );
132     }
133 
134     /**
135      * Returns a list of profiles resource ids
136      * 
137      * @param locale
138      *            The current locale
139      * @return A list of resource ids
140      */
141     public ReferenceList getResourceIdList( Locale locale )
142     {
143         Plugin plugin = PluginService.getPlugin( ProfilesPlugin.PLUGIN_NAME );
144 
145         return ProfileHome.getProfilesList( plugin );
146     }
147 
148     /**
149      * Returns the Title of a given resource
150      * 
151      * @param strProfileKey
152      *            the profile key
153      * @param locale
154      *            The current locale
155      * @return The Title of a given resource
156      */
157     public String getTitle( String strProfileKey, Locale locale )
158     {
159         return strProfileKey;
160     }
161 }