Search in sources :

Example 86 with Identifier

use of org.wso2.carbon.apimgt.api.model.Identifier in project carbon-apimgt by wso2.

the class APIUtil method clearResourcePermissions.

/**
 * This function is to set resource permissions based on its visibility
 *
 * @param artifactPath API/Product resource path
 * @throws APIManagementException Throwing exception
 */
public static void clearResourcePermissions(String artifactPath, Identifier id, int tenantId) throws APIManagementException {
    try {
        String resourcePath = RegistryUtils.getAbsolutePath(RegistryContext.getBaseInstance(), APIUtil.getMountedPath(RegistryContext.getBaseInstance(), RegistryConstants.GOVERNANCE_REGISTRY_BASE_PATH) + artifactPath);
        String tenantDomain = MultitenantUtils.getTenantDomain(APIUtil.replaceEmailDomainBack(id.getProviderName()));
        if (!org.wso2.carbon.utils.multitenancy.MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) {
            org.wso2.carbon.user.api.AuthorizationManager authManager = ServiceReferenceHolder.getInstance().getRealmService().getTenantUserRealm(tenantId).getAuthorizationManager();
            authManager.clearResourceAuthorizations(resourcePath);
        } else {
            RegistryAuthorizationManager authorizationManager = new RegistryAuthorizationManager(ServiceReferenceHolder.getUserRealm());
            authorizationManager.clearResourceAuthorizations(resourcePath);
        }
    } catch (UserStoreException e) {
        handleException("Error while adding role permissions to API", e);
    }
}
Also used : RegistryAuthorizationManager(org.wso2.carbon.registry.core.jdbc.realm.RegistryAuthorizationManager) UserStoreException(org.wso2.carbon.user.api.UserStoreException)

Example 87 with Identifier

use of org.wso2.carbon.apimgt.api.model.Identifier in project carbon-apimgt by wso2.

the class APIUtil method isPerAPISequence.

/**
 * Returns true if the sequence is a per API one
 *
 * @param sequenceName
 * @param tenantId
 * @param identifier   API identifier
 * @param sequenceType in/out/fault
 * @return true/false
 * @throws APIManagementException
 */
public static boolean isPerAPISequence(String sequenceName, int tenantId, APIIdentifier identifier, String sequenceType) throws APIManagementException {
    org.wso2.carbon.registry.api.Collection seqCollection = null;
    try {
        UserRegistry registry = ServiceReferenceHolder.getInstance().getRegistryService().getGovernanceSystemRegistry(tenantId);
        if (registry.resourceExists(getSequencePath(identifier, sequenceType))) {
            seqCollection = (org.wso2.carbon.registry.api.Collection) registry.get(getSequencePath(identifier, sequenceType));
            if (seqCollection != null) {
                String[] childPaths = seqCollection.getChildren();
                for (String childPath : childPaths) {
                    Resource sequence = registry.get(childPath);
                    OMElement seqElment = APIUtil.buildOMElement(sequence.getContentStream());
                    if (sequenceName.equals(seqElment.getAttributeValue(new QName("name")))) {
                        return true;
                    }
                }
            }
        }
    } catch (RegistryException e) {
        String msg = "Error while retrieving registry for tenant " + tenantId;
        log.error(msg);
        throw new APIManagementException(msg, e);
    } catch (org.wso2.carbon.registry.api.RegistryException e) {
        String msg = "Error while processing the " + sequenceType + " sequences of " + identifier + " in the registry";
        log.error(msg);
        throw new APIManagementException(msg, e);
    } catch (Exception e) {
        throw new APIManagementException(e.getMessage(), e);
    }
    return false;
}
Also used : QName(javax.xml.namespace.QName) Resource(org.wso2.carbon.registry.core.Resource) APIProductResource(org.wso2.carbon.apimgt.api.model.APIProductResource) APIResource(org.wso2.carbon.apimgt.api.doc.model.APIResource) UserRegistry(org.wso2.carbon.registry.core.session.UserRegistry) OMElement(org.apache.axiom.om.OMElement) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException) KeyStoreException(java.security.KeyStoreException) JSONException(org.json.JSONException) XMLStreamException(javax.xml.stream.XMLStreamException) ClientProtocolException(org.apache.http.client.ClientProtocolException) ExceptionException(org.wso2.carbon.core.commons.stub.loggeduserinfo.ExceptionException) APIMgtInternalException(org.wso2.carbon.apimgt.api.APIMgtInternalException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) URISyntaxException(java.net.URISyntaxException) SignatureException(java.security.SignatureException) RemoteException(java.rmi.RemoteException) CertificateEncodingException(javax.security.cert.CertificateEncodingException) AuthorizationFailedException(org.wso2.carbon.registry.core.secure.AuthorizationFailedException) EventPublisherException(org.wso2.carbon.apimgt.eventing.EventPublisherException) UserStoreException(org.wso2.carbon.user.api.UserStoreException) GovernanceException(org.wso2.carbon.governance.api.exception.GovernanceException) ValidationException(org.everit.json.schema.ValidationException) CryptoException(org.wso2.carbon.core.util.CryptoException) NotifierException(org.wso2.carbon.apimgt.impl.notifier.exceptions.NotifierException) APIMgtResourceNotFoundException(org.wso2.carbon.apimgt.api.APIMgtResourceNotFoundException) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException) KeyManagementException(java.security.KeyManagementException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException) SocketException(java.net.SocketException) APIMgtResourceAlreadyExistsException(org.wso2.carbon.apimgt.api.APIMgtResourceAlreadyExistsException) IndexerException(org.wso2.carbon.registry.indexing.indexer.IndexerException) SAXException(org.xml.sax.SAXException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) APIMgtAuthorizationFailedException(org.wso2.carbon.apimgt.api.APIMgtAuthorizationFailedException) ParseException(org.json.simple.parser.ParseException) MalformedURLException(java.net.MalformedURLException) CertificateException(java.security.cert.CertificateException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException)

Example 88 with Identifier

use of org.wso2.carbon.apimgt.api.model.Identifier in project carbon-apimgt by wso2.

the class APIUtil method getAPIIdentifier.

/**
 * Utility method to get api identifier from api path.
 *
 * @param apiPath Path of the API in registry
 * @return relevant API Identifier
 */
public static APIIdentifier getAPIIdentifier(String apiPath) {
    int length = (APIConstants.API_ROOT_LOCATION + RegistryConstants.PATH_SEPARATOR).length();
    if (!apiPath.contains(APIConstants.API_ROOT_LOCATION + RegistryConstants.PATH_SEPARATOR)) {
        length = (APIConstants.API_IMAGE_LOCATION + RegistryConstants.PATH_SEPARATOR).length();
    }
    if (length <= 0) {
        length = (APIConstants.API_DOC_LOCATION + RegistryConstants.PATH_SEPARATOR).length();
    }
    String relativePath = apiPath.substring(length);
    String[] values = relativePath.split(RegistryConstants.PATH_SEPARATOR);
    if (values.length > 3) {
        return new APIIdentifier(values[0], values[1], values[2]);
    }
    return null;
}
Also used : APIIdentifier(org.wso2.carbon.apimgt.api.model.APIIdentifier) Endpoint(org.wso2.carbon.governance.api.endpoints.dataobjects.Endpoint)

Example 89 with Identifier

use of org.wso2.carbon.apimgt.api.model.Identifier in project carbon-apimgt by wso2.

the class APIAPIProductNameComparator method compare.

@Override
public int compare(Object o1, Object o2) {
    Identifier identifier1;
    Identifier identifier2;
    if (o1 instanceof API) {
        identifier1 = ((API) o1).getId();
    } else {
        identifier1 = ((APIProduct) o1).getId();
    }
    if (o2 instanceof API) {
        identifier2 = ((API) o2).getId();
    } else {
        identifier2 = ((APIProduct) o2).getId();
    }
    Provider provider = new Provider(identifier1.getProviderName(), identifier2.getProviderName());
    Name name = new Name(identifier1.getName(), identifier2.getName());
    Version version = new Version(identifier1.getVersion(), identifier2.getVersion());
    return compareFields(provider, name, version);
}
Also used : Identifier(org.wso2.carbon.apimgt.api.model.Identifier) API(org.wso2.carbon.apimgt.api.model.API)

Example 90 with Identifier

use of org.wso2.carbon.apimgt.api.model.Identifier in project carbon-apimgt by wso2.

the class APIConsumerImpl method getLightweightAPI.

/**
 * Get minimal details of API by API identifier
 *
 * @param identifier APIIdentifier object
 * @return API of the provided APIIdentifier
 * @throws APIManagementException
 */
public API getLightweightAPI(APIIdentifier identifier, String orgId) throws APIManagementException {
    String uuid = null;
    try {
        Organization org = new Organization(orgId);
        if (identifier.getUUID() != null) {
            uuid = identifier.getUUID();
        } else {
            uuid = apiMgtDAO.getUUIDFromIdentifier(identifier.getProviderName(), identifier.getApiName(), identifier.getVersion(), orgId);
        }
        DevPortalAPI devPortalApi = apiPersistenceInstance.getDevPortalAPI(org, uuid);
        if (devPortalApi != null) {
            API api = APIMapper.INSTANCE.toApi(devPortalApi);
            api.setOrganization(orgId);
            return api;
        } else {
            String msg = "Failed to get API. API artifact corresponding to artifactId " + uuid + " does not exist";
            throw new APIMgtResourceNotFoundException(msg);
        }
    } catch (APIPersistenceException e) {
        String msg = "Failed to get API with uuid " + uuid;
        throw new APIManagementException(msg, e);
    }
}
Also used : DevPortalAPI(org.wso2.carbon.apimgt.persistence.dto.DevPortalAPI) APIPersistenceException(org.wso2.carbon.apimgt.persistence.exceptions.APIPersistenceException) Organization(org.wso2.carbon.apimgt.persistence.dto.Organization) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) SubscribedAPI(org.wso2.carbon.apimgt.api.model.SubscribedAPI) DevPortalAPI(org.wso2.carbon.apimgt.persistence.dto.DevPortalAPI) API(org.wso2.carbon.apimgt.api.model.API) APIMgtResourceNotFoundException(org.wso2.carbon.apimgt.api.APIMgtResourceNotFoundException)

Aggregations

APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)118 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)83 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)66 API (org.wso2.carbon.apimgt.api.model.API)42 Resource (org.wso2.carbon.registry.core.Resource)40 APIProductIdentifier (org.wso2.carbon.apimgt.api.model.APIProductIdentifier)39 Test (org.junit.Test)36 PreparedStatement (java.sql.PreparedStatement)34 SQLException (java.sql.SQLException)34 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)34 Connection (java.sql.Connection)33 UserStoreException (org.wso2.carbon.user.core.UserStoreException)31 ResultSet (java.sql.ResultSet)29 ArrayList (java.util.ArrayList)29 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)29 UserRegistry (org.wso2.carbon.registry.core.session.UserRegistry)27 IOException (java.io.IOException)26 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)26 APIProductResource (org.wso2.carbon.apimgt.api.model.APIProductResource)25 HumanTaskException (org.wso2.carbon.humantask.core.engine.HumanTaskException)24