- public void SyncApplicationRolesWithEcompDB(EPApp app){
- try{
- ResponseEntity<String> response = null;
- List<EPRole> finalRoleList = new ArrayList<>();
- ExternalRoleDescription ApplicationRole = new ExternalRoleDescription();
- ExternalAccessPerms externalAccessPerms = null;
- List<String> functionCodelist = new ArrayList<>();
- List<ExternalRoleDetails> externalRoleDetailsList = new ArrayList<>();
- ObjectMapper mapper = new ObjectMapper();
- HttpHeaders headers = EcompPortalUtils.base64encodeKeyForAAFBasicAuth();
- HttpEntity<String> entity = new HttpEntity<>(headers);
- logger.debug(EELFLoggerDelegate.debugLogger, "Connecting to External Access system");
- response = template.exchange(SystemProperties.getProperty(EPCommonSystemProperties.EXTERNAL_CENTRAL_ACCESS_URL)
- + "roles/ns/" + app.getNameSpace(), HttpMethod.GET, entity, String.class);
- String res = response.getBody();
- logger.debug(EELFLoggerDelegate.debugLogger, "Connected to External Access system and the result is :", res);
- JSONObject jsonObj = new JSONObject(res);
- JSONArray extRole = jsonObj.getJSONArray("role");
- for (int i = 0; i < extRole.length(); i++) {
- if (extRole.getJSONObject(i).getString("name").equals(app.getNameSpace() + ".admin")
- || extRole.getJSONObject(i).getString("name").equals(app.getNameSpace() + ".owner")
- ) {
- extRole.remove(i);
- i--;
- }
- if(!app.getId().equals(PortalConstants.PORTAL_APP_ID) && extRole.getJSONObject(i).get("name").equals(app.getNameSpace()+"."+PortalConstants.ADMIN_ROLE.replaceAll(" ", "_"))){
- extRole.remove(i);
- i--;
- }
- }
- List<EPAppRoleFunction> applicationRoleFunctionList = new ArrayList<>();
- for (int i = 0; i < extRole.length(); i++) {
- ExternalRoleDetails externalRoleDetail = new ExternalRoleDetails();
- EPAppRoleFunction ePAppRoleFunction = new EPAppRoleFunction();
- JSONObject Role = (JSONObject) extRole.get(i);
- if(!extRole.getJSONObject(i).has("description"))
- {
- ApplicationRole.setActive("true");
- ApplicationRole.setAppId("null");
- ApplicationRole.setPriority("null");
- ApplicationRole.setAppRoleId("null");
- String roleName =extRole.getJSONObject(i).getString("name");
- ApplicationRole.setName(roleName.substring(app.getNameSpace().length()+1));
- }
- else {
- String desc = extRole.getJSONObject(i).getString("description");
- ApplicationRole = mapper.readValue(desc, ExternalRoleDescription.class);
+ public void syncApplicationRolesWithEcompDB(EPApp app) {
+ try {
+ ResponseEntity<String> response = null;
+ List<EPRole> finalRoleList = new ArrayList<>();
+ ExternalRoleDescription ApplicationRole = new ExternalRoleDescription();
+ ExternalAccessPerms externalAccessPerms = null;
+ List<String> functionCodelist = new ArrayList<>();
+ List<ExternalRoleDetails> externalRoleDetailsList = new ArrayList<>();
+ ObjectMapper mapper = new ObjectMapper();
+ HttpHeaders headers = EcompPortalUtils.base64encodeKeyForAAFBasicAuth();
+ HttpEntity<String> entity = new HttpEntity<>(headers);
+ logger.debug(EELFLoggerDelegate.debugLogger, "syncApplicationRolesWithEcompDB: {} " , CONNECTING_TO_EXTERNAL_AUTH_SYSTEM_LOG_MESSAGE);
+ response = template
+ .exchange(SystemProperties.getProperty(EPCommonSystemProperties.EXTERNAL_CENTRAL_ACCESS_URL)
+ + "roles/ns/" + app.getNameSpace(), HttpMethod.GET, entity, String.class);
+ String res = response.getBody();
+ logger.debug(EELFLoggerDelegate.debugLogger, "syncApplicationRolesWithEcompDB: Finished GET roles from External Auth system and the result is :",
+ res);
+ JSONObject jsonObj = new JSONObject(res);
+ JSONArray extRole = jsonObj.getJSONArray("role");
+ for (int i = 0; i < extRole.length(); i++) {
+ if (extRole.getJSONObject(i).getString(ROLE_NAME).equals(app.getNameSpace() + ".admin")
+ || extRole.getJSONObject(i).getString(ROLE_NAME).equals(app.getNameSpace() + ".owner")) {
+ extRole.remove(i);
+ i--;
+ }
+ if (!app.getId().equals(PortalConstants.PORTAL_APP_ID) && extRole.getJSONObject(i).get(ROLE_NAME)
+ .equals(app.getNameSpace() + "." + PortalConstants.ADMIN_ROLE.replaceAll(" ", "_"))) {
+ extRole.remove(i);
+ i--;
+ }