Search in sources :

Example 1 with APIException

use of org.wso2.carbon.rest.api.APIException in project carbon-identity-framework by wso2.

the class IdentityManagementEndpointUtil method getBasePath.

/**
 * Get base path URL for API clients.
 *
 * @param tenantDomain          Tenant Domain.
 * @param context               URL context.
 * @param isEndpointTenantAware Whether the endpoint is tenant aware.
 * @return Base path.
 * @throws ApiException ApiException.
 */
public static String getBasePath(String tenantDomain, String context, boolean isEndpointTenantAware) throws ApiException {
    String basePath;
    String serverUrl = IdentityManagementServiceUtil.getInstance().getContextURLFromFile();
    try {
        if (StringUtils.isBlank(serverUrl)) {
            if (IdentityTenantUtil.isTenantQualifiedUrlsEnabled()) {
                basePath = ServiceURLBuilder.create().addPath(context).setTenant(tenantDomain).build().getAbsoluteInternalURL();
            } else {
                serverUrl = ServiceURLBuilder.create().build().getAbsoluteInternalURL();
                if (StringUtils.isNotBlank(tenantDomain) && !MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equalsIgnoreCase(tenantDomain) && isEndpointTenantAware) {
                    basePath = serverUrl + "/t/" + tenantDomain + context;
                } else {
                    basePath = serverUrl + context;
                }
            }
        } else {
            if (StringUtils.isNotBlank(tenantDomain) && !MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equalsIgnoreCase(tenantDomain) && isEndpointTenantAware) {
                basePath = serverUrl + "/t/" + tenantDomain + context;
            } else {
                basePath = serverUrl + context;
            }
        }
    } catch (URLBuilderException e) {
        throw new ApiException("Error while building url for context: " + context);
    }
    return basePath;
}
Also used : URLBuilderException(org.wso2.carbon.identity.core.URLBuilderException) ApiException(org.wso2.carbon.identity.mgt.endpoint.util.client.ApiException)

Example 2 with APIException

use of org.wso2.carbon.rest.api.APIException in project carbon-identity-framework by wso2.

the class LiteRegisterApi method introspectCode.

/**
 * This API is used to validate code of self registered lite users.
 *
 * @param code Code retried after lite user registration and optional property parameters (required)
 * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
 */
public CodeIntrospectResponse introspectCode(CodeValidationRequest code) throws ApiException {
    Object localVarPostBody = code;
    // verify the required parameter 'code' is set
    if (code == null) {
        throw new ApiException(400, "Missing the required parameter 'code' when introspecting code");
    }
    String tenantDomain = MultitenantConstants.SUPER_TENANT_DOMAIN_NAME;
    List<Property> properties = code.getProperties();
    for (Property property : properties) {
        if (StringUtils.isNotEmpty(property.getKey()) && MultitenantConstants.TENANT_DOMAIN.equals(property.getKey())) {
            tenantDomain = property.getValue();
        }
    }
    basePath = IdentityManagementEndpointUtil.getBasePath(tenantDomain, IdentityManagementEndpointConstants.UserInfoRecovery.USER_API_RELATIVE_PATH);
    apiClient.setBasePath(basePath);
    // create path and map variables
    String localVarPath = "/introspect-code".replaceAll("\\{format\\}", "json");
    List<Pair> localVarQueryParams = new ArrayList<Pair>();
    Map<String, String> localVarHeaderParams = new HashMap<String, String>();
    Map<String, Object> localVarFormParams = new HashMap<String, Object>();
    final String[] localVarAccepts = { "application/json" };
    final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
    if (localVarAccept != null)
        localVarHeaderParams.put("Accept", localVarAccept);
    final String[] localVarContentTypes = { "application/json" };
    final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);
    localVarHeaderParams.put("Content-Type", localVarContentType);
    String[] localVarAuthNames = new String[] {};
    GenericType<CodeIntrospectResponse> localVarReturnType = new GenericType<CodeIntrospectResponse>() {
    };
    return apiClient.invokeAPI(localVarPath, "POST", localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAccept, localVarContentType, localVarAuthNames, localVarReturnType);
}
Also used : CodeIntrospectResponse(org.wso2.carbon.identity.mgt.endpoint.util.client.model.CodeIntrospectResponse) GenericType(com.sun.jersey.api.client.GenericType) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Property(org.wso2.carbon.identity.mgt.endpoint.util.client.model.Property) ApiException(org.wso2.carbon.identity.mgt.endpoint.util.client.ApiException) Pair(org.wso2.carbon.identity.mgt.endpoint.util.client.Pair)

Example 3 with APIException

use of org.wso2.carbon.rest.api.APIException in project carbon-identity-framework by wso2.

the class NotificationApi method setUserPasswordPost.

/**
 * This API will be used to reset user password using the confirmation key received through recovery process.
 *
 * @param resetPasswordRequest The request for password reset.
 * @return The user object.
 * @throws ApiException API exception.
 */
public User setUserPasswordPost(ResetPasswordRequest resetPasswordRequest) throws ApiException {
    Object localVarPostBody = resetPasswordRequest;
    // verify the required parameter 'resetPasswordRequest' is set
    if (resetPasswordRequest == null) {
        throw new ApiException(400, "Missing the required parameter 'resetPasswordRequest' when calling setPasswordPost");
    }
    String userTenantDomain = MultitenantConstants.SUPER_TENANT_DOMAIN_NAME;
    List<Property> properties = resetPasswordRequest.getProperties();
    for (Property property : properties) {
        if (StringUtils.equalsIgnoreCase(IdentityManagementEndpointConstants.TENANT_DOMAIN, property.getKey())) {
            userTenantDomain = property.getValue();
            properties.remove(property);
            break;
        }
    }
    basePath = IdentityManagementEndpointUtil.getBasePath(userTenantDomain, IdentityManagementEndpointConstants.UserInfoRecovery.RECOVERY_API_RELATIVE_PATH);
    apiClient.setBasePath(basePath);
    // create path and map variables
    String localVarPath = "/set-password".replaceAll("\\{format\\}", "json");
    // query params
    List<Pair> localVarQueryParams = new ArrayList<Pair>();
    Map<String, String> localVarHeaderParams = new HashMap<String, String>();
    Map<String, Object> localVarFormParams = new HashMap<String, Object>();
    final String[] localVarAccepts = { "application/json" };
    final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
    final String[] localVarContentTypes = { "application/json" };
    final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);
    String[] localVarAuthNames = new String[] {};
    GenericType<User> localVarReturnType = new GenericType<User>() {
    };
    return apiClient.invokeAPI(localVarPath, "POST", localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAccept, localVarContentType, localVarAuthNames, localVarReturnType);
}
Also used : GenericType(com.sun.jersey.api.client.GenericType) User(org.wso2.carbon.identity.mgt.endpoint.util.client.model.User) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Property(org.wso2.carbon.identity.mgt.endpoint.util.client.model.Property) ApiException(org.wso2.carbon.identity.mgt.endpoint.util.client.ApiException) Pair(org.wso2.carbon.identity.mgt.endpoint.util.client.Pair)

Example 4 with APIException

use of org.wso2.carbon.rest.api.APIException in project carbon-identity-framework by wso2.

the class NotificationApi method setPasswordPost.

/**
 * This API will be used to reset user password using the confirmatin key recieved through recovery process.
 * Need to input &#x60;key&#x60;  and the new &#x60;password&#x60;.
 *
 * @param resetPasswordRequest key, password and optional metadata properties (required)
 * @throws ApiException if fails to make API call
 */
public void setPasswordPost(ResetPasswordRequest resetPasswordRequest, Map<String, String> localVarHeaderParams) throws ApiException {
    Object localVarPostBody = resetPasswordRequest;
    // verify the required parameter 'resetPasswordRequest' is set
    if (resetPasswordRequest == null) {
        throw new ApiException(400, "Missing the required parameter 'resetPasswordRequest' when calling setPasswordPost");
    }
    String userTenantDomain = MultitenantConstants.SUPER_TENANT_DOMAIN_NAME;
    List<Property> properties = resetPasswordRequest.getProperties();
    for (Property property : properties) {
        if (StringUtils.equalsIgnoreCase(IdentityManagementEndpointConstants.TENANT_DOMAIN, property.getKey())) {
            userTenantDomain = property.getValue();
            properties.remove(property);
            break;
        }
    }
    basePath = IdentityManagementEndpointUtil.getBasePath(userTenantDomain, IdentityManagementEndpointConstants.UserInfoRecovery.RECOVERY_API_RELATIVE_PATH);
    apiClient.setBasePath(basePath);
    // create path and map variables
    String localVarPath = "/set-password".replaceAll("\\{format\\}", "json");
    // query params
    List<Pair> localVarQueryParams = new ArrayList<Pair>();
    Map<String, Object> localVarFormParams = new HashMap<String, Object>();
    final String[] localVarAccepts = { "application/json" };
    final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
    final String[] localVarContentTypes = { "application/json" };
    final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);
    String[] localVarAuthNames = new String[] {};
    apiClient.invokeAPI(localVarPath, "POST", localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAccept, localVarContentType, localVarAuthNames, null);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Property(org.wso2.carbon.identity.mgt.endpoint.util.client.model.Property) ApiException(org.wso2.carbon.identity.mgt.endpoint.util.client.ApiException) Pair(org.wso2.carbon.identity.mgt.endpoint.util.client.Pair)

Example 5 with APIException

use of org.wso2.carbon.rest.api.APIException in project carbon-identity-framework by wso2.

the class NotificationApi method setPasswordPost.

/**
 * This API will be used to reset user password using the confirmatin key recieved through recovery process.
 * Need to input &#x60;key&#x60;  and the new &#x60;password&#x60;.
 *
 * @param resetPasswordRequest key, password and optional metadata properties (required)
 * @throws ApiException if fails to make API call
 */
public void setPasswordPost(ResetPasswordRequest resetPasswordRequest) throws ApiException {
    Object localVarPostBody = resetPasswordRequest;
    // verify the required parameter 'resetPasswordRequest' is set
    if (resetPasswordRequest == null) {
        throw new ApiException(400, "Missing the required parameter 'resetPasswordRequest' when calling setPasswordPost");
    }
    String userTenantDomain = MultitenantConstants.SUPER_TENANT_DOMAIN_NAME;
    List<Property> properties = resetPasswordRequest.getProperties();
    for (Property property : properties) {
        if (StringUtils.equalsIgnoreCase(IdentityManagementEndpointConstants.TENANT_DOMAIN, property.getKey())) {
            userTenantDomain = property.getValue();
            properties.remove(property);
            break;
        }
    }
    basePath = IdentityManagementEndpointUtil.getBasePath(userTenantDomain, IdentityManagementEndpointConstants.UserInfoRecovery.RECOVERY_API_RELATIVE_PATH);
    apiClient.setBasePath(basePath);
    // create path and map variables
    String localVarPath = "/set-password".replaceAll("\\{format\\}", "json");
    // query params
    List<Pair> localVarQueryParams = new ArrayList<Pair>();
    Map<String, String> localVarHeaderParams = new HashMap<String, String>();
    Map<String, Object> localVarFormParams = new HashMap<String, Object>();
    final String[] localVarAccepts = { "application/json" };
    final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
    final String[] localVarContentTypes = { "application/json" };
    final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);
    String[] localVarAuthNames = new String[] {};
    apiClient.invokeAPI(localVarPath, "POST", localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAccept, localVarContentType, localVarAuthNames, null);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Property(org.wso2.carbon.identity.mgt.endpoint.util.client.model.Property) ApiException(org.wso2.carbon.identity.mgt.endpoint.util.client.ApiException) Pair(org.wso2.carbon.identity.mgt.endpoint.util.client.Pair)

Aggregations

API (org.apache.synapse.api.API)16 Lock (java.util.concurrent.locks.Lock)10 SynapseConfiguration (org.apache.synapse.config.SynapseConfiguration)10 APIException (org.wso2.carbon.rest.api.APIException)9 APIGenException (org.wso2.carbon.mediation.commons.rest.api.swagger.APIGenException)8 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)8 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)7 XMLStreamException (javax.xml.stream.XMLStreamException)7 ApiException (org.wso2.carbon.identity.mgt.endpoint.util.client.ApiException)7 IOException (java.io.IOException)6 MalformedURLException (java.net.MalformedURLException)6 SocketException (java.net.SocketException)6 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 Pair (org.wso2.carbon.identity.mgt.endpoint.util.client.Pair)6 Property (org.wso2.carbon.identity.mgt.endpoint.util.client.model.Property)6 MediationPersistenceManager (org.wso2.carbon.mediation.initializer.persistence.MediationPersistenceManager)6 GenericType (com.sun.jersey.api.client.GenericType)4 AspectConfiguration (org.apache.synapse.aspects.AspectConfiguration)4 QName (javax.xml.namespace.QName)3