use of org.wso2.broker.amqp.Server in project carbon-apimgt by wso2.
the class RestApiUtil method handleMigrationSpecificPermissionViolations.
/**
* Handle if any cross tenant access permission violations detected. Cross tenant resources (apis/apps) can be
* retrieved only by super tenant admin user, only while a migration process(2.6.0 to 3.0.0). APIM server has to be
* started with the system property 'migrationMode=true' if a migration related exports are to be done.
*
* @param targetTenantDomain Tenant domain of which resources are requested
* @param username Logged in user name
* @throws ForbiddenException
*/
public static void handleMigrationSpecificPermissionViolations(String targetTenantDomain, String username) throws ForbiddenException {
boolean isCrossTenantAccess = !targetTenantDomain.equals(MultitenantUtils.getTenantDomain(username));
if (!isCrossTenantAccess) {
return;
}
String superAdminRole = null;
try {
superAdminRole = ServiceReferenceHolder.getInstance().getRealmService().getTenantUserRealm(MultitenantConstants.SUPER_TENANT_ID).getRealmConfiguration().getAdminRoleName();
} catch (UserStoreException e) {
RestApiUtil.handleInternalServerError("Error in getting super admin role name", e, log);
}
// check whether logged in user is a super tenant user
String superTenantDomain = null;
try {
superTenantDomain = ServiceReferenceHolder.getInstance().getRealmService().getTenantManager().getSuperTenantDomain();
} catch (UserStoreException e) {
RestApiUtil.handleInternalServerError("Error in getting the super tenant domain", e, log);
}
boolean isSuperTenantUser = RestApiCommonUtil.getLoggedInUserTenantDomain().equals(superTenantDomain);
if (!isSuperTenantUser) {
String errorMsg = "Cross Tenant resource access is not allowed for this request. User " + username + " is not allowed to access resources in " + targetTenantDomain + " as the requester is not a super " + "tenant user";
log.error(errorMsg);
ErrorDTO errorDTO = getErrorDTO(RestApiConstants.STATUS_FORBIDDEN_MESSAGE_DEFAULT, 403l, errorMsg);
throw new ForbiddenException(errorDTO);
}
// check whether the user has super tenant admin role
boolean isSuperAdminRoleNameExist = false;
try {
isSuperAdminRoleNameExist = APIUtil.isUserInRole(username, superAdminRole);
} catch (UserStoreException | APIManagementException e) {
RestApiUtil.handleInternalServerError("Error in checking whether the user has admin role", e, log);
}
if (!isSuperAdminRoleNameExist) {
String errorMsg = "Cross Tenant resource access is not allowed for this request. User " + username + " is not allowed to access resources in " + targetTenantDomain + " as the requester is not a " + "super tenant admin";
log.error(errorMsg);
ErrorDTO errorDTO = getErrorDTO(RestApiConstants.STATUS_FORBIDDEN_MESSAGE_DEFAULT, 403l, errorMsg);
throw new ForbiddenException(errorDTO);
}
}
use of org.wso2.broker.amqp.Server in project carbon-apimgt by wso2.
the class BrokerManager method start.
/**
* Starting the broker
*/
public static void start() {
try {
StartupContext startupContext = new StartupContext();
initConfigProvider(startupContext);
BrokerConfigProvider service = startupContext.getService(BrokerConfigProvider.class);
BrokerConfiguration brokerConfiguration = service.getConfigurationObject(BrokerConfiguration.NAMESPACE, BrokerConfiguration.class);
DataSource dataSource = getDataSource(brokerConfiguration.getDataSource());
startupContext.registerService(DataSource.class, dataSource);
restServer = new BrokerRestServer(startupContext);
broker = new Broker(startupContext);
broker.startMessageDelivery();
amqpServer = new Server(startupContext);
amqpServer.start();
restServer.start();
loadUsers();
} catch (Exception e) {
log.error("Error while starting broker", e);
}
}
use of org.wso2.broker.amqp.Server in project carbon-apimgt by wso2.
the class ThreatProtectionPoliciesApiServiceImpl method threatProtectionPoliciesGet.
/**
* Get a list of all threat protection policies
*
* @param request
* @return List of threat protection policies
* @throws NotFoundException
*/
@Override
public Response threatProtectionPoliciesGet(Request request) throws NotFoundException {
try {
APIMgtAdminService apiMgtAdminService = APIManagerFactory.getInstance().getAPIMgtAdminService();
List<ThreatProtectionPolicy> policyList = apiMgtAdminService.getThreatProtectionPolicyList();
ThreatProtectionPolicyListDTO listDTO = new ThreatProtectionPolicyListDTO();
for (ThreatProtectionPolicy policy : policyList) {
listDTO.addListItem(MappingUtil.toThreatProtectionPolicyDTO(policy));
}
return Response.ok().entity(listDTO).build();
} catch (APIManagementException e) {
log.error(e.getMessage(), e);
}
return Response.status(500).entity("Internal Server Error.").build();
}
use of org.wso2.broker.amqp.Server in project carbon-apimgt by wso2.
the class ThreatProtectionPoliciesApiServiceImpl method threatProtectionPoliciesThreatProtectionPolicyIdGet.
/**
* Get a specific threat protection policy
*
* @param threatProtectionPolicyId ID of the policy to be retrieved
* @param request
* @return Threat protection policy
* @throws NotFoundException
*/
@Override
public Response threatProtectionPoliciesThreatProtectionPolicyIdGet(String threatProtectionPolicyId, Request request) throws NotFoundException {
try {
APIMgtAdminService apiMgtAdminService = APIManagerFactory.getInstance().getAPIMgtAdminService();
ThreatProtectionPolicyDTO dto = ThreatProtectionMappingUtil.toThreatProtectionPolicyDTO(apiMgtAdminService.getThreatProtectionPolicy(threatProtectionPolicyId));
return Response.ok().entity(dto).build();
} catch (APIManagementException e) {
log.error(e.getMessage(), e);
}
return Response.status(500).entity("Internal Server Error.").build();
}
use of org.wso2.broker.amqp.Server in project carbon-apimgt by wso2.
the class ThreatProtectionPoliciesApiServiceImpl method threatProtectionPoliciesThreatProtectionPolicyIdDelete.
/**
* Delete a threat protection policy
*
* @param threatProtectionPolicyId ID of the threat protection policy
* @param request
* @return HTTP status 200, 500 if failed to delete the policy
* @throws NotFoundException
*/
@Override
public Response threatProtectionPoliciesThreatProtectionPolicyIdDelete(String threatProtectionPolicyId, Request request) throws NotFoundException {
try {
APIMgtAdminService apiMgtAdminService = APIManagerFactory.getInstance().getAPIMgtAdminService();
apiMgtAdminService.deleteThreatProtectionPolicy(threatProtectionPolicyId);
return Response.ok().build();
} catch (APIManagementException e) {
log.error(e.getMessage(), e);
}
return Response.status(500).entity("Internal Server Error.").build();
}
Aggregations