import org.openecomp.portalapp.portal.domain.EPUserApp;
import org.openecomp.portalapp.portal.domain.ExternalRoleDetails;
import org.openecomp.portalapp.portal.logging.aop.EPMetricsLog;
+import org.openecomp.portalapp.portal.logging.logic.EPLogUtil;
import org.openecomp.portalapp.portal.transport.BulkUploadRoleFunction;
import org.openecomp.portalapp.portal.transport.BulkUploadUserRoles;
import org.openecomp.portalapp.portal.transport.CentralApp;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.RestTemplate;
import com.fasterxml.jackson.core.JsonProcessingException;
List <EPRole> getRoleCreated = null;
if (!app.getId().equals(PortalConstants.PORTAL_APP_ID)) {
List<EPRole> roleCreated = dataAccessService.getList(EPRole.class,
- " where role_name = '" + addRoleInDB.getName() +"'", null, null);
+ " where role_name = '" + addRoleInDB.getName() +"' and app_id = "+ app.getId(), null, null);
EPRole epUpdateRole = roleCreated.get(0);
epUpdateRole.setAppRoleId(epUpdateRole.getId());
dataAccessService.saveDomainObject(epUpdateRole, null);
getRoleCreated = dataAccessService.getList(EPRole.class,
- " where role_name = '" + addRoleInDB.getName() +"'", null, null);
+ " where role_name = '" + addRoleInDB.getName() +"' and app_id = "+ app.getId() , null, null);
} else{
getRoleCreated = dataAccessService.getList(EPRole.class,
- " where role_name = '" + addRoleInDB.getName() +"'", null, null);
+ " where role_name = '" + addRoleInDB.getName() +"' and app_id is null", null, null);
}
// Add role in External Access system
boolean response = addNewRoleInExternalSystem(getRoleCreated, app);
if (((epApp.getId().equals(app.getId()))
&& (!userApp.getRole().getId().equals(PortalConstants.ACCOUNT_ADMIN_ROLE_ID)))
|| ((epApp.getId().equals(PortalConstants.PORTAL_APP_ID))
- && (globalRole.startsWith("global_")))) {
+ && (globalRole.toLowerCase().startsWith("global_")))) {
CentralUserApp cua = new CentralUserApp();
cua.setUserId(null);
CentralApp cenApp = new CentralApp(1L, epApp.getCreated(), epApp.getModified(),
roleFunc.getCode(), roleFunc.getName(), null, null);
roleFunctionSet.add(cenRoleFunc);
}
- CentralRole cenRole = new CentralRole(userApp.getRole().getAppRoleId(),
+ Long userRoleId = null;
+ if(globalRole.toLowerCase().startsWith("global_") && epApp.getId().equals(PortalConstants.PORTAL_APP_ID)){
+ userRoleId = userApp.getRole().getId();
+ } else{
+ userRoleId = userApp.getRole().getAppRoleId();
+ }
+ CentralRole cenRole = new CentralRole(userRoleId,
userApp.getRole().getCreated(), userApp.getRole().getModified(),
userApp.getRole().getCreatedId(), userApp.getRole().getModifiedId(),
userApp.getRole().getRowNum(), userApp.getRole().getName(),
} catch (Exception e) {
logger.error(EELFLoggerDelegate.errorLogger, "getRoleFunction failed", e);
- throw new Exception("getRoleFunction failed");
+ throw new Exception("getRoleFunction failed", e);
}
return getRoleFuncList.get(0);
}
+ app.getNameSpace() + "." + checkType + "/" + roleFuncName + "/*",
HttpMethod.GET, getSinglePermEntity, String.class);
if (getResponse.getStatusCode().value() != 200) {
+ EPLogUtil.logExternalAuthAccessAlarm(logger, getResponse.getStatusCode());
throw new Exception(getResponse.getBody());
}
logger.debug(EELFLoggerDelegate.debugLogger, "Connected to External Access system");
SystemProperties.getProperty(EPCommonSystemProperties.EXTERNAL_CENTRAL_ACCESS_URL) + "perm",
HttpMethod.POST, entity, String.class);
logger.debug(EELFLoggerDelegate.debugLogger, "Connected to External Access system");
+ }catch(HttpClientErrorException e){
+ logger.error(EELFLoggerDelegate.errorLogger, "HttpClientErrorException - Failed to add function in external central auth system", e);
+ EPLogUtil.logExternalAuthAccessAlarm(logger, e.getStatusCode());
}catch(Exception e){
- logger.error(EELFLoggerDelegate.errorLogger, "Failed to add fucntion in external central auth system", e);
+ logger.error(EELFLoggerDelegate.errorLogger, "Failed to add function in external central auth system", e);
}
} else {
try{
SystemProperties.getProperty(EPCommonSystemProperties.EXTERNAL_CENTRAL_ACCESS_URL) + "perm",
HttpMethod.PUT, entity, String.class);
logger.debug(EELFLoggerDelegate.debugLogger, "Connected to External Access system");
- } catch(Exception e){
- logger.error(EELFLoggerDelegate.errorLogger, "Failed to add fucntion in external central auth system", e);
+ }catch(HttpClientErrorException e){
+ logger.error(EELFLoggerDelegate.errorLogger, "HttpClientErrorException - Failed to add function in external central auth system", e);
+ EPLogUtil.logExternalAuthAccessAlarm(logger, e.getStatusCode());
+ }catch(Exception e){
+ logger.error(EELFLoggerDelegate.errorLogger, "Failed to add function in external central auth system", e);
}
}
template.exchange(
SystemProperties.getProperty(EPCommonSystemProperties.EXTERNAL_CENTRAL_ACCESS_URL) + "perm?force=true",
HttpMethod.DELETE, entity, String.class);
+ } catch(HttpClientErrorException e){
+ logger.error(EELFLoggerDelegate.errorLogger, "HttpClientErrorException - Failed to delete functions in External System", e);
+ EPLogUtil.logExternalAuthAccessAlarm(logger, e.getStatusCode());
} catch(Exception e){
if(e.getMessage().equalsIgnoreCase("404 Not Found")){
logger.debug(EELFLoggerDelegate.debugLogger, " It seems like function is already deleted in external central auth system but exists in local DB", e.getMessage());
+ epRoleList.get(0).getName().replaceAll(" ", "_") + "\"}";
deleteResponse = deleteRoleInExternalSystem(deleteRoleKey);
if (deleteResponse.getStatusCode().value() != 200) {
+ EPLogUtil.logExternalAuthAccessAlarm(logger, deleteResponse.getStatusCode());
throw new Exception("Failed to delete role in external access system!");
}
logger.debug(EELFLoggerDelegate.debugLogger, "about to commit the transaction");
transaction.commit();
logger.debug(EELFLoggerDelegate.debugLogger, "committed the transaction");
result = true;
- } catch (Exception e) {
+ }catch(HttpClientErrorException e){
+ logger.error(EELFLoggerDelegate.errorLogger, "HttpClientErrorException - Failed to deleteRoleDependeciesRecord", e);
+ EPLogUtil.logExternalAuthAccessAlarm(logger, e.getStatusCode());
+ }catch (Exception e) {
EcompPortalUtils.rollbackTransaction(transaction,
"deleteDependcyRoleRecord rollback, exception = " + e);
logger.error(EELFLoggerDelegate.errorLogger, EcompPortalUtils.getStackTrace(e));
addRoleFunctionInExternalSystem(cenRoleFunc, app);
functionsAdded++;
}
- } catch (Exception e) {
+ }catch(HttpClientErrorException e){
+ logger.error(EELFLoggerDelegate.errorLogger, "HttpClientErrorException - bulkUploadFunctions failed", e);
+ EPLogUtil.logExternalAuthAccessAlarm(logger, e.getStatusCode());
+ }catch (Exception e) {
logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadFunctions failed", e.getMessage(), e);
}
return functionsAdded;
template.exchange(
SystemProperties.getProperty(EPCommonSystemProperties.EXTERNAL_CENTRAL_ACCESS_URL) + "role",
HttpMethod.POST, entity, String.class);
- } catch(Exception e){
+ }catch(HttpClientErrorException e){
+ logger.error(EELFLoggerDelegate.errorLogger, "HttpClientErrorException - Failed to addRoleInExternalSystem", e);
+ EPLogUtil.logExternalAuthAccessAlarm(logger, e.getStatusCode());
+ }catch(Exception e){
if (e.getMessage().equalsIgnoreCase("409 Conflict")) {
logger.error(EELFLoggerDelegate.errorLogger, "Role already exits but does not break functionality");
} else {
}
}
}
+ } catch(HttpClientErrorException e){
+ logger.error(EELFLoggerDelegate.errorLogger, "HttpClientErrorException - Failed to bulkUploadRolesFunctions", e);
+ EPLogUtil.logExternalAuthAccessAlarm(logger, e.getStatusCode());
} catch (Exception e) {
logger.error(EELFLoggerDelegate.errorLogger, "bulkUploadRolesFunctions failed", e);
}
}
logger.debug(EELFLoggerDelegate.debugLogger, "Finished SyncApplicationRolesWithEcompDB");
+ }catch(HttpClientErrorException e){
+ logger.error(EELFLoggerDelegate.errorLogger, "Failed to SyncApplicationRolesWithEcompDB", e);
+ EPLogUtil.logExternalAuthAccessAlarm(logger, e.getStatusCode());
}catch(Exception e){
logger.error(EELFLoggerDelegate.errorLogger, "Failed to SyncApplicationRolesWithEcompDB", e);
}
template.exchange(
SystemProperties.getProperty(EPCommonSystemProperties.EXTERNAL_CENTRAL_ACCESS_URL) + "userRole",
HttpMethod.POST, entity, String.class);
- } catch (Exception e) {
+ }catch(HttpClientErrorException e){
+ logger.error(EELFLoggerDelegate.errorLogger, "HttpClientErrorException - Failed to addUserRoleInExternalSystem", e);
+ EPLogUtil.logExternalAuthAccessAlarm(logger, e.getStatusCode());
+ }catch (Exception e) {
if (e.getMessage().equalsIgnoreCase("409 Conflict")) {
logger.error(EELFLoggerDelegate.errorLogger, "UserRole already exits but does not break functionality");
} else {