Search in sources :

Example 56 with Server

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);
    }
}
Also used : ForbiddenException(org.wso2.carbon.apimgt.rest.api.util.exception.ForbiddenException) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) ErrorDTO(org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO) UserStoreException(org.wso2.carbon.user.api.UserStoreException)

Example 57 with Server

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);
    }
}
Also used : StartupContext(org.wso2.broker.common.StartupContext) BrokerRestServer(org.wso2.broker.rest.BrokerRestServer) Broker(org.wso2.broker.core.Broker) Server(org.wso2.broker.amqp.Server) BrokerRestServer(org.wso2.broker.rest.BrokerRestServer) BrokerConfiguration(org.wso2.broker.core.configuration.BrokerConfiguration) BrokerConfigProvider(org.wso2.broker.common.BrokerConfigProvider) ConfigurationException(org.wso2.carbon.config.ConfigurationException) HikariDataSource(com.zaxxer.hikari.HikariDataSource) DataSource(javax.sql.DataSource)

Example 58 with Server

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();
}
Also used : APIMgtAdminService(org.wso2.carbon.apimgt.core.api.APIMgtAdminService) ThreatProtectionPolicy(org.wso2.carbon.apimgt.core.models.policy.ThreatProtectionPolicy) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException)

Example 59 with Server

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();
}
Also used : APIMgtAdminService(org.wso2.carbon.apimgt.core.api.APIMgtAdminService) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException)

Example 60 with Server

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();
}
Also used : APIMgtAdminService(org.wso2.carbon.apimgt.core.api.APIMgtAdminService) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException)

Aggregations

APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)28 IOException (java.io.IOException)19 ArrayList (java.util.ArrayList)14 HashMap (java.util.HashMap)14 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)10 File (java.io.File)8 JSONObject (org.json.simple.JSONObject)7 MalformedURLException (java.net.MalformedURLException)6 URL (java.net.URL)6 OMElement (org.apache.axiom.om.OMElement)6 JSONObject (org.json.JSONObject)6 URI (java.net.URI)5 URISyntaxException (java.net.URISyntaxException)5 Test (org.testng.annotations.Test)5 KeyManager (org.wso2.carbon.apimgt.api.model.KeyManager)5 APIMgtAdminService (org.wso2.carbon.apimgt.core.api.APIMgtAdminService)5 BadRequestException (org.wso2.charon3.core.exceptions.BadRequestException)5 Connection (java.sql.Connection)4 SQLException (java.sql.SQLException)4 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)4