|
|
@ -18,6 +18,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
package org.wso2.carbon.apimgt.application.extension.api;
|
|
|
|
package org.wso2.carbon.apimgt.application.extension.api;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
import org.json.simple.JSONObject;
|
|
|
|
import org.json.simple.JSONObject;
|
|
|
@ -95,6 +96,8 @@ public class ApiApplicationRegistrationServiceImpl implements ApiApplicationRegi
|
|
|
|
return Response.status(Response.Status.NOT_ACCEPTABLE).entity("APIs(Tags) are not allowed to this user."
|
|
|
|
return Response.status(Response.Status.NOT_ACCEPTABLE).entity("APIs(Tags) are not allowed to this user."
|
|
|
|
).build();
|
|
|
|
).build();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(PrivilegedCarbonContext.
|
|
|
|
|
|
|
|
getThreadLocalCarbonContext().getUserRealm().getRealmConfiguration().getAdminUserName());
|
|
|
|
String username = APIUtil.getAuthenticatedUser();
|
|
|
|
String username = APIUtil.getAuthenticatedUser();
|
|
|
|
APIManagementProviderService apiManagementProviderService = APIUtil.getAPIManagementProviderService();
|
|
|
|
APIManagementProviderService apiManagementProviderService = APIUtil.getAPIManagementProviderService();
|
|
|
|
String validityPeriod;
|
|
|
|
String validityPeriod;
|
|
|
@ -103,35 +106,27 @@ public class ApiApplicationRegistrationServiceImpl implements ApiApplicationRegi
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
validityPeriod = registrationProfile.getValidityPeriod();
|
|
|
|
validityPeriod = registrationProfile.getValidityPeriod();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String applicationName = "devicetype_app_" + StringUtils.join(registrationProfile.getTags(), "_");
|
|
|
|
ApiApplicationKey apiApplicationKey = apiManagementProviderService.generateAndRetrieveApplicationKeys(
|
|
|
|
ApiApplicationKey apiApplicationKey = apiManagementProviderService.generateAndRetrieveApplicationKeys(
|
|
|
|
registrationProfile.getApplicationName(), registrationProfile.getTags(),
|
|
|
|
applicationName, registrationProfile.getTags(),
|
|
|
|
ApiApplicationConstants.DEFAULT_TOKEN_TYPE, username,
|
|
|
|
ApiApplicationConstants.DEFAULT_TOKEN_TYPE, username,
|
|
|
|
registrationProfile.isAllowedToAllDomains(), validityPeriod);
|
|
|
|
registrationProfile.isAllowedToAllDomains(), validityPeriod);
|
|
|
|
return Response.status(Response.Status.CREATED).entity(apiApplicationKey.toString()).build();
|
|
|
|
return Response.status(Response.Status.CREATED).entity(apiApplicationKey.toString()).build();
|
|
|
|
} catch (APIManagerException e) {
|
|
|
|
} catch (APIManagerException e) {
|
|
|
|
String msg = "Error occurred while registering an application '"
|
|
|
|
String msg = "Error occurred while registering an application with apis '"
|
|
|
|
+ registrationProfile.getApplicationName() + "'";
|
|
|
|
+ StringUtils.join(registrationProfile.getTags(), ",") + "'";
|
|
|
|
log.error(msg, e);
|
|
|
|
log.error(msg, e);
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("false").build();
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("false").build();
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
String msg = "Failed to retrieve the device service";
|
|
|
|
String msg = "Failed to retrieve the device service";
|
|
|
|
log.error(msg, e);
|
|
|
|
log.error(msg, e);
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
|
|
}
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
}
|
|
|
|
String msg = "Failed to access user space.";
|
|
|
|
|
|
|
|
|
|
|
|
@Path("unregister")
|
|
|
|
|
|
|
|
@DELETE
|
|
|
|
|
|
|
|
public Response unregister(@QueryParam("applicationName") String applicationName) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
String username = APIUtil.getAuthenticatedUser() + "@" + APIUtil.getTenantDomainOftheUser();
|
|
|
|
|
|
|
|
APIManagementProviderService apiManagementProviderService = APIUtil.getAPIManagementProviderService();
|
|
|
|
|
|
|
|
apiManagementProviderService.removeAPIApplication(applicationName, username);
|
|
|
|
|
|
|
|
return Response.status(Response.Status.ACCEPTED).build();
|
|
|
|
|
|
|
|
} catch (APIManagerException e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred while removing the application '" + applicationName;
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
log.error(msg, e);
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|