170d432389d810bccc5772e5ec8983f0e6401154
[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  * 
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.ecomp.model.UploadRoleFunctionExtSystem;
53 import org.onap.portalapp.portal.exceptions.InvalidUserException;
54 import org.onap.portalapp.portal.transport.CentralRole;
55 import org.onap.portalapp.portal.transport.CentralRoleFunction;
56 import org.onap.portalapp.portal.transport.CentralUser;
57 import org.onap.portalapp.portal.transport.CentralV2Role;
58 import org.onap.portalapp.portal.transport.ExternalRequestFieldsValidator;
59 import org.onap.portalsdk.core.domain.Role;
60 import org.onap.portalsdk.core.restful.domain.EcompUser;
61 import org.springframework.http.HttpEntity;
62 import org.springframework.http.ResponseEntity;
63 import org.springframework.web.client.HttpClientErrorException;
64
65 import com.fasterxml.jackson.core.JsonParseException;
66 import com.fasterxml.jackson.databind.JsonMappingException;
67 import com.fasterxml.jackson.databind.ObjectMapper;
68
69 public interface ExternalAccessRolesService {
70         
71         /**
72          * It gets list of application roles 
73          * 
74          * @param appId
75          * @return List
76          * @throws Exception 
77          */
78         public List<EPRole> getAppRoles(Long appId) throws Exception;
79         
80         /**
81          * It returns single app record
82          * 
83          * @param uebkey
84          * @return List
85          * @throws Exception 
86          */             
87         public List<EPApp> getApp(String uebkey) throws Exception;
88         
89         /**
90          * Adds role in the external access system if fails throws exception
91          * 
92          * @param addRoles
93          * @param uebkey
94          * @return boolean
95          * @throws Exception
96          */
97         public boolean addRole(Role addRoles, String uebkey) throws Exception;
98
99         /**
100          * It returns complete user information
101          * 
102          * @param loginId
103          * @return EPUser object
104          * @throws Exception
105          */
106         List<EPUser> getUser(String loginId) throws InvalidUserException;
107         
108         /**
109          * It returns complete user information including application roles permissions
110          * 
111          * @param loginId
112          * @param uebkey
113          * @return String
114          * @throws Exception
115          */
116         String getV2UserWithRoles(String loginId, String uebkey) throws Exception;
117
118         /**
119          * It returns list of all role functions
120          * @param string 
121          * @return List
122          * @throws Exception 
123          */
124         List<CentralV2RoleFunction> getRoleFuncList(String string) throws Exception;
125         
126         /**
127          * It return list of role provided by the app uebkey and roleId
128          * 
129          * @param roleId
130          * @param uebkey
131          * @return CentralRole
132          * @throws Exception
133          */
134         CentralV2Role getRoleInfo(Long roleId, String uebkey) throws Exception;
135         
136         /**
137          *  It returns the CentralV2RoleFunction object 
138          *   
139          * @param functionCode
140          * @param uebkey 
141          * @return CentralV2RoleFunction
142          * @throws Exception 
143          */
144         public CentralV2RoleFunction getRoleFunction(String functionCode, String uebkey) throws Exception;
145
146         /**
147          *  It saves role function in the DB
148          *  
149          * @param domainCentralRoleFunction
150          * @param requestedApp 
151          * @return true else false
152          * @throws Exception 
153          */
154         public boolean saveCentralRoleFunction(CentralV2RoleFunction domainCentralRoleFunction, EPApp requestedApp) throws Exception;
155         
156         /**
157          * It deletes role function in the DB
158          * 
159          * @param code
160          * @param app 
161          */
162         public boolean deleteCentralRoleFunction(String code, EPApp app);
163
164         /**
165          * It gets all roles the applications
166          * 
167          * @param uebkey
168          * @return List
169          * @throws Exception 
170          */
171         public List<CentralV2Role> getRolesForApp(String uebkey) throws Exception;
172         
173         /**
174          * 
175          * It saves role function in the DB
176          * 
177          * @param saveRole
178          * @param uebkey
179          * @return message and true or false  
180          * @throws Exception
181          */
182         ExternalRequestFieldsValidator saveRoleForApplication(Role saveRole, String uebkey) throws Exception;
183
184         /**
185          *  It deletes role in the DB
186          *  
187          * @param code
188          * @param uebkey
189          * @return true else false
190          * @throws Exception 
191          */
192         boolean deleteRoleForApplication(String code, String uebkey) throws Exception;
193         
194         /**
195          * It gets all active roles for single application 
196          * 
197          * @param uebkey
198          * @return List
199          * @throws Exception
200          */
201         List<CentralV2Role> getActiveRoles(String uebkey) throws Exception;
202         
203         /**
204          * It deletes user related roles for an application in the table
205          * @param roleId
206          * @param uebkey
207          * @param LoginId 
208          * @return true else false
209          * @throws Exception 
210          */
211         public ExternalRequestFieldsValidator deleteDependencyRoleRecord(Long roleId, String uebkey, String LoginId) throws Exception;
212         
213         /**
214          * It sync new functions codes and names from and updates role functions from external access system
215          * 
216          * @param app
217          * @throws Exception
218          */
219         public void syncRoleFunctionFromExternalAccessSystem(EPApp app) throws Exception;
220
221         /**
222          * It uploads portal functions into external auth system
223          * @param uebkey
224          * @return
225          * @throws Exception
226          */
227         public Integer bulkUploadFunctions(String uebkey) throws Exception;
228
229         /**
230          * It uploads portal roles into external auth system
231          * @param uebkey
232          * @return
233          * @throws Exception
234          */
235         public Integer bulkUploadRoles(String uebkey) throws Exception;
236
237         /**
238          * It uploads partner application role functions into external auth system
239          * 
240          * @param uebkey
241          * @param upload
242          * @throws Exception
243          */
244         public Integer bulkUploadPartnerFunctions(String uebkey) throws Exception;
245
246         /** 
247          * It uploads partner application role functions into external auth system
248          * 
249          * @param uebkey
250          * @param upload
251          * @throws Exception
252          */
253         public void bulkUploadPartnerRoles(String uebkey, List<Role> upload) throws Exception;
254
255         /**
256          * It returns total no. of portal application role functions records added in external auth system 
257          * @param uebkey
258          * @return
259          * @throws Exception
260          */
261         Integer bulkUploadRolesFunctions(String uebkey) throws Exception;
262         
263         /**
264          *  It syncs the roles and rolefunctions to the ONAP DB from AAF
265          * @param app
266          * @throws Exception
267          */
268         void syncApplicationRolesWithEcompDB(EPApp app) throws Exception;
269
270         /**
271          * It uploads list of user roles of the application into external auth system 
272          * 
273          * @param uebkey
274          * @return
275          * @throws Exception
276          */
277         public Integer bulkUploadUserRoles(String uebkey) throws Exception;
278
279         /**
280          * It Uploads partner application role functions into external auth system
281          * 
282          * @param uebkey
283          * @param roleList
284          * @throws Exception
285          */
286         Integer bulkUploadPartnerRoleFunctions(String uebkey) throws Exception;
287
288         /**
289          * it deletes all dependency role records 
290          * 
291          * @param localSession
292          * @param roleId
293          * @param appId
294          * @param isPortalRequest 
295          * @throws Exception
296          */
297         public void deleteRoleDependencyRecords(Session localSession, Long roleId, Long appId, boolean isPortalRequest) throws Exception;
298
299         /**
300          * It returns list of applications functions along with functions associated with global role
301          * 
302          * @param uebkey
303          * @return
304          * @throws Exception
305          */
306         List<String> getMenuFunctionsList(String uebkey) throws Exception;
307         
308         /**
309          * 
310          * @param uebkey applications UebKey
311          * @return
312          * @throws Exception
313          * Method getAllUsers returns all the active users of application
314          */
315         List<EcompUser> getAllAppUsers(String uebkey) throws Exception;
316         
317         /**
318          * 
319          * @param result
320          * @return returns Role Object
321          * Method ConvertCentralRoleToRole converts the CentralRole String to Role Object
322          */
323         public Role ConvertCentralRoleToRole(String result);
324         
325         /**
326          * It returns the list of centralized applications
327          * 
328          * @param userId
329          * @return List
330          */
331         public List<CentralizedApp> getCentralizedAppsOfUser(String userId);
332         
333         /**
334          * It returns the list of globalRoles of Portal
335          * @return
336          */
337         public  List<EPRole> getGlobalRolesOfPortal();
338         
339         /**
340          * It converts list of CentralV2RoleFunction objects to older version of CentralRoleFunction objects
341          * @param answer contains list of CentralRoleFunction objects
342          * @return List of CentralRoleFunction objects
343          */
344         public List<CentralRoleFunction> convertCentralRoleFunctionToRoleFunctionObject(List<CentralV2RoleFunction> answer);
345         
346         /**
347          * 
348          * It returns user roles for older version
349          * 
350          * @param loginId
351          * @param uebkey
352          * @return EPUser
353          * @throws Exception 
354          */
355         public CentralUser getUserRoles(String loginId, String uebkey) throws Exception;
356         
357         /**
358          * It converts list of V2 CentralRole objects to old version CentralRole objects
359          * 
360          * @param v2CenRole
361          * @return List of CentralRole objects
362          */
363         public List<CentralRole> convertV2CentralRoleListToOldVerisonCentralRoleList(List<CentralV2Role> v2CenRole);
364         
365         /**
366          * 
367          * It finds namespace in external auth system if found returns namespace information
368          * 
369          * @param epApp
370          * @return Http response
371          */
372         public ResponseEntity<String> getNameSpaceIfExists(EPApp epApp) throws Exception, HttpClientErrorException;
373         
374         /**
375          * 
376          * It converts V2 CentralRole objects to old version CentralRole objects
377          * 
378          * @param answer
379          * @return
380          */
381         public CentralRole convertV2CentralRoleToOldVerisonCentralRole(CentralV2Role answer);
382
383         /**
384          * 
385          * Returns list of EPRole Objects if exists
386          * 
387          * @param app
388          * @return List of EPRole objects
389          */
390         Map<String, EPRole> getCurrentRolesInDB(EPApp app);
391     
392         
393         /**
394          * 
395          * It uploads list of users for single role when role name is re-named
396          * 
397          * @param header
398          * @param roleId
399          * @param roleName 
400          * @return number of user roles added in External Auth System
401          * @throws Exception 
402          */
403         public Integer bulkUploadUsersSingleRole(String uebkey, Long roleId, String roleName) throws Exception;
404         
405         /**
406          * 
407          * It returns JSON array of external auth roles and its corresponding functions
408          * 
409          * @param app
410          * @return JSON Array
411          * @throws Exception
412          */
413         public JSONArray getAppRolesJSONFromExtAuthSystem(EPApp app) throws Exception;
414         
415         /**
416          * It encodes the function code  based on Hex encoding
417          * @param funCode
418          * 
419          */
420         public String encodeFunctionCode(String funCode);
421         
422         /**
423          * 
424          * It returns list of ExternalRoleDetails which is converted from JSON array of roles
425          * 
426          * @param app 
427          * @param mapper
428          * @param extRole contains external auth application roles JSON array
429          * @return List of ExternalRoleDetails objects
430          * @throws IOException
431          * @throws JsonParseException
432          * @throws JsonMappingException
433          */
434         public List<ExternalRoleDetails> getExternalRoleDetailsList(EPApp app,
435                         ObjectMapper mapper, JSONArray extRole) throws IOException, JsonParseException, JsonMappingException;
436         
437         public JSONArray getAllUsersByRole(String roleName) throws Exception;
438         
439         /**
440          * 
441          * It check function code has any pipes, if found return function type
442          * 
443          * @param roleFuncItem
444          * @param type
445          * @return function type
446          */
447         String getFunctionCodeType(String roleFuncItem);
448         
449         /**
450          * It return function action
451          * 
452          * @param roleFuncItem
453          * @return String action
454          */
455         String getFunctionCodeAction(String roleFuncItem);
456         
457         /**
458          * 
459          * Adds function to role in external auth system
460          * 
461          * @param data
462          * @param app
463          */
464         void bulkUploadRoleFunc(UploadRoleFunctionExtSystem data, EPApp app) throws Exception;
465
466         /**
467          * 
468          * Syncs user roles from external auth system to ecomp portal 
469          * 
470          * @param orgUserId
471          * @throws Exception 
472          */
473         public void syncApplicationUserRolesFromExtAuthSystem(String orgUserId) throws Exception;
474
475         /**
476          * 
477          * Gets all user roles from external auth system
478          * 
479          * @param orgUserId
480          * @param getUserRolesEntity
481          * @return user roles from external auth system 
482          */
483         ResponseEntity<String> getUserRolesFromExtAuthSystem(String orgUserId, HttpEntity<String> getUserRolesEntity) throws Exception;
484
485 }