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