Security/ Package Name changes
[portal.git] / ecomp-portal-BE-common / src / main / java / org / onap / portalapp / portal / service / ExternalAccessRolesService.java
1 /*-
2  * ============LICENSE_START==========================================
3  * ONAP Portal
4  * ===================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ===================================================================
7  *
8  * Unless otherwise specified, all software contained herein is licensed
9  * under the Apache License, Version 2.0 (the "License");
10  * you may not use this software except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *             http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  * Unless otherwise specified, all documentation contained herein is licensed
22  * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23  * you may not use this documentation except in compliance with the License.
24  * You may obtain a copy of the License at
25  *
26  *             https://creativecommons.org/licenses/by/4.0/
27  *
28  * Unless required by applicable law or agreed to in writing, documentation
29  * distributed under the License is distributed on an "AS IS" BASIS,
30  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31  * See the License for the specific language governing permissions and
32  * limitations under the License.
33  *
34  * ============LICENSE_END============================================
35  *
36  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
37  */
38 package org.onap.portalapp.portal.service;
39
40 import java.io.IOException;
41 import java.util.List;
42 import java.util.Map;
43
44 import org.hibernate.Session;
45 import org.json.JSONArray;
46 import org.onap.portalapp.portal.domain.CentralV2RoleFunction;
47 import org.onap.portalapp.portal.domain.CentralizedApp;
48 import org.onap.portalapp.portal.domain.EPApp;
49 import org.onap.portalapp.portal.domain.EPRole;
50 import org.onap.portalapp.portal.domain.EPUser;
51 import org.onap.portalapp.portal.domain.ExternalRoleDetails;
52 import org.onap.portalapp.portal.transport.CentralRole;
53 import org.onap.portalapp.portal.transport.CentralUser;
54 import org.onap.portalapp.portal.transport.CentralV2Role;
55 import org.onap.portalapp.portal.transport.ExternalRequestFieldsValidator;
56 import org.onap.portalsdk.core.domain.Role;
57 import org.onap.portalsdk.core.domain.RoleFunction;
58 import org.onap.portalsdk.core.restful.domain.EcompUser;
59 import org.springframework.http.ResponseEntity;
60 import org.springframework.web.client.HttpClientErrorException;
61
62 import com.fasterxml.jackson.core.JsonParseException;
63 import com.fasterxml.jackson.databind.JsonMappingException;
64 import com.fasterxml.jackson.databind.ObjectMapper;
65
66 public interface ExternalAccessRolesService {
67         
68         /**
69          * It gets list of application roles 
70          * 
71          * @param appId
72          * @return List
73          * @throws Exception 
74          */
75         public List<EPRole> getAppRoles(Long appId) throws Exception;
76         
77         /**
78          * It returns single app record
79          * 
80          * @param uebkey
81          * @return List
82          * @throws Exception 
83          */             
84         public List<EPApp> getApp(String uebkey) throws Exception;
85         
86         /**
87          * Adds role in the external access system if fails throws exception
88          * 
89          * @param addRoles
90          * @param uebkey
91          * @return boolean
92          * @throws Exception
93          */
94         public boolean addRole(Role addRoles, String uebkey) throws Exception;
95
96         /**
97          * It returns complete user information
98          * 
99          * @param loginId
100          * @return EPUser object
101          * @throws Exception
102          */
103         List<EPUser> getUser(String loginId) throws Exception;
104         
105         /**
106          * It returns complete user information including application roles permissions
107          * 
108          * @param loginId
109          * @param uebkey
110          * @return String
111          * @throws Exception
112          */
113         String getV2UserWithRoles(String loginId, String uebkey) throws Exception;
114
115         /**
116          * It returns list of all role functions
117          * @param string 
118          * @return List
119          * @throws Exception 
120          */
121         List<CentralV2RoleFunction> getRoleFuncList(String string) throws Exception;
122         
123         /**
124          * It return list of role provided by the app uebkey and roleId
125          * 
126          * @param roleId
127          * @param uebkey
128          * @return CentralRole
129          * @throws Exception
130          */
131         CentralV2Role getRoleInfo(Long roleId, String uebkey) throws Exception;
132         
133         /**
134          *  It returns the CentralRoleFunction object 
135          *   
136          * @param functionCode
137          * @param uebkey 
138          * @return CentralRoleFunction
139          * @throws Exception 
140          */
141         public CentralV2RoleFunction getRoleFunction(String functionCode, String uebkey) throws Exception;
142
143         /**
144          *  It saves role function in the DB
145          *  
146          * @param domainCentralRoleFunction
147          * @param requestedApp 
148          * @return true else false
149          * @throws Exception 
150          */
151         public boolean saveCentralRoleFunction(CentralV2RoleFunction domainCentralRoleFunction, EPApp requestedApp) throws Exception;
152
153         /**
154          * It deletes role function in the DB
155          * 
156          * @param code
157          * @param app 
158          */
159         public boolean deleteCentralRoleFunction(String code, EPApp app);
160
161         /**
162          * It gets all roles the applications
163          * 
164          * @param uebkey
165          * @return List
166          * @throws Exception 
167          */
168         public List<CentralV2Role> getRolesForApp(String uebkey) throws Exception;
169         
170         /**
171          * 
172          * It saves role function in the DB
173          * 
174          * @param saveRole
175          * @param uebkey
176          * @return message and true or false  
177          * @throws Exception
178          */
179         ExternalRequestFieldsValidator saveRoleForApplication(Role saveRole, String uebkey) throws Exception;
180
181         /**
182          *  It deletes role in the DB
183          *  
184          * @param code
185          * @param uebkey
186          * @return true else false
187          * @throws Exception 
188          */
189         boolean deleteRoleForApplication(String code, String uebkey) throws Exception;
190         
191         /**
192          * It gets all active roles for single application 
193          * 
194          * @param uebkey
195          * @return List
196          * @throws Exception
197          */
198         List<CentralV2Role> getActiveRoles(String uebkey) throws Exception;
199         
200         /**
201          * It deletes user related roles for an application in the table
202          * @param roleId
203          * @param uebkey
204          * @param LoginId 
205          * @return true else false
206          * @throws Exception 
207          */
208         public ExternalRequestFieldsValidator deleteDependencyRoleRecord(Long roleId, String uebkey, String LoginId) throws Exception;
209         
210         /**
211          * It sync new functions codes and names from and updates role functions from external access system
212          * 
213          * @param app
214          * @throws Exception
215          */
216         public void syncRoleFunctionFromExternalAccessSystem(EPApp app) throws Exception;
217
218         /**
219          * It uploads portal functions into external auth system
220          * @param uebkey
221          * @return
222          * @throws Exception
223          */
224         public Integer bulkUploadFunctions(String uebkey) throws Exception;
225
226         /**
227          * It uploads portal roles into external auth system
228          * @param uebkey
229          * @return
230          * @throws Exception
231          */
232         public Integer bulkUploadRoles(String uebkey) throws Exception;
233
234         /**
235          * It uploads partner application role functions into external auth system
236          * 
237          * @param uebkey
238          * @param upload
239          * @throws Exception
240          */
241         public void bulkUploadPartnerFunctions(String uebkey, List<RoleFunction> upload) throws Exception;
242
243         /** 
244          * It uploads partner application role functions into external auth system
245          * 
246          * @param uebkey
247          * @param upload
248          * @throws Exception
249          */
250         public void bulkUploadPartnerRoles(String uebkey, List<Role> upload) throws Exception;
251
252         /**
253          * It returns total no. of portal application role functions records added in external auth system 
254          * @param uebkey
255          * @return
256          * @throws Exception
257          */
258         Integer bulkUploadRolesFunctions(String uebkey) throws Exception;
259         
260         /**
261          *  It syncs the roles and rolefunctions to the ecomp DB from AAF
262          * @param app
263          * @throws Exception
264          */
265         void syncApplicationRolesWithEcompDB(EPApp app) throws Exception;
266
267         /**
268          * It uploads list of user roles of the application into external auth system 
269          * 
270          * @param uebkey
271          * @return
272          * @throws Exception
273          */
274         public Integer bulkUploadUserRoles(String uebkey) throws Exception;
275
276         /**
277          * It Uploads partner application role functions into external auth system
278          * 
279          * @param uebkey
280          * @param roleList
281          * @throws Exception
282          */
283         void bulkUploadPartnerRoleFunctions(String uebkey, List<Role> roleList) throws Exception;
284
285         /**
286          * it deletes all dependency role records 
287          * 
288          * @param localSession
289          * @param roleId
290          * @param appId
291          * @param isPortalRequest 
292          * @throws Exception
293          */
294         public void deleteRoleDependencyRecords(Session localSession, Long roleId, Long appId, boolean isPortalRequest) throws Exception;
295
296         /**
297          * It returns list of applications functions along with functions associated with global role
298          * 
299          * @param uebkey
300          * @return
301          * @throws Exception
302          */
303         List<String> getMenuFunctionsList(String uebkey) throws Exception;
304         
305         /**
306          * 
307          * @param uebkey applications UebKey
308          * @return
309          * @throws Exception
310          * Method getAllUsers returns all the active users of application
311          */
312         List<EcompUser> getAllAppUsers(String uebkey) throws Exception;
313         
314         /**
315          * 
316          * @param result
317          * @return returns Role Object
318          * Method ConvertCentralRoleToRole converts the CentralRole String to Role Object
319          */
320         public Role ConvertCentralRoleToRole(String result);
321         
322         /**
323          * It returns the list of centralized applications
324          * 
325          * @param userId
326          * @return List
327          */
328         public List<CentralizedApp> getCentralizedAppsOfUser(String userId);
329         
330         /**
331          * It returns the list of globalRoles of Portal
332          * @return
333          */
334         public  List<EPRole> getGlobalRolesOfPortal();
335         
336         /**
337          * It converts list of CentralRoleFunction objects to RoleFunction objects
338          * @param answer contains list of CentralRoleFunction objects
339          * @return List of RoleFunction objects
340          */
341         public List<RoleFunction> convertCentralRoleFunctionToRoleFunctionObject(List<CentralV2RoleFunction> answer);
342         
343         /**
344          * 
345          * It returns user roles for older version
346          * 
347          * @param loginId
348          * @param uebkey
349          * @return EPUser
350          * @throws Exception 
351          */
352         public CentralUser getUserRoles(String loginId, String uebkey) throws Exception;
353         
354         /**
355          * It converts list of V2 CentralRole objects to old version CentralRole objects
356          * 
357          * @param v2CenRole
358          * @return List of CentralRole objects
359          */
360         public List<CentralRole> convertV2CentralRoleListToOldVerisonCentralRoleList(List<CentralV2Role> v2CenRole);
361         
362         /**
363          * 
364          * It finds namespace in external auth system if found returns namespace information
365          * 
366          * @param epApp
367          * @return Http response
368          */
369         public ResponseEntity<String> getNameSpaceIfExists(EPApp epApp) throws Exception, HttpClientErrorException;
370         
371         /**
372          * 
373          * It converts V2 CentralRole objects to old version CentralRole objects
374          * 
375          * @param answer
376          * @return
377          */
378         public CentralRole convertV2CentralRoleToOldVerisonCentralRole(CentralV2Role answer);
379
380         /**
381          * 
382          * Returns list of EPRole Objects if exists
383          * 
384          * @param app
385          * @return List of EPRole objects
386          */
387         Map<String, EPRole> getCurrentRolesInDB(EPApp app);
388     
389         
390         /**
391          * 
392          * It uploads list of users for single role when role name is re-named
393          * 
394          * @param header
395          * @param roleId
396          * @param roleName 
397          * @return number of user roles added in External Auth System
398          * @throws Exception 
399          */
400         public Integer bulkUploadUsersSingleRole(String uebkey, Long roleId, String roleName) throws Exception;
401         
402         /**
403          * 
404          * It returns JSON array of external auth roles and its corresponding functions
405          * 
406          * @param app
407          * @return JSON Array
408          * @throws Exception
409          */
410         public JSONArray getAppRolesJSONFromExtAuthSystem(EPApp app) throws Exception;
411         
412         /**
413          * It encodes the function code  based on Hex encoding
414          * @param funCode
415          * 
416          */
417         public String encodeFunctionCode(String funCode);
418         
419         /**
420          * 
421          * It returns list of ExternalRoleDetails which is converted from JSON array of roles
422          * 
423          * @param app 
424          * @param mapper
425          * @param extRole contains external auth application roles JSON array
426          * @return List of ExternalRoleDetails objects
427          * @throws IOException
428          * @throws JsonParseException
429          * @throws JsonMappingException
430          */
431         public List<ExternalRoleDetails> getExternalRoleDetailsList(EPApp app,
432                         ObjectMapper mapper, JSONArray extRole) throws IOException, JsonParseException, JsonMappingException;
433         
434         public JSONArray getAllUsersByRole(String roleName) throws Exception;
435
436 }