mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Merge branch 'master' of https://github.com/wso2/carbon-device-mgt
This commit is contained in:
commit
a888cf39c0
@ -77,7 +77,18 @@
|
|||||||
<artifactId>commons-httpclient</artifactId>
|
<artifactId>commons-httpclient</artifactId>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.base</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.googlecode.json-simple.wso2</groupId>
|
||||||
|
<artifactId>json-simple</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.user.api</artifactId>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.wso2.carbon</groupId>
|
<groupId>org.wso2.carbon</groupId>
|
||||||
<artifactId>org.wso2.carbon.utils</artifactId>
|
<artifactId>org.wso2.carbon.utils</artifactId>
|
||||||
|
|||||||
@ -53,6 +53,11 @@ public interface ApiApplicationRegistrationService {
|
|||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
Response register(RegistrationProfile registrationProfile);
|
Response register(RegistrationProfile registrationProfile);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method is used to unregister an API application.
|
||||||
|
* @param applicationName name of the application that needs to be unregistered.
|
||||||
|
* @return the response status of request.
|
||||||
|
*/
|
||||||
@DELETE
|
@DELETE
|
||||||
Response unregister(@QueryParam("applicationName") String applicationName);
|
Response unregister(@QueryParam("applicationName") String applicationName);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,6 +26,7 @@ import org.wso2.carbon.apimgt.application.extension.api.util.RegistrationProfile
|
|||||||
import org.wso2.carbon.apimgt.application.extension.constants.ApiApplicationConstants;
|
import org.wso2.carbon.apimgt.application.extension.constants.ApiApplicationConstants;
|
||||||
import org.wso2.carbon.apimgt.application.extension.dto.ApiApplicationKey;
|
import org.wso2.carbon.apimgt.application.extension.dto.ApiApplicationKey;
|
||||||
import org.wso2.carbon.apimgt.application.extension.exception.APIManagerException;
|
import org.wso2.carbon.apimgt.application.extension.exception.APIManagerException;
|
||||||
|
import org.wso2.carbon.base.MultitenantConstants;
|
||||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||||
import org.wso2.carbon.apimgt.application.extension.api.util.APIUtil;
|
import org.wso2.carbon.apimgt.application.extension.api.util.APIUtil;
|
||||||
import org.wso2.carbon.user.api.UserStoreException;
|
import org.wso2.carbon.user.api.UserStoreException;
|
||||||
@ -45,13 +46,16 @@ public class ApiApplicationRegistrationServiceImpl implements ApiApplicationRegi
|
|||||||
@POST
|
@POST
|
||||||
public Response register(@PathParam("tenantDomain") String tenantDomain,
|
public Response register(@PathParam("tenantDomain") String tenantDomain,
|
||||||
@QueryParam("applicationName") String applicationName) {
|
@QueryParam("applicationName") String applicationName) {
|
||||||
Response response;
|
String authenticatedTenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
|
||||||
|
if (authenticatedTenantDomain.equals(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)) {
|
||||||
|
return Response.status(Response.Status.NOT_ACCEPTABLE).build();
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
PrivilegedCarbonContext.startTenantFlow();
|
PrivilegedCarbonContext.startTenantFlow();
|
||||||
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain, true);
|
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain, true);
|
||||||
if (PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId() == -1) {
|
if (PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId() == -1) {
|
||||||
String msg = "Invalid tenant domain : " + tenantDomain;
|
String msg = "Invalid tenant domain : " + tenantDomain;
|
||||||
response = Response.status(Response.Status.NOT_ACCEPTABLE).entity(msg).build();
|
return Response.status(Response.Status.NOT_ACCEPTABLE).entity(msg).build();
|
||||||
}
|
}
|
||||||
String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUserRealm()
|
String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUserRealm()
|
||||||
.getRealmConfiguration().getAdminUserName();
|
.getRealmConfiguration().getAdminUserName();
|
||||||
@ -63,21 +67,19 @@ public class ApiApplicationRegistrationServiceImpl implements ApiApplicationRegi
|
|||||||
} catch (APIManagerException e) {
|
} catch (APIManagerException e) {
|
||||||
String msg = "Error occurred while registering an application '" + applicationName + "'";
|
String msg = "Error occurred while registering an application '" + applicationName + "'";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
response = Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
} catch (UserStoreException e) {
|
} catch (UserStoreException e) {
|
||||||
String msg = "Failed to retrieve the tenant" + tenantDomain + "'";
|
String msg = "Failed to retrieve the tenant" + tenantDomain + "'";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
response = Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
} finally {
|
} finally {
|
||||||
PrivilegedCarbonContext.endTenantFlow();
|
PrivilegedCarbonContext.endTenantFlow();
|
||||||
}
|
}
|
||||||
return response;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Path("register")
|
@Path("register")
|
||||||
@POST
|
@POST
|
||||||
public Response register(RegistrationProfile registrationProfile) {
|
public Response register(RegistrationProfile registrationProfile) {
|
||||||
Response response;
|
|
||||||
try {
|
try {
|
||||||
String username = APIUtil.getAuthenticatedUser();
|
String username = APIUtil.getAuthenticatedUser();
|
||||||
APIManagementProviderService apiManagementProviderService = APIUtil.getAPIManagementProviderService();
|
APIManagementProviderService apiManagementProviderService = APIUtil.getAPIManagementProviderService();
|
||||||
@ -93,8 +95,9 @@ public class ApiApplicationRegistrationServiceImpl implements ApiApplicationRegi
|
|||||||
ApiApplicationConstants.DEFAULT_VALIDITY_PERIOD);
|
ApiApplicationConstants.DEFAULT_VALIDITY_PERIOD);
|
||||||
apiManagementProviderService.registerExistingOAuthApplicationToAPIApplication(
|
apiManagementProviderService.registerExistingOAuthApplicationToAPIApplication(
|
||||||
jsonStringObject.toJSONString(), registrationProfile.getApplicationName(),
|
jsonStringObject.toJSONString(), registrationProfile.getApplicationName(),
|
||||||
registrationProfile.getConsumerKey(), username, registrationProfile.isAllowedToAllDomains());
|
registrationProfile.getConsumerKey(), username, registrationProfile.isAllowedToAllDomains(),
|
||||||
return Response.status(Response.Status.ACCEPTED).entity("OAuth App is mapped as APIM App").build();
|
ApiApplicationConstants.DEFAULT_TOKEN_TYPE);
|
||||||
|
return Response.status(Response.Status.ACCEPTED).entity("true").build();
|
||||||
} else {
|
} else {
|
||||||
ApiApplicationKey apiApplicationKey = apiManagementProviderService.generateAndRetrieveApplicationKeys(
|
ApiApplicationKey apiApplicationKey = apiManagementProviderService.generateAndRetrieveApplicationKeys(
|
||||||
registrationProfile.getApplicationName(), registrationProfile.getTags(),
|
registrationProfile.getApplicationName(), registrationProfile.getTags(),
|
||||||
@ -103,17 +106,15 @@ public class ApiApplicationRegistrationServiceImpl implements ApiApplicationRegi
|
|||||||
}
|
}
|
||||||
} catch (APIManagerException e) {
|
} catch (APIManagerException e) {
|
||||||
String msg = "Error occurred while registering an application '"
|
String msg = "Error occurred while registering an application '"
|
||||||
+ registrationProfile.getApplicationName() + "'";
|
+ registrationProfile.getApplicationName() + "'";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
response = Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("false").build();
|
||||||
}
|
}
|
||||||
return response;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Path("unregister")
|
@Path("unregister")
|
||||||
@DELETE
|
@DELETE
|
||||||
public Response unregister(@QueryParam("applicationName") String applicationName) {
|
public Response unregister(@QueryParam("applicationName") String applicationName) {
|
||||||
Response response;
|
|
||||||
try {
|
try {
|
||||||
String username = APIUtil.getAuthenticatedUser();
|
String username = APIUtil.getAuthenticatedUser();
|
||||||
APIManagementProviderService apiManagementProviderService = APIUtil.getAPIManagementProviderService();
|
APIManagementProviderService apiManagementProviderService = APIUtil.getAPIManagementProviderService();
|
||||||
@ -122,8 +123,7 @@ public class ApiApplicationRegistrationServiceImpl implements ApiApplicationRegi
|
|||||||
} catch (APIManagerException e) {
|
} catch (APIManagerException e) {
|
||||||
String msg = "Error occurred while removing the application '" + applicationName;
|
String msg = "Error occurred while removing the application '" + applicationName;
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
response = Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
}
|
}
|
||||||
return response;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -30,7 +30,7 @@
|
|||||||
<!-- Device related APIs -->
|
<!-- Device related APIs -->
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>Register tenant specific application</name>
|
<name>Register tenant specific application</name>
|
||||||
<path>/permission/super admin</path>
|
<path>/device-mgt</path>
|
||||||
<url>/register/tenants/*</url>
|
<url>/register/tenants/*</url>
|
||||||
<method>POST</method>
|
<method>POST</method>
|
||||||
<scope>super_admin_user</scope>
|
<scope>super_admin_user</scope>
|
||||||
|
|||||||
@ -59,7 +59,7 @@ public interface APIManagementProviderService {
|
|||||||
* Register existing Oauth application as apim application.
|
* Register existing Oauth application as apim application.
|
||||||
*/
|
*/
|
||||||
void registerExistingOAuthApplicationToAPIApplication(String jsonString, String applicationName, String clientId,
|
void registerExistingOAuthApplicationToAPIApplication(String jsonString, String applicationName, String clientId,
|
||||||
String username, boolean isAllowedAllDomains)
|
String username, boolean isAllowedAllDomains, String keyType)
|
||||||
throws APIManagerException;
|
throws APIManagerException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -118,13 +118,47 @@ public class APIManagementProviderServiceImpl implements APIManagementProviderSe
|
|||||||
@Override
|
@Override
|
||||||
public void registerExistingOAuthApplicationToAPIApplication(String jsonString, String applicationName,
|
public void registerExistingOAuthApplicationToAPIApplication(String jsonString, String applicationName,
|
||||||
String clientId, String username,
|
String clientId, String username,
|
||||||
boolean isAllowedAllDomains)
|
boolean isAllowedAllDomains, String keyType)
|
||||||
throws APIManagerException {
|
throws APIManagerException {
|
||||||
try {
|
try {
|
||||||
APIConsumer apiConsumer = APIManagerFactory.getInstance().getAPIConsumer(username);
|
APIConsumer apiConsumer = APIManagerFactory.getInstance().getAPIConsumer(username);
|
||||||
if (apiConsumer != null) {
|
if (apiConsumer != null) {
|
||||||
String groupId = getLoggedInUserGroupId(username, APIManagerUtil.getTenantDomain());
|
String groupId = getLoggedInUserGroupId(username, APIManagerUtil.getTenantDomain());
|
||||||
createApplication(apiConsumer, applicationName, username, groupId);
|
int applicationId = createApplication(apiConsumer, applicationName, username, groupId);
|
||||||
|
Subscriber subscriber = apiConsumer.getSubscriber(username);
|
||||||
|
if (subscriber == null) {
|
||||||
|
String tenantDomain = MultitenantUtils.getTenantDomain(username);
|
||||||
|
addSubscriber(username, "", groupId, APIManagerUtil.getTenantId(tenantDomain));
|
||||||
|
subscriber = apiConsumer.getSubscriber(username);
|
||||||
|
}
|
||||||
|
Application[] applications = apiConsumer.getApplications(subscriber, groupId);
|
||||||
|
Application application = null;
|
||||||
|
for (Application app : applications) {
|
||||||
|
if (app.getId() == applicationId) {
|
||||||
|
application = app;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (application == null) {
|
||||||
|
throw new APIManagerException(
|
||||||
|
"Api application creation failed for " + applicationName + " to the user " + username);
|
||||||
|
}
|
||||||
|
|
||||||
|
APIKey retrievedApiApplicationKey = null;
|
||||||
|
for (APIKey apiKey : application.getKeys()) {
|
||||||
|
String applicationKeyType = apiKey.getType();
|
||||||
|
if (applicationKeyType != null && applicationKeyType.equals(keyType)) {
|
||||||
|
retrievedApiApplicationKey = apiKey;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (retrievedApiApplicationKey != null) {
|
||||||
|
if (retrievedApiApplicationKey.getConsumerKey().equals(clientId)) {
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
throw new APIManagerException("Api application already mapped to another OAuth App");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
String[] allowedDomains = new String[1];
|
String[] allowedDomains = new String[1];
|
||||||
if (isAllowedAllDomains) {
|
if (isAllowedAllDomains) {
|
||||||
allowedDomains[0] = ApiApplicationConstants.ALLOWED_DOMAINS;
|
allowedDomains[0] = ApiApplicationConstants.ALLOWED_DOMAINS;
|
||||||
@ -286,14 +320,18 @@ public class APIManagementProviderServiceImpl implements APIManagementProviderSe
|
|||||||
try {
|
try {
|
||||||
APIConsumer consumer = APIManagerFactory.getInstance().getAPIConsumer(subscriberName);
|
APIConsumer consumer = APIManagerFactory.getInstance().getAPIConsumer(subscriberName);
|
||||||
if (consumer != null) {
|
if (consumer != null) {
|
||||||
Subscriber subscriber = new Subscriber(subscriberName);
|
synchronized (consumer) {
|
||||||
subscriber.setSubscribedDate(new Date());
|
if (consumer.getSubscriber(subscriberName) == null) {
|
||||||
subscriber.setEmail(subscriberEmail);
|
Subscriber subscriber = new Subscriber(subscriberName);
|
||||||
subscriber.setTenantId(tenantId);
|
subscriber.setSubscribedDate(new Date());
|
||||||
consumer.addSubscriber(subscriber, groupId);
|
subscriber.setEmail(subscriberEmail);
|
||||||
if (log.isDebugEnabled()) {
|
subscriber.setTenantId(tenantId);
|
||||||
log.debug("Successfully created subscriber with name : " + subscriberName + " with groupID : " +
|
consumer.addSubscriber(subscriber, groupId);
|
||||||
groupId);
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Successfully created subscriber with name : " + subscriberName +
|
||||||
|
" with groupID : " + groupId);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new APIManagerException("API provider configured for the given API configuration is null. " +
|
throw new APIManagerException("API provider configured for the given API configuration is null. " +
|
||||||
@ -332,8 +370,8 @@ public class APIManagementProviderServiceImpl implements APIManagementProviderSe
|
|||||||
if (userVisibleAPIs != null) {
|
if (userVisibleAPIs != null) {
|
||||||
Set<SubscribedAPI> subscribedAPIs = apiConsumer.getSubscribedAPIs(subscriber, apiApplicationName,
|
Set<SubscribedAPI> subscribedAPIs = apiConsumer.getSubscribedAPIs(subscriber, apiApplicationName,
|
||||||
groupId);
|
groupId);
|
||||||
for (API userVisbleAPI : userVisibleAPIs) {
|
for (API userVisibleAPI : userVisibleAPIs) {
|
||||||
APIIdentifier apiIdentifier = userVisbleAPI.getId();
|
APIIdentifier apiIdentifier = userVisibleAPI.getId();
|
||||||
boolean isSubscribed = false;
|
boolean isSubscribed = false;
|
||||||
if (subscribedAPIs != null) {
|
if (subscribedAPIs != null) {
|
||||||
for (SubscribedAPI subscribedAPI : subscribedAPIs) {
|
for (SubscribedAPI subscribedAPI : subscribedAPIs) {
|
||||||
|
|||||||
@ -26,18 +26,22 @@ import org.wso2.carbon.apimgt.api.APIProvider;
|
|||||||
import org.wso2.carbon.apimgt.api.FaultGatewaysException;
|
import org.wso2.carbon.apimgt.api.FaultGatewaysException;
|
||||||
import org.wso2.carbon.apimgt.api.model.API;
|
import org.wso2.carbon.apimgt.api.model.API;
|
||||||
import org.wso2.carbon.apimgt.api.model.APIIdentifier;
|
import org.wso2.carbon.apimgt.api.model.APIIdentifier;
|
||||||
|
import org.wso2.carbon.apimgt.api.model.APIStatus;
|
||||||
import org.wso2.carbon.apimgt.api.model.URITemplate;
|
import org.wso2.carbon.apimgt.api.model.URITemplate;
|
||||||
import org.wso2.carbon.apimgt.impl.APIManagerFactory;
|
import org.wso2.carbon.apimgt.impl.APIManagerFactory;
|
||||||
import org.wso2.carbon.apimgt.webapp.publisher.internal.APIPublisherDataHolder;
|
import org.wso2.carbon.apimgt.webapp.publisher.internal.APIPublisherDataHolder;
|
||||||
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||||
import org.wso2.carbon.governance.lcm.util.CommonUtil;
|
import org.wso2.carbon.governance.lcm.util.CommonUtil;
|
||||||
import org.wso2.carbon.registry.core.exceptions.RegistryException;
|
import org.wso2.carbon.registry.core.exceptions.RegistryException;
|
||||||
import org.wso2.carbon.registry.core.service.RegistryService;
|
import org.wso2.carbon.registry.core.service.RegistryService;
|
||||||
import org.wso2.carbon.user.api.UserStoreException;
|
|
||||||
import org.wso2.carbon.utils.multitenancy.MultitenantUtils;
|
import org.wso2.carbon.utils.multitenancy.MultitenantUtils;
|
||||||
|
|
||||||
import javax.xml.stream.XMLStreamException;
|
import javax.xml.stream.XMLStreamException;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class represents the concrete implementation of the APIPublisherService that corresponds to providing all
|
* This class represents the concrete implementation of the APIPublisherService that corresponds to providing all
|
||||||
@ -46,83 +50,96 @@ import java.util.List;
|
|||||||
public class APIPublisherServiceImpl implements APIPublisherService {
|
public class APIPublisherServiceImpl implements APIPublisherService {
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(APIPublisherServiceImpl.class);
|
private static final Log log = LogFactory.getLog(APIPublisherServiceImpl.class);
|
||||||
|
private static final String PUBLISH_ACTION = "Publish";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void publishAPI(API api) throws APIManagementException, FaultGatewaysException {
|
public void publishAPI(final API api) throws APIManagementException, FaultGatewaysException {
|
||||||
if (log.isDebugEnabled()) {
|
String tenantDomain = MultitenantUtils.getTenantDomain(api.getApiOwner());
|
||||||
log.debug("Publishing API '" + api.getId() + "'");
|
PrivilegedCarbonContext.startTenantFlow();
|
||||||
}
|
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain, true);
|
||||||
try {
|
try {
|
||||||
String tenantDomain = MultitenantUtils.getTenantDomain(api.getApiOwner());
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
int tenantId =
|
// Below code snippet is added to load API Lifecycle in tenant mode.
|
||||||
APIPublisherDataHolder.getInstance().getRealmService().getTenantManager().getTenantId(tenantDomain);
|
RegistryService registryService = APIPublisherDataHolder.getInstance().getRegistryService();
|
||||||
// Below code snippet is added load API Lifecycle in tenant mode, where in it does not load when tenant is loaded.
|
CommonUtil.addDefaultLifecyclesIfNotAvailable(registryService.getConfigSystemRegistry(tenantId),
|
||||||
RegistryService registryService = APIPublisherDataHolder.getInstance().getRegistryService();
|
CommonUtil.getRootSystemRegistry(tenantId));
|
||||||
CommonUtil.addDefaultLifecyclesIfNotAvailable(registryService.getConfigSystemRegistry(tenantId),
|
APIProvider provider = APIManagerFactory.getInstance().getAPIProvider(api.getApiOwner());
|
||||||
CommonUtil.getRootSystemRegistry(tenantId));
|
MultitenantUtils.getTenantDomain(api.getApiOwner());
|
||||||
APIProvider provider = APIManagerFactory.getInstance().getAPIProvider(api.getApiOwner());
|
if (provider != null) {
|
||||||
MultitenantUtils.getTenantDomain(api.getApiOwner());
|
if (provider.isDuplicateContextTemplate(api.getContext())) {
|
||||||
if (provider != null) {
|
throw new APIManagementException(
|
||||||
if (!provider.isAPIAvailable(api.getId())) {
|
"Error occurred while adding the API. A duplicate API" +
|
||||||
provider.addAPI(api);
|
" context already exists for " + api.getContext());
|
||||||
log.info("Successfully published API '" + api.getId().getApiName() + "' with context '" +
|
}
|
||||||
api.getContext() + "' and version '" + api.getId().getVersion() + "'");
|
if (!provider.isAPIAvailable(api.getId())) {
|
||||||
} else {
|
provider.addAPI(api);
|
||||||
provider.updateAPI(api);
|
provider.changeLifeCycleStatus(api.getId(), PUBLISH_ACTION);
|
||||||
log.info("An API already exists with the name '" + api.getId().getApiName() + "', context '" +
|
if (log.isDebugEnabled()) {
|
||||||
api.getContext() + "' and version '" + api.getId().getVersion() +
|
log.debug("Successfully published API '" + api.getId().getApiName() +
|
||||||
"'. Thus, the API config is updated");
|
"' with context '" + api.getContext() + "' and version '"
|
||||||
}
|
+ api.getId().getVersion() + "'");
|
||||||
provider.saveSwagger20Definition(api.getId(), createSwaggerDefinition(api));
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new APIManagementException("API provider configured for the given API configuration is null. " +
|
api.setStatus(APIStatus.PUBLISHED);
|
||||||
"Thus, the API is not published");
|
provider.updateAPI(api);
|
||||||
}
|
if (log.isDebugEnabled()) {
|
||||||
} catch (UserStoreException e) {
|
log.debug("An API already exists with the name '" + api.getId().getApiName() +
|
||||||
throw new APIManagementException("Failed to get the tenant id for the user " + api.getApiOwner(), e);
|
"', context '" + api.getContext() + "' and version '"
|
||||||
} catch (FileNotFoundException e) {
|
+ api.getId().getVersion() + "'. Thus, the API config is updated");
|
||||||
throw new APIManagementException("Failed to retrieve life cycle file ", e);
|
}
|
||||||
} catch (RegistryException e) {
|
}
|
||||||
throw new APIManagementException("Failed to access the registry ", e);
|
provider.saveSwagger20Definition(api.getId(), createSwaggerDefinition(api));
|
||||||
} catch (XMLStreamException e) {
|
} else {
|
||||||
throw new APIManagementException("Failed parsing the lifecycle xml.", e);
|
throw new APIManagementException("API provider configured for the given API configuration " +
|
||||||
}
|
"is null. Thus, the API is not published");
|
||||||
}
|
}
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
throw new APIManagementException("Failed to retrieve life cycle file ", e);
|
||||||
|
} catch (RegistryException e) {
|
||||||
|
throw new APIManagementException("Failed to access the registry ", e);
|
||||||
|
} catch (XMLStreamException e) {
|
||||||
|
throw new APIManagementException("Failed parsing the lifecycle xml.", e);
|
||||||
|
} finally {
|
||||||
|
PrivilegedCarbonContext.endTenantFlow();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private String createSwaggerDefinition(API api) {
|
private String createSwaggerDefinition(API api) {
|
||||||
//{"paths":{"/controller/*":{"get":{"responses":{"200":{}}}},"/manager/*":{"get":{"responses":{"200":{}}}}},
|
Map<String, JsonObject> httpVerbsMap = new HashMap<>();
|
||||||
// "swagger":"2.0","info":{"title":"RaspberryPi","version":"1.0.0"}}
|
|
||||||
JsonObject swaggerDefinition = new JsonObject();
|
|
||||||
|
|
||||||
JsonObject paths = new JsonObject();
|
for (URITemplate uriTemplate : api.getUriTemplates()) {
|
||||||
for (URITemplate uriTemplate : api.getUriTemplates()) {
|
JsonObject response = new JsonObject();
|
||||||
JsonObject response = new JsonObject();
|
response.addProperty("200", "");
|
||||||
response.addProperty("200", "");
|
|
||||||
|
|
||||||
JsonObject responses = new JsonObject();
|
JsonObject responses = new JsonObject();
|
||||||
responses.add("responses", response);
|
responses.add("responses", response);
|
||||||
|
JsonObject httpVerbs = httpVerbsMap.get(uriTemplate.getUriTemplate());
|
||||||
|
if (httpVerbs == null) {
|
||||||
|
httpVerbs = new JsonObject();
|
||||||
|
}
|
||||||
|
httpVerbs.add(uriTemplate.getHTTPVerb().toLowerCase(), responses);
|
||||||
|
httpVerbsMap.put(uriTemplate.getUriTemplate(), httpVerbs);
|
||||||
|
}
|
||||||
|
|
||||||
JsonObject httpVerb = new JsonObject();
|
Iterator it = httpVerbsMap.entrySet().iterator();
|
||||||
httpVerb.add(uriTemplate.getHTTPVerb().toLowerCase(), responses);
|
JsonObject paths = new JsonObject();
|
||||||
|
while (it.hasNext()) {
|
||||||
|
Map.Entry<String, JsonObject> pair = (Map.Entry) it.next();
|
||||||
|
paths.add(pair.getKey(), pair.getValue());
|
||||||
|
it.remove();
|
||||||
|
}
|
||||||
|
|
||||||
JsonObject path = new JsonObject();
|
JsonObject info = new JsonObject();
|
||||||
path.add(uriTemplate.getUriTemplate(), httpVerb);
|
info.addProperty("title", api.getId().getApiName());
|
||||||
|
info.addProperty("version", api.getId().getVersion());
|
||||||
|
|
||||||
paths.add(uriTemplate.getUriTemplate(), httpVerb);
|
JsonObject swaggerDefinition = new JsonObject();
|
||||||
}
|
swaggerDefinition.add("paths", paths);
|
||||||
swaggerDefinition.add("paths", paths);
|
swaggerDefinition.addProperty("swagger", "2.0");
|
||||||
swaggerDefinition.addProperty("swagger", "2.0");
|
swaggerDefinition.add("info", info);
|
||||||
|
|
||||||
JsonObject info = new JsonObject();
|
return swaggerDefinition.toString();
|
||||||
info.addProperty("title", api.getId().getApiName());
|
}
|
||||||
info.addProperty("version", api.getId().getVersion());
|
|
||||||
swaggerDefinition.add("info", info);
|
|
||||||
|
|
||||||
return swaggerDefinition.toString();
|
|
||||||
//return "{\"paths\":{\"/controller/*\":{\"get\":{\"responses\":{\"200\":{}}}},
|
|
||||||
// \"/manager/*\":{\"get\":{\"responses\":{\"200\":{}}}}},\"swagger\":\"2.0\",
|
|
||||||
// \"info\":{\"title\":\"RaspberryPi\",\"version\":\"1.0.0\"}}";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeAPI(APIIdentifier id) throws APIManagementException {
|
public void removeAPI(APIIdentifier id) throws APIManagementException {
|
||||||
|
|||||||
@ -37,6 +37,7 @@ public class APIPublisherUtil {
|
|||||||
|
|
||||||
private static final String DEFAULT_API_VERSION = "1.0.0";
|
private static final String DEFAULT_API_VERSION = "1.0.0";
|
||||||
public static final String API_VERSION_PARAM="{version}";
|
public static final String API_VERSION_PARAM="{version}";
|
||||||
|
public static final String API_PUBLISH_ENVIRONEMENT = "Production and Sandbox";
|
||||||
|
|
||||||
enum HTTPMethod {
|
enum HTTPMethod {
|
||||||
GET, POST, DELETE, PUT, OPTIONS
|
GET, POST, DELETE, PUT, OPTIONS
|
||||||
@ -75,10 +76,13 @@ public class APIPublisherUtil {
|
|||||||
api.setUrl(config.getEndpoint());
|
api.setUrl(config.getEndpoint());
|
||||||
api.addAvailableTiers(provider.getTiers());
|
api.addAvailableTiers(provider.getTiers());
|
||||||
api.setEndpointSecured(true);
|
api.setEndpointSecured(true);
|
||||||
api.setStatus(APIStatus.PUBLISHED);
|
api.setStatus(APIStatus.CREATED);
|
||||||
api.setTransports(config.getTransports());
|
api.setTransports(config.getTransports());
|
||||||
api.setContextTemplate(config.getContextTemplate());
|
api.setContextTemplate(config.getContextTemplate());
|
||||||
api.setUriTemplates(config.getUriTemplates());
|
api.setUriTemplates(config.getUriTemplates());
|
||||||
|
Set<String> environements = new HashSet<>();
|
||||||
|
environements.add(API_PUBLISH_ENVIRONEMENT);
|
||||||
|
api.setEnvironments(environements);
|
||||||
Set<Tier> tiers = new HashSet<Tier>();
|
Set<Tier> tiers = new HashSet<Tier>();
|
||||||
tiers.add(new Tier(APIConstants.UNLIMITED_TIER));
|
tiers.add(new Tier(APIConstants.UNLIMITED_TIER));
|
||||||
api.addAvailableTiers(tiers);
|
api.addAvailableTiers(tiers);
|
||||||
@ -91,7 +95,7 @@ public class APIPublisherUtil {
|
|||||||
}
|
}
|
||||||
api.setResponseCache(APIConstants.DISABLED);
|
api.setResponseCache(APIConstants.DISABLED);
|
||||||
|
|
||||||
String endpointConfig = "{\"production_endpoints\":{\"url\":\" " + config.getEndpoint() + "\",\"config\":null},\"endpoint_type\":\"http\"}";
|
String endpointConfig = "{\"production_endpoints\":{\"url\":\" " + config.getEndpoint() + "\",\"config\":null},\"implementation_status\":\"managed\",\"endpoint_type\":\"http\"}";
|
||||||
api.setEndpointConfig(endpointConfig);
|
api.setEndpointConfig(endpointConfig);
|
||||||
|
|
||||||
if ("".equals(id.getVersion()) || (DEFAULT_API_VERSION.equals(id.getVersion()))) {
|
if ("".equals(id.getVersion()) || (DEFAULT_API_VERSION.equals(id.getVersion()))) {
|
||||||
|
|||||||
@ -59,7 +59,6 @@ public class APIPublisherServiceComponent {
|
|||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Initializing device management core bundle");
|
log.debug("Initializing device management core bundle");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Registering declarative service instances exposed by DeviceManagementServiceComponent */
|
/* Registering declarative service instances exposed by DeviceManagementServiceComponent */
|
||||||
this.registerServices(componentContext);
|
this.registerServices(componentContext);
|
||||||
|
|
||||||
|
|||||||
@ -25,6 +25,7 @@ import org.apache.catalina.core.StandardContext;
|
|||||||
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.wso2.carbon.apimgt.api.model.*;
|
import org.wso2.carbon.apimgt.api.model.*;
|
||||||
|
import org.wso2.carbon.apimgt.impl.APIConstants;
|
||||||
import org.wso2.carbon.apimgt.webapp.publisher.*;
|
import org.wso2.carbon.apimgt.webapp.publisher.*;
|
||||||
import org.wso2.carbon.apimgt.webapp.publisher.config.APIResource;
|
import org.wso2.carbon.apimgt.webapp.publisher.config.APIResource;
|
||||||
import org.wso2.carbon.apimgt.webapp.publisher.config.APIResourceConfiguration;
|
import org.wso2.carbon.apimgt.webapp.publisher.config.APIResourceConfiguration;
|
||||||
@ -51,7 +52,6 @@ public class APIPublisherLifecycleListener implements LifecycleListener {
|
|||||||
private static final String PARAM_MANAGED_API_TRANSPORTS = "managed-api-transports";
|
private static final String PARAM_MANAGED_API_TRANSPORTS = "managed-api-transports";
|
||||||
private static final String PARAM_MANAGED_API_IS_SECURED = "managed-api-isSecured";
|
private static final String PARAM_MANAGED_API_IS_SECURED = "managed-api-isSecured";
|
||||||
private static final String PARAM_MANAGED_API_APPLICATION = "managed-api-application";
|
private static final String PARAM_MANAGED_API_APPLICATION = "managed-api-application";
|
||||||
private static final String PARAM_MANAGED_API_CONTEXT_TEMPLATE = "managed-api-context-template";
|
|
||||||
private static final String PARAM_SHARED_WITH_ALL_TENANTS = "isSharedWithAllTenants";
|
private static final String PARAM_SHARED_WITH_ALL_TENANTS = "isSharedWithAllTenants";
|
||||||
private static final String PARAM_PROVIDER_TENANT_DOMAIN = "providerTenantDomain";
|
private static final String PARAM_PROVIDER_TENANT_DOMAIN = "providerTenantDomain";
|
||||||
private static final Log log = LogFactory.getLog(APIPublisherLifecycleListener.class);
|
private static final Log log = LogFactory.getLog(APIPublisherLifecycleListener.class);
|
||||||
@ -69,7 +69,7 @@ public class APIPublisherLifecycleListener implements LifecycleListener {
|
|||||||
AnnotationUtil annotationUtil = new AnnotationUtil(context);
|
AnnotationUtil annotationUtil = new AnnotationUtil(context);
|
||||||
Set<String> annotatedAPIClasses = annotationUtil.
|
Set<String> annotatedAPIClasses = annotationUtil.
|
||||||
scanStandardContext(org.wso2.carbon.apimgt.annotations.api.API.class.getName());
|
scanStandardContext(org.wso2.carbon.apimgt.annotations.api.API.class.getName());
|
||||||
List<APIResourceConfiguration> apiDefinitions = annotationUtil.extractAPIInfo(annotatedAPIClasses);
|
List<APIResourceConfiguration> apiDefinitions = annotationUtil.extractAPIInfo(servletContext, annotatedAPIClasses);
|
||||||
|
|
||||||
for (APIResourceConfiguration apiDefinition : apiDefinitions) {
|
for (APIResourceConfiguration apiDefinition : apiDefinitions) {
|
||||||
APIConfig apiConfig = this.buildApiConfig(servletContext, apiDefinition);
|
APIConfig apiConfig = this.buildApiConfig(servletContext, apiDefinition);
|
||||||
@ -156,14 +156,13 @@ public class APIPublisherLifecycleListener implements LifecycleListener {
|
|||||||
apiConfig.setTags(tags);
|
apiConfig.setTags(tags);
|
||||||
}
|
}
|
||||||
|
|
||||||
String contextTemplate = servletContext.getInitParameter(PARAM_MANAGED_API_CONTEXT_TEMPLATE);
|
String tenantDomain = servletContext.getInitParameter(PARAM_PROVIDER_TENANT_DOMAIN);
|
||||||
if (contextTemplate == null || contextTemplate.isEmpty()) {
|
tenantDomain = (tenantDomain != null && !tenantDomain.isEmpty()) ? tenantDomain :
|
||||||
if (log.isDebugEnabled()) {
|
MultitenantConstants.SUPER_TENANT_DOMAIN_NAME;
|
||||||
log.debug("'managed-api-context-template' attribute is not configured. Therefore, using the default," +
|
apiConfig.setTenantDomain(tenantDomain);
|
||||||
" " +
|
String contextTemplate = context + "/" + APIConstants.VERSION_PLACEHOLDER;
|
||||||
"which is the original context template assigned to the web application");
|
if (!tenantDomain.equals(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)) {
|
||||||
}
|
contextTemplate = context + "/t/" + tenantDomain + "/" + APIConstants.VERSION_PLACEHOLDER;
|
||||||
contextTemplate = servletContext.getContextPath();
|
|
||||||
}
|
}
|
||||||
apiConfig.setContextTemplate(contextTemplate);
|
apiConfig.setContextTemplate(contextTemplate);
|
||||||
|
|
||||||
@ -172,7 +171,8 @@ public class APIPublisherLifecycleListener implements LifecycleListener {
|
|||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("'managed-api-endpoint' attribute is not configured");
|
log.debug("'managed-api-endpoint' attribute is not configured");
|
||||||
}
|
}
|
||||||
endpoint = APIPublisherUtil.getApiEndpointUrl(context);
|
String endpointContext = servletContext.getContextPath();
|
||||||
|
endpoint = APIPublisherUtil.getApiEndpointUrl(endpointContext);
|
||||||
}
|
}
|
||||||
apiConfig.setEndpoint(endpoint);
|
apiConfig.setEndpoint(endpoint);
|
||||||
|
|
||||||
@ -208,13 +208,10 @@ public class APIPublisherLifecycleListener implements LifecycleListener {
|
|||||||
apiConfig.setTransports(transports);
|
apiConfig.setTransports(transports);
|
||||||
|
|
||||||
String sharingValueParam = servletContext.getInitParameter(PARAM_SHARED_WITH_ALL_TENANTS);
|
String sharingValueParam = servletContext.getInitParameter(PARAM_SHARED_WITH_ALL_TENANTS);
|
||||||
boolean isSharedWithAllTenants = (sharingValueParam == null || (!sharingValueParam.isEmpty()) && Boolean.parseBoolean(sharingValueParam) );
|
boolean isSharedWithAllTenants = (sharingValueParam == null || (!sharingValueParam.isEmpty()) && Boolean.parseBoolean(
|
||||||
|
sharingValueParam));
|
||||||
apiConfig.setSharedWithAllTenants(isSharedWithAllTenants);
|
apiConfig.setSharedWithAllTenants(isSharedWithAllTenants);
|
||||||
|
|
||||||
String tenantDomain = servletContext.getInitParameter(PARAM_PROVIDER_TENANT_DOMAIN);
|
|
||||||
tenantDomain = (tenantDomain!= null && !tenantDomain.isEmpty()) ? tenantDomain : MultitenantConstants.SUPER_TENANT_DOMAIN_NAME;
|
|
||||||
apiConfig.setTenantDomain(tenantDomain);
|
|
||||||
|
|
||||||
Set<URITemplate> uriTemplates = new LinkedHashSet<URITemplate>();
|
Set<URITemplate> uriTemplates = new LinkedHashSet<URITemplate>();
|
||||||
for (APIResource apiResource : apidef.getResources()) {
|
for (APIResource apiResource : apidef.getResources()) {
|
||||||
URITemplate template = new URITemplate();
|
URITemplate template = new URITemplate();
|
||||||
|
|||||||
@ -92,7 +92,7 @@ public class AnnotationUtil {
|
|||||||
* @param entityClasses
|
* @param entityClasses
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public List<APIResourceConfiguration> extractAPIInfo(Set<String> entityClasses)
|
public List<APIResourceConfiguration> extractAPIInfo(final ServletContext servletContext, Set<String> entityClasses)
|
||||||
throws ClassNotFoundException {
|
throws ClassNotFoundException {
|
||||||
|
|
||||||
List<APIResourceConfiguration> apiResourceConfigs = new ArrayList<APIResourceConfiguration>();
|
List<APIResourceConfiguration> apiResourceConfigs = new ArrayList<APIResourceConfiguration>();
|
||||||
@ -111,7 +111,7 @@ public class AnnotationUtil {
|
|||||||
classLoader.loadClass(org.wso2.carbon.apimgt.annotations.api.API.class.getName());
|
classLoader.loadClass(org.wso2.carbon.apimgt.annotations.api.API.class.getName());
|
||||||
Annotation apiAnno = clazz.getAnnotation(apiClazz);
|
Annotation apiAnno = clazz.getAnnotation(apiClazz);
|
||||||
|
|
||||||
List<APIResource> resourceList = null;
|
List<APIResource> resourceList;
|
||||||
apiResourceConfig = new APIResourceConfiguration();
|
apiResourceConfig = new APIResourceConfiguration();
|
||||||
|
|
||||||
if (apiAnno != null) {
|
if (apiAnno != null) {
|
||||||
@ -139,21 +139,27 @@ public class AnnotationUtil {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// All the apis should map to same root "/"
|
||||||
String rootContext = "";
|
String rootContext = servletContext.getContextPath();
|
||||||
pathClazz = (Class<Path>) classLoader.loadClass(Path.class.getName());
|
pathClazz = (Class<Path>) classLoader.loadClass(Path.class.getName());
|
||||||
pathClazzMethods = pathClazz.getMethods();
|
pathClazzMethods = pathClazz.getMethods();
|
||||||
|
|
||||||
Annotation rootContectAnno = clazz.getAnnotation(pathClazz);
|
Annotation rootContectAnno = clazz.getAnnotation(pathClazz);
|
||||||
|
String subContext = "";
|
||||||
if (rootContectAnno != null) {
|
if (rootContectAnno != null) {
|
||||||
rootContext = invokeMethod(pathClazzMethods[0], rootContectAnno, STRING);
|
subContext = invokeMethod(pathClazzMethods[0], rootContectAnno, STRING);
|
||||||
|
if (subContext != null && !subContext.isEmpty()) {
|
||||||
|
rootContext = rootContext + "/" + subContext;
|
||||||
|
} else {
|
||||||
|
subContext = "";
|
||||||
|
}
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("API Root Context = " + rootContext);
|
log.debug("API Root Context = " + rootContext);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Method[] annotatedMethods = clazz.getDeclaredMethods();
|
Method[] annotatedMethods = clazz.getDeclaredMethods();
|
||||||
resourceList = getApiResources(rootContext, annotatedMethods);
|
resourceList = getApiResources(rootContext, subContext, annotatedMethods);
|
||||||
apiResourceConfig.setResources(resourceList);
|
apiResourceConfig.setResources(resourceList);
|
||||||
} catch (Throwable throwable) {
|
} catch (Throwable throwable) {
|
||||||
log.error("Error encountered while scanning for annotations", throwable);
|
log.error("Error encountered while scanning for annotations", throwable);
|
||||||
@ -171,7 +177,7 @@ public class AnnotationUtil {
|
|||||||
return apiResourceConfigs;
|
return apiResourceConfigs;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<APIResource> getApiResources(String rootContext, Method[] annotatedMethods) throws Throwable {
|
private List<APIResource> getApiResources(String resourceRootContext, String apiRootContext, Method[] annotatedMethods) throws Throwable {
|
||||||
List<APIResource> resourceList;
|
List<APIResource> resourceList;
|
||||||
resourceList = new ArrayList<APIResource>();
|
resourceList = new ArrayList<APIResource>();
|
||||||
for (Method method : annotatedMethods) {
|
for (Method method : annotatedMethods) {
|
||||||
@ -179,12 +185,13 @@ public class AnnotationUtil {
|
|||||||
if (methodContextAnno != null) {
|
if (methodContextAnno != null) {
|
||||||
String subCtx = invokeMethod(pathClazzMethods[0], methodContextAnno, STRING);
|
String subCtx = invokeMethod(pathClazzMethods[0], methodContextAnno, STRING);
|
||||||
APIResource resource = new APIResource();
|
APIResource resource = new APIResource();
|
||||||
resource.setUriTemplate(makeContextURLReady(subCtx));
|
resource.setUriTemplate(makeContextURLReady(apiRootContext + subCtx));
|
||||||
|
|
||||||
String serverIP = System.getProperty(SERVER_HOST);
|
String serverIP = System.getProperty(SERVER_HOST);
|
||||||
String httpServerPort = System.getProperty(HTTP_PORT);
|
String httpServerPort = System.getProperty(HTTP_PORT);
|
||||||
|
|
||||||
resource.setUri(PROTOCOL_HTTP + "://" + serverIP + ":" + httpServerPort + makeContextURLReady(rootContext) + makeContextURLReady(subCtx));
|
resource.setUri(PROTOCOL_HTTP + "://" + serverIP + ":" + httpServerPort + makeContextURLReady(
|
||||||
|
resourceRootContext) + makeContextURLReady(subCtx));
|
||||||
resource.setAuthType(AUTH_TYPE);
|
resource.setAuthType(AUTH_TYPE);
|
||||||
|
|
||||||
Annotation[] annotations = method.getDeclaredAnnotations();
|
Annotation[] annotations = method.getDeclaredAnnotations();
|
||||||
|
|||||||
@ -80,10 +80,6 @@
|
|||||||
<groupId>org.wso2.carbon.analytics-common</groupId>
|
<groupId>org.wso2.carbon.analytics-common</groupId>
|
||||||
<artifactId>org.wso2.carbon.databridge.commons</artifactId>
|
<artifactId>org.wso2.carbon.databridge.commons</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.wso2.carbon.analytics</groupId>
|
|
||||||
<artifactId>org.wso2.carbon.analytics.api</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.wso2.carbon.registry</groupId>
|
<groupId>org.wso2.carbon.registry</groupId>
|
||||||
<artifactId>org.wso2.carbon.registry.indexing</artifactId>
|
<artifactId>org.wso2.carbon.registry.indexing</artifactId>
|
||||||
@ -123,7 +119,6 @@
|
|||||||
org.wso2.carbon.context;version="${carbon.kernel.version.range}",
|
org.wso2.carbon.context;version="${carbon.kernel.version.range}",
|
||||||
org.wso2.carbon.utils;version="${carbon.kernel.version.range}",
|
org.wso2.carbon.utils;version="${carbon.kernel.version.range}",
|
||||||
org.wso2.carbon.databridge.*;version="${carbon.analytics.common.version.range}",
|
org.wso2.carbon.databridge.*;version="${carbon.analytics.common.version.range}",
|
||||||
org.wso2.carbon.analytics.*;version="${carbon.analytics.version.range}",
|
|
||||||
org.wso2.carbon.registry.core.*;resolution:=optional,
|
org.wso2.carbon.registry.core.*;resolution:=optional,
|
||||||
org.wso2.carbon.registry.common.*;version="${carbon.registry.imp.pkg.version.range}",
|
org.wso2.carbon.registry.common.*;version="${carbon.registry.imp.pkg.version.range}",
|
||||||
org.wso2.carbon.registry.indexing.*; version="${carbon.registry.imp.pkg.version.range}",
|
org.wso2.carbon.registry.indexing.*; version="${carbon.registry.imp.pkg.version.range}",
|
||||||
|
|||||||
@ -1,59 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
||||||
*
|
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
|
||||||
* in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package org.wso2.carbon.device.mgt.analytics.data.publisher;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class AnalyticsDataRecord {
|
|
||||||
private Map<String, Object> values;
|
|
||||||
private long timestamp;
|
|
||||||
|
|
||||||
public AnalyticsDataRecord() {
|
|
||||||
values = new HashMap<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public AnalyticsDataRecord(Map<String, Object> values) {
|
|
||||||
this.values = values;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<String, Object> getValues() {
|
|
||||||
return this.values;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setValue(String name, Object value) {
|
|
||||||
values.put(name, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object getValue(String name) {
|
|
||||||
return this.values.get(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setValues(Map<String, Object> values) {
|
|
||||||
this.values = values;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getTimestamp() {
|
|
||||||
return this.timestamp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTimestamp(long timestamp) {
|
|
||||||
this.timestamp = timestamp;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -25,7 +25,7 @@ import javax.xml.parsers.DocumentBuilder;
|
|||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
public class DeviceAnalyticsUtil {
|
public class DataPublisherUtil {
|
||||||
|
|
||||||
public static Document convertToDocument(File file) throws DataPublisherConfigurationException {
|
public static Document convertToDocument(File file) throws DataPublisherConfigurationException {
|
||||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||||
@ -34,7 +34,7 @@ import org.wso2.carbon.databridge.commons.exception.TransportException;
|
|||||||
import org.wso2.carbon.device.mgt.analytics.data.publisher.config.AnalyticsConfiguration;
|
import org.wso2.carbon.device.mgt.analytics.data.publisher.config.AnalyticsConfiguration;
|
||||||
import org.wso2.carbon.device.mgt.analytics.data.publisher.exception.DataPublisherAlreadyExistsException;
|
import org.wso2.carbon.device.mgt.analytics.data.publisher.exception.DataPublisherAlreadyExistsException;
|
||||||
import org.wso2.carbon.device.mgt.analytics.data.publisher.exception.DataPublisherConfigurationException;
|
import org.wso2.carbon.device.mgt.analytics.data.publisher.exception.DataPublisherConfigurationException;
|
||||||
import org.wso2.carbon.device.mgt.analytics.data.publisher.internal.DeviceAnalyticsDataHolder;
|
import org.wso2.carbon.device.mgt.analytics.data.publisher.internal.DataPublisherDataHolder;
|
||||||
import org.wso2.carbon.registry.core.Registry;
|
import org.wso2.carbon.registry.core.Registry;
|
||||||
import org.wso2.carbon.registry.core.Resource;
|
import org.wso2.carbon.registry.core.Resource;
|
||||||
import org.wso2.carbon.registry.core.exceptions.RegistryException;
|
import org.wso2.carbon.registry.core.exceptions.RegistryException;
|
||||||
@ -71,7 +71,7 @@ public class DeviceDataPublisher {
|
|||||||
return deviceDataPublisher;
|
return deviceDataPublisher;
|
||||||
}
|
}
|
||||||
|
|
||||||
private DeviceDataPublisher() {
|
public DeviceDataPublisher() {
|
||||||
dataPublisherMap = new ConcurrentHashMap<>();
|
dataPublisherMap = new ConcurrentHashMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -196,7 +196,7 @@ public class DeviceDataPublisher {
|
|||||||
try {
|
try {
|
||||||
PrivilegedCarbonContext.startTenantFlow();
|
PrivilegedCarbonContext.startTenantFlow();
|
||||||
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenantId, true);
|
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenantId, true);
|
||||||
RegistryService registryService = DeviceAnalyticsDataHolder.getInstance().getRegistryService();
|
RegistryService registryService = DataPublisherDataHolder.getInstance().getRegistryService();
|
||||||
if (registryService != null) {
|
if (registryService != null) {
|
||||||
Registry registry = registryService.getConfigSystemRegistry(tenantId);
|
Registry registry = registryService.getConfigSystemRegistry(tenantId);
|
||||||
this.loadTenantRegistry(tenantId);
|
this.loadTenantRegistry(tenantId);
|
||||||
@ -213,8 +213,8 @@ public class DeviceDataPublisher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void loadTenantRegistry(int tenantId) throws RegistryException {
|
private void loadTenantRegistry(int tenantId) throws RegistryException {
|
||||||
TenantRegistryLoader tenantRegistryLoader = DeviceAnalyticsDataHolder.getInstance().getTenantRegistryLoader();
|
TenantRegistryLoader tenantRegistryLoader = DataPublisherDataHolder.getInstance().getTenantRegistryLoader();
|
||||||
DeviceAnalyticsDataHolder.getInstance().getIndexLoaderService().loadTenantIndex(tenantId);
|
DataPublisherDataHolder.getInstance().getIndexLoaderService().loadTenantIndex(tenantId);
|
||||||
tenantRegistryLoader.loadTenantRegistry(tenantId);
|
tenantRegistryLoader.loadTenantRegistry(tenantId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -21,7 +21,7 @@ package org.wso2.carbon.device.mgt.analytics.data.publisher.config;
|
|||||||
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.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
import org.wso2.carbon.device.mgt.analytics.data.publisher.DeviceAnalyticsUtil;
|
import org.wso2.carbon.device.mgt.analytics.data.publisher.DataPublisherUtil;
|
||||||
import org.wso2.carbon.device.mgt.analytics.data.publisher.exception.DataPublisherConfigurationException;
|
import org.wso2.carbon.device.mgt.analytics.data.publisher.exception.DataPublisherConfigurationException;
|
||||||
import org.wso2.carbon.utils.CarbonUtils;
|
import org.wso2.carbon.utils.CarbonUtils;
|
||||||
|
|
||||||
@ -100,7 +100,7 @@ public class AnalyticsConfiguration {
|
|||||||
public static void init() throws DataPublisherConfigurationException {
|
public static void init() throws DataPublisherConfigurationException {
|
||||||
try {
|
try {
|
||||||
File authConfig = new File(AnalyticsConfiguration.DEVICE_ANALYTICS_CONFIG_PATH);
|
File authConfig = new File(AnalyticsConfiguration.DEVICE_ANALYTICS_CONFIG_PATH);
|
||||||
Document doc = DeviceAnalyticsUtil.convertToDocument(authConfig);
|
Document doc = DataPublisherUtil.convertToDocument(authConfig);
|
||||||
|
|
||||||
/* Un-marshaling device analytics configuration */
|
/* Un-marshaling device analytics configuration */
|
||||||
JAXBContext ctx = JAXBContext.newInstance(AnalyticsConfiguration.class);
|
JAXBContext ctx = JAXBContext.newInstance(AnalyticsConfiguration.class);
|
||||||
|
|||||||
@ -1,43 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
||||||
*
|
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
|
||||||
* in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package org.wso2.carbon.device.mgt.analytics.data.publisher.exception;
|
|
||||||
|
|
||||||
public class DeviceManagementAnalyticsException extends Exception {
|
|
||||||
public DeviceManagementAnalyticsException() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
public DeviceManagementAnalyticsException(String message) {
|
|
||||||
super(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public DeviceManagementAnalyticsException(String message, Throwable cause) {
|
|
||||||
super(message, cause);
|
|
||||||
}
|
|
||||||
|
|
||||||
public DeviceManagementAnalyticsException(Throwable cause) {
|
|
||||||
super(cause);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected DeviceManagementAnalyticsException(String message, Throwable cause,
|
|
||||||
boolean enableSuppression,
|
|
||||||
boolean writableStackTrace) {
|
|
||||||
super(message, cause, enableSuppression, writableStackTrace);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -18,36 +18,24 @@
|
|||||||
*/
|
*/
|
||||||
package org.wso2.carbon.device.mgt.analytics.data.publisher.internal;
|
package org.wso2.carbon.device.mgt.analytics.data.publisher.internal;
|
||||||
|
|
||||||
import org.wso2.carbon.analytics.api.AnalyticsDataAPI;
|
|
||||||
import org.wso2.carbon.registry.core.service.RegistryService;
|
import org.wso2.carbon.registry.core.service.RegistryService;
|
||||||
import org.wso2.carbon.registry.core.service.TenantRegistryLoader;
|
import org.wso2.carbon.registry.core.service.TenantRegistryLoader;
|
||||||
import org.wso2.carbon.registry.indexing.service.TenantIndexingLoader;
|
import org.wso2.carbon.registry.indexing.service.TenantIndexingLoader;
|
||||||
|
|
||||||
public class DeviceAnalyticsDataHolder {
|
public class DataPublisherDataHolder {
|
||||||
private static DeviceAnalyticsDataHolder thisInstance = new DeviceAnalyticsDataHolder();
|
private static DataPublisherDataHolder thisInstance = new DataPublisherDataHolder();
|
||||||
/**
|
|
||||||
* AnalyticsDataAPI is service used to retrieve data from DAS.
|
|
||||||
*/
|
|
||||||
private AnalyticsDataAPI analyticsDataAPI;
|
|
||||||
private TenantRegistryLoader tenantRegistryLoader;
|
private TenantRegistryLoader tenantRegistryLoader;
|
||||||
private TenantIndexingLoader indexLoader;
|
private TenantIndexingLoader indexLoader;
|
||||||
private RegistryService registryService;
|
private RegistryService registryService;
|
||||||
private DeviceAnalyticsDataHolder() {
|
private DataPublisherDataHolder() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static DeviceAnalyticsDataHolder getInstance() {
|
public static DataPublisherDataHolder getInstance() {
|
||||||
return thisInstance;
|
return thisInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AnalyticsDataAPI getAnalyticsDataAPI() {
|
|
||||||
return analyticsDataAPI;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAnalyticsDataAPI(AnalyticsDataAPI analyticsDataAPI) {
|
|
||||||
this.analyticsDataAPI = analyticsDataAPI;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTenantRegistryLoader(TenantRegistryLoader tenantRegistryLoader){
|
public void setTenantRegistryLoader(TenantRegistryLoader tenantRegistryLoader){
|
||||||
this.tenantRegistryLoader = tenantRegistryLoader;
|
this.tenantRegistryLoader = tenantRegistryLoader;
|
||||||
}
|
}
|
||||||
@ -23,23 +23,16 @@ import org.apache.commons.logging.LogFactory;
|
|||||||
import org.osgi.framework.BundleContext;
|
import org.osgi.framework.BundleContext;
|
||||||
import org.osgi.framework.ServiceRegistration;
|
import org.osgi.framework.ServiceRegistration;
|
||||||
import org.osgi.service.component.ComponentContext;
|
import org.osgi.service.component.ComponentContext;
|
||||||
import org.wso2.carbon.analytics.api.AnalyticsDataAPI;
|
|
||||||
import org.wso2.carbon.device.mgt.analytics.data.publisher.config.AnalyticsConfiguration;
|
import org.wso2.carbon.device.mgt.analytics.data.publisher.config.AnalyticsConfiguration;
|
||||||
import org.wso2.carbon.device.mgt.analytics.data.publisher.service.DeviceAnalyticsService;
|
import org.wso2.carbon.device.mgt.analytics.data.publisher.service.EventsPublisherService;
|
||||||
import org.wso2.carbon.device.mgt.analytics.data.publisher.service.DeviceAnalyticsServiceImpl;
|
import org.wso2.carbon.device.mgt.analytics.data.publisher.service.EventsPublisherServiceImpl;
|
||||||
import org.wso2.carbon.registry.core.service.RegistryService;
|
import org.wso2.carbon.registry.core.service.RegistryService;
|
||||||
import org.wso2.carbon.registry.core.service.TenantRegistryLoader;
|
import org.wso2.carbon.registry.core.service.TenantRegistryLoader;
|
||||||
import org.wso2.carbon.registry.indexing.service.TenantIndexingLoader;
|
import org.wso2.carbon.registry.indexing.service.TenantIndexingLoader;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @scr.component name="org.wso2.carbon.device.mgt.analytics.internal.DeviceAnalyticsServiceComponent"
|
* @scr.component name="org.wso2.carbon.device.mgt.analytics.data.publisher.internal.DataPublisherServiceComponent"
|
||||||
* immediate="true"
|
* immediate="true"
|
||||||
* @scr.reference name="device.analytics.api"
|
|
||||||
* interface="org.wso2.carbon.analytics.api.AnalyticsDataAPI"
|
|
||||||
* cardinality="1..1"
|
|
||||||
* policy="dynamic"
|
|
||||||
* bind="setAnalyticsDataAPI"
|
|
||||||
* unbind="unsetAnalyticsDataAPI"
|
|
||||||
* @scr.reference name="registry.service"
|
* @scr.reference name="registry.service"
|
||||||
* interface="org.wso2.carbon.registry.core.service.RegistryService"
|
* interface="org.wso2.carbon.registry.core.service.RegistryService"
|
||||||
* cardinality="1..1"
|
* cardinality="1..1"
|
||||||
@ -58,10 +51,10 @@ import org.wso2.carbon.registry.indexing.service.TenantIndexingLoader;
|
|||||||
* bind="setIndexLoader"
|
* bind="setIndexLoader"
|
||||||
* unbind="unsetIndexLoader"
|
* unbind="unsetIndexLoader"
|
||||||
*/
|
*/
|
||||||
public class DeviceAnalyticsServiceComponent {
|
public class DataPublisherServiceComponent {
|
||||||
|
|
||||||
private ServiceRegistration analyticsServiceRef;
|
private ServiceRegistration analyticsServiceRef;
|
||||||
private static Log log = LogFactory.getLog(DeviceAnalyticsServiceComponent.class);
|
private static Log log = LogFactory.getLog(DataPublisherServiceComponent.class);
|
||||||
|
|
||||||
protected void activate(ComponentContext componentCtx) {
|
protected void activate(ComponentContext componentCtx) {
|
||||||
try {
|
try {
|
||||||
@ -72,7 +65,7 @@ public class DeviceAnalyticsServiceComponent {
|
|||||||
|
|
||||||
BundleContext bundleCtx = componentCtx.getBundleContext();
|
BundleContext bundleCtx = componentCtx.getBundleContext();
|
||||||
this.analyticsServiceRef =
|
this.analyticsServiceRef =
|
||||||
bundleCtx.registerService(DeviceAnalyticsService.class, new DeviceAnalyticsServiceImpl(), null);
|
bundleCtx.registerService(EventsPublisherService.class, new EventsPublisherServiceImpl(), null);
|
||||||
|
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Device management analytics bundle has been successfully initialized");
|
log.debug("Device management analytics bundle has been successfully initialized");
|
||||||
@ -94,58 +87,34 @@ public class DeviceAnalyticsServiceComponent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets AnalyticsDataAPI Service.
|
|
||||||
*
|
|
||||||
* @param analyticsDataAPI An instance of AnalyticsDataAPI
|
|
||||||
*/
|
|
||||||
protected void setAnalyticsDataAPI(AnalyticsDataAPI analyticsDataAPI) {
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Setting AnalyticsDataAPI Service");
|
|
||||||
}
|
|
||||||
DeviceAnalyticsDataHolder.getInstance().setAnalyticsDataAPI(analyticsDataAPI);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Un sets AnalyticsDataAPI Service.
|
|
||||||
*
|
|
||||||
* @param analyticsDataAPI An instance of AnalyticsDataAPI
|
|
||||||
*/
|
|
||||||
protected void unsetAnalyticsDataAPI(AnalyticsDataAPI analyticsDataAPI) {
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Un-Setting AnalyticsDataAPI Service");
|
|
||||||
}
|
|
||||||
DeviceAnalyticsDataHolder.getInstance().setAnalyticsDataAPI(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void setRegistryService(RegistryService registryService) {
|
protected void setRegistryService(RegistryService registryService) {
|
||||||
if (registryService != null && log.isDebugEnabled()) {
|
if (registryService != null && log.isDebugEnabled()) {
|
||||||
log.debug("Registry service initialized");
|
log.debug("Registry service initialized");
|
||||||
}
|
}
|
||||||
DeviceAnalyticsDataHolder.getInstance().setRegistryService(registryService);
|
DataPublisherDataHolder.getInstance().setRegistryService(registryService);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void unsetRegistryService(RegistryService registryService) {
|
protected void unsetRegistryService(RegistryService registryService) {
|
||||||
DeviceAnalyticsDataHolder.getInstance().setRegistryService(null);
|
DataPublisherDataHolder.getInstance().setRegistryService(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setTenantRegistryLoader(TenantRegistryLoader tenantRegistryLoader) {
|
protected void setTenantRegistryLoader(TenantRegistryLoader tenantRegistryLoader) {
|
||||||
DeviceAnalyticsDataHolder.getInstance().setTenantRegistryLoader(tenantRegistryLoader);
|
DataPublisherDataHolder.getInstance().setTenantRegistryLoader(tenantRegistryLoader);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void unsetTenantRegistryLoader(TenantRegistryLoader tenantRegistryLoader) {
|
protected void unsetTenantRegistryLoader(TenantRegistryLoader tenantRegistryLoader) {
|
||||||
DeviceAnalyticsDataHolder.getInstance().setTenantRegistryLoader(null);
|
DataPublisherDataHolder.getInstance().setTenantRegistryLoader(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setIndexLoader(TenantIndexingLoader indexLoader) {
|
protected void setIndexLoader(TenantIndexingLoader indexLoader) {
|
||||||
if (indexLoader != null && log.isDebugEnabled()) {
|
if (indexLoader != null && log.isDebugEnabled()) {
|
||||||
log.debug("IndexLoader service initialized");
|
log.debug("IndexLoader service initialized");
|
||||||
}
|
}
|
||||||
DeviceAnalyticsDataHolder.getInstance().setIndexLoaderService(indexLoader);
|
DataPublisherDataHolder.getInstance().setIndexLoaderService(indexLoader);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void unsetIndexLoader(TenantIndexingLoader indexLoader) {
|
protected void unsetIndexLoader(TenantIndexingLoader indexLoader) {
|
||||||
DeviceAnalyticsDataHolder.getInstance().setIndexLoaderService(null);
|
DataPublisherDataHolder.getInstance().setIndexLoaderService(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -1,121 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
||||||
*
|
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
|
||||||
* in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.wso2.carbon.device.mgt.analytics.data.publisher.service;
|
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
import org.wso2.carbon.analytics.api.AnalyticsDataAPI;
|
|
||||||
import org.wso2.carbon.analytics.dataservice.commons.AnalyticsDataResponse;
|
|
||||||
import org.wso2.carbon.analytics.dataservice.commons.AnalyticsDrillDownRequest;
|
|
||||||
import org.wso2.carbon.analytics.dataservice.commons.SearchResultEntry;
|
|
||||||
import org.wso2.carbon.analytics.dataservice.core.AnalyticsDataServiceUtils;
|
|
||||||
import org.wso2.carbon.analytics.datasource.commons.Record;
|
|
||||||
import org.wso2.carbon.analytics.datasource.commons.exception.AnalyticsException;
|
|
||||||
import org.wso2.carbon.context.CarbonContext;
|
|
||||||
import org.wso2.carbon.databridge.agent.DataPublisher;
|
|
||||||
import org.wso2.carbon.databridge.commons.utils.DataBridgeCommonsUtils;
|
|
||||||
import org.wso2.carbon.device.mgt.analytics.data.publisher.AnalyticsDataRecord;
|
|
||||||
import org.wso2.carbon.device.mgt.analytics.data.publisher.DeviceDataPublisher;
|
|
||||||
import org.wso2.carbon.device.mgt.analytics.data.publisher.exception.DataPublisherConfigurationException;
|
|
||||||
import org.wso2.carbon.device.mgt.analytics.data.publisher.exception.DeviceManagementAnalyticsException;
|
|
||||||
import org.wso2.carbon.device.mgt.analytics.data.publisher.internal.DeviceAnalyticsDataHolder;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This is the implementation of Osgi Service which can be used to publish and retireved
|
|
||||||
* event/records.
|
|
||||||
*/
|
|
||||||
public class DeviceAnalyticsServiceImpl implements DeviceAnalyticsService {
|
|
||||||
private static Log log = LogFactory.getLog(DeviceAnalyticsServiceImpl.class);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param streamName is the name of the stream that the data needs to pushed
|
|
||||||
* @param version is the version of the stream
|
|
||||||
* @param metaDataArray - meta data that needs to pushed
|
|
||||||
* @param correlationDataArray - correlation data that needs to be pushed
|
|
||||||
* @param payloadDataArray - payload data that needs to be pushed
|
|
||||||
* @return
|
|
||||||
* @throws DataPublisherConfigurationException
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean publishEvent(String streamName, String version, Object[] metaDataArray,
|
|
||||||
Object[] correlationDataArray,
|
|
||||||
Object[] payloadDataArray) throws DataPublisherConfigurationException {
|
|
||||||
DataPublisher dataPublisher = DeviceDataPublisher.getInstance().getDataPublisher();
|
|
||||||
if (dataPublisher != null) {
|
|
||||||
String streamId = DataBridgeCommonsUtils.generateStreamId(streamName, version);
|
|
||||||
return dataPublisher.tryPublish(streamId, System.currentTimeMillis(), metaDataArray, correlationDataArray,
|
|
||||||
payloadDataArray);
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param tableName is the name of the table that events need to be retrieved
|
|
||||||
* @param query is query to be executed.
|
|
||||||
* @return
|
|
||||||
* @throws AnalyticsException
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public List<AnalyticsDataRecord> getAllEventsForDevice(String tableName, String query) throws
|
|
||||||
DeviceManagementAnalyticsException {
|
|
||||||
try {
|
|
||||||
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
||||||
AnalyticsDataAPI analyticsDataAPI = DeviceAnalyticsDataHolder.getInstance().getAnalyticsDataAPI();
|
|
||||||
int eventCount = analyticsDataAPI.searchCount(tenantId, tableName, query);
|
|
||||||
if (eventCount == 0) {
|
|
||||||
return new ArrayList<>();
|
|
||||||
}
|
|
||||||
AnalyticsDrillDownRequest drillDownRequest = new AnalyticsDrillDownRequest();
|
|
||||||
drillDownRequest.setQuery(query);
|
|
||||||
drillDownRequest.setTableName(tableName);
|
|
||||||
drillDownRequest.setRecordCount(eventCount);
|
|
||||||
List<SearchResultEntry> resultEntries = analyticsDataAPI.drillDownSearch(tenantId, drillDownRequest);
|
|
||||||
List<String> recordIds = getRecordIds(resultEntries);
|
|
||||||
AnalyticsDataResponse response = analyticsDataAPI.get(tenantId, tableName, 1, null, recordIds);
|
|
||||||
List<Record> records = AnalyticsDataServiceUtils.listRecords(analyticsDataAPI, response);
|
|
||||||
return getAnalyticsDataRecords(records);
|
|
||||||
} catch (AnalyticsException e) {
|
|
||||||
throw new DeviceManagementAnalyticsException(
|
|
||||||
"Failed fetch data for table " + tableName + "with the query " + query);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<String> getRecordIds(List<SearchResultEntry> searchResults) {
|
|
||||||
List<String> ids = new ArrayList<>();
|
|
||||||
for (SearchResultEntry searchResult : searchResults) {
|
|
||||||
ids.add(searchResult.getId());
|
|
||||||
}
|
|
||||||
return ids;
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<AnalyticsDataRecord> getAnalyticsDataRecords(List<Record> records) {
|
|
||||||
List<AnalyticsDataRecord> analyticsDataRecords = new ArrayList<>();
|
|
||||||
for (Record record : records) {
|
|
||||||
AnalyticsDataRecord analyticsDataRecord = new AnalyticsDataRecord(record.getValues());
|
|
||||||
analyticsDataRecords.add(analyticsDataRecord);
|
|
||||||
}
|
|
||||||
return analyticsDataRecords;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -18,16 +18,12 @@
|
|||||||
*/
|
*/
|
||||||
package org.wso2.carbon.device.mgt.analytics.data.publisher.service;
|
package org.wso2.carbon.device.mgt.analytics.data.publisher.service;
|
||||||
|
|
||||||
import org.wso2.carbon.device.mgt.analytics.data.publisher.AnalyticsDataRecord;
|
|
||||||
import org.wso2.carbon.device.mgt.analytics.data.publisher.exception.DataPublisherConfigurationException;
|
import org.wso2.carbon.device.mgt.analytics.data.publisher.exception.DataPublisherConfigurationException;
|
||||||
import org.wso2.carbon.device.mgt.analytics.data.publisher.exception.DeviceManagementAnalyticsException;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This service can be used to publish and retreive data from the Analytics Server.
|
* This service can be used to publish and retreive data from the Analytics Server.
|
||||||
*/
|
*/
|
||||||
public interface DeviceAnalyticsService {
|
public interface EventsPublisherService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is used to publish an event to DAS.
|
* This is used to publish an event to DAS.
|
||||||
@ -42,14 +38,4 @@ public interface DeviceAnalyticsService {
|
|||||||
boolean publishEvent(String streamName, String version, Object[] metaDataArray, Object[] correlationDataArray,
|
boolean publishEvent(String streamName, String version, Object[] metaDataArray, Object[] correlationDataArray,
|
||||||
Object[] payloadDataArray) throws DataPublisherConfigurationException;
|
Object[] payloadDataArray) throws DataPublisherConfigurationException;
|
||||||
|
|
||||||
/**
|
|
||||||
* This service can be used to retrieve all the event for the query.
|
|
||||||
* @param tableName is the name of the table that events need to be retrieved
|
|
||||||
* @param query is query to be executed.
|
|
||||||
* @return the record list
|
|
||||||
* @throws DeviceManagementAnalyticsException
|
|
||||||
*/
|
|
||||||
List<AnalyticsDataRecord> getAllEventsForDevice(String tableName,
|
|
||||||
String query) throws DeviceManagementAnalyticsException;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.wso2.carbon.device.mgt.analytics.data.publisher.service;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.wso2.carbon.databridge.agent.DataPublisher;
|
||||||
|
import org.wso2.carbon.databridge.commons.utils.DataBridgeCommonsUtils;
|
||||||
|
import org.wso2.carbon.device.mgt.analytics.data.publisher.DeviceDataPublisher;
|
||||||
|
import org.wso2.carbon.device.mgt.analytics.data.publisher.exception.DataPublisherConfigurationException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is the implementation of Osgi Service which can be used to publish and retireved
|
||||||
|
* event/records.
|
||||||
|
*/
|
||||||
|
public class EventsPublisherServiceImpl implements EventsPublisherService {
|
||||||
|
private static Log log = LogFactory.getLog(EventsPublisherServiceImpl.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param streamName is the name of the stream that the data needs to pushed
|
||||||
|
* @param version is the version of the stream
|
||||||
|
* @param metaDataArray - meta data that needs to pushed
|
||||||
|
* @param correlationDataArray - correlation data that needs to be pushed
|
||||||
|
* @param payloadDataArray - payload data that needs to be pushed
|
||||||
|
* @return
|
||||||
|
* @throws DataPublisherConfigurationException
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean publishEvent(String streamName, String version, Object[] metaDataArray,
|
||||||
|
Object[] correlationDataArray,
|
||||||
|
Object[] payloadDataArray) throws DataPublisherConfigurationException {
|
||||||
|
DataPublisher dataPublisher = DeviceDataPublisher.getInstance().getDataPublisher();
|
||||||
|
if (dataPublisher != null) {
|
||||||
|
String streamId = DataBridgeCommonsUtils.generateStreamId(streamName, version);
|
||||||
|
return dataPublisher.tryPublish(streamId, System.currentTimeMillis(), metaDataArray, correlationDataArray,
|
||||||
|
payloadDataArray);
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -50,7 +50,7 @@
|
|||||||
<version>2.2</version>
|
<version>2.2</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<packagingExcludes>WEB-INF/lib/*cxf*.jar</packagingExcludes>
|
<packagingExcludes>WEB-INF/lib/*cxf*.jar</packagingExcludes>
|
||||||
<warName>mdm-admin</warName>
|
<warName>devicemgt_admin</warName>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
@ -77,7 +77,7 @@
|
|||||||
<copy todir="${basedir}/../../../repository/deployment/server/webapps"
|
<copy todir="${basedir}/../../../repository/deployment/server/webapps"
|
||||||
overwrite="true">
|
overwrite="true">
|
||||||
<fileset dir="${basedir}/target">
|
<fileset dir="${basedir}/target">
|
||||||
<include name="mdm-admin.war"/>
|
<include name="devicemgt_admin.war"/>
|
||||||
</fileset>
|
</fileset>
|
||||||
</copy>
|
</copy>
|
||||||
</tasks>
|
</tasks>
|
||||||
|
|||||||
@ -18,7 +18,6 @@
|
|||||||
|
|
||||||
package org.wso2.carbon.mdm.api;
|
package org.wso2.carbon.mdm.api;
|
||||||
|
|
||||||
import org.apache.commons.httpclient.HttpStatus;
|
|
||||||
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.wso2.carbon.certificate.mgt.core.dao.CertificateManagementDAOException;
|
import org.wso2.carbon.certificate.mgt.core.dao.CertificateManagementDAOException;
|
||||||
@ -29,14 +28,19 @@ import org.wso2.carbon.context.PrivilegedCarbonContext;
|
|||||||
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
||||||
import org.wso2.carbon.device.mgt.common.PaginationResult;
|
import org.wso2.carbon.device.mgt.common.PaginationResult;
|
||||||
import org.wso2.carbon.mdm.api.common.MDMAPIException;
|
import org.wso2.carbon.mdm.api.common.MDMAPIException;
|
||||||
import org.wso2.carbon.mdm.api.util.MDMAPIUtils;
|
import org.wso2.carbon.mdm.api.util.DeviceMgtAPIUtils;
|
||||||
import org.wso2.carbon.mdm.api.util.ResponsePayload;
|
|
||||||
import org.wso2.carbon.mdm.beans.EnrollmentCertificate;
|
import org.wso2.carbon.mdm.beans.EnrollmentCertificate;
|
||||||
import org.wso2.carbon.mdm.exception.*;
|
import org.wso2.carbon.mdm.exception.Message;
|
||||||
import org.wso2.carbon.mdm.exception.BadRequestException;
|
|
||||||
import org.wso2.carbon.mdm.util.MDMUtil;
|
|
||||||
|
|
||||||
import javax.ws.rs.*;
|
import javax.ws.rs.Consumes;
|
||||||
|
import javax.ws.rs.DELETE;
|
||||||
|
import javax.ws.rs.GET;
|
||||||
|
import javax.ws.rs.HeaderParam;
|
||||||
|
import javax.ws.rs.POST;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.PathParam;
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
|
import javax.ws.rs.QueryParam;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -45,7 +49,8 @@ import java.util.List;
|
|||||||
/**
|
/**
|
||||||
* All the certificate related tasks such as saving certificates, can be done through this endpoint.
|
* All the certificate related tasks such as saving certificates, can be done through this endpoint.
|
||||||
*/
|
*/
|
||||||
@Produces({ "application/json", "application/xml" })
|
@SuppressWarnings("NonJaxWsWebServices")
|
||||||
|
@Produces({"application/json", "application/xml"})
|
||||||
@Consumes({ "application/json", "application/xml" })
|
@Consumes({ "application/json", "application/xml" })
|
||||||
public class Certificate {
|
public class Certificate {
|
||||||
|
|
||||||
@ -57,18 +62,16 @@ public class Certificate {
|
|||||||
* @param enrollmentCertificates List of all the certificates which includes the tenant id, certificate as
|
* @param enrollmentCertificates List of all the certificates which includes the tenant id, certificate as
|
||||||
* a pem and a serial number.
|
* a pem and a serial number.
|
||||||
* @return Status of the data persist operation.
|
* @return Status of the data persist operation.
|
||||||
* @throws MDMAPIException
|
|
||||||
*/
|
*/
|
||||||
@POST
|
@POST
|
||||||
@Path("saveCertificate")
|
@Path("saveCertificate")
|
||||||
public Response saveCertificate(@HeaderParam("Accept") String acceptHeader,
|
public Response saveCertificate(@HeaderParam("Accept") String acceptHeader,
|
||||||
EnrollmentCertificate[] enrollmentCertificates) throws MDMAPIException {
|
EnrollmentCertificate[] enrollmentCertificates) {
|
||||||
MediaType responseMediaType = MDMAPIUtils.getResponseMediaType(acceptHeader);
|
MediaType responseMediaType = DeviceMgtAPIUtils.getResponseMediaType(acceptHeader);
|
||||||
CertificateManagementService certificateService;
|
CertificateManagementService certificateService;
|
||||||
List<org.wso2.carbon.certificate.mgt.core.bean.Certificate> certificates = new ArrayList<org.wso2.carbon
|
List<org.wso2.carbon.certificate.mgt.core.bean.Certificate> certificates = new ArrayList<>();
|
||||||
.certificate.mgt.core.bean.Certificate>();
|
|
||||||
org.wso2.carbon.certificate.mgt.core.bean.Certificate certificate;
|
org.wso2.carbon.certificate.mgt.core.bean.Certificate certificate;
|
||||||
certificateService = MDMAPIUtils.getCertificateManagementService();
|
certificateService = DeviceMgtAPIUtils.getCertificateManagementService();
|
||||||
try {
|
try {
|
||||||
for (EnrollmentCertificate enrollmentCertificate : enrollmentCertificates) {
|
for (EnrollmentCertificate enrollmentCertificate : enrollmentCertificates) {
|
||||||
certificate = new org.wso2.carbon.certificate.mgt.core.bean.Certificate();
|
certificate = new org.wso2.carbon.certificate.mgt.core.bean.Certificate();
|
||||||
@ -83,7 +86,7 @@ public class Certificate {
|
|||||||
} catch (KeystoreException e) {
|
} catch (KeystoreException e) {
|
||||||
String msg = "Error occurred while converting PEM file to X509Certificate.";
|
String msg = "Error occurred while converting PEM file to X509Certificate.";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new MDMAPIException(msg, e);
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).type(responseMediaType).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,22 +95,21 @@ public class Certificate {
|
|||||||
*
|
*
|
||||||
* @param serialNumber serial of the certificate needed.
|
* @param serialNumber serial of the certificate needed.
|
||||||
* @return certificate response.
|
* @return certificate response.
|
||||||
* @throws MDMAPIException
|
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@Path("{serialNumber}")
|
@Path("{serialNumber}")
|
||||||
public Response getCertificate(@HeaderParam("Accept") String acceptHeader,
|
public Response getCertificate(@HeaderParam("Accept") String acceptHeader,
|
||||||
@PathParam("serialNumber") String serialNumber) throws MDMAPIException {
|
@PathParam("serialNumber") String serialNumber) {
|
||||||
MediaType responseMediaType = MDMAPIUtils.getResponseMediaType(acceptHeader);
|
MediaType responseMediaType = DeviceMgtAPIUtils.getResponseMediaType(acceptHeader);
|
||||||
Message message = new Message();
|
Message message = new Message();
|
||||||
|
|
||||||
if (serialNumber == null || serialNumber.isEmpty()) {
|
if (serialNumber == null || serialNumber.isEmpty()) {
|
||||||
message.setErrorMessage("Invalid serial number");
|
message.setErrorMessage("Invalid serial number");
|
||||||
message.setDiscription("Serial number is missing or invalid.");
|
message.setDiscription("Serial number is missing or invalid.");
|
||||||
throw new BadRequestException(message, responseMediaType);
|
return Response.status(Response.Status.BAD_REQUEST).entity(message).type(responseMediaType).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
CertificateManagementService certificateService = MDMAPIUtils.getCertificateManagementService();
|
CertificateManagementService certificateService = DeviceMgtAPIUtils.getCertificateManagementService();
|
||||||
CertificateResponse certificateResponse;
|
CertificateResponse certificateResponse;
|
||||||
try {
|
try {
|
||||||
certificateResponse = certificateService.getCertificateBySerial(serialNumber);
|
certificateResponse = certificateService.getCertificateBySerial(serialNumber);
|
||||||
@ -118,7 +120,7 @@ public class Certificate {
|
|||||||
} catch (KeystoreException e) {
|
} catch (KeystoreException e) {
|
||||||
String msg = "Error occurred while converting PEM file to X509Certificate";
|
String msg = "Error occurred while converting PEM file to X509Certificate";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
return Response.serverError().build();
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).type(responseMediaType).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,20 +138,20 @@ public class Certificate {
|
|||||||
@QueryParam("start") int startIndex,
|
@QueryParam("start") int startIndex,
|
||||||
@QueryParam("length") int length)
|
@QueryParam("length") int length)
|
||||||
throws MDMAPIException {
|
throws MDMAPIException {
|
||||||
MediaType responseMediaType = MDMAPIUtils.getResponseMediaType(acceptHeader);
|
MediaType responseMediaType = DeviceMgtAPIUtils.getResponseMediaType(acceptHeader);
|
||||||
Message message = new Message();
|
Message message = new Message();
|
||||||
|
|
||||||
if (startIndex < 0) {
|
if (startIndex < 0) {
|
||||||
message.setErrorMessage("Invalid start index.");
|
message.setErrorMessage("Invalid start index.");
|
||||||
message.setDiscription("Start index cannot be less that 0.");
|
message.setDiscription("Start index cannot be less that 0.");
|
||||||
throw new BadRequestException(message, responseMediaType);
|
return Response.status(Response.Status.BAD_REQUEST).entity(message).type(responseMediaType).build();
|
||||||
} else if (length <= 0) {
|
} else if (length <= 0) {
|
||||||
message.setErrorMessage("Invalid length value.");
|
message.setErrorMessage("Invalid length value.");
|
||||||
message.setDiscription("Length should be a positive integer.");
|
message.setDiscription("Length should be a positive integer.");
|
||||||
throw new BadRequestException(message, responseMediaType);
|
return Response.status(Response.Status.BAD_REQUEST).entity(message).type(responseMediaType).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
CertificateManagementService certificateService = MDMAPIUtils.getCertificateManagementService();
|
CertificateManagementService certificateService = DeviceMgtAPIUtils.getCertificateManagementService();
|
||||||
PaginationRequest paginationRequest = new PaginationRequest(startIndex, length);
|
PaginationRequest paginationRequest = new PaginationRequest(startIndex, length);
|
||||||
try {
|
try {
|
||||||
PaginationResult certificates = certificateService.getAllCertificates(paginationRequest);
|
PaginationResult certificates = certificateService.getAllCertificates(paginationRequest);
|
||||||
@ -157,7 +159,7 @@ public class Certificate {
|
|||||||
} catch (CertificateManagementDAOException e) {
|
} catch (CertificateManagementDAOException e) {
|
||||||
String msg = "Error occurred while fetching all certificates.";
|
String msg = "Error occurred while fetching all certificates.";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new MDMAPIException(msg, e);
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).type(responseMediaType).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -165,16 +167,16 @@ public class Certificate {
|
|||||||
@Path("{serialNumber}")
|
@Path("{serialNumber}")
|
||||||
public Response removeCertificate(@HeaderParam("Accept") String acceptHeader,
|
public Response removeCertificate(@HeaderParam("Accept") String acceptHeader,
|
||||||
@PathParam("serialNumber") String serialNumber) throws MDMAPIException {
|
@PathParam("serialNumber") String serialNumber) throws MDMAPIException {
|
||||||
MediaType responseMediaType = MDMAPIUtils.getResponseMediaType(acceptHeader);
|
MediaType responseMediaType = DeviceMgtAPIUtils.getResponseMediaType(acceptHeader);
|
||||||
Message message = new Message();
|
Message message = new Message();
|
||||||
|
|
||||||
if (serialNumber == null || serialNumber.isEmpty()) {
|
if (serialNumber == null || serialNumber.isEmpty()) {
|
||||||
message.setErrorMessage("Invalid serial number");
|
message.setErrorMessage("Invalid serial number");
|
||||||
message.setDiscription("Serial number is missing or invalid.");
|
message.setDiscription("Serial number is missing or invalid.");
|
||||||
throw new BadRequestException(message, responseMediaType);
|
return Response.status(Response.Status.BAD_REQUEST).entity(message).type(responseMediaType).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
CertificateManagementService certificateService = MDMAPIUtils.getCertificateManagementService();
|
CertificateManagementService certificateService = DeviceMgtAPIUtils.getCertificateManagementService();
|
||||||
boolean deleted;
|
boolean deleted;
|
||||||
try {
|
try {
|
||||||
deleted = certificateService.removeCertificate(serialNumber);
|
deleted = certificateService.removeCertificate(serialNumber);
|
||||||
@ -186,7 +188,7 @@ public class Certificate {
|
|||||||
} catch (CertificateManagementDAOException e) {
|
} catch (CertificateManagementDAOException e) {
|
||||||
String msg = "Error occurred while converting PEM file to X509Certificate";
|
String msg = "Error occurred while converting PEM file to X509Certificate";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
return Response.serverError().build();
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).type(responseMediaType).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,14 +24,16 @@ import org.apache.commons.logging.LogFactory;
|
|||||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry;
|
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry;
|
||||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationManagementException;
|
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationManagementException;
|
||||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfiguration;
|
import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfiguration;
|
||||||
import org.wso2.carbon.mdm.api.common.MDMAPIException;
|
import org.wso2.carbon.mdm.api.util.DeviceMgtAPIUtils;
|
||||||
import org.wso2.carbon.mdm.api.util.MDMAPIUtils;
|
|
||||||
import org.wso2.carbon.mdm.api.util.MDMAppConstants;
|
import org.wso2.carbon.mdm.api.util.MDMAppConstants;
|
||||||
import org.wso2.carbon.mdm.api.util.ResponsePayload;
|
import org.wso2.carbon.mdm.api.util.ResponsePayload;
|
||||||
import org.wso2.carbon.policy.mgt.core.util.PolicyManagerUtil;
|
import org.wso2.carbon.policy.mgt.core.util.PolicyManagerUtil;
|
||||||
|
|
||||||
import javax.jws.WebService;
|
import javax.ws.rs.Consumes;
|
||||||
import javax.ws.rs.*;
|
import javax.ws.rs.GET;
|
||||||
|
import javax.ws.rs.POST;
|
||||||
|
import javax.ws.rs.PUT;
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -40,74 +42,72 @@ import java.util.List;
|
|||||||
* General Tenant Configuration REST-API implementation.
|
* General Tenant Configuration REST-API implementation.
|
||||||
* All end points support JSON, XMl with content negotiation.
|
* All end points support JSON, XMl with content negotiation.
|
||||||
*/
|
*/
|
||||||
@WebService
|
|
||||||
@Produces({ "application/json", "application/xml" })
|
@SuppressWarnings("NonJaxWsWebServices")
|
||||||
|
@Produces({"application/json", "application/xml"})
|
||||||
@Consumes({ "application/json", "application/xml" })
|
@Consumes({ "application/json", "application/xml" })
|
||||||
public class Configuration {
|
public class Configuration {
|
||||||
|
|
||||||
private static Log log = LogFactory.getLog(Configuration.class);
|
private static Log log = LogFactory.getLog(Configuration.class);
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
public ResponsePayload saveTenantConfiguration(TenantConfiguration configuration)
|
public Response saveTenantConfiguration(TenantConfiguration configuration) {
|
||||||
throws MDMAPIException {
|
ResponsePayload responseMsg = new ResponsePayload();
|
||||||
ResponsePayload responseMsg = new ResponsePayload();
|
try {
|
||||||
try {
|
DeviceMgtAPIUtils.getTenantConfigurationManagementService().saveConfiguration(configuration,
|
||||||
MDMAPIUtils.getTenantConfigurationManagementService().saveConfiguration(configuration,
|
MDMAppConstants.RegistryConstants.GENERAL_CONFIG_RESOURCE_PATH);
|
||||||
MDMAppConstants.RegistryConstants.GENERAL_CONFIG_RESOURCE_PATH);
|
|
||||||
//Schedule the task service
|
//Schedule the task service
|
||||||
MDMAPIUtils.scheduleTaskService(MDMAPIUtils.getNotifierFrequency(configuration));
|
DeviceMgtAPIUtils.scheduleTaskService(DeviceMgtAPIUtils.getNotifierFrequency(configuration));
|
||||||
Response.status(HttpStatus.SC_CREATED);
|
responseMsg.setMessageFromServer("Tenant configuration saved successfully.");
|
||||||
responseMsg.setMessageFromServer("Tenant configuration saved successfully.");
|
|
||||||
responseMsg.setStatusCode(HttpStatus.SC_CREATED);
|
responseMsg.setStatusCode(HttpStatus.SC_CREATED);
|
||||||
return responseMsg;
|
return Response.status(Response.Status.CREATED).entity(responseMsg).build();
|
||||||
} catch (ConfigurationManagementException e) {
|
} catch (ConfigurationManagementException e) {
|
||||||
String msg = "Error occurred while saving the tenant configuration.";
|
String msg = "Error occurred while saving the tenant configuration.";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new MDMAPIException(msg, e);
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
public TenantConfiguration getConfiguration() throws MDMAPIException {
|
public Response getConfiguration() {
|
||||||
String msg;
|
String msg;
|
||||||
try {
|
try {
|
||||||
TenantConfiguration tenantConfiguration = MDMAPIUtils.getTenantConfigurationManagementService().
|
TenantConfiguration tenantConfiguration = DeviceMgtAPIUtils.getTenantConfigurationManagementService().
|
||||||
getConfiguration(MDMAppConstants.RegistryConstants.GENERAL_CONFIG_RESOURCE_PATH);
|
getConfiguration(MDMAppConstants.RegistryConstants.GENERAL_CONFIG_RESOURCE_PATH);
|
||||||
ConfigurationEntry configurationEntry = new ConfigurationEntry();
|
ConfigurationEntry configurationEntry = new ConfigurationEntry();
|
||||||
configurationEntry.setContentType("text");
|
configurationEntry.setContentType("text");
|
||||||
configurationEntry.setName("notifierFrequency");
|
configurationEntry.setName("notifierFrequency");
|
||||||
configurationEntry.setValue(PolicyManagerUtil.getMonitoringFequency());
|
configurationEntry.setValue(PolicyManagerUtil.getMonitoringFequency());
|
||||||
List<ConfigurationEntry> configList = tenantConfiguration.getConfiguration();
|
List<ConfigurationEntry> configList = tenantConfiguration.getConfiguration();
|
||||||
if (configList == null) {
|
if (configList == null) {
|
||||||
configList = new ArrayList<ConfigurationEntry>();
|
configList = new ArrayList<>();
|
||||||
}
|
}
|
||||||
configList.add(configurationEntry);
|
configList.add(configurationEntry);
|
||||||
tenantConfiguration.setConfiguration(configList);
|
tenantConfiguration.setConfiguration(configList);
|
||||||
return tenantConfiguration;
|
return Response.status(Response.Status.OK).entity(tenantConfiguration).build();
|
||||||
} catch (ConfigurationManagementException e) {
|
} catch (ConfigurationManagementException e) {
|
||||||
msg = "Error occurred while retrieving the tenant configuration.";
|
msg = "Error occurred while retrieving the tenant configuration.";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new MDMAPIException(msg, e);
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@PUT
|
@PUT
|
||||||
public ResponsePayload updateConfiguration(TenantConfiguration configuration) throws MDMAPIException {
|
public Response updateConfiguration(TenantConfiguration configuration) {
|
||||||
ResponsePayload responseMsg = new ResponsePayload();
|
ResponsePayload responseMsg = new ResponsePayload();
|
||||||
try {
|
try {
|
||||||
MDMAPIUtils.getTenantConfigurationManagementService().saveConfiguration(configuration,
|
DeviceMgtAPIUtils.getTenantConfigurationManagementService().saveConfiguration(configuration,
|
||||||
MDMAppConstants.RegistryConstants.GENERAL_CONFIG_RESOURCE_PATH);
|
MDMAppConstants.RegistryConstants.GENERAL_CONFIG_RESOURCE_PATH);
|
||||||
//Schedule the task service
|
//Schedule the task service
|
||||||
MDMAPIUtils.scheduleTaskService(MDMAPIUtils.getNotifierFrequency(configuration));
|
DeviceMgtAPIUtils.scheduleTaskService(DeviceMgtAPIUtils.getNotifierFrequency(configuration));
|
||||||
Response.status(HttpStatus.SC_CREATED);
|
responseMsg.setMessageFromServer("Tenant configuration updated successfully.");
|
||||||
responseMsg.setMessageFromServer("Tenant configuration updated successfully.");
|
|
||||||
responseMsg.setStatusCode(HttpStatus.SC_CREATED);
|
responseMsg.setStatusCode(HttpStatus.SC_CREATED);
|
||||||
return responseMsg;
|
return Response.status(Response.Status.CREATED).entity(responseMsg).build();
|
||||||
} catch (ConfigurationManagementException e) {
|
} catch (ConfigurationManagementException e) {
|
||||||
String msg = "Error occurred while updating the tenant configuration.";
|
String msg = "Error occurred while updating the tenant configuration.";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new MDMAPIException(msg, e);
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,14 +21,20 @@ package org.wso2.carbon.mdm.api;
|
|||||||
import org.apache.commons.httpclient.HttpStatus;
|
import org.apache.commons.httpclient.HttpStatus;
|
||||||
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.wso2.carbon.device.mgt.common.*;
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
||||||
|
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
||||||
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
||||||
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
||||||
import org.wso2.carbon.mdm.api.common.MDMAPIException;
|
import org.wso2.carbon.mdm.api.util.DeviceMgtAPIUtils;
|
||||||
import org.wso2.carbon.mdm.api.util.MDMAPIUtils;
|
|
||||||
import org.wso2.carbon.mdm.api.util.ResponsePayload;
|
import org.wso2.carbon.mdm.api.util.ResponsePayload;
|
||||||
|
|
||||||
import javax.ws.rs.*;
|
import javax.ws.rs.GET;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.PathParam;
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
|
import javax.ws.rs.QueryParam;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -36,25 +42,24 @@ import java.util.List;
|
|||||||
/**
|
/**
|
||||||
* Device related operations
|
* Device related operations
|
||||||
*/
|
*/
|
||||||
public class MobileDevice {
|
@SuppressWarnings("NonJaxWsWebServices")
|
||||||
private static Log log = LogFactory.getLog(MobileDevice.class);
|
public class Device {
|
||||||
|
private static Log log = LogFactory.getLog(Device.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all devices. We have to use accept all the necessary query parameters sent by datatable.
|
* Get all devices. We have to use accept all the necessary query parameters sent by datatable.
|
||||||
* Hence had to put lot of query params here.
|
* Hence had to put lot of query params here.
|
||||||
*
|
*
|
||||||
* @return Device List
|
* @return Device List
|
||||||
* @throws MDMAPIException
|
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
public Object getAllDevices(@QueryParam("type") String type, @QueryParam("user") String user,
|
public Response getAllDevices(@QueryParam("type") String type, @QueryParam("user") String user,
|
||||||
@QueryParam("role") String role, @QueryParam("status") EnrolmentInfo.Status status,
|
@QueryParam("role") String role, @QueryParam("status") EnrolmentInfo.Status status,
|
||||||
@QueryParam("start") int startIdx, @QueryParam("length") int length,
|
@QueryParam("start") int startIdx, @QueryParam("length") int length,
|
||||||
@QueryParam("device-name") String deviceName,
|
@QueryParam("device-name") String deviceName,
|
||||||
@QueryParam("ownership") EnrolmentInfo.OwnerShip ownership
|
@QueryParam("ownership") EnrolmentInfo.OwnerShip ownership) {
|
||||||
) throws MDMAPIException {
|
|
||||||
try {
|
try {
|
||||||
DeviceManagementProviderService service = MDMAPIUtils.getDeviceManagementService();
|
DeviceManagementProviderService service = DeviceMgtAPIUtils.getDeviceManagementService();
|
||||||
//Length > 0 means this is a pagination request.
|
//Length > 0 means this is a pagination request.
|
||||||
if (length > 0) {
|
if (length > 0) {
|
||||||
PaginationRequest paginationRequest = new PaginationRequest(startIdx, length);
|
PaginationRequest paginationRequest = new PaginationRequest(startIdx, length);
|
||||||
@ -67,10 +72,10 @@ public class MobileDevice {
|
|||||||
paginationRequest.setStatus(status.toString());
|
paginationRequest.setStatus(status.toString());
|
||||||
}
|
}
|
||||||
paginationRequest.setDeviceType(type);
|
paginationRequest.setDeviceType(type);
|
||||||
return service.getAllDevices(paginationRequest);
|
return Response.status(Response.Status.OK).entity(service.getAllDevices(paginationRequest)).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Device> allDevices = null;
|
List<org.wso2.carbon.device.mgt.common.Device> allDevices;
|
||||||
if ((type != null) && !type.isEmpty()) {
|
if ((type != null) && !type.isEmpty()) {
|
||||||
allDevices = service.getAllDevices(type);
|
allDevices = service.getAllDevices(type);
|
||||||
} else if ((user != null) && !user.isEmpty()) {
|
} else if ((user != null) && !user.isEmpty()) {
|
||||||
@ -84,11 +89,11 @@ public class MobileDevice {
|
|||||||
} else {
|
} else {
|
||||||
allDevices = service.getAllDevices();
|
allDevices = service.getAllDevices();
|
||||||
}
|
}
|
||||||
return allDevices;
|
return Response.status(Response.Status.OK).entity(allDevices).build();
|
||||||
} catch (DeviceManagementException e) {
|
} catch (DeviceManagementException e) {
|
||||||
String msg = "Error occurred while fetching the device list.";
|
String msg = "Error occurred while fetching the device list.";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new MDMAPIException(msg, e);
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,60 +101,75 @@ public class MobileDevice {
|
|||||||
* Fetch device details for a given device type and device Id.
|
* Fetch device details for a given device type and device Id.
|
||||||
*
|
*
|
||||||
* @return Device wrapped inside Response
|
* @return Device wrapped inside Response
|
||||||
* @throws MDMAPIException
|
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@Path("view")
|
@Path("view")
|
||||||
@Produces({MediaType.APPLICATION_JSON})
|
@Produces({MediaType.APPLICATION_JSON})
|
||||||
public Response getDevice(@QueryParam("type") String type,
|
public Response getDevice(@QueryParam("type") String type,
|
||||||
@QueryParam("id") String id) throws MDMAPIException {
|
@QueryParam("id") String id) {
|
||||||
DeviceIdentifier deviceIdentifier = MDMAPIUtils.instantiateDeviceIdentifier(type, id);
|
DeviceIdentifier deviceIdentifier = DeviceMgtAPIUtils.instantiateDeviceIdentifier(type, id);
|
||||||
DeviceManagementProviderService deviceManagementProviderService = MDMAPIUtils.getDeviceManagementService();
|
DeviceManagementProviderService deviceManagementProviderService = DeviceMgtAPIUtils.getDeviceManagementService();
|
||||||
Device device;
|
org.wso2.carbon.device.mgt.common.Device device;
|
||||||
try {
|
try {
|
||||||
device = deviceManagementProviderService.getDevice(deviceIdentifier);
|
device = deviceManagementProviderService.getDevice(deviceIdentifier);
|
||||||
} catch (DeviceManagementException e) {
|
} catch (DeviceManagementException e) {
|
||||||
String error = "Error occurred while fetching the device information.";
|
String msg = "Error occurred while fetching the device information.";
|
||||||
log.error(error, e);
|
log.error(msg, e);
|
||||||
throw new MDMAPIException(error, e);
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
}
|
}
|
||||||
ResponsePayload responsePayload = new ResponsePayload();
|
ResponsePayload responsePayload = new ResponsePayload();
|
||||||
if (device == null) {
|
if (device == null) {
|
||||||
responsePayload.setStatusCode(HttpStatus.SC_NOT_FOUND);
|
responsePayload.setStatusCode(HttpStatus.SC_NOT_FOUND);
|
||||||
responsePayload.setMessageFromServer("Requested device by type: " +
|
responsePayload.setMessageFromServer("Requested device by type: " +
|
||||||
type + " and id: " + id + " does not exist.");
|
type + " and id: " + id + " does not exist.");
|
||||||
return Response.status(HttpStatus.SC_NOT_FOUND).entity(responsePayload).build();
|
return Response.status(Response.Status.NOT_FOUND).entity(responsePayload).build();
|
||||||
} else {
|
} else {
|
||||||
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
||||||
responsePayload.setMessageFromServer("Sending Requested device by type: " + type + " and id: " + id + ".");
|
responsePayload.setMessageFromServer("Sending Requested device by type: " + type + " and id: " + id + ".");
|
||||||
responsePayload.setResponseContent(device);
|
responsePayload.setResponseContent(device);
|
||||||
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
|
return Response.status(Response.Status.OK).entity(responsePayload).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch Android device details of a given user.
|
* Fetch device details of a given user.
|
||||||
*
|
*
|
||||||
* @param user User Name
|
* @param user User Name
|
||||||
* @param tenantDomain tenant domain
|
|
||||||
* @return Device
|
* @return Device
|
||||||
* @throws MDMAPIException
|
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@Path("user/{user}/{tenantDomain}")
|
@Path("user/{user}")
|
||||||
public List<Device> getDeviceByUser(@PathParam("user") String user,
|
public Response getDevice(@PathParam("user") String user) {
|
||||||
@PathParam("tenantDomain") String tenantDomain) throws MDMAPIException {
|
List<org.wso2.carbon.device.mgt.common.Device> devices;
|
||||||
List<Device> devices;
|
|
||||||
try {
|
try {
|
||||||
devices = MDMAPIUtils.getDeviceManagementService().getDevicesOfUser(user);
|
devices = DeviceMgtAPIUtils.getDeviceManagementService().getDevicesOfUser(user);
|
||||||
if (devices == null) {
|
if (devices == null) {
|
||||||
Response.status(Response.Status.NOT_FOUND);
|
return Response.status(Response.Status.NOT_FOUND).build();
|
||||||
}
|
}
|
||||||
return devices;
|
return Response.status(Response.Status.OK).entity(devices).build();
|
||||||
} catch (DeviceManagementException e) {
|
} catch (DeviceManagementException e) {
|
||||||
String msg = "Error occurred while fetching the devices list of given user.";
|
String msg = "Error occurred while fetching the devices list of given user.";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new MDMAPIException(msg, e);
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch device count of a given user.
|
||||||
|
*
|
||||||
|
* @param user User Name
|
||||||
|
* @return Device
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@Path("user/{user}/count")
|
||||||
|
public Response getDeviceCount(@PathParam("user") String user) {
|
||||||
|
try {
|
||||||
|
Integer count = DeviceMgtAPIUtils.getDeviceManagementService().getDeviceCount(user);
|
||||||
|
return Response.status(Response.Status.OK).entity(count).build();
|
||||||
|
} catch (DeviceManagementException e) {
|
||||||
|
String msg = "Error occurred while fetching the devices list of given user.";
|
||||||
|
log.error(msg, e);
|
||||||
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,17 +177,17 @@ public class MobileDevice {
|
|||||||
* Get current device count
|
* Get current device count
|
||||||
*
|
*
|
||||||
* @return device count
|
* @return device count
|
||||||
* @throws MDMAPIException
|
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@Path("count")
|
@Path("count")
|
||||||
public int getDeviceCount() throws MDMAPIException {
|
public Response getDeviceCount() {
|
||||||
try {
|
try {
|
||||||
return MDMAPIUtils.getDeviceManagementService().getDeviceCount();
|
Integer count = DeviceMgtAPIUtils.getDeviceManagementService().getDeviceCount();
|
||||||
|
return Response.status(Response.Status.OK).entity(count).build();
|
||||||
} catch (DeviceManagementException e) {
|
} catch (DeviceManagementException e) {
|
||||||
String msg = "Error occurred while fetching the device count.";
|
String msg = "Error occurred while fetching the device count.";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new MDMAPIException(msg, e);
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -177,42 +197,38 @@ public class MobileDevice {
|
|||||||
* @param deviceName Device name
|
* @param deviceName Device name
|
||||||
* @param tenantDomain Callee tenant domain
|
* @param tenantDomain Callee tenant domain
|
||||||
* @return list of devices.
|
* @return list of devices.
|
||||||
* @throws MDMAPIException If some unusual behaviour is observed while fetching the device list
|
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@Path("name/{name}/{tenantDomain}")
|
@Path("name/{name}/{tenantDomain}")
|
||||||
public List<Device> getDevicesByName(@PathParam("name") String deviceName,
|
public Response getDevicesByName(@PathParam("name") String deviceName,
|
||||||
@PathParam("tenantDomain") String tenantDomain) throws MDMAPIException {
|
@PathParam("tenantDomain") String tenantDomain) {
|
||||||
|
List<org.wso2.carbon.device.mgt.common.Device> devices;
|
||||||
List<Device> devices;
|
|
||||||
try {
|
try {
|
||||||
devices = MDMAPIUtils.getDeviceManagementService().getDevicesByName(deviceName);
|
devices = DeviceMgtAPIUtils.getDeviceManagementService().getDevicesByName(deviceName);
|
||||||
|
return Response.status(Response.Status.OK).entity(devices).build();
|
||||||
} catch (DeviceManagementException e) {
|
} catch (DeviceManagementException e) {
|
||||||
String msg = "Error occurred while fetching the devices list of device name.";
|
String msg = "Error occurred while fetching the devices list of device name.";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new MDMAPIException(msg, e);
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
}
|
}
|
||||||
return devices;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the list of available device types.
|
* Get the list of available device types.
|
||||||
*
|
*
|
||||||
* @return list of device types.
|
* @return list of device types.
|
||||||
* @throws MDMAPIException If some unusual behaviour is observed while fetching the device list
|
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@Path("types")
|
@Path("types")
|
||||||
public List<DeviceType> getDeviceTypes() throws MDMAPIException {
|
public Response getDeviceTypes() {
|
||||||
|
List<DeviceType> deviceTypes;
|
||||||
List<DeviceType> deviceTypes;
|
try {
|
||||||
try {
|
deviceTypes = DeviceMgtAPIUtils.getDeviceManagementService().getAvailableDeviceTypes();
|
||||||
deviceTypes = MDMAPIUtils.getDeviceManagementService().getAvailableDeviceTypes();
|
return Response.status(Response.Status.OK).entity(deviceTypes).build();
|
||||||
} catch (DeviceManagementException e) {
|
} catch (DeviceManagementException e) {
|
||||||
String msg = "Error occurred while fetching the list of device types.";
|
String msg = "Error occurred while fetching the list of device types.";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new MDMAPIException(msg, e);
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
}
|
}
|
||||||
return deviceTypes;
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@ -19,7 +19,6 @@
|
|||||||
|
|
||||||
package org.wso2.carbon.mdm.api;
|
package org.wso2.carbon.mdm.api;
|
||||||
|
|
||||||
import org.apache.commons.httpclient.HttpStatus;
|
|
||||||
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.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||||
@ -27,57 +26,55 @@ import org.wso2.carbon.device.mgt.common.device.details.DeviceInfo;
|
|||||||
import org.wso2.carbon.device.mgt.common.device.details.DeviceLocation;
|
import org.wso2.carbon.device.mgt.common.device.details.DeviceLocation;
|
||||||
import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceDetailsMgtException;
|
import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceDetailsMgtException;
|
||||||
import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceInformationManager;
|
import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceInformationManager;
|
||||||
import org.wso2.carbon.mdm.api.common.MDMAPIException;
|
import org.wso2.carbon.mdm.api.util.DeviceMgtAPIUtils;
|
||||||
import org.wso2.carbon.mdm.api.util.MDMAPIUtils;
|
|
||||||
|
|
||||||
import javax.ws.rs.GET;
|
import javax.ws.rs.GET;
|
||||||
import javax.ws.rs.Path;
|
import javax.ws.rs.Path;
|
||||||
import javax.ws.rs.PathParam;
|
import javax.ws.rs.PathParam;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
|
|
||||||
|
@SuppressWarnings("NonJaxWsWebServices")
|
||||||
public class DeviceInformation {
|
public class DeviceInformation {
|
||||||
|
|
||||||
private static Log log = LogFactory.getLog(DeviceInformation.class);
|
private static Log log = LogFactory.getLog(DeviceInformation.class);
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("{type}/{id}")
|
@Path("{type}/{id}")
|
||||||
public Response getDeviceInfo(@PathParam("type") String type, @PathParam("id") String id) throws MDMAPIException {
|
public Response getDeviceInfo(@PathParam("type") String type, @PathParam("id") String id) {
|
||||||
DeviceInformationManager informationManager;
|
DeviceInformationManager informationManager;
|
||||||
DeviceInfo deviceInfo;
|
DeviceInfo deviceInfo;
|
||||||
try {
|
try {
|
||||||
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
||||||
deviceIdentifier.setId(id);
|
deviceIdentifier.setId(id);
|
||||||
deviceIdentifier.setType(type);
|
deviceIdentifier.setType(type);
|
||||||
informationManager = MDMAPIUtils.getDeviceInformationManagerService();
|
informationManager = DeviceMgtAPIUtils.getDeviceInformationManagerService();
|
||||||
deviceInfo = informationManager.getDeviceInfo(deviceIdentifier);
|
deviceInfo = informationManager.getDeviceInfo(deviceIdentifier);
|
||||||
|
|
||||||
} catch (DeviceDetailsMgtException e) {
|
} catch (DeviceDetailsMgtException e) {
|
||||||
String msg = "Error occurred while getting the device information.";
|
String msg = "Error occurred while getting the device information.";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new MDMAPIException(msg, e);
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
}
|
}
|
||||||
return Response.status(HttpStatus.SC_OK).entity(deviceInfo).build();
|
return Response.status(Response.Status.OK).entity(deviceInfo).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("location/{type}/{id}")
|
@Path("location/{type}/{id}")
|
||||||
public Response getDeviceLocation(@PathParam("type") String type, @PathParam("id") String id) throws MDMAPIException {
|
public Response getDeviceLocation(@PathParam("type") String type, @PathParam("id") String id) {
|
||||||
DeviceInformationManager informationManager;
|
DeviceInformationManager informationManager;
|
||||||
DeviceLocation deviceLocation;
|
DeviceLocation deviceLocation;
|
||||||
try {
|
try {
|
||||||
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
||||||
deviceIdentifier.setId(id);
|
deviceIdentifier.setId(id);
|
||||||
deviceIdentifier.setType(type);
|
deviceIdentifier.setType(type);
|
||||||
informationManager = MDMAPIUtils.getDeviceInformationManagerService();
|
informationManager = DeviceMgtAPIUtils.getDeviceInformationManagerService();
|
||||||
deviceLocation = informationManager.getDeviceLocation(deviceIdentifier);
|
deviceLocation = informationManager.getDeviceLocation(deviceIdentifier);
|
||||||
|
|
||||||
} catch (DeviceDetailsMgtException e) {
|
} catch (DeviceDetailsMgtException e) {
|
||||||
String msg = "Error occurred while getting the device location.";
|
String msg = "Error occurred while getting the device location.";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new MDMAPIException(msg, e);
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
}
|
}
|
||||||
return Response.status(HttpStatus.SC_OK).entity(deviceLocation).build();
|
return Response.status(Response.Status.OK).entity(deviceLocation).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,17 +1,17 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
*
|
*
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
* in compliance with the License.
|
* in compliance with the License.
|
||||||
* you may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing,
|
* Unless required by applicable law or agreed to in writing,
|
||||||
* software distributed under the License is distributed on an
|
* software distributed under the License is distributed on an
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
* KIND, either express or implied. See the License for the
|
* KIND, either express or implied. See the License for the
|
||||||
* specific language governing permissions and limitations
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
@ -21,14 +21,18 @@ package org.wso2.carbon.mdm.api;
|
|||||||
import org.apache.commons.httpclient.HttpStatus;
|
import org.apache.commons.httpclient.HttpStatus;
|
||||||
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.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementException;
|
|
||||||
import org.wso2.carbon.device.mgt.common.notification.mgt.Notification;
|
import org.wso2.carbon.device.mgt.common.notification.mgt.Notification;
|
||||||
import org.wso2.carbon.mdm.api.common.MDMAPIException;
|
import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementException;
|
||||||
import org.wso2.carbon.mdm.api.util.MDMAPIUtils;
|
import org.wso2.carbon.mdm.api.util.DeviceMgtAPIUtils;
|
||||||
import org.wso2.carbon.mdm.api.util.ResponsePayload;
|
import org.wso2.carbon.mdm.api.util.ResponsePayload;
|
||||||
|
|
||||||
import javax.jws.WebService;
|
import javax.ws.rs.Consumes;
|
||||||
import javax.ws.rs.*;
|
import javax.ws.rs.GET;
|
||||||
|
import javax.ws.rs.POST;
|
||||||
|
import javax.ws.rs.PUT;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.PathParam;
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -36,73 +40,70 @@ import java.util.List;
|
|||||||
* DeviceNotification management REST-API implementation.
|
* DeviceNotification management REST-API implementation.
|
||||||
* All end points support JSON, XMl with content negotiation.
|
* All end points support JSON, XMl with content negotiation.
|
||||||
*/
|
*/
|
||||||
@WebService
|
@SuppressWarnings("NonJaxWsWebServices")
|
||||||
@Produces({ "application/json", "application/xml" })
|
@Produces({"application/json", "application/xml"})
|
||||||
@Consumes({ "application/json", "application/xml" })
|
@Consumes({ "application/json", "application/xml" })
|
||||||
public class DeviceNotification {
|
public class DeviceNotification {
|
||||||
|
|
||||||
private static Log log = LogFactory.getLog(Configuration.class);
|
private static Log log = LogFactory.getLog(Configuration.class);
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
public List<Notification> getNotifications() throws MDMAPIException {
|
public Response getNotifications() {
|
||||||
String msg;
|
String msg;
|
||||||
try {
|
try {
|
||||||
return MDMAPIUtils.getNotificationManagementService().getAllNotifications();
|
List<Notification> notifications = DeviceMgtAPIUtils.getNotificationManagementService().getAllNotifications();
|
||||||
} catch (NotificationManagementException e) {
|
return Response.status(Response.Status.OK).entity(notifications).build();
|
||||||
msg = "Error occurred while retrieving the notification list.";
|
} catch (NotificationManagementException e) {
|
||||||
log.error(msg, e);
|
msg = "Error occurred while retrieving the notification list.";
|
||||||
throw new MDMAPIException(msg, e);
|
log.error(msg, e);
|
||||||
}
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("{status}")
|
@Path("{status}")
|
||||||
public List<Notification> getNotificationsByStatus(@PathParam("status") Notification.Status status)
|
public Response getNotificationsByStatus(@PathParam("status") Notification.Status status) {
|
||||||
throws MDMAPIException {
|
String msg;
|
||||||
String msg;
|
try {
|
||||||
try {
|
List<Notification> notifications = DeviceMgtAPIUtils.getNotificationManagementService().getNotificationsByStatus(status);
|
||||||
return MDMAPIUtils.getNotificationManagementService().getNotificationsByStatus(status);
|
return Response.status(Response.Status.OK).entity(notifications).build();
|
||||||
} catch (NotificationManagementException e) {
|
} catch (NotificationManagementException e) {
|
||||||
msg = "Error occurred while retrieving the notification list.";
|
msg = "Error occurred while retrieving the notification list.";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new MDMAPIException(msg, e);
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@PUT
|
@PUT
|
||||||
@Path("{id}/{status}")
|
@Path("{id}/{status}")
|
||||||
public ResponsePayload updateNotificationStatus(@PathParam("id") int id,
|
public Response updateNotificationStatus(@PathParam("id") int id,
|
||||||
@PathParam("status") Notification.Status status)
|
@PathParam("status") Notification.Status status) {
|
||||||
throws MDMAPIException{
|
ResponsePayload responseMsg = new ResponsePayload();
|
||||||
ResponsePayload responseMsg = new ResponsePayload();
|
try {
|
||||||
try {
|
DeviceMgtAPIUtils.getNotificationManagementService().updateNotificationStatus(id, status);
|
||||||
MDMAPIUtils.getNotificationManagementService().updateNotificationStatus(id, status);
|
responseMsg.setMessageFromServer("Notification status updated successfully.");
|
||||||
Response.status(HttpStatus.SC_ACCEPTED);
|
|
||||||
responseMsg.setMessageFromServer("Notification status updated successfully.");
|
|
||||||
responseMsg.setStatusCode(HttpStatus.SC_ACCEPTED);
|
responseMsg.setStatusCode(HttpStatus.SC_ACCEPTED);
|
||||||
return responseMsg;
|
return Response.status(Response.Status.ACCEPTED).entity(responseMsg).build();
|
||||||
} catch (NotificationManagementException e) {
|
} catch (NotificationManagementException e) {
|
||||||
String msg = "Error occurred while updating notification status.";
|
String msg = "Error occurred while updating notification status.";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new MDMAPIException(msg, e);
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
public ResponsePayload addNotification(Notification notification)
|
public Response addNotification(Notification notification) {
|
||||||
throws MDMAPIException{
|
ResponsePayload responseMsg = new ResponsePayload();
|
||||||
ResponsePayload responseMsg = new ResponsePayload();
|
try {
|
||||||
try {
|
DeviceMgtAPIUtils.getNotificationManagementService().addNotification(notification);
|
||||||
MDMAPIUtils.getNotificationManagementService().addNotification(notification);
|
responseMsg.setMessageFromServer("Notification has added successfully.");
|
||||||
Response.status(HttpStatus.SC_CREATED);
|
|
||||||
responseMsg.setMessageFromServer("Notification has added successfully.");
|
|
||||||
responseMsg.setStatusCode(HttpStatus.SC_CREATED);
|
responseMsg.setStatusCode(HttpStatus.SC_CREATED);
|
||||||
return responseMsg;
|
return Response.status(Response.Status.CREATED).entity(responseMsg).build();
|
||||||
} catch (NotificationManagementException e) {
|
} catch (NotificationManagementException e) {
|
||||||
String msg = "Error occurred while updating notification status.";
|
String msg = "Error occurred while updating notification status.";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new MDMAPIException(msg, e);
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,38 +19,37 @@
|
|||||||
|
|
||||||
package org.wso2.carbon.mdm.api;
|
package org.wso2.carbon.mdm.api;
|
||||||
|
|
||||||
import org.apache.commons.httpclient.HttpStatus;
|
|
||||||
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.wso2.carbon.device.mgt.common.device.details.DeviceWrapper;
|
import org.wso2.carbon.device.mgt.common.device.details.DeviceWrapper;
|
||||||
import org.wso2.carbon.device.mgt.common.search.SearchContext;
|
import org.wso2.carbon.device.mgt.common.search.SearchContext;
|
||||||
import org.wso2.carbon.device.mgt.core.search.mgt.SearchManagerService;
|
import org.wso2.carbon.device.mgt.core.search.mgt.SearchManagerService;
|
||||||
import org.wso2.carbon.device.mgt.core.search.mgt.SearchMgtException;
|
import org.wso2.carbon.device.mgt.core.search.mgt.SearchMgtException;
|
||||||
import org.wso2.carbon.mdm.api.common.MDMAPIException;
|
import org.wso2.carbon.mdm.api.util.DeviceMgtAPIUtils;
|
||||||
import org.wso2.carbon.mdm.api.util.MDMAPIUtils;
|
|
||||||
|
|
||||||
import javax.ws.rs.GET;
|
import javax.ws.rs.GET;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@SuppressWarnings("NonJaxWsWebServices")
|
||||||
public class DeviceSearch {
|
public class DeviceSearch {
|
||||||
|
|
||||||
private static Log log = LogFactory.getLog(DeviceSearch.class);
|
private static Log log = LogFactory.getLog(DeviceSearch.class);
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
public Response getDeviceInfo(SearchContext searchContext) throws MDMAPIException {
|
public Response getDeviceInfo(SearchContext searchContext) {
|
||||||
SearchManagerService searchManagerService;
|
SearchManagerService searchManagerService;
|
||||||
List<DeviceWrapper> devices;
|
List<DeviceWrapper> devices;
|
||||||
try {
|
try {
|
||||||
searchManagerService = MDMAPIUtils.getSearchManagerService();
|
searchManagerService = DeviceMgtAPIUtils.getSearchManagerService();
|
||||||
devices = searchManagerService.search(searchContext);
|
devices = searchManagerService.search(searchContext);
|
||||||
|
|
||||||
} catch (SearchMgtException e) {
|
} catch (SearchMgtException e) {
|
||||||
String msg = "Error occurred while searching the device information.";
|
String msg = "Error occurred while searching the device information.";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new MDMAPIException(msg, e);
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
}
|
}
|
||||||
return Response.status(HttpStatus.SC_OK).entity(devices).build();
|
return Response.status(Response.Status.OK).entity(devices).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -22,15 +22,20 @@ import org.apache.commons.logging.Log;
|
|||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||||
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
||||||
import org.wso2.carbon.mdm.api.common.MDMAPIException;
|
import org.wso2.carbon.mdm.api.util.DeviceMgtAPIUtils;
|
||||||
import org.wso2.carbon.mdm.api.util.MDMAPIUtils;
|
|
||||||
|
|
||||||
import javax.ws.rs.*;
|
import javax.ws.rs.Consumes;
|
||||||
|
import javax.ws.rs.GET;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.PathParam;
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Features
|
* Features
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("NonJaxWsWebServices")
|
||||||
@Produces({"application/json", "application/xml"})
|
@Produces({"application/json", "application/xml"})
|
||||||
@Consumes({"application/json", "application/xml"})
|
@Consumes({"application/json", "application/xml"})
|
||||||
public class Feature {
|
public class Feature {
|
||||||
@ -40,24 +45,21 @@ public class Feature {
|
|||||||
* Get all features for Mobile Device Type
|
* Get all features for Mobile Device Type
|
||||||
*
|
*
|
||||||
* @return Feature
|
* @return Feature
|
||||||
* @throws MDMAPIException
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@Path("/{type}")
|
@Path("/{type}")
|
||||||
public List<org.wso2.carbon.device.mgt.common.Feature> getFeatures(@PathParam("type") String type)
|
public Response getFeatures(@PathParam("type") String type) {
|
||||||
throws MDMAPIException {
|
|
||||||
List<org.wso2.carbon.device.mgt.common.Feature> features;
|
List<org.wso2.carbon.device.mgt.common.Feature> features;
|
||||||
DeviceManagementProviderService dmService;
|
DeviceManagementProviderService dmService;
|
||||||
try {
|
try {
|
||||||
dmService = MDMAPIUtils.getDeviceManagementService();
|
dmService = DeviceMgtAPIUtils.getDeviceManagementService();
|
||||||
features = dmService.getFeatureManager(type).getFeatures();
|
features = dmService.getFeatureManager(type).getFeatures();
|
||||||
} catch (DeviceManagementException e) {
|
} catch (DeviceManagementException e) {
|
||||||
String msg = "Error occurred while retrieving the list of features";
|
String msg = "Error occurred while retrieving the list of features";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new MDMAPIException(msg, e);
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
}
|
}
|
||||||
return features;
|
return Response.status(Response.Status.OK).entity(features).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,443 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.wso2.carbon.mdm.api;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||||
|
import org.wso2.carbon.device.mgt.common.Device;
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||||
|
import org.wso2.carbon.device.mgt.common.PaginationResult;
|
||||||
|
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup;
|
||||||
|
import org.wso2.carbon.device.mgt.common.group.mgt.GroupAlreadyEixistException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.group.mgt.GroupManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.group.mgt.GroupUser;
|
||||||
|
import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService;
|
||||||
|
import org.wso2.carbon.mdm.api.util.DeviceMgtAPIUtils;
|
||||||
|
|
||||||
|
import javax.ws.rs.Consumes;
|
||||||
|
import javax.ws.rs.DELETE;
|
||||||
|
import javax.ws.rs.FormParam;
|
||||||
|
import javax.ws.rs.GET;
|
||||||
|
import javax.ws.rs.POST;
|
||||||
|
import javax.ws.rs.PUT;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.PathParam;
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
|
import javax.ws.rs.QueryParam;
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@SuppressWarnings("NonJaxWsWebServices")
|
||||||
|
public class Group {
|
||||||
|
|
||||||
|
private static final String DEFAULT_ADMIN_ROLE = "admin";
|
||||||
|
private static final String DEFAULT_OPERATOR_ROLE = "invoke-device-operations";
|
||||||
|
private static final String DEFAULT_STATS_MONITOR_ROLE = "view-statistics";
|
||||||
|
private static final String DEFAULT_VIEW_POLICIES = "view-policies";
|
||||||
|
private static final String DEFAULT_MANAGE_POLICIES = "mange-policies";
|
||||||
|
private static final String DEFAULT_VIEW_EVENTS = "view-events";
|
||||||
|
private static final String[] DEFAULT_ADMIN_PERMISSIONS = {"/permission/device-mgt/admin/groups",
|
||||||
|
"/permission/device-mgt/user/groups"};
|
||||||
|
private static final String[] DEFAULT_OPERATOR_PERMISSIONS = {"/permission/device-mgt/user/groups/device_operation"};
|
||||||
|
private static final String[] DEFAULT_STATS_MONITOR_PERMISSIONS = {"/permission/device-mgt/user/groups/device_monitor"};
|
||||||
|
private static final String[] DEFAULT_MANAGE_POLICIES_PERMISSIONS = {"/permission/device-mgt/user/groups/device_policies/add"};
|
||||||
|
private static final String[] DEFAULT_VIEW_POLICIES_PERMISSIONS = {"/permission/device-mgt/user/groups/device_policies/view"};
|
||||||
|
private static final String[] DEFAULT_VIEW_EVENTS_PERMISSIONS = {"/permission/device-mgt/user/groups/device_events"};
|
||||||
|
|
||||||
|
private static Log log = LogFactory.getLog(Group.class);
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Consumes("application/json")
|
||||||
|
public Response createGroup(DeviceGroup group) {
|
||||||
|
String owner = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
||||||
|
if (group == null) {
|
||||||
|
return Response.status(Response.Status.BAD_REQUEST).build();
|
||||||
|
}
|
||||||
|
group.setOwner(owner);
|
||||||
|
group.setDateOfCreation(new Date().getTime());
|
||||||
|
group.setDateOfLastUpdate(new Date().getTime());
|
||||||
|
try {
|
||||||
|
GroupManagementProviderService groupManagementService = DeviceMgtAPIUtils.getGroupManagementProviderService();
|
||||||
|
groupManagementService.createGroup(group, DEFAULT_ADMIN_ROLE, DEFAULT_ADMIN_PERMISSIONS);
|
||||||
|
groupManagementService.addGroupSharingRole(owner, group.getName(), owner,
|
||||||
|
DEFAULT_OPERATOR_ROLE,
|
||||||
|
DEFAULT_OPERATOR_PERMISSIONS);
|
||||||
|
groupManagementService.addGroupSharingRole(owner, group.getName(), owner, DEFAULT_STATS_MONITOR_ROLE,
|
||||||
|
DEFAULT_STATS_MONITOR_PERMISSIONS);
|
||||||
|
groupManagementService.addGroupSharingRole(owner, group.getName(), owner, DEFAULT_VIEW_POLICIES,
|
||||||
|
DEFAULT_VIEW_POLICIES_PERMISSIONS);
|
||||||
|
groupManagementService.addGroupSharingRole(owner, group.getName(), owner, DEFAULT_MANAGE_POLICIES,
|
||||||
|
DEFAULT_MANAGE_POLICIES_PERMISSIONS);
|
||||||
|
groupManagementService.addGroupSharingRole(owner, group.getName(), owner, DEFAULT_VIEW_EVENTS,
|
||||||
|
DEFAULT_VIEW_EVENTS_PERMISSIONS);
|
||||||
|
return Response.status(Response.Status.CREATED).build();
|
||||||
|
} catch (GroupAlreadyEixistException e) {
|
||||||
|
return Response.status(Response.Status.CONFLICT).entity(e.getMessage()).build();
|
||||||
|
} catch (GroupManagementException e) {
|
||||||
|
log.error(e.getErrorMessage(), e);
|
||||||
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Path("/{owner}/{groupName}")
|
||||||
|
@PUT
|
||||||
|
@Consumes("application/json")
|
||||||
|
@Produces("application/json")
|
||||||
|
public Response updateGroup(@PathParam("groupName") String groupName, @PathParam("owner") String owner,
|
||||||
|
DeviceGroup deviceGroup) {
|
||||||
|
try {
|
||||||
|
DeviceMgtAPIUtils.getGroupManagementProviderService().updateGroup(deviceGroup, groupName, owner);
|
||||||
|
return Response.status(Response.Status.OK).build();
|
||||||
|
} catch (GroupManagementException e) {
|
||||||
|
log.error(e.getErrorMessage(), e);
|
||||||
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Path("/{owner}/{groupName}")
|
||||||
|
@DELETE
|
||||||
|
public Response deleteGroup(@PathParam("groupName") String groupName, @PathParam("owner") String owner) {
|
||||||
|
try {
|
||||||
|
DeviceMgtAPIUtils.getGroupManagementProviderService().deleteGroup(groupName, owner);
|
||||||
|
return Response.status(Response.Status.OK).build();
|
||||||
|
} catch (GroupManagementException e) {
|
||||||
|
log.error(e.getMessage());
|
||||||
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Produces("application/json")
|
||||||
|
public Response getGroups(@QueryParam("start") int startIndex, @PathParam("rowCount") int rowCount) {
|
||||||
|
try {
|
||||||
|
PaginationResult paginationResult = DeviceMgtAPIUtils.getGroupManagementProviderService()
|
||||||
|
.getGroups(startIndex, rowCount);
|
||||||
|
if (paginationResult.getRecordsTotal() > 0) {
|
||||||
|
return Response.status(Response.Status.OK).entity(paginationResult).build();
|
||||||
|
} else {
|
||||||
|
return Response.status(Response.Status.NOT_FOUND).build();
|
||||||
|
}
|
||||||
|
} catch (GroupManagementException e) {
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Path("/user/{user}")
|
||||||
|
@GET
|
||||||
|
@Produces("application/json")
|
||||||
|
public Response getGroups(@PathParam("user") String userName, @QueryParam("start") int startIndex,
|
||||||
|
@QueryParam("rowCount") int rowCount) {
|
||||||
|
try {
|
||||||
|
PaginationResult paginationResult = DeviceMgtAPIUtils.getGroupManagementProviderService()
|
||||||
|
.getGroups(userName, startIndex, rowCount);
|
||||||
|
if (paginationResult.getRecordsTotal() > 0) {
|
||||||
|
return Response.status(Response.Status.OK).entity(paginationResult).build();
|
||||||
|
} else {
|
||||||
|
return Response.status(Response.Status.NOT_FOUND).build();
|
||||||
|
}
|
||||||
|
} catch (GroupManagementException e) {
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Path("/{owner}/{groupName}")
|
||||||
|
@GET
|
||||||
|
@Produces("application/json")
|
||||||
|
public Response getGroup(@PathParam("groupName") String groupName, @PathParam("owner") String owner) {
|
||||||
|
try {
|
||||||
|
DeviceGroup deviceGroup = DeviceMgtAPIUtils.getGroupManagementProviderService().getGroup(groupName, owner);
|
||||||
|
if (deviceGroup != null) {
|
||||||
|
return Response.status(Response.Status.OK).entity(deviceGroup).build();
|
||||||
|
} else {
|
||||||
|
return Response.status(Response.Status.NOT_FOUND).build();
|
||||||
|
}
|
||||||
|
} catch (GroupManagementException e) {
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Path("/search")
|
||||||
|
@GET
|
||||||
|
@Produces("application/json")
|
||||||
|
public Response findGroups(@QueryParam("groupName") String groupName,
|
||||||
|
@QueryParam("userName") String userName) {
|
||||||
|
try {
|
||||||
|
List<DeviceGroup> groups = DeviceMgtAPIUtils.getGroupManagementProviderService()
|
||||||
|
.findInGroups(groupName, userName);
|
||||||
|
DeviceGroup[] deviceGroups = new DeviceGroup[groups.size()];
|
||||||
|
groups.toArray(deviceGroups);
|
||||||
|
return Response.status(Response.Status.OK).entity(deviceGroups).build();
|
||||||
|
} catch (GroupManagementException e) {
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Path("/user/{user}/all")
|
||||||
|
@GET
|
||||||
|
@Produces("application/json")
|
||||||
|
public Response getGroups(@PathParam("user") String userName,
|
||||||
|
@QueryParam("permission") String permission) {
|
||||||
|
try {
|
||||||
|
GroupManagementProviderService groupManagementService = DeviceMgtAPIUtils.getGroupManagementProviderService();
|
||||||
|
List<DeviceGroup> groups;
|
||||||
|
if (permission != null) {
|
||||||
|
groups = groupManagementService.getGroups(userName, permission);
|
||||||
|
} else {
|
||||||
|
groups = groupManagementService.getGroups(userName);
|
||||||
|
}
|
||||||
|
DeviceGroup[] deviceGroups = new DeviceGroup[groups.size()];
|
||||||
|
groups.toArray(deviceGroups);
|
||||||
|
return Response.status(Response.Status.OK).entity(deviceGroups).build();
|
||||||
|
} catch (GroupManagementException e) {
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Path("/user/{user}/count")
|
||||||
|
@GET
|
||||||
|
@Produces("application/json")
|
||||||
|
public Response getGroupCount(@PathParam("user") String userName) {
|
||||||
|
try {
|
||||||
|
int count = DeviceMgtAPIUtils.getGroupManagementProviderService().getGroupCount(userName);
|
||||||
|
return Response.status(Response.Status.OK).entity(count).build();
|
||||||
|
} catch (GroupManagementException e) {
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Path("/{owner}/{groupName}/share")
|
||||||
|
@PUT
|
||||||
|
@Produces("application/json")
|
||||||
|
public Response shareGroup(@PathParam("groupName") String groupName, @PathParam("owner") String owner,
|
||||||
|
@FormParam("shareUser") String shareUser,
|
||||||
|
@FormParam("roleName") String sharingRole) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
boolean isShared = DeviceMgtAPIUtils.getGroupManagementProviderService().shareGroup(
|
||||||
|
shareUser, groupName, owner, sharingRole);
|
||||||
|
if (isShared) {
|
||||||
|
return Response.status(Response.Status.OK).build();
|
||||||
|
} else {
|
||||||
|
return Response.status(Response.Status.NOT_FOUND).build();
|
||||||
|
}
|
||||||
|
} catch (GroupManagementException e) {
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Path("/{owner}/{groupName}/unshare")
|
||||||
|
@PUT
|
||||||
|
@Produces("application/json")
|
||||||
|
public Response unShareGroup(@PathParam("groupName") String groupName, @PathParam("owner") String owner,
|
||||||
|
@FormParam("unShareUser") String unShareUser,
|
||||||
|
@FormParam("roleName") String sharingRole) {
|
||||||
|
try {
|
||||||
|
boolean isUnShared = DeviceMgtAPIUtils.getGroupManagementProviderService().unshareGroup(
|
||||||
|
unShareUser, groupName, owner, sharingRole);
|
||||||
|
if (isUnShared) {
|
||||||
|
return Response.status(Response.Status.OK).build();
|
||||||
|
} else {
|
||||||
|
return Response.status(Response.Status.NOT_FOUND).build();
|
||||||
|
}
|
||||||
|
} catch (GroupManagementException e) {
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Path("/{owner}/{groupName}/share/roles/{roleName}/permissions")
|
||||||
|
@PUT
|
||||||
|
@Produces("application/json")
|
||||||
|
public Response addSharing(@QueryParam("shareUser") String shareUser, @PathParam("groupName") String groupName,
|
||||||
|
@PathParam("owner") String owner,
|
||||||
|
@PathParam("roleName") String roleName,
|
||||||
|
@FormParam("permissions") String[] permissions) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
boolean isAdded = DeviceMgtAPIUtils.getGroupManagementProviderService().addGroupSharingRole(
|
||||||
|
shareUser, groupName, owner, roleName, permissions);
|
||||||
|
if (isAdded) {
|
||||||
|
return Response.status(Response.Status.OK).build();
|
||||||
|
} else {
|
||||||
|
return Response.status(Response.Status.NOT_FOUND).build();
|
||||||
|
}
|
||||||
|
} catch (GroupManagementException e) {
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@DELETE
|
||||||
|
@Path("/{owner}/{groupName}/share/roles/{roleName}/permissions")
|
||||||
|
@Produces("application/json")
|
||||||
|
public Response removeSharing(@QueryParam("userName") String userName, @PathParam("groupName") String groupName,
|
||||||
|
@PathParam("owner") String owner,
|
||||||
|
@PathParam("roleName") String roleName) {
|
||||||
|
try {
|
||||||
|
boolean isRemoved = DeviceMgtAPIUtils.getGroupManagementProviderService().removeGroupSharingRole(
|
||||||
|
groupName, owner, roleName);
|
||||||
|
if (isRemoved) {
|
||||||
|
return Response.status(Response.Status.OK).build();
|
||||||
|
} else {
|
||||||
|
return Response.status(Response.Status.NOT_FOUND).build();
|
||||||
|
}
|
||||||
|
} catch (GroupManagementException e) {
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("/{owner}/{groupName}/share/roles")
|
||||||
|
@Produces("application/json")
|
||||||
|
public Response getRoles(@PathParam("groupName") String groupName,
|
||||||
|
@PathParam("owner") String owner, @QueryParam("userName") String userName) {
|
||||||
|
try {
|
||||||
|
List<String> roles;
|
||||||
|
if (userName != null && !userName.isEmpty()) {
|
||||||
|
roles = DeviceMgtAPIUtils.getGroupManagementProviderService().getRoles(userName, groupName, owner);
|
||||||
|
} else {
|
||||||
|
roles = DeviceMgtAPIUtils.getGroupManagementProviderService().getRoles(groupName, owner);
|
||||||
|
}
|
||||||
|
String[] rolesArray = new String[roles.size()];
|
||||||
|
roles.toArray(rolesArray);
|
||||||
|
return Response.status(Response.Status.OK).entity(rolesArray).build();
|
||||||
|
} catch (GroupManagementException e) {
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("/{owner}/{groupName}/users")
|
||||||
|
@Produces("application/json")
|
||||||
|
public Response getUsers(@PathParam("groupName") String groupName,
|
||||||
|
@PathParam("owner") String owner) {
|
||||||
|
try {
|
||||||
|
List<GroupUser> users = DeviceMgtAPIUtils.getGroupManagementProviderService().getUsers(
|
||||||
|
groupName, owner);
|
||||||
|
GroupUser[] usersArray = new GroupUser[users.size()];
|
||||||
|
users.toArray(usersArray);
|
||||||
|
return Response.status(Response.Status.OK).entity(usersArray).build();
|
||||||
|
} catch (GroupManagementException e) {
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("/{owner}/{groupName}/devices/all")
|
||||||
|
@Produces("application/json")
|
||||||
|
public Response getDevices(@PathParam("groupName") String groupName,
|
||||||
|
@PathParam("owner") String owner) {
|
||||||
|
try {
|
||||||
|
List<Device> devices = DeviceMgtAPIUtils.getGroupManagementProviderService().getDevices(
|
||||||
|
groupName, owner);
|
||||||
|
Device[] deviceArray = new Device[devices.size()];
|
||||||
|
devices.toArray(deviceArray);
|
||||||
|
return Response.status(Response.Status.OK).entity(deviceArray).build();
|
||||||
|
} catch (GroupManagementException e) {
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("/{owner}/{groupName}/devices/count")
|
||||||
|
@Produces("application/json")
|
||||||
|
public Response getDeviceCount(@PathParam("groupName") String groupName,
|
||||||
|
@PathParam("owner") String owner) {
|
||||||
|
try {
|
||||||
|
int count = DeviceMgtAPIUtils.getGroupManagementProviderService().getDeviceCount(groupName, owner);
|
||||||
|
return Response.status(Response.Status.OK).entity(count).build();
|
||||||
|
} catch (GroupManagementException e) {
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@PUT
|
||||||
|
@Path("/{owner}/{groupName}/devices/{deviceType}/{deviceId}")
|
||||||
|
@Produces("application/json")
|
||||||
|
public Response addDevice(@PathParam("groupName") String groupName,
|
||||||
|
@PathParam("owner") String owner, @PathParam("deviceId") String deviceId,
|
||||||
|
@PathParam("deviceType") String deviceType,
|
||||||
|
@FormParam("userName") String userName) {
|
||||||
|
try {
|
||||||
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier(deviceId, deviceType);
|
||||||
|
boolean isAdded = DeviceMgtAPIUtils.getGroupManagementProviderService().addDevice(
|
||||||
|
deviceIdentifier, groupName, owner);
|
||||||
|
if (isAdded) {
|
||||||
|
return Response.status(Response.Status.OK).build();
|
||||||
|
} else {
|
||||||
|
return Response.status(Response.Status.NOT_FOUND).build();
|
||||||
|
}
|
||||||
|
} catch (GroupManagementException e) {
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@DELETE
|
||||||
|
@Path("/{owner}/{groupName}/devices/{deviceType}/{deviceId}")
|
||||||
|
@Produces("application/json")
|
||||||
|
public Response removeDevice(@PathParam("groupName") String groupName,
|
||||||
|
@PathParam("owner") String owner, @PathParam("deviceId") String deviceId,
|
||||||
|
@PathParam("deviceType") String deviceType) {
|
||||||
|
try {
|
||||||
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier(deviceId, deviceType);
|
||||||
|
boolean isRemoved = DeviceMgtAPIUtils.getGroupManagementProviderService().removeDevice(
|
||||||
|
deviceIdentifier, groupName, owner);
|
||||||
|
if (isRemoved) {
|
||||||
|
return Response.status(Response.Status.OK).build();
|
||||||
|
} else {
|
||||||
|
return Response.status(Response.Status.NOT_FOUND).build();
|
||||||
|
}
|
||||||
|
} catch (GroupManagementException e) {
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("/{owner}/{groupName}/users/{userName}/permissions")
|
||||||
|
@Produces("application/json")
|
||||||
|
public Response getPermissions(@PathParam("userName") String userName,
|
||||||
|
@PathParam("groupName") String groupName,
|
||||||
|
@PathParam("owner") String owner) {
|
||||||
|
try {
|
||||||
|
String[] permissions = DeviceMgtAPIUtils.getGroupManagementProviderService()
|
||||||
|
.getPermissions(userName, groupName, owner);
|
||||||
|
return Response.status(Response.Status.OK).entity(permissions).build();
|
||||||
|
} catch (GroupManagementException e) {
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,17 +1,17 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
*
|
*
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
* in compliance with the License.
|
* in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing,
|
* Unless required by applicable law or agreed to in writing,
|
||||||
* software distributed under the License is distributed on an
|
* software distributed under the License is distributed on an
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
* either express or implied. See the License for the
|
* KIND, either express or implied. See the License for the
|
||||||
* specific language governing permissions and limitations
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
@ -22,17 +22,21 @@ import org.apache.commons.httpclient.HttpStatus;
|
|||||||
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.wso2.carbon.device.mgt.common.DeviceManagementException;
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||||
import org.wso2.carbon.mdm.api.common.MDMAPIException;
|
import org.wso2.carbon.mdm.api.util.DeviceMgtAPIUtils;
|
||||||
import org.wso2.carbon.mdm.api.util.MDMAPIUtils;
|
|
||||||
import org.wso2.carbon.mdm.api.util.ResponsePayload;
|
import org.wso2.carbon.mdm.api.util.ResponsePayload;
|
||||||
|
|
||||||
import javax.ws.rs.*;
|
import javax.ws.rs.GET;
|
||||||
|
import javax.ws.rs.POST;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.PathParam;
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class represents license related operations.
|
* This class represents license related operations.
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("NonJaxWsWebServices")
|
||||||
public class License {
|
public class License {
|
||||||
|
|
||||||
private static Log log = LogFactory.getLog(License.class);
|
private static Log log = LogFactory.getLog(License.class);
|
||||||
@ -43,18 +47,17 @@ public class License {
|
|||||||
* @param deviceType Device type, ex: android, ios
|
* @param deviceType Device type, ex: android, ios
|
||||||
* @param languageCode Language code, ex: en_US
|
* @param languageCode Language code, ex: en_US
|
||||||
* @return Returns the license text
|
* @return Returns the license text
|
||||||
* @throws MDMAPIException If the device type or language code arguments are not available or invalid.
|
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@Path ("{deviceType}/{languageCode}")
|
@Path ("{deviceType}/{languageCode}")
|
||||||
@Produces ({MediaType.APPLICATION_JSON})
|
@Produces ({MediaType.APPLICATION_JSON})
|
||||||
public Response getLicense(@PathParam ("deviceType") String deviceType,
|
public Response getLicense(@PathParam ("deviceType") String deviceType,
|
||||||
@PathParam ("languageCode") String languageCode) throws MDMAPIException {
|
@PathParam("languageCode") String languageCode) {
|
||||||
|
|
||||||
org.wso2.carbon.device.mgt.common.license.mgt.License license;
|
org.wso2.carbon.device.mgt.common.license.mgt.License license;
|
||||||
ResponsePayload responsePayload = new ResponsePayload();
|
ResponsePayload responsePayload;
|
||||||
try {
|
try {
|
||||||
license = MDMAPIUtils.getDeviceManagementService().getLicense(deviceType, languageCode);
|
license = DeviceMgtAPIUtils.getDeviceManagementService().getLicense(deviceType, languageCode);
|
||||||
if (license == null) {
|
if (license == null) {
|
||||||
return Response.status(HttpStatus.SC_NOT_FOUND).build();
|
return Response.status(HttpStatus.SC_NOT_FOUND).build();
|
||||||
}
|
}
|
||||||
@ -65,9 +68,9 @@ public class License {
|
|||||||
} catch (DeviceManagementException e) {
|
} catch (DeviceManagementException e) {
|
||||||
String msg = "Error occurred while retrieving the license configured for '" + deviceType + "' device type";
|
String msg = "Error occurred while retrieving the license configured for '" + deviceType + "' device type";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new MDMAPIException(msg, e);
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
}
|
}
|
||||||
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
|
return Response.status(Response.Status.OK).entity(responsePayload).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -76,24 +79,23 @@ public class License {
|
|||||||
* @param deviceType Device type, ex: android, ios
|
* @param deviceType Device type, ex: android, ios
|
||||||
* @param license License object
|
* @param license License object
|
||||||
* @return Returns the acknowledgement for the action
|
* @return Returns the acknowledgement for the action
|
||||||
* @throws MDMAPIException
|
|
||||||
*/
|
*/
|
||||||
@POST
|
@POST
|
||||||
@Path ("{deviceType}")
|
@Path ("{deviceType}")
|
||||||
public Response addLicense(@PathParam ("deviceType") String deviceType,
|
public Response addLicense(@PathParam ("deviceType") String deviceType,
|
||||||
org.wso2.carbon.device.mgt.common.license.mgt.License license) throws MDMAPIException {
|
org.wso2.carbon.device.mgt.common.license.mgt.License license) {
|
||||||
|
|
||||||
ResponsePayload responsePayload;
|
ResponsePayload responsePayload;
|
||||||
try {
|
try {
|
||||||
MDMAPIUtils.getDeviceManagementService().addLicense(deviceType, license);
|
DeviceMgtAPIUtils.getDeviceManagementService().addLicense(deviceType, license);
|
||||||
responsePayload = ResponsePayload.statusCode(HttpStatus.SC_OK).
|
responsePayload = ResponsePayload.statusCode(HttpStatus.SC_OK).
|
||||||
messageFromServer("License added successfully for '" + deviceType + "' device type").
|
messageFromServer("License added successfully for '" + deviceType + "' device type").
|
||||||
build();
|
build();
|
||||||
} catch (DeviceManagementException e) {
|
} catch (DeviceManagementException e) {
|
||||||
String msg = "Error occurred while adding license for '" + deviceType + "' device type";
|
String msg = "Error occurred while adding license for '" + deviceType + "' device type";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new MDMAPIException(msg, e);
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
}
|
}
|
||||||
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
|
return Response.status(Response.Status.OK).entity(responsePayload).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -33,50 +33,54 @@ import org.wso2.carbon.device.mgt.core.app.mgt.ApplicationManagementProviderServ
|
|||||||
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
||||||
import org.wso2.carbon.mdm.api.common.MDMAPIException;
|
import org.wso2.carbon.mdm.api.common.MDMAPIException;
|
||||||
import org.wso2.carbon.mdm.api.context.DeviceOperationContext;
|
import org.wso2.carbon.mdm.api.context.DeviceOperationContext;
|
||||||
import org.wso2.carbon.mdm.api.util.MDMAPIUtils;
|
import org.wso2.carbon.mdm.api.util.DeviceMgtAPIUtils;
|
||||||
import org.wso2.carbon.mdm.api.util.MDMAndroidOperationUtil;
|
import org.wso2.carbon.mdm.api.util.MDMAndroidOperationUtil;
|
||||||
import org.wso2.carbon.mdm.api.util.MDMIOSOperationUtil;
|
import org.wso2.carbon.mdm.api.util.MDMIOSOperationUtil;
|
||||||
import org.wso2.carbon.mdm.api.util.ResponsePayload;
|
import org.wso2.carbon.mdm.api.util.ResponsePayload;
|
||||||
import org.wso2.carbon.mdm.beans.ApplicationWrapper;
|
import org.wso2.carbon.mdm.beans.ApplicationWrapper;
|
||||||
import org.wso2.carbon.mdm.beans.MobileApp;
|
import org.wso2.carbon.mdm.beans.MobileApp;
|
||||||
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
|
|
||||||
|
|
||||||
import javax.ws.rs.*;
|
import javax.ws.rs.Consumes;
|
||||||
|
import javax.ws.rs.GET;
|
||||||
|
import javax.ws.rs.POST;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.PathParam;
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
|
import javax.ws.rs.QueryParam;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Operation related REST-API implementation.
|
* Operation related REST-API implementation.
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("NonJaxWsWebServices")
|
||||||
@Produces({"application/json", "application/xml"})
|
@Produces({"application/json", "application/xml"})
|
||||||
@Consumes({"application/json", "application/xml"})
|
@Consumes({"application/json", "application/xml"})
|
||||||
public class Operation {
|
public class Operation {
|
||||||
|
|
||||||
private static Log log = LogFactory.getLog(Operation.class);
|
private static Log log = LogFactory.getLog(Operation.class);
|
||||||
|
|
||||||
/* @deprecated */
|
/* @deprecated */
|
||||||
@GET
|
@GET
|
||||||
public List<? extends org.wso2.carbon.device.mgt.common.operation.mgt.Operation> getAllOperations()
|
public Response getAllOperations() {
|
||||||
throws MDMAPIException {
|
|
||||||
List<? extends org.wso2.carbon.device.mgt.common.operation.mgt.Operation> operations;
|
List<? extends org.wso2.carbon.device.mgt.common.operation.mgt.Operation> operations;
|
||||||
DeviceManagementProviderService dmService;
|
DeviceManagementProviderService dmService;
|
||||||
try {
|
try {
|
||||||
dmService = MDMAPIUtils.getDeviceManagementService();
|
dmService = DeviceMgtAPIUtils.getDeviceManagementService();
|
||||||
operations = dmService.getOperations(null);
|
operations = dmService.getOperations(null);
|
||||||
} catch (OperationManagementException e) {
|
} catch (OperationManagementException e) {
|
||||||
String msg = "Error occurred while fetching the operations for the device.";
|
String msg = "Error occurred while fetching the operations for the device.";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new MDMAPIException(msg, e);
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
}
|
}
|
||||||
return operations;
|
return Response.status(Response.Status.OK).entity(operations).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("paginate/{type}/{id}")
|
@Path("paginate/{type}/{id}")
|
||||||
public PaginationResult getDeviceOperations(
|
public Response getDeviceOperations(
|
||||||
@PathParam("type") String type, @PathParam("id") String id, @QueryParam("start") int startIdx,
|
@PathParam("type") String type, @PathParam("id") String id, @QueryParam("start") int startIdx,
|
||||||
@QueryParam("length") int length, @QueryParam("search") String search)
|
@QueryParam("length") int length, @QueryParam("search") String search) {
|
||||||
throws MDMAPIException {
|
|
||||||
PaginationResult operations;
|
PaginationResult operations;
|
||||||
DeviceManagementProviderService dmService;
|
DeviceManagementProviderService dmService;
|
||||||
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
||||||
@ -84,147 +88,133 @@ public class Operation {
|
|||||||
try {
|
try {
|
||||||
deviceIdentifier.setType(type);
|
deviceIdentifier.setType(type);
|
||||||
deviceIdentifier.setId(id);
|
deviceIdentifier.setId(id);
|
||||||
dmService = MDMAPIUtils.getDeviceManagementService();
|
dmService = DeviceMgtAPIUtils.getDeviceManagementService();
|
||||||
operations = dmService.getOperations(deviceIdentifier, paginationRequest);
|
operations = dmService.getOperations(deviceIdentifier, paginationRequest);
|
||||||
} catch (OperationManagementException e) {
|
} catch (OperationManagementException e) {
|
||||||
String msg = "Error occurred while fetching the operations for the device.";
|
String msg = "Error occurred while fetching the operations for the device.";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new MDMAPIException(msg, e);
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
}
|
}
|
||||||
return operations;
|
return Response.status(Response.Status.OK).entity(operations).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("{type}/{id}")
|
@Path("{type}/{id}")
|
||||||
public List<? extends org.wso2.carbon.device.mgt.common.operation.mgt.Operation> getDeviceOperations(
|
public Response getDeviceOperations(@PathParam("type") String type, @PathParam("id") String id) {
|
||||||
@PathParam("type") String type, @PathParam("id") String id)
|
List<? extends org.wso2.carbon.device.mgt.common.operation.mgt.Operation> operations;
|
||||||
throws MDMAPIException {
|
DeviceManagementProviderService dmService;
|
||||||
List<? extends org.wso2.carbon.device.mgt.common.operation.mgt.Operation> operations;
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
||||||
DeviceManagementProviderService dmService;
|
try {
|
||||||
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
deviceIdentifier.setType(type);
|
||||||
try {
|
deviceIdentifier.setId(id);
|
||||||
deviceIdentifier.setType(type);
|
dmService = DeviceMgtAPIUtils.getDeviceManagementService();
|
||||||
deviceIdentifier.setId(id);
|
operations = dmService.getOperations(deviceIdentifier);
|
||||||
dmService = MDMAPIUtils.getDeviceManagementService();
|
} catch (OperationManagementException e) {
|
||||||
operations = dmService.getOperations(deviceIdentifier);
|
String msg = "Error occurred while fetching the operations for the device.";
|
||||||
} catch (OperationManagementException e) {
|
log.error(msg, e);
|
||||||
String msg = "Error occurred while fetching the operations for the device.";
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
log.error(msg, e);
|
}
|
||||||
throw new MDMAPIException(msg, e);
|
return Response.status(Response.Status.OK).entity(operations).build();
|
||||||
}
|
}
|
||||||
return operations;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* @deprecated */
|
/* @deprecated */
|
||||||
@POST
|
@POST
|
||||||
public ResponsePayload addOperation(DeviceOperationContext operationContext) throws MDMAPIException {
|
public Response addOperation(DeviceOperationContext operationContext) {
|
||||||
DeviceManagementProviderService dmService;
|
DeviceManagementProviderService dmService;
|
||||||
ResponsePayload responseMsg = new ResponsePayload();
|
ResponsePayload responseMsg = new ResponsePayload();
|
||||||
try {
|
try {
|
||||||
dmService = MDMAPIUtils.getDeviceManagementService();
|
dmService = DeviceMgtAPIUtils.getDeviceManagementService();
|
||||||
int operationId = dmService.addOperation(operationContext.getOperation(),
|
int operationId = dmService.addOperation(operationContext.getOperation(), operationContext.getDevices());
|
||||||
operationContext.getDevices());
|
if (operationId > 0) {
|
||||||
if (operationId>0) {
|
responseMsg.setStatusCode(HttpStatus.SC_CREATED);
|
||||||
Response.status(HttpStatus.SC_CREATED);
|
|
||||||
responseMsg.setMessageFromServer("Operation has added successfully.");
|
responseMsg.setMessageFromServer("Operation has added successfully.");
|
||||||
}
|
}
|
||||||
return responseMsg;
|
return Response.status(Response.Status.CREATED).entity(responseMsg).build();
|
||||||
} catch (OperationManagementException e) {
|
} catch (OperationManagementException e) {
|
||||||
String msg = "Error occurred while saving the operation";
|
String msg = "Error occurred while saving the operation";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new MDMAPIException(msg, e);
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("{type}/{id}/apps")
|
@Path("{type}/{id}/apps")
|
||||||
public List<? extends Application> getInstalledApps(
|
public Response getInstalledApps(@PathParam("type") String type, @PathParam("id") String id) {
|
||||||
@PathParam("type") String type,
|
List<Application> applications;
|
||||||
@PathParam("id") String id)
|
ApplicationManagementProviderService appManagerConnector;
|
||||||
throws MDMAPIException {
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
||||||
List<Application> applications;
|
try {
|
||||||
ApplicationManagementProviderService appManagerConnector;
|
deviceIdentifier.setType(type);
|
||||||
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
deviceIdentifier.setId(id);
|
||||||
try {
|
appManagerConnector = DeviceMgtAPIUtils.getAppManagementService();
|
||||||
deviceIdentifier.setType(type);
|
applications = appManagerConnector.getApplicationListForDevice(deviceIdentifier);
|
||||||
deviceIdentifier.setId(id);
|
} catch (ApplicationManagementException e) {
|
||||||
appManagerConnector = MDMAPIUtils.getAppManagementService();
|
String msg = "Error occurred while fetching the apps of the device.";
|
||||||
applications = appManagerConnector.getApplicationListForDevice(deviceIdentifier);
|
log.error(msg, e);
|
||||||
} catch (ApplicationManagementException e) {
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
String msg = "Error occurred while fetching the apps of the device.";
|
}
|
||||||
log.error(msg, e);
|
return Response.status(Response.Status.CREATED).entity(applications).build();
|
||||||
throw new MDMAPIException(msg, e);
|
}
|
||||||
}
|
|
||||||
return applications;
|
|
||||||
}
|
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path("installApp/{tenantDomain}")
|
@Path("installApp/{tenantDomain}")
|
||||||
public ResponsePayload installApplication(ApplicationWrapper applicationWrapper,
|
public Response installApplication(ApplicationWrapper applicationWrapper,
|
||||||
@PathParam("tenantDomain") String tenantDomain) throws MDMAPIException {
|
@PathParam("tenantDomain") String tenantDomain) {
|
||||||
ResponsePayload responseMsg = new ResponsePayload();
|
ResponsePayload responseMsg = new ResponsePayload();
|
||||||
ApplicationManager appManagerConnector;
|
ApplicationManager appManagerConnector;
|
||||||
org.wso2.carbon.device.mgt.common.operation.mgt.Operation operation = null;
|
org.wso2.carbon.device.mgt.common.operation.mgt.Operation operation = null;
|
||||||
ArrayList<DeviceIdentifier> deviceIdentifiers;
|
|
||||||
try {
|
try {
|
||||||
appManagerConnector = MDMAPIUtils.getAppManagementService();
|
appManagerConnector = DeviceMgtAPIUtils.getAppManagementService();
|
||||||
MobileApp mobileApp = applicationWrapper.getApplication();
|
MobileApp mobileApp = applicationWrapper.getApplication();
|
||||||
|
|
||||||
if (applicationWrapper.getDeviceIdentifiers() != null) {
|
if (applicationWrapper.getDeviceIdentifiers() != null) {
|
||||||
for (DeviceIdentifier deviceIdentifier : applicationWrapper.getDeviceIdentifiers()) {
|
for (DeviceIdentifier deviceIdentifier : applicationWrapper.getDeviceIdentifiers()) {
|
||||||
deviceIdentifiers = new ArrayList<DeviceIdentifier>();
|
|
||||||
|
|
||||||
if (deviceIdentifier.getType().equals(Platform.android.toString())) {
|
if (deviceIdentifier.getType().equals(Platform.android.toString())) {
|
||||||
operation = MDMAndroidOperationUtil.createInstallAppOperation(mobileApp);
|
operation = MDMAndroidOperationUtil.createInstallAppOperation(mobileApp);
|
||||||
} else if (deviceIdentifier.getType().equals(Platform.ios.toString())) {
|
} else if (deviceIdentifier.getType().equals(Platform.ios.toString())) {
|
||||||
operation = MDMIOSOperationUtil.createInstallAppOperation(mobileApp);
|
operation = MDMIOSOperationUtil.createInstallAppOperation(mobileApp);
|
||||||
}
|
}
|
||||||
deviceIdentifiers.add(deviceIdentifier);
|
|
||||||
}
|
}
|
||||||
appManagerConnector.installApplicationForDevices(operation, applicationWrapper.getDeviceIdentifiers());
|
appManagerConnector.installApplicationForDevices(operation, applicationWrapper.getDeviceIdentifiers());
|
||||||
}
|
}
|
||||||
Response.status(HttpStatus.SC_CREATED);
|
responseMsg.setStatusCode(HttpStatus.SC_CREATED);
|
||||||
responseMsg.setMessageFromServer("Application installation request has been sent to the device.");
|
responseMsg.setMessageFromServer("Application installation request has been sent to the device.");
|
||||||
return responseMsg;
|
return Response.status(Response.Status.CREATED).entity(responseMsg).build();
|
||||||
} catch (ApplicationManagementException e) {
|
} catch (ApplicationManagementException | MDMAPIException e) {
|
||||||
String msg = "Error occurred while saving the operation";
|
String msg = "Error occurred while saving the operation";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new MDMAPIException(msg, e);
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path("uninstallApp/{tenantDomain}")
|
@Path("uninstallApp/{tenantDomain}")
|
||||||
public ResponsePayload uninstallApplication(ApplicationWrapper applicationWrapper,
|
public Response uninstallApplication(ApplicationWrapper applicationWrapper,
|
||||||
@PathParam("tenantDomain") String tenantDomain) throws MDMAPIException {
|
@PathParam("tenantDomain") String tenantDomain) {
|
||||||
ResponsePayload responseMsg = new ResponsePayload();
|
ResponsePayload responseMsg = new ResponsePayload();
|
||||||
ApplicationManager appManagerConnector;
|
ApplicationManager appManagerConnector;
|
||||||
org.wso2.carbon.device.mgt.common.operation.mgt.Operation operation = null;
|
org.wso2.carbon.device.mgt.common.operation.mgt.Operation operation = null;
|
||||||
ArrayList<DeviceIdentifier> deviceIdentifiers;
|
|
||||||
try {
|
try {
|
||||||
appManagerConnector = MDMAPIUtils.getAppManagementService();
|
appManagerConnector = DeviceMgtAPIUtils.getAppManagementService();
|
||||||
MobileApp mobileApp = applicationWrapper.getApplication();
|
MobileApp mobileApp = applicationWrapper.getApplication();
|
||||||
|
|
||||||
if (applicationWrapper.getDeviceIdentifiers() != null) {
|
if (applicationWrapper.getDeviceIdentifiers() != null) {
|
||||||
for (DeviceIdentifier deviceIdentifier : applicationWrapper.getDeviceIdentifiers()) {
|
for (DeviceIdentifier deviceIdentifier : applicationWrapper.getDeviceIdentifiers()) {
|
||||||
deviceIdentifiers = new ArrayList<DeviceIdentifier>();
|
|
||||||
|
|
||||||
if (deviceIdentifier.getType().equals(Platform.android.toString())) {
|
if (deviceIdentifier.getType().equals(Platform.android.toString())) {
|
||||||
operation = MDMAndroidOperationUtil.createAppUninstallOperation(mobileApp);
|
operation = MDMAndroidOperationUtil.createAppUninstallOperation(mobileApp);
|
||||||
} else if (deviceIdentifier.getType().equals(Platform.ios.toString())) {
|
} else if (deviceIdentifier.getType().equals(Platform.ios.toString())) {
|
||||||
operation = MDMIOSOperationUtil.createAppUninstallOperation(mobileApp);
|
operation = MDMIOSOperationUtil.createAppUninstallOperation(mobileApp);
|
||||||
}
|
}
|
||||||
deviceIdentifiers.add(deviceIdentifier);
|
|
||||||
}
|
}
|
||||||
appManagerConnector.installApplicationForDevices(operation, applicationWrapper.getDeviceIdentifiers());
|
appManagerConnector.installApplicationForDevices(operation, applicationWrapper.getDeviceIdentifiers());
|
||||||
}
|
}
|
||||||
Response.status(HttpStatus.SC_CREATED);
|
responseMsg.setStatusCode(HttpStatus.SC_CREATED);
|
||||||
responseMsg.setMessageFromServer("Application removal request has been sent to the device.");
|
responseMsg.setMessageFromServer("Application removal request has been sent to the device.");
|
||||||
return responseMsg;
|
return Response.status(Response.Status.CREATED).entity(responseMsg).build();
|
||||||
} catch (ApplicationManagementException e) {
|
} catch (ApplicationManagementException | MDMAPIException e) {
|
||||||
String msg = "Error occurred while saving the operation";
|
String msg = "Error occurred while saving the operation";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new MDMAPIException(msg, e);
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -23,7 +23,7 @@ import org.apache.commons.logging.Log;
|
|||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||||
import org.wso2.carbon.mdm.api.common.MDMAPIException;
|
import org.wso2.carbon.mdm.api.common.MDMAPIException;
|
||||||
import org.wso2.carbon.mdm.api.util.MDMAPIUtils;
|
import org.wso2.carbon.mdm.api.util.DeviceMgtAPIUtils;
|
||||||
import org.wso2.carbon.mdm.api.util.ResponsePayload;
|
import org.wso2.carbon.mdm.api.util.ResponsePayload;
|
||||||
import org.wso2.carbon.mdm.beans.PolicyWrapper;
|
import org.wso2.carbon.mdm.beans.PolicyWrapper;
|
||||||
import org.wso2.carbon.mdm.beans.PriorityUpdatedPolicyWrapper;
|
import org.wso2.carbon.mdm.beans.PriorityUpdatedPolicyWrapper;
|
||||||
@ -36,20 +36,27 @@ import org.wso2.carbon.policy.mgt.common.monitor.PolicyComplianceException;
|
|||||||
import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
|
import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
|
||||||
import org.wso2.carbon.policy.mgt.core.task.TaskScheduleService;
|
import org.wso2.carbon.policy.mgt.core.task.TaskScheduleService;
|
||||||
|
|
||||||
import javax.ws.rs.*;
|
import javax.ws.rs.Consumes;
|
||||||
|
import javax.ws.rs.GET;
|
||||||
|
import javax.ws.rs.POST;
|
||||||
|
import javax.ws.rs.PUT;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.PathParam;
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@SuppressWarnings("NonJaxWsWebServices")
|
||||||
public class Policy {
|
public class Policy {
|
||||||
private static Log log = LogFactory.getLog(Policy.class);
|
private static Log log = LogFactory.getLog(Policy.class);
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path("inactive-policy")
|
@Path("inactive-policy")
|
||||||
public ResponsePayload addPolicy(PolicyWrapper policyWrapper) throws MDMAPIException {
|
public Response addPolicy(PolicyWrapper policyWrapper) {
|
||||||
|
|
||||||
PolicyManagerService policyManagementService = MDMAPIUtils.getPolicyManagementService();
|
PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
|
||||||
ResponsePayload responseMsg = new ResponsePayload();
|
ResponsePayload responseMsg = new ResponsePayload();
|
||||||
org.wso2.carbon.policy.mgt.common.Policy policy = new org.wso2.carbon.policy.mgt.common.Policy();
|
org.wso2.carbon.policy.mgt.common.Policy policy = new org.wso2.carbon.policy.mgt.common.Policy();
|
||||||
policy.setPolicyName(policyWrapper.getPolicyName());
|
policy.setPolicyName(policyWrapper.getPolicyName());
|
||||||
@ -62,25 +69,14 @@ public class Policy {
|
|||||||
policy.setTenantId(policyWrapper.getTenantId());
|
policy.setTenantId(policyWrapper.getTenantId());
|
||||||
policy.setCompliance(policyWrapper.getCompliance());
|
policy.setCompliance(policyWrapper.getCompliance());
|
||||||
|
|
||||||
try {
|
return addPolicy(policyManagementService, responseMsg, policy);
|
||||||
PolicyAdministratorPoint pap = policyManagementService.getPAP();
|
|
||||||
pap.addPolicy(policy);
|
|
||||||
Response.status(HttpStatus.SC_CREATED);
|
|
||||||
responseMsg.setStatusCode(HttpStatus.SC_CREATED);
|
|
||||||
responseMsg.setMessageFromServer("Policy has been added successfully.");
|
|
||||||
return responseMsg;
|
|
||||||
} catch (PolicyManagementException e) {
|
|
||||||
String error = "Policy Management related exception";
|
|
||||||
log.error(error, e);
|
|
||||||
throw new MDMAPIException(error, e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path("active-policy")
|
@Path("active-policy")
|
||||||
public ResponsePayload addActivePolicy(PolicyWrapper policyWrapper) throws MDMAPIException {
|
public Response addActivePolicy(PolicyWrapper policyWrapper) {
|
||||||
|
|
||||||
PolicyManagerService policyManagementService = MDMAPIUtils.getPolicyManagementService();
|
PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
|
||||||
ResponsePayload responseMsg = new ResponsePayload();
|
ResponsePayload responseMsg = new ResponsePayload();
|
||||||
org.wso2.carbon.policy.mgt.common.Policy policy = new org.wso2.carbon.policy.mgt.common.Policy();
|
org.wso2.carbon.policy.mgt.common.Policy policy = new org.wso2.carbon.policy.mgt.common.Policy();
|
||||||
policy.setPolicyName(policyWrapper.getPolicyName());
|
policy.setPolicyName(policyWrapper.getPolicyName());
|
||||||
@ -94,87 +90,91 @@ public class Policy {
|
|||||||
policy.setCompliance(policyWrapper.getCompliance());
|
policy.setCompliance(policyWrapper.getCompliance());
|
||||||
policy.setActive(true);
|
policy.setActive(true);
|
||||||
|
|
||||||
|
return addPolicy(policyManagementService, responseMsg, policy);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Response addPolicy(PolicyManagerService policyManagementService, ResponsePayload responseMsg,
|
||||||
|
org.wso2.carbon.policy.mgt.common.Policy policy) {
|
||||||
try {
|
try {
|
||||||
PolicyAdministratorPoint pap = policyManagementService.getPAP();
|
PolicyAdministratorPoint pap = policyManagementService.getPAP();
|
||||||
pap.addPolicy(policy);
|
pap.addPolicy(policy);
|
||||||
Response.status(HttpStatus.SC_CREATED);
|
|
||||||
responseMsg.setStatusCode(HttpStatus.SC_CREATED);
|
responseMsg.setStatusCode(HttpStatus.SC_CREATED);
|
||||||
responseMsg.setMessageFromServer("Policy has been added successfully.");
|
responseMsg.setMessageFromServer("Policy has been added successfully.");
|
||||||
return responseMsg;
|
return Response.status(Response.Status.CREATED).entity(responseMsg).build();
|
||||||
} catch (PolicyManagementException e) {
|
} catch (PolicyManagementException e) {
|
||||||
String error = "Policy Management related exception";
|
String msg = "Policy Management related exception";
|
||||||
log.error(error, e);
|
log.error(msg, e);
|
||||||
throw new MDMAPIException(error, e);
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Produces({MediaType.APPLICATION_JSON})
|
@Produces({MediaType.APPLICATION_JSON})
|
||||||
public Response getAllPolicies() throws MDMAPIException {
|
public Response getAllPolicies() {
|
||||||
PolicyManagerService policyManagementService = MDMAPIUtils.getPolicyManagementService();
|
PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
|
||||||
List<org.wso2.carbon.policy.mgt.common.Policy> policies;
|
List<org.wso2.carbon.policy.mgt.common.Policy> policies;
|
||||||
try {
|
try {
|
||||||
PolicyAdministratorPoint policyAdministratorPoint = policyManagementService.getPAP();
|
PolicyAdministratorPoint policyAdministratorPoint = policyManagementService.getPAP();
|
||||||
policies = policyAdministratorPoint.getPolicies();
|
policies = policyAdministratorPoint.getPolicies();
|
||||||
} catch (PolicyManagementException e) {
|
} catch (PolicyManagementException e) {
|
||||||
String error = "Policy Management related exception";
|
String msg = "Policy Management related exception";
|
||||||
log.error(error, e);
|
log.error(msg, e);
|
||||||
throw new MDMAPIException(error, e);
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
}
|
}
|
||||||
ResponsePayload responsePayload = new ResponsePayload();
|
ResponsePayload responsePayload = new ResponsePayload();
|
||||||
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
||||||
responsePayload.setMessageFromServer("Sending all retrieved device policies.");
|
responsePayload.setMessageFromServer("Sending all retrieved device policies.");
|
||||||
responsePayload.setResponseContent(policies);
|
responsePayload.setResponseContent(policies);
|
||||||
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
|
return Response.status(Response.Status.OK).entity(responsePayload).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Produces({MediaType.APPLICATION_JSON})
|
@Produces({MediaType.APPLICATION_JSON})
|
||||||
@Path("{id}")
|
@Path("{id}")
|
||||||
public Response getPolicy(@PathParam("id") int policyId) throws MDMAPIException {
|
public Response getPolicy(@PathParam("id") int policyId) {
|
||||||
PolicyManagerService policyManagementService = MDMAPIUtils.getPolicyManagementService();
|
PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
|
||||||
final org.wso2.carbon.policy.mgt.common.Policy policy;
|
final org.wso2.carbon.policy.mgt.common.Policy policy;
|
||||||
try {
|
try {
|
||||||
PolicyAdministratorPoint policyAdministratorPoint = policyManagementService.getPAP();
|
PolicyAdministratorPoint policyAdministratorPoint = policyManagementService.getPAP();
|
||||||
policy = policyAdministratorPoint.getPolicy(policyId);
|
policy = policyAdministratorPoint.getPolicy(policyId);
|
||||||
} catch (PolicyManagementException e) {
|
} catch (PolicyManagementException e) {
|
||||||
String error = "Policy Management related exception";
|
String msg = "Policy Management related exception";
|
||||||
log.error(error, e);
|
log.error(msg, e);
|
||||||
throw new MDMAPIException(error, e);
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
}
|
}
|
||||||
if (policy == null){
|
if (policy == null){
|
||||||
ResponsePayload responsePayload = new ResponsePayload();
|
ResponsePayload responsePayload = new ResponsePayload();
|
||||||
responsePayload.setStatusCode(HttpStatus.SC_NOT_FOUND);
|
responsePayload.setStatusCode(HttpStatus.SC_NOT_FOUND);
|
||||||
responsePayload.setMessageFromServer("Policy for ID " + policyId + " not found.");
|
responsePayload.setMessageFromServer("Policy for ID " + policyId + " not found.");
|
||||||
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
|
return Response.status(Response.Status.NOT_FOUND).entity(responsePayload).build();
|
||||||
}
|
}
|
||||||
ResponsePayload responsePayload = new ResponsePayload();
|
ResponsePayload responsePayload = new ResponsePayload();
|
||||||
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
||||||
responsePayload.setMessageFromServer("Sending all retrieved device policies.");
|
responsePayload.setMessageFromServer("Sending all retrieved device policies.");
|
||||||
responsePayload.setResponseContent(policy);
|
responsePayload.setResponseContent(policy);
|
||||||
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
|
return Response.status(Response.Status.OK).entity(responsePayload).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("count")
|
@Path("count")
|
||||||
public int getPolicyCount() throws MDMAPIException {
|
public Response getPolicyCount() {
|
||||||
PolicyManagerService policyManagementService = MDMAPIUtils.getPolicyManagementService();
|
PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
|
||||||
try {
|
try {
|
||||||
PolicyAdministratorPoint policyAdministratorPoint = policyManagementService.getPAP();
|
PolicyAdministratorPoint policyAdministratorPoint = policyManagementService.getPAP();
|
||||||
return policyAdministratorPoint.getPolicyCount();
|
Integer count = policyAdministratorPoint.getPolicyCount();
|
||||||
|
return Response.status(Response.Status.OK).entity(count).build();
|
||||||
} catch (PolicyManagementException e) {
|
} catch (PolicyManagementException e) {
|
||||||
String error = "Policy Management related exception";
|
String msg = "Policy Management related exception";
|
||||||
log.error(error, e);
|
log.error(msg, e);
|
||||||
throw new MDMAPIException(error, e);
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@PUT
|
@PUT
|
||||||
@Path("{id}")
|
@Path("{id}")
|
||||||
public ResponsePayload updatePolicy(PolicyWrapper policyWrapper, @PathParam("id") int policyId)
|
public Response updatePolicy(PolicyWrapper policyWrapper, @PathParam("id") int policyId) {
|
||||||
throws MDMAPIException {
|
|
||||||
|
|
||||||
PolicyManagerService policyManagementService = MDMAPIUtils.getPolicyManagementService();
|
PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
|
||||||
ResponsePayload responseMsg = new ResponsePayload();
|
ResponsePayload responseMsg = new ResponsePayload();
|
||||||
org.wso2.carbon.policy.mgt.common.Policy policy = new org.wso2.carbon.policy.mgt.common.Policy();
|
org.wso2.carbon.policy.mgt.common.Policy policy = new org.wso2.carbon.policy.mgt.common.Policy();
|
||||||
policy.setPolicyName(policyWrapper.getPolicyName());
|
policy.setPolicyName(policyWrapper.getPolicyName());
|
||||||
@ -191,14 +191,13 @@ public class Policy {
|
|||||||
try {
|
try {
|
||||||
PolicyAdministratorPoint pap = policyManagementService.getPAP();
|
PolicyAdministratorPoint pap = policyManagementService.getPAP();
|
||||||
pap.updatePolicy(policy);
|
pap.updatePolicy(policy);
|
||||||
Response.status(HttpStatus.SC_OK);
|
|
||||||
responseMsg.setStatusCode(HttpStatus.SC_CREATED);
|
responseMsg.setStatusCode(HttpStatus.SC_CREATED);
|
||||||
responseMsg.setMessageFromServer("Policy has been updated successfully.");
|
responseMsg.setMessageFromServer("Policy has been updated successfully.");
|
||||||
return responseMsg;
|
return Response.status(Response.Status.CREATED).entity(responseMsg).build();
|
||||||
} catch (PolicyManagementException e) {
|
} catch (PolicyManagementException e) {
|
||||||
String error = "Policy Management related exception in policy update.";
|
String msg = "Policy Management related exception in policy update.";
|
||||||
log.error(error, e);
|
log.error(msg, e);
|
||||||
throw new MDMAPIException(error, e);
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -206,11 +205,10 @@ public class Policy {
|
|||||||
@Path("priorities")
|
@Path("priorities")
|
||||||
@Consumes({MediaType.APPLICATION_JSON})
|
@Consumes({MediaType.APPLICATION_JSON})
|
||||||
@Produces({MediaType.APPLICATION_JSON})
|
@Produces({MediaType.APPLICATION_JSON})
|
||||||
public Response updatePolicyPriorities(List<PriorityUpdatedPolicyWrapper> priorityUpdatedPolicies)
|
public Response updatePolicyPriorities(List<PriorityUpdatedPolicyWrapper> priorityUpdatedPolicies) {
|
||||||
throws MDMAPIException {
|
PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
|
||||||
PolicyManagerService policyManagementService = MDMAPIUtils.getPolicyManagementService();
|
|
||||||
List<org.wso2.carbon.policy.mgt.common.Policy> policiesToUpdate =
|
List<org.wso2.carbon.policy.mgt.common.Policy> policiesToUpdate =
|
||||||
new ArrayList<org.wso2.carbon.policy.mgt.common.Policy>(priorityUpdatedPolicies.size());
|
new ArrayList<>(priorityUpdatedPolicies.size());
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < priorityUpdatedPolicies.size(); i++) {
|
for (i = 0; i < priorityUpdatedPolicies.size(); i++) {
|
||||||
org.wso2.carbon.policy.mgt.common.Policy policyObj = new org.wso2.carbon.policy.mgt.common.Policy();
|
org.wso2.carbon.policy.mgt.common.Policy policyObj = new org.wso2.carbon.policy.mgt.common.Policy();
|
||||||
@ -223,19 +221,19 @@ public class Policy {
|
|||||||
PolicyAdministratorPoint pap = policyManagementService.getPAP();
|
PolicyAdministratorPoint pap = policyManagementService.getPAP();
|
||||||
policiesUpdated = pap.updatePolicyPriorities(policiesToUpdate);
|
policiesUpdated = pap.updatePolicyPriorities(policiesToUpdate);
|
||||||
} catch (PolicyManagementException e) {
|
} catch (PolicyManagementException e) {
|
||||||
String error = "Exception in updating policy priorities.";
|
String msg = "Exception in updating policy priorities.";
|
||||||
log.error(error, e);
|
log.error(msg, e);
|
||||||
throw new MDMAPIException(error, e);
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
}
|
}
|
||||||
ResponsePayload responsePayload = new ResponsePayload();
|
ResponsePayload responsePayload = new ResponsePayload();
|
||||||
if (policiesUpdated) {
|
if (policiesUpdated) {
|
||||||
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
||||||
responsePayload.setMessageFromServer("Policy Priorities successfully updated.");
|
responsePayload.setMessageFromServer("Policy Priorities successfully updated.");
|
||||||
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
|
return Response.status(Response.Status.OK).entity(responsePayload).build();
|
||||||
} else {
|
} else {
|
||||||
responsePayload.setStatusCode(HttpStatus.SC_BAD_REQUEST);
|
responsePayload.setStatusCode(HttpStatus.SC_BAD_REQUEST);
|
||||||
responsePayload.setMessageFromServer("Policy priorities did not update. Bad Request.");
|
responsePayload.setMessageFromServer("Policy priorities did not update. Bad Request.");
|
||||||
return Response.status(HttpStatus.SC_BAD_REQUEST).entity(responsePayload).build();
|
return Response.status(Response.Status.BAD_REQUEST).entity(responsePayload).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -243,8 +241,8 @@ public class Policy {
|
|||||||
@Path("bulk-remove")
|
@Path("bulk-remove")
|
||||||
@Consumes("application/json")
|
@Consumes("application/json")
|
||||||
@Produces("application/json")
|
@Produces("application/json")
|
||||||
public Response bulkRemovePolicy(List<Integer> policyIds) throws MDMAPIException {
|
public Response bulkRemovePolicy(List<Integer> policyIds) {
|
||||||
PolicyManagerService policyManagementService = MDMAPIUtils.getPolicyManagementService();
|
PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
|
||||||
boolean policyDeleted = true;
|
boolean policyDeleted = true;
|
||||||
try {
|
try {
|
||||||
PolicyAdministratorPoint pap = policyManagementService.getPAP();
|
PolicyAdministratorPoint pap = policyManagementService.getPAP();
|
||||||
@ -255,43 +253,42 @@ public class Policy {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (PolicyManagementException e) {
|
} catch (PolicyManagementException e) {
|
||||||
String error = "Exception in deleting policies.";
|
String msg = "Exception in deleting policies.";
|
||||||
log.error(error, e);
|
log.error(msg, e);
|
||||||
throw new MDMAPIException(error, e);
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
}
|
}
|
||||||
ResponsePayload responsePayload = new ResponsePayload();
|
ResponsePayload responsePayload = new ResponsePayload();
|
||||||
if (policyDeleted) {
|
if (policyDeleted) {
|
||||||
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
||||||
responsePayload.setMessageFromServer("Policies have been successfully deleted.");
|
responsePayload.setMessageFromServer("Policies have been successfully deleted.");
|
||||||
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
|
return Response.status(Response.Status.OK).entity(responsePayload).build();
|
||||||
} else {
|
} else {
|
||||||
responsePayload.setStatusCode(HttpStatus.SC_BAD_REQUEST);
|
responsePayload.setStatusCode(HttpStatus.SC_BAD_REQUEST);
|
||||||
responsePayload.setMessageFromServer("Policy does not exist.");
|
responsePayload.setMessageFromServer("Policy does not exist.");
|
||||||
return Response.status(HttpStatus.SC_BAD_REQUEST).entity(responsePayload).build();
|
return Response.status(Response.Status.BAD_REQUEST).entity(responsePayload).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@PUT
|
@PUT
|
||||||
@Produces("application/json")
|
@Produces("application/json")
|
||||||
@Path("activate")
|
@Path("activate")
|
||||||
public Response activatePolicy(List<Integer> policyIds) throws MDMAPIException {
|
public Response activatePolicy(List<Integer> policyIds) {
|
||||||
try {
|
try {
|
||||||
PolicyManagerService policyManagementService = MDMAPIUtils.getPolicyManagementService();
|
PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
|
||||||
PolicyAdministratorPoint pap = policyManagementService.getPAP();
|
PolicyAdministratorPoint pap = policyManagementService.getPAP();
|
||||||
for(int i : policyIds) {
|
for(int i : policyIds) {
|
||||||
pap.activatePolicy(i);
|
pap.activatePolicy(i);
|
||||||
}
|
}
|
||||||
} catch (PolicyManagementException e) {
|
} catch (PolicyManagementException e) {
|
||||||
String error = "Exception in activating policies.";
|
String msg = "Exception in activating policies.";
|
||||||
log.error(error, e);
|
log.error(msg, e);
|
||||||
throw new MDMAPIException(error, e);
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
ResponsePayload responsePayload = new ResponsePayload();
|
ResponsePayload responsePayload = new ResponsePayload();
|
||||||
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
||||||
responsePayload.setMessageFromServer("Selected policies have been successfully activated.");
|
responsePayload.setMessageFromServer("Selected policies have been successfully activated.");
|
||||||
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
|
return Response.status(Response.Status.OK).entity(responsePayload).build();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@PUT
|
@PUT
|
||||||
@ -300,132 +297,134 @@ public class Policy {
|
|||||||
public Response inactivatePolicy(List<Integer> policyIds) throws MDMAPIException {
|
public Response inactivatePolicy(List<Integer> policyIds) throws MDMAPIException {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
PolicyManagerService policyManagementService = MDMAPIUtils.getPolicyManagementService();
|
PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
|
||||||
PolicyAdministratorPoint pap = policyManagementService.getPAP();
|
PolicyAdministratorPoint pap = policyManagementService.getPAP();
|
||||||
for(int i : policyIds) {
|
for(int i : policyIds) {
|
||||||
pap.inactivatePolicy(i);
|
pap.inactivatePolicy(i);
|
||||||
}
|
}
|
||||||
} catch (PolicyManagementException e) {
|
} catch (PolicyManagementException e) {
|
||||||
String error = "Exception in inactivating policies.";
|
String msg = "Exception in inactivating policies.";
|
||||||
log.error(error, e);
|
log.error(msg, e);
|
||||||
throw new MDMAPIException(error, e);
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
}
|
}
|
||||||
ResponsePayload responsePayload = new ResponsePayload();
|
ResponsePayload responsePayload = new ResponsePayload();
|
||||||
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
||||||
responsePayload.setMessageFromServer("Selected policies have been successfully inactivated.");
|
responsePayload.setMessageFromServer("Selected policies have been successfully inactivated.");
|
||||||
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
|
return Response.status(Response.Status.OK).entity(responsePayload).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@PUT
|
@PUT
|
||||||
@Produces("application/json")
|
@Produces("application/json")
|
||||||
@Path("apply-changes")
|
@Path("apply-changes")
|
||||||
public Response applyChanges() throws MDMAPIException {
|
public Response applyChanges() {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
PolicyManagerService policyManagementService = MDMAPIUtils.getPolicyManagementService();
|
PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
|
||||||
PolicyAdministratorPoint pap = policyManagementService.getPAP();
|
PolicyAdministratorPoint pap = policyManagementService.getPAP();
|
||||||
pap.publishChanges();
|
pap.publishChanges();
|
||||||
|
|
||||||
|
|
||||||
} catch (PolicyManagementException e) {
|
} catch (PolicyManagementException e) {
|
||||||
String error = "Exception in applying changes.";
|
String msg = "Exception in applying changes.";
|
||||||
log.error(error, e);
|
log.error(msg, e);
|
||||||
throw new MDMAPIException(error, e);
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
}
|
}
|
||||||
ResponsePayload responsePayload = new ResponsePayload();
|
ResponsePayload responsePayload = new ResponsePayload();
|
||||||
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
||||||
responsePayload.setMessageFromServer("Changes have been successfully updated.");
|
responsePayload.setMessageFromServer("Changes have been successfully updated.");
|
||||||
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
|
return Response.status(Response.Status.OK).entity(responsePayload).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("start-task/{milliseconds}")
|
@Path("start-task/{milliseconds}")
|
||||||
public Response startTaskService(@PathParam("milliseconds") int monitoringFrequency) throws MDMAPIException {
|
public Response startTaskService(@PathParam("milliseconds") int monitoringFrequency) {
|
||||||
|
|
||||||
PolicyManagerService policyManagementService = MDMAPIUtils.getPolicyManagementService();
|
PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
|
||||||
try {
|
try {
|
||||||
TaskScheduleService taskScheduleService = policyManagementService.getTaskScheduleService();
|
TaskScheduleService taskScheduleService = policyManagementService.getTaskScheduleService();
|
||||||
taskScheduleService.startTask(monitoringFrequency);
|
taskScheduleService.startTask(monitoringFrequency);
|
||||||
|
|
||||||
|
|
||||||
} catch (PolicyMonitoringTaskException e) {
|
} catch (PolicyMonitoringTaskException e) {
|
||||||
String error = "Policy Management related exception.";
|
String msg = "Policy Management related exception.";
|
||||||
log.error(error, e);
|
log.error(msg, e);
|
||||||
throw new MDMAPIException(error, e);
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
}
|
}
|
||||||
ResponsePayload responsePayload = new ResponsePayload();
|
ResponsePayload responsePayload = new ResponsePayload();
|
||||||
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
||||||
responsePayload.setMessageFromServer("Policy monitoring service started successfully.");
|
responsePayload.setMessageFromServer("Policy monitoring service started successfully.");
|
||||||
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
|
return Response.status(Response.Status.OK).entity(responsePayload).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("update-task/{milliseconds}")
|
@Path("update-task/{milliseconds}")
|
||||||
public Response updateTaskService(@PathParam("milliseconds") int monitoringFrequency) throws MDMAPIException {
|
public Response updateTaskService(@PathParam("milliseconds") int monitoringFrequency) {
|
||||||
|
|
||||||
PolicyManagerService policyManagementService = MDMAPIUtils.getPolicyManagementService();
|
PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
|
||||||
try {
|
try {
|
||||||
TaskScheduleService taskScheduleService = policyManagementService.getTaskScheduleService();
|
TaskScheduleService taskScheduleService = policyManagementService.getTaskScheduleService();
|
||||||
taskScheduleService.updateTask(monitoringFrequency);
|
taskScheduleService.updateTask(monitoringFrequency);
|
||||||
|
|
||||||
} catch (PolicyMonitoringTaskException e) {
|
} catch (PolicyMonitoringTaskException e) {
|
||||||
String error = "Policy Management related exception.";
|
String msg = "Policy Management related exception.";
|
||||||
log.error(error, e);
|
log.error(msg, e);
|
||||||
throw new MDMAPIException(error, e);
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
}
|
}
|
||||||
ResponsePayload responsePayload = new ResponsePayload();
|
ResponsePayload responsePayload = new ResponsePayload();
|
||||||
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
||||||
responsePayload.setMessageFromServer("Policy monitoring service updated successfully.");
|
responsePayload.setMessageFromServer("Policy monitoring service updated successfully.");
|
||||||
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
|
return Response.status(Response.Status.OK).entity(responsePayload).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("stop-task")
|
@Path("stop-task")
|
||||||
public Response stopTaskService() throws MDMAPIException {
|
public Response stopTaskService() {
|
||||||
|
|
||||||
PolicyManagerService policyManagementService = MDMAPIUtils.getPolicyManagementService();
|
PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
|
||||||
try {
|
try {
|
||||||
TaskScheduleService taskScheduleService = policyManagementService.getTaskScheduleService();
|
TaskScheduleService taskScheduleService = policyManagementService.getTaskScheduleService();
|
||||||
taskScheduleService.stopTask();
|
taskScheduleService.stopTask();
|
||||||
|
|
||||||
} catch (PolicyMonitoringTaskException e) {
|
} catch (PolicyMonitoringTaskException e) {
|
||||||
String error = "Policy Management related exception.";
|
String msg = "Policy Management related exception.";
|
||||||
log.error(error, e);
|
log.error(msg, e);
|
||||||
throw new MDMAPIException(error, e);
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
}
|
}
|
||||||
ResponsePayload responsePayload = new ResponsePayload();
|
ResponsePayload responsePayload = new ResponsePayload();
|
||||||
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
||||||
responsePayload.setMessageFromServer("Policy monitoring service stopped successfully.");
|
responsePayload.setMessageFromServer("Policy monitoring service stopped successfully.");
|
||||||
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
|
return Response.status(Response.Status.OK).entity(responsePayload).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("{type}/{id}")
|
@Path("{type}/{id}")
|
||||||
public ComplianceData getComplianceDataOfDevice(@PathParam("type") String type, @PathParam("id") String id) throws
|
public Response getComplianceDataOfDevice(@PathParam("type") String type, @PathParam("id") String id) {
|
||||||
MDMAPIException {
|
|
||||||
try {
|
try {
|
||||||
DeviceIdentifier deviceIdentifier = MDMAPIUtils.instantiateDeviceIdentifier(type, id);
|
DeviceIdentifier deviceIdentifier = DeviceMgtAPIUtils.instantiateDeviceIdentifier(type, id);
|
||||||
PolicyManagerService policyManagementService = MDMAPIUtils.getPolicyManagementService();
|
PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
|
||||||
return policyManagementService.getDeviceCompliance(deviceIdentifier);
|
ComplianceData complianceData = policyManagementService.getDeviceCompliance(deviceIdentifier);
|
||||||
|
return Response.status(Response.Status.OK).entity(complianceData).build();
|
||||||
} catch (PolicyComplianceException e) {
|
} catch (PolicyComplianceException e) {
|
||||||
String error = "Error occurred while getting the compliance data.";
|
String msg = "Error occurred while getting the compliance data.";
|
||||||
log.error(error, e);
|
log.error(msg, e);
|
||||||
throw new MDMAPIException(error, e);
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("{type}/{id}/active-policy")
|
@Path("{type}/{id}/active-policy")
|
||||||
public org.wso2.carbon.policy.mgt.common.Policy getDeviceActivePolicy(@PathParam("type") String type,
|
public Response getDeviceActivePolicy(@PathParam("type") String type,
|
||||||
@PathParam("id") String id) throws MDMAPIException {
|
@PathParam("id") String id) {
|
||||||
try {
|
try {
|
||||||
DeviceIdentifier deviceIdentifier = MDMAPIUtils.instantiateDeviceIdentifier(type, id);
|
DeviceIdentifier deviceIdentifier = DeviceMgtAPIUtils.instantiateDeviceIdentifier(type, id);
|
||||||
PolicyManagerService policyManagementService = MDMAPIUtils.getPolicyManagementService();
|
PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
|
||||||
return policyManagementService.getAppliedPolicyToDevice(deviceIdentifier);
|
org.wso2.carbon.policy.mgt.common.Policy policy = policyManagementService
|
||||||
} catch (PolicyManagementException e) {
|
.getAppliedPolicyToDevice(deviceIdentifier);
|
||||||
String error = "Error occurred while getting the current policy.";
|
return Response.status(Response.Status.OK).entity(policy).build();
|
||||||
log.error(error, e);
|
} catch (PolicyManagementException e) {
|
||||||
throw new MDMAPIException(error, e);
|
String msg = "Error occurred while getting the current policy.";
|
||||||
}
|
log.error(msg, e);
|
||||||
}
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
*
|
*
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
@ -11,17 +11,16 @@
|
|||||||
* Unless required by applicable law or agreed to in writing,
|
* Unless required by applicable law or agreed to in writing,
|
||||||
* software distributed under the License is distributed on an
|
* software distributed under the License is distributed on an
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
* KIND, either express or implied. See the License for the
|
* KIND, either express or implied. See the License for the
|
||||||
* specific language governing permissions and limitations
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.wso2.carbon.mdm.api;
|
package org.wso2.carbon.mdm.api;
|
||||||
|
|
||||||
import org.apache.commons.httpclient.HttpStatus;
|
|
||||||
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.wso2.carbon.mdm.api.common.MDMAPIException;
|
import org.wso2.carbon.mdm.api.util.DeviceMgtAPIUtils;
|
||||||
import org.wso2.carbon.mdm.api.util.MDMAPIUtils;
|
|
||||||
import org.wso2.carbon.mdm.api.util.ResponsePayload;
|
import org.wso2.carbon.mdm.api.util.ResponsePayload;
|
||||||
import org.wso2.carbon.policy.mgt.common.PolicyAdministratorPoint;
|
import org.wso2.carbon.policy.mgt.common.PolicyAdministratorPoint;
|
||||||
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
|
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
|
||||||
@ -33,57 +32,55 @@ import javax.ws.rs.Path;
|
|||||||
import javax.ws.rs.PathParam;
|
import javax.ws.rs.PathParam;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
|
|
||||||
|
@SuppressWarnings("NonJaxWsWebServices")
|
||||||
public class Profile {
|
public class Profile {
|
||||||
private static Log log = LogFactory.getLog(Profile.class);
|
private static Log log = LogFactory.getLog(Profile.class);
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
public org.wso2.carbon.policy.mgt.common.Profile addProfile(org.wso2.carbon.policy.mgt.common.Profile profile) throws MDMAPIException {
|
public Response addProfile(org.wso2.carbon.policy.mgt.common.Profile profile) {
|
||||||
PolicyManagerService policyManagementService = MDMAPIUtils.getPolicyManagementService();
|
PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
|
||||||
try {
|
try {
|
||||||
PolicyAdministratorPoint pap = policyManagementService.getPAP();
|
PolicyAdministratorPoint pap = policyManagementService.getPAP();
|
||||||
profile = pap.addProfile(profile);
|
profile = pap.addProfile(profile);
|
||||||
Response.status(HttpStatus.SC_CREATED);
|
return Response.status(Response.Status.OK).entity(profile).build();
|
||||||
return profile;
|
} catch (PolicyManagementException e) {
|
||||||
} catch (PolicyManagementException e) {
|
String msg = "Policy Management related exception";
|
||||||
String error = "Policy Management related exception";
|
log.error(msg, e);
|
||||||
log.error(error, e);
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
throw new MDMAPIException(error, e);
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@POST
|
@POST
|
||||||
@Path("{id}")
|
@Path("{id}")
|
||||||
public ResponsePayload updateProfile(org.wso2.carbon.policy.mgt.common.Profile profile, @PathParam("id") String profileId)
|
public Response updateProfile(org.wso2.carbon.policy.mgt.common.Profile profile,
|
||||||
throws MDMAPIException {
|
@PathParam("id") String profileId) {
|
||||||
PolicyManagerService policyManagementService = MDMAPIUtils.getPolicyManagementService();
|
PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
|
||||||
ResponsePayload responseMsg = new ResponsePayload();
|
ResponsePayload responseMsg = new ResponsePayload();
|
||||||
try {
|
try {
|
||||||
PolicyAdministratorPoint pap = policyManagementService.getPAP();
|
PolicyAdministratorPoint pap = policyManagementService.getPAP();
|
||||||
pap.updateProfile(profile);
|
pap.updateProfile(profile);
|
||||||
Response.status(HttpStatus.SC_OK);
|
|
||||||
responseMsg.setMessageFromServer("Profile has been updated successfully.");
|
responseMsg.setMessageFromServer("Profile has been updated successfully.");
|
||||||
return responseMsg;
|
return Response.status(Response.Status.OK).entity(responseMsg).build();
|
||||||
} catch (PolicyManagementException e) {
|
} catch (PolicyManagementException e) {
|
||||||
String error = "Policy Management related exception";
|
String msg = "Policy Management related exception";
|
||||||
log.error(error, e);
|
log.error(msg, e);
|
||||||
throw new MDMAPIException(error, e);
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@DELETE
|
@DELETE
|
||||||
@Path("{id}")
|
@Path("{id}")
|
||||||
public ResponsePayload deleteProfile(@PathParam("id") int profileId) throws MDMAPIException {
|
public Response deleteProfile(@PathParam("id") int profileId) {
|
||||||
PolicyManagerService policyManagementService = MDMAPIUtils.getPolicyManagementService();
|
PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
|
||||||
ResponsePayload responseMsg = new ResponsePayload();
|
ResponsePayload responseMsg = new ResponsePayload();
|
||||||
try {
|
try {
|
||||||
PolicyAdministratorPoint pap = policyManagementService.getPAP();
|
PolicyAdministratorPoint pap = policyManagementService.getPAP();
|
||||||
org.wso2.carbon.policy.mgt.common.Profile profile = pap.getProfile(profileId);
|
org.wso2.carbon.policy.mgt.common.Profile profile = pap.getProfile(profileId);
|
||||||
pap.deleteProfile(profile);
|
pap.deleteProfile(profile);
|
||||||
Response.status(HttpStatus.SC_OK);
|
|
||||||
responseMsg.setMessageFromServer("Profile has been deleted successfully.");
|
responseMsg.setMessageFromServer("Profile has been deleted successfully.");
|
||||||
return responseMsg;
|
return Response.status(Response.Status.OK).entity(responseMsg).build();
|
||||||
} catch (PolicyManagementException e) {
|
} catch (PolicyManagementException e) {
|
||||||
String error = "Policy Management related exception";
|
String msg = "Policy Management related exception";
|
||||||
log.error(error, e);
|
log.error(msg, e);
|
||||||
throw new MDMAPIException(error, e);
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,23 +24,35 @@ import org.apache.commons.logging.LogFactory;
|
|||||||
import org.wso2.carbon.CarbonConstants;
|
import org.wso2.carbon.CarbonConstants;
|
||||||
import org.wso2.carbon.base.MultitenantConstants;
|
import org.wso2.carbon.base.MultitenantConstants;
|
||||||
import org.wso2.carbon.mdm.api.common.MDMAPIException;
|
import org.wso2.carbon.mdm.api.common.MDMAPIException;
|
||||||
import org.wso2.carbon.mdm.api.util.MDMAPIUtils;
|
import org.wso2.carbon.mdm.api.util.DeviceMgtAPIUtils;
|
||||||
import org.wso2.carbon.mdm.api.util.ResponsePayload;
|
import org.wso2.carbon.mdm.api.util.ResponsePayload;
|
||||||
import org.wso2.carbon.mdm.beans.RoleWrapper;
|
import org.wso2.carbon.mdm.beans.RoleWrapper;
|
||||||
import org.wso2.carbon.mdm.util.SetReferenceTransformer;
|
import org.wso2.carbon.mdm.util.SetReferenceTransformer;
|
||||||
import org.wso2.carbon.user.api.*;
|
import org.wso2.carbon.user.api.AuthorizationManager;
|
||||||
|
import org.wso2.carbon.user.api.Permission;
|
||||||
|
import org.wso2.carbon.user.api.UserRealm;
|
||||||
|
import org.wso2.carbon.user.api.UserStoreException;
|
||||||
|
import org.wso2.carbon.user.api.UserStoreManager;
|
||||||
import org.wso2.carbon.user.core.common.AbstractUserStoreManager;
|
import org.wso2.carbon.user.core.common.AbstractUserStoreManager;
|
||||||
import org.wso2.carbon.user.mgt.UserRealmProxy;
|
import org.wso2.carbon.user.mgt.UserRealmProxy;
|
||||||
import org.wso2.carbon.user.mgt.common.UIPermissionNode;
|
import org.wso2.carbon.user.mgt.common.UIPermissionNode;
|
||||||
import org.wso2.carbon.user.mgt.common.UserAdminException;
|
import org.wso2.carbon.user.mgt.common.UserAdminException;
|
||||||
|
|
||||||
import javax.ws.rs.*;
|
import javax.ws.rs.DELETE;
|
||||||
|
import javax.ws.rs.GET;
|
||||||
|
import javax.ws.rs.POST;
|
||||||
|
import javax.ws.rs.PUT;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.PathParam;
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
|
import javax.ws.rs.QueryParam;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@SuppressWarnings("NonJaxWsWebServices")
|
||||||
public class Role {
|
public class Role {
|
||||||
|
|
||||||
private static Log log = LogFactory.getLog(Role.class);
|
private static Log log = LogFactory.getLog(Role.class);
|
||||||
@ -49,63 +61,49 @@ public class Role {
|
|||||||
* Get user roles (except all internal roles) from system.
|
* Get user roles (except all internal roles) from system.
|
||||||
*
|
*
|
||||||
* @return A list of users
|
* @return A list of users
|
||||||
* @throws MDMAPIException
|
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@Produces ({MediaType.APPLICATION_JSON})
|
@Produces({MediaType.APPLICATION_JSON})
|
||||||
public Response getRoles() throws MDMAPIException {
|
public Response getRoles() {
|
||||||
UserStoreManager userStoreManager = MDMAPIUtils.getUserStoreManager();
|
List<String> filteredRoles;
|
||||||
String[] roles;
|
|
||||||
try {
|
try {
|
||||||
if (log.isDebugEnabled()) {
|
filteredRoles = getRolesFromUserStore();
|
||||||
log.debug("Getting the list of user roles");
|
} catch (MDMAPIException e) {
|
||||||
}
|
log.error(e.getErrorMessage(), e);
|
||||||
roles = userStoreManager.getRoleNames();
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getErrorMessage()).build();
|
||||||
|
|
||||||
} catch (UserStoreException e) {
|
|
||||||
String msg = "Error occurred while retrieving the list of user roles.";
|
|
||||||
log.error(msg, e);
|
|
||||||
throw new MDMAPIException(msg, e);
|
|
||||||
}
|
|
||||||
// removing all internal roles and roles created for Service-providers
|
|
||||||
List<String> filteredRoles = new ArrayList<String>();
|
|
||||||
for (String role : roles) {
|
|
||||||
if (!(role.startsWith("Internal/") || role.startsWith("Application/"))) {
|
|
||||||
filteredRoles.add(role);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
ResponsePayload responsePayload = new ResponsePayload();
|
ResponsePayload responsePayload = new ResponsePayload();
|
||||||
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
||||||
responsePayload.setMessageFromServer("All user roles were successfully retrieved.");
|
responsePayload.setMessageFromServer("All user roles were successfully retrieved.");
|
||||||
responsePayload.setResponseContent(filteredRoles);
|
responsePayload.setResponseContent(filteredRoles);
|
||||||
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
|
return Response.status(Response.Status.OK).entity(responsePayload).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get user roles by user store(except all internal roles) from system.
|
* Get user roles by user store(except all internal roles) from system.
|
||||||
*
|
*
|
||||||
* @return A list of users
|
* @return A list of users
|
||||||
* @throws MDMAPIException
|
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@Path ("{userStore}")
|
@Path("{userStore}")
|
||||||
@Produces ({MediaType.APPLICATION_JSON})
|
@Produces({MediaType.APPLICATION_JSON})
|
||||||
public Response getRoles(@PathParam ("userStore") String userStore) throws MDMAPIException {
|
public Response getRoles(@PathParam("userStore") String userStore) {
|
||||||
AbstractUserStoreManager abstractUserStoreManager = (AbstractUserStoreManager) MDMAPIUtils.getUserStoreManager();
|
|
||||||
String[] roles;
|
String[] roles;
|
||||||
try {
|
try {
|
||||||
|
AbstractUserStoreManager abstractUserStoreManager =
|
||||||
|
(AbstractUserStoreManager) DeviceMgtAPIUtils.getUserStoreManager();
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Getting the list of user roles");
|
log.debug("Getting the list of user roles");
|
||||||
}
|
}
|
||||||
roles = abstractUserStoreManager.getRoleNames(userStore+"/*", -1, false, true, true);
|
roles = abstractUserStoreManager.getRoleNames(userStore + "/*", -1, false, true, true);
|
||||||
|
|
||||||
} catch (UserStoreException e) {
|
} catch (UserStoreException | MDMAPIException e) {
|
||||||
String msg = "Error occurred while retrieving the list of user roles.";
|
String msg = "Error occurred while retrieving the list of user roles.";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new MDMAPIException(msg, e);
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
}
|
}
|
||||||
// removing all internal roles and roles created for Service-providers
|
// removing all internal roles and roles created for Service-providers
|
||||||
List<String> filteredRoles = new ArrayList<String>();
|
List<String> filteredRoles = new ArrayList<>();
|
||||||
for (String role : roles) {
|
for (String role : roles) {
|
||||||
if (!(role.startsWith("Internal/") || role.startsWith("Application/"))) {
|
if (!(role.startsWith("Internal/") || role.startsWith("Application/"))) {
|
||||||
filteredRoles.add(role);
|
filteredRoles.add(role);
|
||||||
@ -115,34 +113,34 @@ public class Role {
|
|||||||
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
||||||
responsePayload.setMessageFromServer("All user roles were successfully retrieved.");
|
responsePayload.setMessageFromServer("All user roles were successfully retrieved.");
|
||||||
responsePayload.setResponseContent(filteredRoles);
|
responsePayload.setResponseContent(filteredRoles);
|
||||||
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
|
return Response.status(Response.Status.OK).entity(responsePayload).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get user roles by providing a filtering criteria(except all internal roles & system roles) from system.
|
* Get user roles by providing a filtering criteria(except all internal roles & system roles) from system.
|
||||||
*
|
*
|
||||||
* @return A list of users
|
* @return A list of users
|
||||||
* @throws MDMAPIException
|
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@Path ("search")
|
@Path("search")
|
||||||
@Produces ({MediaType.APPLICATION_JSON})
|
@Produces({MediaType.APPLICATION_JSON})
|
||||||
public Response getMatchingRoles(@QueryParam ("filter") String filter) throws MDMAPIException {
|
public Response getMatchingRoles(@QueryParam("filter") String filter) {
|
||||||
AbstractUserStoreManager abstractUserStoreManager = (AbstractUserStoreManager) MDMAPIUtils.getUserStoreManager();
|
|
||||||
String[] roles;
|
String[] roles;
|
||||||
try {
|
try {
|
||||||
|
AbstractUserStoreManager abstractUserStoreManager =
|
||||||
|
(AbstractUserStoreManager) DeviceMgtAPIUtils.getUserStoreManager();
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Getting the list of user roles using filter : " + filter);
|
log.debug("Getting the list of user roles using filter : " + filter);
|
||||||
}
|
}
|
||||||
roles = abstractUserStoreManager.getRoleNames("*" + filter + "*", -1, true, true, true);
|
roles = abstractUserStoreManager.getRoleNames("*" + filter + "*", -1, true, true, true);
|
||||||
|
|
||||||
} catch (UserStoreException e) {
|
} catch (UserStoreException | MDMAPIException e) {
|
||||||
String msg = "Error occurred while retrieving the list of user roles using the filter : " + filter;
|
String msg = "Error occurred while retrieving the list of user roles using the filter : " + filter;
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new MDMAPIException(msg, e);
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
}
|
}
|
||||||
// removing all internal roles and roles created for Service-providers
|
// removing all internal roles and roles created for Service-providers
|
||||||
List<String> filteredRoles = new ArrayList<String>();
|
List<String> filteredRoles = new ArrayList<>();
|
||||||
for (String role : roles) {
|
for (String role : roles) {
|
||||||
if (!(role.startsWith("Internal/") || role.startsWith("Application/"))) {
|
if (!(role.startsWith("Internal/") || role.startsWith("Application/"))) {
|
||||||
filteredRoles.add(role);
|
filteredRoles.add(role);
|
||||||
@ -152,74 +150,57 @@ public class Role {
|
|||||||
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
||||||
responsePayload.setMessageFromServer("All matching user roles were successfully retrieved.");
|
responsePayload.setMessageFromServer("All matching user roles were successfully retrieved.");
|
||||||
responsePayload.setResponseContent(filteredRoles);
|
responsePayload.setResponseContent(filteredRoles);
|
||||||
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
|
return Response.status(Response.Status.OK).entity(responsePayload).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get role permissions.
|
* Get role permissions.
|
||||||
*
|
*
|
||||||
* @return list of permissions
|
* @return list of permissions
|
||||||
* @throws MDMAPIException
|
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@Path ("permissions")
|
@Path("permissions")
|
||||||
@Produces ({MediaType.APPLICATION_JSON})
|
@Produces({MediaType.APPLICATION_JSON})
|
||||||
public ResponsePayload getPermissions(@QueryParam ("rolename") String roleName) throws MDMAPIException {
|
public Response getPermissions(@QueryParam("rolename") String roleName) {
|
||||||
final UserRealm userRealm = MDMAPIUtils.getUserRealm();
|
|
||||||
org.wso2.carbon.user.core.UserRealm userRealmCore = null;
|
|
||||||
final UIPermissionNode rolePermissions;
|
|
||||||
if (userRealm instanceof org.wso2.carbon.user.core.UserRealm) {
|
|
||||||
userRealmCore = (org.wso2.carbon.user.core.UserRealm) userRealm;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final UserRealmProxy userRealmProxy = new UserRealmProxy(userRealmCore);
|
final UserRealm userRealm = DeviceMgtAPIUtils.getUserRealm();
|
||||||
rolePermissions = userRealmProxy.getRolePermissions(roleName, MultitenantConstants.SUPER_TENANT_ID);
|
org.wso2.carbon.user.core.UserRealm userRealmCore = null;
|
||||||
UIPermissionNode[] deviceMgtPermissions = new UIPermissionNode[2];
|
final UIPermissionNode rolePermissions;
|
||||||
|
if (userRealm instanceof org.wso2.carbon.user.core.UserRealm) {
|
||||||
for (UIPermissionNode permissionNode : rolePermissions.getNodeList()) {
|
userRealmCore = (org.wso2.carbon.user.core.UserRealm) userRealm;
|
||||||
if (permissionNode.getResourcePath().equals("/permission/admin")) {
|
|
||||||
for (UIPermissionNode node : permissionNode.getNodeList()) {
|
|
||||||
if (node.getResourcePath().equals("/permission/admin/device-mgt")) {
|
|
||||||
deviceMgtPermissions[0] = node;
|
|
||||||
} else if (node.getResourcePath().equals("/permission/admin/login")) {
|
|
||||||
deviceMgtPermissions[1] = node;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
rolePermissions.setNodeList(deviceMgtPermissions);
|
final UserRealmProxy userRealmProxy = new UserRealmProxy(userRealmCore);
|
||||||
} catch (UserAdminException e) {
|
rolePermissions = getUIPermissionNode(roleName, userRealmProxy);
|
||||||
|
ResponsePayload responsePayload = new ResponsePayload();
|
||||||
|
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
||||||
|
responsePayload.setMessageFromServer("All permissions retrieved");
|
||||||
|
responsePayload.setResponseContent(rolePermissions);
|
||||||
|
return Response.status(Response.Status.OK).entity(responsePayload).build();
|
||||||
|
} catch (UserAdminException | MDMAPIException e) {
|
||||||
String msg = "Error occurred while retrieving the user role";
|
String msg = "Error occurred while retrieving the user role";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new MDMAPIException(msg, e);
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
}
|
}
|
||||||
ResponsePayload responsePayload = new ResponsePayload();
|
|
||||||
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
|
||||||
responsePayload.setMessageFromServer("All permissions retrieved");
|
|
||||||
responsePayload.setResponseContent(rolePermissions);
|
|
||||||
return responsePayload;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get user role of the system
|
* Get user role of the system
|
||||||
*
|
*
|
||||||
* @return user role
|
* @return user role
|
||||||
* @throws MDMAPIException
|
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@Path("role")
|
@Path("role")
|
||||||
@Produces ({MediaType.APPLICATION_JSON})
|
@Produces({MediaType.APPLICATION_JSON})
|
||||||
public ResponsePayload getRole(@QueryParam ("rolename") String roleName) throws MDMAPIException {
|
public Response getRole(@QueryParam("rolename") String roleName) {
|
||||||
final UserStoreManager userStoreManager = MDMAPIUtils.getUserStoreManager();
|
|
||||||
final UserRealm userRealm = MDMAPIUtils.getUserRealm();
|
|
||||||
org.wso2.carbon.user.core.UserRealm userRealmCore = null;
|
|
||||||
if (userRealm instanceof org.wso2.carbon.user.core.UserRealm) {
|
|
||||||
userRealmCore = (org.wso2.carbon.user.core.UserRealm) userRealm;
|
|
||||||
}
|
|
||||||
|
|
||||||
RoleWrapper roleWrapper = new RoleWrapper();
|
RoleWrapper roleWrapper = new RoleWrapper();
|
||||||
try {
|
try {
|
||||||
|
final UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
||||||
|
final UserRealm userRealm = DeviceMgtAPIUtils.getUserRealm();
|
||||||
|
org.wso2.carbon.user.core.UserRealm userRealmCore = null;
|
||||||
|
if (userRealm instanceof org.wso2.carbon.user.core.UserRealm) {
|
||||||
|
userRealmCore = (org.wso2.carbon.user.core.UserRealm) userRealm;
|
||||||
|
}
|
||||||
|
|
||||||
final UserRealmProxy userRealmProxy = new UserRealmProxy(userRealmCore);
|
final UserRealmProxy userRealmProxy = new UserRealmProxy(userRealmCore);
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Getting the list of user roles");
|
log.debug("Getting the list of user roles");
|
||||||
@ -228,56 +209,57 @@ public class Role {
|
|||||||
roleWrapper.setRoleName(roleName);
|
roleWrapper.setRoleName(roleName);
|
||||||
roleWrapper.setUsers(userStoreManager.getUserListOfRole(roleName));
|
roleWrapper.setUsers(userStoreManager.getUserListOfRole(roleName));
|
||||||
// Get the permission nodes and hand picking only device management and login perms
|
// Get the permission nodes and hand picking only device management and login perms
|
||||||
final UIPermissionNode rolePermissions =
|
final UIPermissionNode rolePermissions = getUIPermissionNode(roleName, userRealmProxy);
|
||||||
userRealmProxy.getRolePermissions(roleName, MultitenantConstants.SUPER_TENANT_ID);
|
ArrayList<String> permList = new ArrayList<>();
|
||||||
UIPermissionNode[] deviceMgtPermissions = new UIPermissionNode[2];
|
|
||||||
|
|
||||||
for (UIPermissionNode permissionNode : rolePermissions.getNodeList()) {
|
|
||||||
if (permissionNode.getResourcePath().equals("/permission/admin")) {
|
|
||||||
for (UIPermissionNode node : permissionNode.getNodeList()) {
|
|
||||||
if (node.getResourcePath().equals("/permission/admin/device-mgt")) {
|
|
||||||
deviceMgtPermissions[0] = node;
|
|
||||||
} else if (node.getResourcePath().equals("/permission/admin/login")) {
|
|
||||||
deviceMgtPermissions[1] = node;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
rolePermissions.setNodeList(deviceMgtPermissions);
|
|
||||||
ArrayList<String> permList = new ArrayList<String>();
|
|
||||||
iteratePermissions(rolePermissions, permList);
|
iteratePermissions(rolePermissions, permList);
|
||||||
roleWrapper.setPermissionList(rolePermissions);
|
roleWrapper.setPermissionList(rolePermissions);
|
||||||
String[] permListAr = new String[permList.size()];
|
String[] permListAr = new String[permList.size()];
|
||||||
roleWrapper.setPermissions(permList.toArray(permListAr));
|
roleWrapper.setPermissions(permList.toArray(permListAr));
|
||||||
}
|
}
|
||||||
} catch (UserStoreException e) {
|
} catch (UserStoreException | UserAdminException | MDMAPIException e) {
|
||||||
String msg = "Error occurred while retrieving the user role";
|
String msg = "Error occurred while retrieving the user role";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new MDMAPIException(msg, e);
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
} catch (UserAdminException e) {
|
|
||||||
String msg = "Error occurred while retrieving the user role";
|
|
||||||
log.error(msg, e);
|
|
||||||
throw new MDMAPIException(msg, e);
|
|
||||||
}
|
}
|
||||||
ResponsePayload responsePayload = new ResponsePayload();
|
ResponsePayload responsePayload = new ResponsePayload();
|
||||||
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
||||||
responsePayload.setMessageFromServer("All user roles were successfully retrieved.");
|
responsePayload.setMessageFromServer("All user roles were successfully retrieved.");
|
||||||
responsePayload.setResponseContent(roleWrapper);
|
responsePayload.setResponseContent(roleWrapper);
|
||||||
return responsePayload;
|
return Response.status(Response.Status.OK).entity(responsePayload).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private UIPermissionNode getUIPermissionNode(String roleName, UserRealmProxy userRealmProxy)
|
||||||
|
throws UserAdminException {
|
||||||
|
final UIPermissionNode rolePermissions =
|
||||||
|
userRealmProxy.getRolePermissions(roleName, MultitenantConstants.SUPER_TENANT_ID);
|
||||||
|
UIPermissionNode[] deviceMgtPermissions = new UIPermissionNode[2];
|
||||||
|
|
||||||
|
for (UIPermissionNode permissionNode : rolePermissions.getNodeList()) {
|
||||||
|
if (permissionNode.getResourcePath().equals("/permission/admin")) {
|
||||||
|
for (UIPermissionNode node : permissionNode.getNodeList()) {
|
||||||
|
if (node.getResourcePath().equals("/permission/admin/device-mgt")) {
|
||||||
|
deviceMgtPermissions[0] = node;
|
||||||
|
} else if (node.getResourcePath().equals("/permission/admin/login")) {
|
||||||
|
deviceMgtPermissions[1] = node;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
rolePermissions.setNodeList(deviceMgtPermissions);
|
||||||
|
return rolePermissions;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* API is used to persist a new Role
|
* API is used to persist a new Role
|
||||||
*
|
*
|
||||||
* @param roleWrapper
|
* @param roleWrapper for role
|
||||||
* @return
|
* @return response
|
||||||
* @throws MDMAPIException
|
|
||||||
*/
|
*/
|
||||||
@POST
|
@POST
|
||||||
@Produces ({MediaType.APPLICATION_JSON})
|
@Produces({MediaType.APPLICATION_JSON})
|
||||||
public Response addRole(RoleWrapper roleWrapper) throws MDMAPIException {
|
public Response addRole(RoleWrapper roleWrapper) {
|
||||||
UserStoreManager userStoreManager = MDMAPIUtils.getUserStoreManager();
|
|
||||||
try {
|
try {
|
||||||
|
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Persisting the role to user store");
|
log.debug("Persisting the role to user store");
|
||||||
}
|
}
|
||||||
@ -291,29 +273,27 @@ public class Role {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
userStoreManager.addRole(roleWrapper.getRoleName(), roleWrapper.getUsers(), permissions);
|
userStoreManager.addRole(roleWrapper.getRoleName(), roleWrapper.getUsers(), permissions);
|
||||||
} catch (UserStoreException e) {
|
} catch (UserStoreException | MDMAPIException e) {
|
||||||
String msg = e.getMessage();
|
String msg = e.getMessage();
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new MDMAPIException(msg, e);
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
}
|
}
|
||||||
return Response.status(HttpStatus.SC_CREATED).build();
|
return Response.status(Response.Status.OK).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* API is used to update a role Role
|
* API is used to update a role Role
|
||||||
*
|
*
|
||||||
* @param roleWrapper
|
* @param roleWrapper for role
|
||||||
* @return
|
* @return response
|
||||||
* @throws MDMAPIException
|
|
||||||
*/
|
*/
|
||||||
@PUT
|
@PUT
|
||||||
@Produces ({MediaType.APPLICATION_JSON})
|
@Produces({MediaType.APPLICATION_JSON})
|
||||||
public Response updateRole(@QueryParam ("rolename") String roleName, RoleWrapper roleWrapper) throws
|
public Response updateRole(@QueryParam("rolename") String roleName, RoleWrapper roleWrapper) {
|
||||||
MDMAPIException {
|
|
||||||
final UserStoreManager userStoreManager = MDMAPIUtils.getUserStoreManager();
|
|
||||||
final AuthorizationManager authorizationManager = MDMAPIUtils.getAuthorizationManager();
|
|
||||||
String newRoleName = roleWrapper.getRoleName();
|
String newRoleName = roleWrapper.getRoleName();
|
||||||
try {
|
try {
|
||||||
|
final UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
||||||
|
final AuthorizationManager authorizationManager = DeviceMgtAPIUtils.getAuthorizationManager();
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Updating the role to user store");
|
log.debug("Updating the role to user store");
|
||||||
}
|
}
|
||||||
@ -321,13 +301,13 @@ public class Role {
|
|||||||
userStoreManager.updateRoleName(roleName, newRoleName);
|
userStoreManager.updateRoleName(roleName, newRoleName);
|
||||||
}
|
}
|
||||||
if (roleWrapper.getUsers() != null) {
|
if (roleWrapper.getUsers() != null) {
|
||||||
SetReferenceTransformer transformer = new SetReferenceTransformer();
|
SetReferenceTransformer<String> transformer = new SetReferenceTransformer<>();
|
||||||
transformer.transform(Arrays.asList(userStoreManager.getUserListOfRole(newRoleName)),
|
transformer.transform(Arrays.asList(userStoreManager.getUserListOfRole(newRoleName)),
|
||||||
Arrays.asList(roleWrapper.getUsers()));
|
Arrays.asList(roleWrapper.getUsers()));
|
||||||
final String[] usersToAdd = (String[])
|
final String[] usersToAdd = transformer.getObjectsToAdd().toArray(new String[transformer
|
||||||
transformer.getObjectsToAdd().toArray(new String[transformer.getObjectsToAdd().size()]);
|
.getObjectsToAdd().size()]);
|
||||||
final String[] usersToDelete = (String[])
|
final String[] usersToDelete = transformer.getObjectsToRemove().toArray(new String[transformer
|
||||||
transformer.getObjectsToRemove().toArray(new String[transformer.getObjectsToRemove().size()]);
|
.getObjectsToRemove().size()]);
|
||||||
userStoreManager.updateUserListOfRole(newRoleName, usersToDelete, usersToAdd);
|
userStoreManager.updateUserListOfRole(newRoleName, usersToDelete, usersToAdd);
|
||||||
}
|
}
|
||||||
if (roleWrapper.getPermissions() != null) {
|
if (roleWrapper.getPermissions() != null) {
|
||||||
@ -340,77 +320,74 @@ public class Role {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (UserStoreException e) {
|
} catch (UserStoreException | MDMAPIException e) {
|
||||||
String msg = e.getMessage();
|
String msg = e.getMessage();
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new MDMAPIException(msg, e);
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
}
|
}
|
||||||
return Response.status(HttpStatus.SC_OK).build();
|
return Response.status(Response.Status.OK).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* API is used to delete a role and authorizations
|
* API is used to delete a role and authorizations
|
||||||
*
|
*
|
||||||
* @param roleName
|
* @param roleName to delete
|
||||||
* @return
|
* @return response
|
||||||
* @throws MDMAPIException
|
|
||||||
*/
|
*/
|
||||||
@DELETE
|
@DELETE
|
||||||
@Produces ({MediaType.APPLICATION_JSON})
|
@Produces({MediaType.APPLICATION_JSON})
|
||||||
public Response deleteRole(@QueryParam ("rolename") String roleName) throws MDMAPIException {
|
public Response deleteRole(@QueryParam("rolename") String roleName) {
|
||||||
final UserStoreManager userStoreManager = MDMAPIUtils.getUserStoreManager();
|
|
||||||
final AuthorizationManager authorizationManager = MDMAPIUtils.getAuthorizationManager();
|
|
||||||
try {
|
try {
|
||||||
|
final UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
||||||
|
final AuthorizationManager authorizationManager = DeviceMgtAPIUtils.getAuthorizationManager();
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Deleting the role in user store");
|
log.debug("Deleting the role in user store");
|
||||||
}
|
}
|
||||||
userStoreManager.deleteRole(roleName);
|
userStoreManager.deleteRole(roleName);
|
||||||
// Delete all authorizations for the current role before deleting
|
// Delete all authorizations for the current role before deleting
|
||||||
authorizationManager.clearRoleAuthorization(roleName);
|
authorizationManager.clearRoleAuthorization(roleName);
|
||||||
} catch (UserStoreException e) {
|
} catch (UserStoreException | MDMAPIException e) {
|
||||||
String msg = "Error occurred while deleting the role: " + roleName;
|
String msg = "Error occurred while deleting the role: " + roleName;
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new MDMAPIException(msg, e);
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
}
|
}
|
||||||
return Response.status(HttpStatus.SC_OK).build();
|
return Response.status(Response.Status.OK).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* API is used to update users of a role
|
* API is used to update users of a role
|
||||||
*
|
*
|
||||||
* @param roleName
|
* @param roleName to update
|
||||||
* @param userList
|
* @param userList of the users
|
||||||
* @return
|
* @return response
|
||||||
* @throws MDMAPIException
|
|
||||||
*/
|
*/
|
||||||
@PUT
|
@PUT
|
||||||
@Path ("users")
|
@Path("users")
|
||||||
@Produces ({MediaType.APPLICATION_JSON})
|
@Produces({MediaType.APPLICATION_JSON})
|
||||||
public Response updateUsers(@QueryParam ("rolename") String roleName, List<String> userList)
|
public Response updateUsers(@QueryParam("rolename") String roleName, List<String> userList) {
|
||||||
throws MDMAPIException {
|
|
||||||
final UserStoreManager userStoreManager = MDMAPIUtils.getUserStoreManager();
|
|
||||||
try {
|
try {
|
||||||
|
final UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Updating the users of a role");
|
log.debug("Updating the users of a role");
|
||||||
}
|
}
|
||||||
SetReferenceTransformer transformer = new SetReferenceTransformer();
|
SetReferenceTransformer<String> transformer = new SetReferenceTransformer<>();
|
||||||
transformer.transform(Arrays.asList(userStoreManager.getUserListOfRole(roleName)),
|
transformer.transform(Arrays.asList(userStoreManager.getUserListOfRole(roleName)),
|
||||||
userList);
|
userList);
|
||||||
final String[] usersToAdd = (String[])
|
final String[] usersToAdd = transformer.getObjectsToAdd().toArray(new String[transformer
|
||||||
transformer.getObjectsToAdd().toArray(new String[transformer.getObjectsToAdd().size()]);
|
.getObjectsToAdd().size()]);
|
||||||
final String[] usersToDelete = (String[])
|
final String[] usersToDelete = transformer.getObjectsToRemove().toArray(new String[transformer
|
||||||
transformer.getObjectsToRemove().toArray(new String[transformer.getObjectsToRemove().size()]);
|
.getObjectsToRemove().size()]);
|
||||||
|
|
||||||
userStoreManager.updateUserListOfRole(roleName, usersToDelete, usersToAdd);
|
userStoreManager.updateUserListOfRole(roleName, usersToDelete, usersToAdd);
|
||||||
} catch (UserStoreException e) {
|
} catch (UserStoreException | MDMAPIException e) {
|
||||||
String msg = "Error occurred while saving the users of the role: " + roleName;
|
String msg = "Error occurred while saving the users of the role: " + roleName;
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new MDMAPIException(e.getMessage(), e);
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
}
|
}
|
||||||
return Response.status(HttpStatus.SC_OK).build();
|
return Response.status(Response.Status.OK).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<String> iteratePermissions(UIPermissionNode uiPermissionNode, ArrayList<String> list) {
|
private ArrayList<String> iteratePermissions(UIPermissionNode uiPermissionNode, ArrayList<String> list) {
|
||||||
for (UIPermissionNode permissionNode : uiPermissionNode.getNodeList()) {
|
for (UIPermissionNode permissionNode : uiPermissionNode.getNodeList()) {
|
||||||
list.add(permissionNode.getResourcePath());
|
list.add(permissionNode.getResourcePath());
|
||||||
if (permissionNode.getNodeList() != null && permissionNode.getNodeList().length > 0) {
|
if (permissionNode.getNodeList() != null && permissionNode.getNodeList().length > 0) {
|
||||||
@ -424,12 +401,22 @@ public class Role {
|
|||||||
* This method is used to retrieve the role count of the system.
|
* This method is used to retrieve the role count of the system.
|
||||||
*
|
*
|
||||||
* @return returns the count.
|
* @return returns the count.
|
||||||
* @throws MDMAPIException
|
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@Path("count")
|
@Path("count")
|
||||||
public int getRoleCount() throws MDMAPIException {
|
public Response getRoleCount() {
|
||||||
UserStoreManager userStoreManager = MDMAPIUtils.getUserStoreManager();
|
try {
|
||||||
|
List<String> filteredRoles = getRolesFromUserStore();
|
||||||
|
Integer count = filteredRoles.size();
|
||||||
|
return Response.status(Response.Status.OK).entity(count).build();
|
||||||
|
} catch (MDMAPIException e) {
|
||||||
|
log.error(e.getErrorMessage(), e);
|
||||||
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getErrorMessage()).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<String> getRolesFromUserStore() throws MDMAPIException {
|
||||||
|
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
||||||
String[] roles;
|
String[] roles;
|
||||||
try {
|
try {
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
@ -439,16 +426,15 @@ public class Role {
|
|||||||
|
|
||||||
} catch (UserStoreException e) {
|
} catch (UserStoreException e) {
|
||||||
String msg = "Error occurred while retrieving the list of user roles.";
|
String msg = "Error occurred while retrieving the list of user roles.";
|
||||||
log.error(msg, e);
|
|
||||||
throw new MDMAPIException(msg, e);
|
throw new MDMAPIException(msg, e);
|
||||||
}
|
}
|
||||||
// removing all internal roles and roles created for Service-providers
|
// removing all internal roles and roles created for Service-providers
|
||||||
List<String> filteredRoles = new ArrayList<String>();
|
List<String> filteredRoles = new ArrayList<>();
|
||||||
for (String role : roles) {
|
for (String role : roles) {
|
||||||
if (!(role.startsWith("Internal/") || role.startsWith("Application/"))) {
|
if (!(role.startsWith("Internal/") || role.startsWith("Application/"))) {
|
||||||
filteredRoles.add(role);
|
filteredRoles.add(role);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return filteredRoles.size();
|
return filteredRoles;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -30,7 +30,7 @@ import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
|||||||
import org.wso2.carbon.device.mgt.core.service.EmailMetaInfo;
|
import org.wso2.carbon.device.mgt.core.service.EmailMetaInfo;
|
||||||
import org.wso2.carbon.mdm.api.common.MDMAPIException;
|
import org.wso2.carbon.mdm.api.common.MDMAPIException;
|
||||||
import org.wso2.carbon.mdm.api.util.CredentialManagementResponseBuilder;
|
import org.wso2.carbon.mdm.api.util.CredentialManagementResponseBuilder;
|
||||||
import org.wso2.carbon.mdm.api.util.MDMAPIUtils;
|
import org.wso2.carbon.mdm.api.util.DeviceMgtAPIUtils;
|
||||||
import org.wso2.carbon.mdm.api.util.ResponsePayload;
|
import org.wso2.carbon.mdm.api.util.ResponsePayload;
|
||||||
import org.wso2.carbon.mdm.beans.UserCredentialWrapper;
|
import org.wso2.carbon.mdm.beans.UserCredentialWrapper;
|
||||||
import org.wso2.carbon.mdm.beans.UserWrapper;
|
import org.wso2.carbon.mdm.beans.UserWrapper;
|
||||||
@ -52,30 +52,38 @@ import javax.ws.rs.QueryParam;
|
|||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Properties;
|
||||||
|
import java.util.Random;
|
||||||
|
import java.util.TreeSet;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class represents the JAX-RS services of User related functionality.
|
* This class represents the JAX-RS services of User related functionality.
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("NonJaxWsWebServices")
|
||||||
public class User {
|
public class User {
|
||||||
|
|
||||||
private static Log log = LogFactory.getLog(User.class);
|
|
||||||
private static final String ROLE_EVERYONE = "Internal/everyone";
|
private static final String ROLE_EVERYONE = "Internal/everyone";
|
||||||
|
private static Log log = LogFactory.getLog(User.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method to add user to emm-user-store.
|
* Method to add user to emm-user-store.
|
||||||
*
|
*
|
||||||
* @param userWrapper Wrapper object representing input json payload
|
* @param userWrapper Wrapper object representing input json payload
|
||||||
* @return {Response} Status of the request wrapped inside Response object
|
* @return {Response} Status of the request wrapped inside Response object
|
||||||
* @throws MDMAPIException
|
|
||||||
*/
|
*/
|
||||||
@POST
|
@POST
|
||||||
@Consumes({MediaType.APPLICATION_JSON})
|
@Consumes({MediaType.APPLICATION_JSON})
|
||||||
@Produces({MediaType.APPLICATION_JSON})
|
@Produces({MediaType.APPLICATION_JSON})
|
||||||
public Response addUser(UserWrapper userWrapper) throws MDMAPIException {
|
public Response addUser(UserWrapper userWrapper) {
|
||||||
UserStoreManager userStoreManager = MDMAPIUtils.getUserStoreManager();
|
|
||||||
ResponsePayload responsePayload = new ResponsePayload();
|
ResponsePayload responsePayload = new ResponsePayload();
|
||||||
try {
|
try {
|
||||||
|
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
||||||
if (userStoreManager.isExistingUser(userWrapper.getUsername())) {
|
if (userStoreManager.isExistingUser(userWrapper.getUsername())) {
|
||||||
// if user already exists
|
// if user already exists
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
@ -87,7 +95,7 @@ public class User {
|
|||||||
responsePayload.
|
responsePayload.
|
||||||
setMessageFromServer("User by username: " + userWrapper.getUsername() +
|
setMessageFromServer("User by username: " + userWrapper.getUsername() +
|
||||||
" already exists. Therefore, request made to add user was refused.");
|
" already exists. Therefore, request made to add user was refused.");
|
||||||
return Response.status(HttpStatus.SC_CONFLICT).entity(responsePayload).build();
|
return Response.status(Response.Status.CONFLICT).entity(responsePayload).build();
|
||||||
} else {
|
} else {
|
||||||
String initialUserPassword = generateInitialUserPassword();
|
String initialUserPassword = generateInitialUserPassword();
|
||||||
Map<String, String> defaultUserClaims =
|
Map<String, String> defaultUserClaims =
|
||||||
@ -106,12 +114,12 @@ public class User {
|
|||||||
responsePayload.setStatusCode(HttpStatus.SC_CREATED);
|
responsePayload.setStatusCode(HttpStatus.SC_CREATED);
|
||||||
responsePayload.setMessageFromServer("User by username: " + userWrapper.getUsername() +
|
responsePayload.setMessageFromServer("User by username: " + userWrapper.getUsername() +
|
||||||
" was successfully added.");
|
" was successfully added.");
|
||||||
return Response.status(HttpStatus.SC_CREATED).entity(responsePayload).build();
|
return Response.status(Response.Status.CREATED).entity(responsePayload).build();
|
||||||
}
|
}
|
||||||
} catch (UserStoreException e) {
|
} catch (UserStoreException | MDMAPIException e) {
|
||||||
String msg = "Exception in trying to add user by username: " + userWrapper.getUsername();
|
String msg = "Exception in trying to add user by username: " + userWrapper.getUsername();
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new MDMAPIException(msg, e);
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,16 +127,15 @@ public class User {
|
|||||||
* Method to get user information from emm-user-store.
|
* Method to get user information from emm-user-store.
|
||||||
*
|
*
|
||||||
* @param username User-name of the user
|
* @param username User-name of the user
|
||||||
* @return {Response} Status of the request wrapped inside Response object
|
* @return {Response} Status of the request wrapped inside Response object.
|
||||||
* @throws MDMAPIException
|
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@Path("view")
|
@Path("view")
|
||||||
@Produces({MediaType.APPLICATION_JSON})
|
@Produces({MediaType.APPLICATION_JSON})
|
||||||
public Response getUser(@QueryParam("username") String username) throws MDMAPIException {
|
public Response getUser(@QueryParam("username") String username) {
|
||||||
UserStoreManager userStoreManager = MDMAPIUtils.getUserStoreManager();
|
|
||||||
ResponsePayload responsePayload = new ResponsePayload();
|
ResponsePayload responsePayload = new ResponsePayload();
|
||||||
try {
|
try {
|
||||||
|
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
||||||
if (userStoreManager.isExistingUser(username)) {
|
if (userStoreManager.isExistingUser(username)) {
|
||||||
UserWrapper user = new UserWrapper();
|
UserWrapper user = new UserWrapper();
|
||||||
user.setUsername(username);
|
user.setUsername(username);
|
||||||
@ -142,7 +149,7 @@ public class User {
|
|||||||
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
||||||
responsePayload.setMessageFromServer("User information was retrieved successfully.");
|
responsePayload.setMessageFromServer("User information was retrieved successfully.");
|
||||||
responsePayload.setResponseContent(user);
|
responsePayload.setResponseContent(user);
|
||||||
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
|
return Response.status(Response.Status.OK).entity(responsePayload).build();
|
||||||
} else {
|
} else {
|
||||||
// Outputting debug message upon trying to remove non-existing user
|
// Outputting debug message upon trying to remove non-existing user
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
@ -152,12 +159,12 @@ public class User {
|
|||||||
responsePayload.setStatusCode(HttpStatus.SC_BAD_REQUEST);
|
responsePayload.setStatusCode(HttpStatus.SC_BAD_REQUEST);
|
||||||
responsePayload.setMessageFromServer(
|
responsePayload.setMessageFromServer(
|
||||||
"User by username: " + username + " does not exist.");
|
"User by username: " + username + " does not exist.");
|
||||||
return Response.status(HttpStatus.SC_NOT_FOUND).entity(responsePayload).build();
|
return Response.status(Response.Status.BAD_REQUEST).entity(responsePayload).build();
|
||||||
}
|
}
|
||||||
} catch (UserStoreException e) {
|
} catch (UserStoreException | MDMAPIException e) {
|
||||||
String msg = "Exception in trying to retrieve user by username: " + username;
|
String msg = "Exception in trying to retrieve user by username: " + username;
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new MDMAPIException(msg, e);
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -165,17 +172,15 @@ public class User {
|
|||||||
* Update user in user store
|
* Update user in user store
|
||||||
*
|
*
|
||||||
* @param userWrapper Wrapper object representing input json payload
|
* @param userWrapper Wrapper object representing input json payload
|
||||||
* @return {Response} Status of the request wrapped inside Response object
|
* @return {Response} Status of the request wrapped inside Response object.
|
||||||
* @throws MDMAPIException
|
|
||||||
*/
|
*/
|
||||||
@PUT
|
@PUT
|
||||||
@Consumes({MediaType.APPLICATION_JSON})
|
@Consumes({MediaType.APPLICATION_JSON})
|
||||||
@Produces({MediaType.APPLICATION_JSON})
|
@Produces({MediaType.APPLICATION_JSON})
|
||||||
public Response updateUser(UserWrapper userWrapper, @QueryParam("username") String username)
|
public Response updateUser(UserWrapper userWrapper, @QueryParam("username") String username) {
|
||||||
throws MDMAPIException {
|
|
||||||
UserStoreManager userStoreManager = MDMAPIUtils.getUserStoreManager();
|
|
||||||
ResponsePayload responsePayload = new ResponsePayload();
|
ResponsePayload responsePayload = new ResponsePayload();
|
||||||
try {
|
try {
|
||||||
|
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
||||||
if (userStoreManager.isExistingUser(userWrapper.getUsername())) {
|
if (userStoreManager.isExistingUser(userWrapper.getUsername())) {
|
||||||
Map<String, String> defaultUserClaims =
|
Map<String, String> defaultUserClaims =
|
||||||
buildDefaultUserClaims(userWrapper.getFirstname(), userWrapper.getLastname(),
|
buildDefaultUserClaims(userWrapper.getFirstname(), userWrapper.getLastname(),
|
||||||
@ -221,7 +226,7 @@ public class User {
|
|||||||
responsePayload.setStatusCode(HttpStatus.SC_CREATED);
|
responsePayload.setStatusCode(HttpStatus.SC_CREATED);
|
||||||
responsePayload.setMessageFromServer("User by username: " + userWrapper.getUsername() +
|
responsePayload.setMessageFromServer("User by username: " + userWrapper.getUsername() +
|
||||||
" was successfully updated.");
|
" was successfully updated.");
|
||||||
return Response.status(HttpStatus.SC_CREATED).entity(responsePayload).build();
|
return Response.status(Response.Status.CREATED).entity(responsePayload).build();
|
||||||
} else {
|
} else {
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("User by username: " + userWrapper.getUsername() +
|
log.debug("User by username: " + userWrapper.getUsername() +
|
||||||
@ -232,12 +237,12 @@ public class User {
|
|||||||
responsePayload.
|
responsePayload.
|
||||||
setMessageFromServer("User by username: " + userWrapper.getUsername() +
|
setMessageFromServer("User by username: " + userWrapper.getUsername() +
|
||||||
" doesn't exists. Therefore, request made to update user was refused.");
|
" doesn't exists. Therefore, request made to update user was refused.");
|
||||||
return Response.status(HttpStatus.SC_CONFLICT).entity(responsePayload).build();
|
return Response.status(Response.Status.CONFLICT).entity(responsePayload).build();
|
||||||
}
|
}
|
||||||
} catch (UserStoreException | UnsupportedEncodingException e) {
|
} catch (UserStoreException | UnsupportedEncodingException | MDMAPIException e) {
|
||||||
String msg = "Exception in trying to update user by username: " + userWrapper.getUsername();
|
String msg = "Exception in trying to update user by username: " + userWrapper.getUsername();
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new MDMAPIException(msg, e);
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -291,15 +296,14 @@ public class User {
|
|||||||
* Method to remove user from emm-user-store.
|
* Method to remove user from emm-user-store.
|
||||||
*
|
*
|
||||||
* @param username Username of the user
|
* @param username Username of the user
|
||||||
* @return {Response} Status of the request wrapped inside Response object
|
* @return {Response} Status of the request wrapped inside Response object.
|
||||||
* @throws MDMAPIException
|
|
||||||
*/
|
*/
|
||||||
@DELETE
|
@DELETE
|
||||||
@Produces({MediaType.APPLICATION_JSON})
|
@Produces({MediaType.APPLICATION_JSON})
|
||||||
public Response removeUser(@QueryParam("username") String username) throws MDMAPIException {
|
public Response removeUser(@QueryParam("username") String username) {
|
||||||
UserStoreManager userStoreManager = MDMAPIUtils.getUserStoreManager();
|
|
||||||
ResponsePayload responsePayload = new ResponsePayload();
|
ResponsePayload responsePayload = new ResponsePayload();
|
||||||
try {
|
try {
|
||||||
|
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
||||||
if (userStoreManager.isExistingUser(username)) {
|
if (userStoreManager.isExistingUser(username)) {
|
||||||
// if user already exists, trying to remove user
|
// if user already exists, trying to remove user
|
||||||
userStoreManager.deleteUser(username);
|
userStoreManager.deleteUser(username);
|
||||||
@ -311,7 +315,7 @@ public class User {
|
|||||||
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
||||||
responsePayload.setMessageFromServer(
|
responsePayload.setMessageFromServer(
|
||||||
"User by username: " + username + " was successfully removed.");
|
"User by username: " + username + " was successfully removed.");
|
||||||
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
|
return Response.status(Response.Status.OK).entity(responsePayload).build();
|
||||||
} else {
|
} else {
|
||||||
// Outputting debug message upon trying to remove non-existing user
|
// Outputting debug message upon trying to remove non-existing user
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
@ -321,12 +325,12 @@ public class User {
|
|||||||
responsePayload.setStatusCode(HttpStatus.SC_BAD_REQUEST);
|
responsePayload.setStatusCode(HttpStatus.SC_BAD_REQUEST);
|
||||||
responsePayload.setMessageFromServer(
|
responsePayload.setMessageFromServer(
|
||||||
"User by username: " + username + " does not exist for removal.");
|
"User by username: " + username + " does not exist for removal.");
|
||||||
return Response.status(HttpStatus.SC_BAD_REQUEST).entity(responsePayload).build();
|
return Response.status(Response.Status.BAD_REQUEST).entity(responsePayload).build();
|
||||||
}
|
}
|
||||||
} catch (UserStoreException e) {
|
} catch (UserStoreException | MDMAPIException e) {
|
||||||
String msg = "Exception in trying to remove user by username: " + username;
|
String msg = "Exception in trying to remove user by username: " + username;
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new MDMAPIException(msg, e);
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -336,11 +340,14 @@ public class User {
|
|||||||
* @param userStoreManager User Store Manager associated with the currently logged in user
|
* @param userStoreManager User Store Manager associated with the currently logged in user
|
||||||
* @param username Username of the currently logged in user
|
* @param username Username of the currently logged in user
|
||||||
* @return the list of filtered roles
|
* @return the list of filtered roles
|
||||||
* @throws UserStoreException
|
|
||||||
*/
|
*/
|
||||||
private List<String> getFilteredRoles(UserStoreManager userStoreManager, String username)
|
private List<String> getFilteredRoles(UserStoreManager userStoreManager, String username) {
|
||||||
throws UserStoreException {
|
String[] roleListOfUser = new String[0];
|
||||||
String[] roleListOfUser = userStoreManager.getRoleListOfUser(username);
|
try {
|
||||||
|
roleListOfUser = userStoreManager.getRoleListOfUser(username);
|
||||||
|
} catch (UserStoreException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
List<String> filteredRoles = new ArrayList<>();
|
List<String> filteredRoles = new ArrayList<>();
|
||||||
for (String role : roleListOfUser) {
|
for (String role : roleListOfUser) {
|
||||||
if (!(role.startsWith("Internal/") || role.startsWith("Application/"))) {
|
if (!(role.startsWith("Internal/") || role.startsWith("Application/"))) {
|
||||||
@ -354,18 +361,17 @@ public class User {
|
|||||||
* Get user's roles by username
|
* Get user's roles by username
|
||||||
*
|
*
|
||||||
* @param username Username of the user
|
* @param username Username of the user
|
||||||
* @return {Response} Status of the request wrapped inside Response object
|
* @return {Response} Status of the request wrapped inside Response object.
|
||||||
* @throws MDMAPIException
|
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@Path("roles")
|
@Path("roles")
|
||||||
@Produces({MediaType.APPLICATION_JSON})
|
@Produces({MediaType.APPLICATION_JSON})
|
||||||
public Response getRoles(@QueryParam("username") String username) throws MDMAPIException {
|
public Response getRoles(@QueryParam("username") String username) {
|
||||||
UserStoreManager userStoreManager = MDMAPIUtils.getUserStoreManager();
|
|
||||||
ResponsePayload responsePayload = new ResponsePayload();
|
ResponsePayload responsePayload = new ResponsePayload();
|
||||||
try {
|
try {
|
||||||
|
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
||||||
if (userStoreManager.isExistingUser(username)) {
|
if (userStoreManager.isExistingUser(username)) {
|
||||||
responsePayload.setResponseContent(Arrays.asList(getFilteredRoles(userStoreManager, username)));
|
responsePayload.setResponseContent(Collections.singletonList(getFilteredRoles(userStoreManager, username)));
|
||||||
// Outputting debug message upon successful removal of user
|
// Outputting debug message upon successful removal of user
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("User by username: " + username + " was successfully removed.");
|
log.debug("User by username: " + username + " was successfully removed.");
|
||||||
@ -374,7 +380,7 @@ public class User {
|
|||||||
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
||||||
responsePayload.setMessageFromServer(
|
responsePayload.setMessageFromServer(
|
||||||
"User roles obtained for user " + username);
|
"User roles obtained for user " + username);
|
||||||
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
|
return Response.status(Response.Status.OK).entity(responsePayload).build();
|
||||||
} else {
|
} else {
|
||||||
// Outputting debug message upon trying to remove non-existing user
|
// Outputting debug message upon trying to remove non-existing user
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
@ -384,12 +390,12 @@ public class User {
|
|||||||
responsePayload.setStatusCode(HttpStatus.SC_BAD_REQUEST);
|
responsePayload.setStatusCode(HttpStatus.SC_BAD_REQUEST);
|
||||||
responsePayload.setMessageFromServer(
|
responsePayload.setMessageFromServer(
|
||||||
"User by username: " + username + " does not exist for role retrieval.");
|
"User by username: " + username + " does not exist for role retrieval.");
|
||||||
return Response.status(HttpStatus.SC_BAD_REQUEST).entity(responsePayload).build();
|
return Response.status(Response.Status.BAD_REQUEST).entity(responsePayload).build();
|
||||||
}
|
}
|
||||||
} catch (UserStoreException e) {
|
} catch (UserStoreException | MDMAPIException e) {
|
||||||
String msg = "Exception in trying to retrieve roles for user by username: " + username;
|
String msg = "Exception in trying to retrieve roles for user by username: " + username;
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new MDMAPIException(msg, e);
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -397,17 +403,16 @@ public class User {
|
|||||||
* Get the list of all users with all user-related info.
|
* Get the list of all users with all user-related info.
|
||||||
*
|
*
|
||||||
* @return A list of users
|
* @return A list of users
|
||||||
* @throws MDMAPIException
|
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@Produces({MediaType.APPLICATION_JSON})
|
@Produces({MediaType.APPLICATION_JSON})
|
||||||
public Response getAllUsers() throws MDMAPIException {
|
public Response getAllUsers() {
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Getting the list of users with all user-related information");
|
log.debug("Getting the list of users with all user-related information");
|
||||||
}
|
}
|
||||||
UserStoreManager userStoreManager = MDMAPIUtils.getUserStoreManager();
|
|
||||||
List<UserWrapper> userList;
|
List<UserWrapper> userList;
|
||||||
try {
|
try {
|
||||||
|
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
||||||
String[] users = userStoreManager.listUsers("*", -1);
|
String[] users = userStoreManager.listUsers("*", -1);
|
||||||
userList = new ArrayList<>(users.length);
|
userList = new ArrayList<>(users.length);
|
||||||
UserWrapper user;
|
UserWrapper user;
|
||||||
@ -419,10 +424,10 @@ public class User {
|
|||||||
user.setLastname(getClaimValue(username, Constants.USER_CLAIM_LAST_NAME));
|
user.setLastname(getClaimValue(username, Constants.USER_CLAIM_LAST_NAME));
|
||||||
userList.add(user);
|
userList.add(user);
|
||||||
}
|
}
|
||||||
} catch (UserStoreException e) {
|
} catch (UserStoreException | MDMAPIException e) {
|
||||||
String msg = "Error occurred while retrieving the list of users";
|
String msg = "Error occurred while retrieving the list of users";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new MDMAPIException(msg, e);
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
}
|
}
|
||||||
ResponsePayload responsePayload = new ResponsePayload();
|
ResponsePayload responsePayload = new ResponsePayload();
|
||||||
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
||||||
@ -431,25 +436,24 @@ public class User {
|
|||||||
responsePayload.setMessageFromServer("All users were successfully retrieved. " +
|
responsePayload.setMessageFromServer("All users were successfully retrieved. " +
|
||||||
"Obtained user count: " + count);
|
"Obtained user count: " + count);
|
||||||
responsePayload.setResponseContent(userList);
|
responsePayload.setResponseContent(userList);
|
||||||
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
|
return Response.status(Response.Status.OK).entity(responsePayload).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the list of all users with all user-related info.
|
* Get the list of all users with all user-related info.
|
||||||
*
|
*
|
||||||
* @return A list of users
|
* @return A list of users
|
||||||
* @throws MDMAPIException
|
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@Path("{filter}")
|
@Path("{filter}")
|
||||||
@Produces({MediaType.APPLICATION_JSON})
|
@Produces({MediaType.APPLICATION_JSON})
|
||||||
public Response getMatchingUsers(@PathParam("filter") String filter) throws MDMAPIException {
|
public Response getMatchingUsers(@PathParam("filter") String filter) {
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Getting the list of users with all user-related information using the filter : " + filter);
|
log.debug("Getting the list of users with all user-related information using the filter : " + filter);
|
||||||
}
|
}
|
||||||
UserStoreManager userStoreManager = MDMAPIUtils.getUserStoreManager();
|
|
||||||
List<UserWrapper> userList;
|
List<UserWrapper> userList;
|
||||||
try {
|
try {
|
||||||
|
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
||||||
String[] users = userStoreManager.listUsers(filter + "*", -1);
|
String[] users = userStoreManager.listUsers(filter + "*", -1);
|
||||||
userList = new ArrayList<>(users.length);
|
userList = new ArrayList<>(users.length);
|
||||||
UserWrapper user;
|
UserWrapper user;
|
||||||
@ -461,10 +465,10 @@ public class User {
|
|||||||
user.setLastname(getClaimValue(username, Constants.USER_CLAIM_LAST_NAME));
|
user.setLastname(getClaimValue(username, Constants.USER_CLAIM_LAST_NAME));
|
||||||
userList.add(user);
|
userList.add(user);
|
||||||
}
|
}
|
||||||
} catch (UserStoreException e) {
|
} catch (UserStoreException | MDMAPIException e) {
|
||||||
String msg = "Error occurred while retrieving the list of users using the filter : " + filter;
|
String msg = "Error occurred while retrieving the list of users using the filter : " + filter;
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new MDMAPIException(msg, e);
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
}
|
}
|
||||||
ResponsePayload responsePayload = new ResponsePayload();
|
ResponsePayload responsePayload = new ResponsePayload();
|
||||||
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
||||||
@ -473,24 +477,23 @@ public class User {
|
|||||||
responsePayload.setMessageFromServer("All users were successfully retrieved. " +
|
responsePayload.setMessageFromServer("All users were successfully retrieved. " +
|
||||||
"Obtained user count: " + count);
|
"Obtained user count: " + count);
|
||||||
responsePayload.setResponseContent(userList);
|
responsePayload.setResponseContent(userList);
|
||||||
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
|
return Response.status(Response.Status.OK).entity(responsePayload).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the list of user names in the system.
|
* Get the list of user names in the system.
|
||||||
*
|
*
|
||||||
* @return A list of user names.
|
* @return A list of user names.
|
||||||
* @throws MDMAPIException
|
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@Path("view-users")
|
@Path("view-users")
|
||||||
public Response getAllUsersByUsername(@QueryParam("username") String userName) throws MDMAPIException {
|
public Response getAllUsersByUsername(@QueryParam("username") String userName) {
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Getting the list of users by name");
|
log.debug("Getting the list of users by name");
|
||||||
}
|
}
|
||||||
UserStoreManager userStoreManager = MDMAPIUtils.getUserStoreManager();
|
|
||||||
List<UserWrapper> userList;
|
List<UserWrapper> userList;
|
||||||
try {
|
try {
|
||||||
|
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
||||||
String[] users = userStoreManager.listUsers("*" + userName + "*", -1);
|
String[] users = userStoreManager.listUsers("*" + userName + "*", -1);
|
||||||
userList = new ArrayList<>(users.length);
|
userList = new ArrayList<>(users.length);
|
||||||
UserWrapper user;
|
UserWrapper user;
|
||||||
@ -502,10 +505,10 @@ public class User {
|
|||||||
user.setLastname(getClaimValue(username, Constants.USER_CLAIM_LAST_NAME));
|
user.setLastname(getClaimValue(username, Constants.USER_CLAIM_LAST_NAME));
|
||||||
userList.add(user);
|
userList.add(user);
|
||||||
}
|
}
|
||||||
} catch (UserStoreException e) {
|
} catch (UserStoreException | MDMAPIException e) {
|
||||||
String msg = "Error occurred while retrieving the list of users";
|
String msg = "Error occurred while retrieving the list of users";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new MDMAPIException(msg, e);
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
}
|
}
|
||||||
ResponsePayload responsePayload = new ResponsePayload();
|
ResponsePayload responsePayload = new ResponsePayload();
|
||||||
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
||||||
@ -514,31 +517,30 @@ public class User {
|
|||||||
responsePayload.setMessageFromServer("All users by username were successfully retrieved. " +
|
responsePayload.setMessageFromServer("All users by username were successfully retrieved. " +
|
||||||
"Obtained user count: " + count);
|
"Obtained user count: " + count);
|
||||||
responsePayload.setResponseContent(userList);
|
responsePayload.setResponseContent(userList);
|
||||||
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
|
return Response.status(Response.Status.OK).entity(responsePayload).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the list of user names in the system.
|
* Get the list of user names in the system.
|
||||||
*
|
*
|
||||||
* @return A list of user names.
|
* @return A list of user names.
|
||||||
* @throws MDMAPIException
|
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@Path("users-by-username")
|
@Path("users-by-username")
|
||||||
public Response getAllUserNamesByUsername(@QueryParam("username") String userName) throws MDMAPIException {
|
public Response getAllUserNamesByUsername(@QueryParam("username") String userName) {
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Getting the list of users by name");
|
log.debug("Getting the list of users by name");
|
||||||
}
|
}
|
||||||
UserStoreManager userStoreManager = MDMAPIUtils.getUserStoreManager();
|
|
||||||
List<String> userList;
|
List<String> userList;
|
||||||
try {
|
try {
|
||||||
|
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
||||||
String[] users = userStoreManager.listUsers("*" + userName + "*", -1);
|
String[] users = userStoreManager.listUsers("*" + userName + "*", -1);
|
||||||
userList = new ArrayList<>(users.length);
|
userList = new ArrayList<>(users.length);
|
||||||
Collections.addAll(userList, users);
|
Collections.addAll(userList, users);
|
||||||
} catch (UserStoreException e) {
|
} catch (UserStoreException | MDMAPIException e) {
|
||||||
String msg = "Error occurred while retrieving the list of users";
|
String msg = "Error occurred while retrieving the list of users";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new MDMAPIException(msg, e);
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
}
|
}
|
||||||
ResponsePayload responsePayload = new ResponsePayload();
|
ResponsePayload responsePayload = new ResponsePayload();
|
||||||
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
||||||
@ -547,7 +549,7 @@ public class User {
|
|||||||
responsePayload.setMessageFromServer("All users by username were successfully retrieved. " +
|
responsePayload.setMessageFromServer("All users by username were successfully retrieved. " +
|
||||||
"Obtained user count: " + count);
|
"Obtained user count: " + count);
|
||||||
responsePayload.setResponseContent(userList);
|
responsePayload.setResponseContent(userList);
|
||||||
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
|
return Response.status(Response.Status.OK).entity(responsePayload).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -555,11 +557,10 @@ public class User {
|
|||||||
*
|
*
|
||||||
* @param username Username of the user
|
* @param username Username of the user
|
||||||
* @param claimUri required ClaimUri
|
* @param claimUri required ClaimUri
|
||||||
* @return A list of usernames
|
* @return claim value
|
||||||
* @throws MDMAPIException, UserStoreException
|
|
||||||
*/
|
*/
|
||||||
private String getClaimValue(String username, String claimUri) throws MDMAPIException {
|
private String getClaimValue(String username, String claimUri) throws MDMAPIException {
|
||||||
UserStoreManager userStoreManager = MDMAPIUtils.getUserStoreManager();
|
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
||||||
try {
|
try {
|
||||||
return userStoreManager.getUserClaimValue(username, claimUri, null);
|
return userStoreManager.getUserClaimValue(username, claimUri, null);
|
||||||
} catch (UserStoreException e) {
|
} catch (UserStoreException e) {
|
||||||
@ -572,10 +573,8 @@ public class User {
|
|||||||
* Method used to send an invitation email to a new user to enroll a device.
|
* Method used to send an invitation email to a new user to enroll a device.
|
||||||
*
|
*
|
||||||
* @param username Username of the user
|
* @param username Username of the user
|
||||||
* @throws MDMAPIException, UserStoreException, DeviceManagementException
|
|
||||||
*/
|
*/
|
||||||
private void inviteNewlyAddedUserToEnrollDevice(
|
private void inviteNewlyAddedUserToEnrollDevice(String username, String password) throws MDMAPIException {
|
||||||
String username, String password) throws MDMAPIException {
|
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Sending invitation mail to user by username: " + username);
|
log.debug("Sending invitation mail to user by username: " + username);
|
||||||
}
|
}
|
||||||
@ -587,7 +586,7 @@ public class User {
|
|||||||
username = "/" + username;
|
username = "/" + username;
|
||||||
}
|
}
|
||||||
String[] usernameBits = username.split("/");
|
String[] usernameBits = username.split("/");
|
||||||
DeviceManagementProviderService deviceManagementProviderService = MDMAPIUtils.getDeviceManagementService();
|
DeviceManagementProviderService deviceManagementProviderService = DeviceMgtAPIUtils.getDeviceManagementService();
|
||||||
|
|
||||||
Properties props = new Properties();
|
Properties props = new Properties();
|
||||||
props.setProperty("username", usernameBits[1]);
|
props.setProperty("username", usernameBits[1]);
|
||||||
@ -611,16 +610,15 @@ public class User {
|
|||||||
* Method used to send an invitation email to a existing user to enroll a device.
|
* Method used to send an invitation email to a existing user to enroll a device.
|
||||||
*
|
*
|
||||||
* @param usernames Username list of the users to be invited
|
* @param usernames Username list of the users to be invited
|
||||||
* @throws MDMAPIException
|
|
||||||
*/
|
*/
|
||||||
@POST
|
@POST
|
||||||
@Path("email-invitation")
|
@Path("email-invitation")
|
||||||
@Produces({MediaType.APPLICATION_JSON})
|
@Produces({MediaType.APPLICATION_JSON})
|
||||||
public Response inviteExistingUsersToEnrollDevice(List<String> usernames) throws MDMAPIException {
|
public Response inviteExistingUsersToEnrollDevice(List<String> usernames) {
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Sending enrollment invitation mail to existing user.");
|
log.debug("Sending enrollment invitation mail to existing user.");
|
||||||
}
|
}
|
||||||
DeviceManagementProviderService deviceManagementProviderService = MDMAPIUtils.getDeviceManagementService();
|
DeviceManagementProviderService deviceManagementProviderService = DeviceMgtAPIUtils.getDeviceManagementService();
|
||||||
try {
|
try {
|
||||||
for (String username : usernames) {
|
for (String username : usernames) {
|
||||||
String recipient = getClaimValue(username, Constants.USER_CLAIM_EMAIL_ADDRESS);
|
String recipient = getClaimValue(username, Constants.USER_CLAIM_EMAIL_ADDRESS);
|
||||||
@ -632,15 +630,15 @@ public class User {
|
|||||||
EmailMetaInfo metaInfo = new EmailMetaInfo(recipient, props);
|
EmailMetaInfo metaInfo = new EmailMetaInfo(recipient, props);
|
||||||
deviceManagementProviderService.sendEnrolmentInvitation(metaInfo);
|
deviceManagementProviderService.sendEnrolmentInvitation(metaInfo);
|
||||||
}
|
}
|
||||||
} catch (DeviceManagementException e) {
|
} catch (DeviceManagementException | MDMAPIException e) {
|
||||||
String msg = "Error occurred while inviting user to enrol their device";
|
String msg = "Error occurred while inviting user to enrol their device";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new MDMAPIException(msg, e);
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
}
|
}
|
||||||
ResponsePayload responsePayload = new ResponsePayload();
|
ResponsePayload responsePayload = new ResponsePayload();
|
||||||
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
responsePayload.setStatusCode(HttpStatus.SC_OK);
|
||||||
responsePayload.setMessageFromServer("Email invitation was successfully sent to user.");
|
responsePayload.setMessageFromServer("Email invitation was successfully sent to user.");
|
||||||
return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
|
return Response.status(Response.Status.OK).entity(responsePayload).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -648,27 +646,25 @@ public class User {
|
|||||||
*
|
*
|
||||||
* @param username Username of the device owner
|
* @param username Username of the device owner
|
||||||
* @return A list of devices
|
* @return A list of devices
|
||||||
* @throws MDMAPIException
|
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@Produces({MediaType.APPLICATION_JSON})
|
@Produces({MediaType.APPLICATION_JSON})
|
||||||
@Path("devices")
|
@Path("devices")
|
||||||
public Object getAllDeviceOfUser(@QueryParam("username") String username, @QueryParam("start") int startIdx,
|
public Response getAllDeviceOfUser(@QueryParam("username") String username, @QueryParam("start") int startIdx,
|
||||||
@QueryParam("length") int length)
|
@QueryParam("length") int length) {
|
||||||
throws MDMAPIException {
|
|
||||||
DeviceManagementProviderService dmService;
|
DeviceManagementProviderService dmService;
|
||||||
try {
|
try {
|
||||||
dmService = MDMAPIUtils.getDeviceManagementService();
|
dmService = DeviceMgtAPIUtils.getDeviceManagementService();
|
||||||
if (length > 0) {
|
if (length > 0) {
|
||||||
PaginationRequest request = new PaginationRequest(startIdx, length);
|
PaginationRequest request = new PaginationRequest(startIdx, length);
|
||||||
request.setOwner(username);
|
request.setOwner(username);
|
||||||
return dmService.getDevicesOfUser(request);
|
return Response.status(Response.Status.OK).entity(dmService.getDevicesOfUser(request)).build();
|
||||||
}
|
}
|
||||||
return dmService.getDevicesOfUser(username);
|
return Response.status(Response.Status.OK).entity(dmService.getDevicesOfUser(username)).build();
|
||||||
} catch (DeviceManagementException e) {
|
} catch (DeviceManagementException e) {
|
||||||
String msg = "Device management error";
|
String msg = "Device management error";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new MDMAPIException(msg, e);
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -676,22 +672,23 @@ public class User {
|
|||||||
* This method is used to retrieve the user count of the system.
|
* This method is used to retrieve the user count of the system.
|
||||||
*
|
*
|
||||||
* @return returns the count.
|
* @return returns the count.
|
||||||
* @throws MDMAPIException
|
* @
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@Path("count")
|
@Path("count")
|
||||||
public int getUserCount() throws MDMAPIException {
|
public Response getUserCount() {
|
||||||
try {
|
try {
|
||||||
String[] users = MDMAPIUtils.getUserStoreManager().listUsers("*", -1);
|
String[] users = DeviceMgtAPIUtils.getUserStoreManager().listUsers("*", -1);
|
||||||
if (users == null) {
|
Integer count = 0;
|
||||||
return 0;
|
if (users != null) {
|
||||||
|
count = users.length;
|
||||||
}
|
}
|
||||||
return users.length;
|
return Response.status(Response.Status.OK).entity(count).build();
|
||||||
} catch (UserStoreException e) {
|
} catch (UserStoreException | MDMAPIException e) {
|
||||||
String msg =
|
String msg =
|
||||||
"Error occurred while retrieving the list of users that exist within the current tenant";
|
"Error occurred while retrieving the list of users that exist within the current tenant";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new MDMAPIException(msg, e);
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -701,33 +698,30 @@ public class User {
|
|||||||
* @param username
|
* @param username
|
||||||
* @param userList
|
* @param userList
|
||||||
* @return
|
* @return
|
||||||
* @throws MDMAPIException
|
* @
|
||||||
*/
|
*/
|
||||||
@PUT
|
@PUT
|
||||||
@Path("{roleName}/users")
|
@Path("{roleName}/users")
|
||||||
@Produces({MediaType.APPLICATION_JSON})
|
@Produces({MediaType.APPLICATION_JSON})
|
||||||
public Response updateRoles(@PathParam("username") String username, List<String> userList)
|
public Response updateRoles(@PathParam("username") String username, List<String> userList) {
|
||||||
throws MDMAPIException {
|
|
||||||
final UserStoreManager userStoreManager = MDMAPIUtils.getUserStoreManager();
|
|
||||||
try {
|
try {
|
||||||
|
final UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Updating the roles of a user");
|
log.debug("Updating the roles of a user");
|
||||||
}
|
}
|
||||||
SetReferenceTransformer transformer = new SetReferenceTransformer();
|
SetReferenceTransformer<String> transformer = new SetReferenceTransformer<>();
|
||||||
transformer.transform(Arrays.asList(userStoreManager.getRoleListOfUser(username)),
|
transformer.transform(Arrays.asList(userStoreManager.getRoleListOfUser(username)),
|
||||||
userList);
|
userList);
|
||||||
final String[] rolesToAdd = (String[])
|
final String[] rolesToAdd = transformer.getObjectsToAdd().toArray(new String[transformer.getObjectsToAdd().size()]);
|
||||||
transformer.getObjectsToAdd().toArray(new String[transformer.getObjectsToAdd().size()]);
|
final String[] rolesToDelete = transformer.getObjectsToRemove().toArray(new String[transformer.getObjectsToRemove().size()]);
|
||||||
final String[] rolesToDelete = (String[])
|
|
||||||
transformer.getObjectsToRemove().toArray(new String[transformer.getObjectsToRemove().size()]);
|
|
||||||
|
|
||||||
userStoreManager.updateRoleListOfUser(username, rolesToDelete, rolesToAdd);
|
userStoreManager.updateRoleListOfUser(username, rolesToDelete, rolesToAdd);
|
||||||
} catch (UserStoreException e) {
|
} catch (UserStoreException | MDMAPIException e) {
|
||||||
String msg = "Error occurred while saving the roles for user: " + username;
|
String msg = "Error occurred while saving the roles for user: " + username;
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new MDMAPIException(msg, e);
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
}
|
}
|
||||||
return Response.status(HttpStatus.SC_OK).build();
|
return Response.status(Response.Status.OK).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -735,13 +729,13 @@ public class User {
|
|||||||
*
|
*
|
||||||
* @param credentials Wrapper object representing user credentials.
|
* @param credentials Wrapper object representing user credentials.
|
||||||
* @return {Response} Status of the request wrapped inside Response object.
|
* @return {Response} Status of the request wrapped inside Response object.
|
||||||
* @throws MDMAPIException
|
* @
|
||||||
*/
|
*/
|
||||||
@POST
|
@POST
|
||||||
@Path("change-password")
|
@Path("change-password")
|
||||||
@Consumes({MediaType.APPLICATION_JSON})
|
@Consumes({MediaType.APPLICATION_JSON})
|
||||||
@Produces({MediaType.APPLICATION_JSON})
|
@Produces({MediaType.APPLICATION_JSON})
|
||||||
public Response resetPassword(UserCredentialWrapper credentials) throws MDMAPIException {
|
public Response resetPassword(UserCredentialWrapper credentials) {
|
||||||
return CredentialManagementResponseBuilder.buildChangePasswordResponse(credentials);
|
return CredentialManagementResponseBuilder.buildChangePasswordResponse(credentials);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -750,13 +744,13 @@ public class User {
|
|||||||
*
|
*
|
||||||
* @param credentials Wrapper object representing user credentials.
|
* @param credentials Wrapper object representing user credentials.
|
||||||
* @return {Response} Status of the request wrapped inside Response object.
|
* @return {Response} Status of the request wrapped inside Response object.
|
||||||
* @throws MDMAPIException
|
* @
|
||||||
*/
|
*/
|
||||||
@POST
|
@POST
|
||||||
@Path("reset-password")
|
@Path("reset-password")
|
||||||
@Consumes({MediaType.APPLICATION_JSON})
|
@Consumes({MediaType.APPLICATION_JSON})
|
||||||
@Produces({MediaType.APPLICATION_JSON})
|
@Produces({MediaType.APPLICATION_JSON})
|
||||||
public Response resetPasswordByAdmin(UserCredentialWrapper credentials) throws MDMAPIException {
|
public Response resetPasswordByAdmin(UserCredentialWrapper credentials) {
|
||||||
return CredentialManagementResponseBuilder.buildResetPasswordResponse(credentials);
|
return CredentialManagementResponseBuilder.buildResetPasswordResponse(credentials);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -37,19 +37,16 @@ public class CredentialManagementResponseBuilder {
|
|||||||
|
|
||||||
private static Log log = LogFactory.getLog(CredentialManagementResponseBuilder.class);
|
private static Log log = LogFactory.getLog(CredentialManagementResponseBuilder.class);
|
||||||
|
|
||||||
private ResponsePayload responsePayload;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds the response to change the password of a user
|
* Builds the response to change the password of a user
|
||||||
* @param credentials - User credentials
|
* @param credentials - User credentials
|
||||||
* @return Response Object
|
* @return Response Object
|
||||||
* @throws MDMAPIException
|
|
||||||
*/
|
*/
|
||||||
public static Response buildChangePasswordResponse(UserCredentialWrapper credentials) throws MDMAPIException {
|
public static Response buildChangePasswordResponse(UserCredentialWrapper credentials) {
|
||||||
UserStoreManager userStoreManager = MDMAPIUtils.getUserStoreManager();
|
|
||||||
ResponsePayload responsePayload = new ResponsePayload();
|
ResponsePayload responsePayload = new ResponsePayload();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
||||||
byte[] decodedNewPassword = Base64.decodeBase64(credentials.getNewPassword());
|
byte[] decodedNewPassword = Base64.decodeBase64(credentials.getNewPassword());
|
||||||
byte[] decodedOldPassword = Base64.decodeBase64(credentials.getOldPassword());
|
byte[] decodedOldPassword = Base64.decodeBase64(credentials.getOldPassword());
|
||||||
userStoreManager.updateCredential(credentials.getUsername(), new String(
|
userStoreManager.updateCredential(credentials.getUsername(), new String(
|
||||||
@ -57,48 +54,52 @@ public class CredentialManagementResponseBuilder {
|
|||||||
responsePayload.setStatusCode(HttpStatus.SC_CREATED);
|
responsePayload.setStatusCode(HttpStatus.SC_CREATED);
|
||||||
responsePayload.setMessageFromServer("User password by username: " + credentials.getUsername() +
|
responsePayload.setMessageFromServer("User password by username: " + credentials.getUsername() +
|
||||||
" was successfully changed.");
|
" was successfully changed.");
|
||||||
return Response.status(HttpStatus.SC_CREATED).entity(responsePayload).build();
|
return Response.status(Response.Status.CREATED).entity(responsePayload).build();
|
||||||
} catch (UserStoreException e) {
|
} catch (UserStoreException e) {
|
||||||
log.error(e.getMessage(), e);
|
log.error(e.getMessage(), e);
|
||||||
responsePayload.setStatusCode(HttpStatus.SC_BAD_REQUEST);
|
responsePayload.setStatusCode(HttpStatus.SC_BAD_REQUEST);
|
||||||
responsePayload.setMessageFromServer("Old password does not match.");
|
responsePayload.setMessageFromServer("Old password does not match.");
|
||||||
return Response.status(HttpStatus.SC_BAD_REQUEST).entity(responsePayload).build();
|
return Response.status(Response.Status.BAD_REQUEST).entity(responsePayload).build();
|
||||||
} catch (UnsupportedEncodingException e) {
|
} catch (UnsupportedEncodingException e) {
|
||||||
String errorMsg = "Could not change the password of the user: " + credentials.getUsername() +
|
String errorMsg = "Could not change the password of the user: " + credentials.getUsername() +
|
||||||
". The Character Encoding is not supported.";
|
". The Character Encoding is not supported.";
|
||||||
log.error(errorMsg, e);
|
log.error(errorMsg, e);
|
||||||
throw new MDMAPIException(errorMsg, e);
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMsg).build();
|
||||||
|
} catch (MDMAPIException e) {
|
||||||
|
log.error(e.getErrorMessage(), e);
|
||||||
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getErrorMessage()).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds the response to reset the password of a user
|
* Builds the response to reset the password of a user
|
||||||
* @param credentials - User credentials
|
* @param credentials - User credentials
|
||||||
* @return Response Object
|
* @return Response Object
|
||||||
* @throws MDMAPIException
|
|
||||||
*/
|
*/
|
||||||
public static Response buildResetPasswordResponse(UserCredentialWrapper credentials) throws MDMAPIException {
|
public static Response buildResetPasswordResponse(UserCredentialWrapper credentials) {
|
||||||
UserStoreManager userStoreManager = MDMAPIUtils.getUserStoreManager();
|
|
||||||
ResponsePayload responsePayload = new ResponsePayload();
|
ResponsePayload responsePayload = new ResponsePayload();
|
||||||
try {
|
try {
|
||||||
|
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
||||||
byte[] decodedNewPassword = Base64.decodeBase64(credentials.getNewPassword());
|
byte[] decodedNewPassword = Base64.decodeBase64(credentials.getNewPassword());
|
||||||
userStoreManager.updateCredentialByAdmin(credentials.getUsername(), new String(
|
userStoreManager.updateCredentialByAdmin(credentials.getUsername(), new String(
|
||||||
decodedNewPassword, "UTF-8"));
|
decodedNewPassword, "UTF-8"));
|
||||||
responsePayload.setStatusCode(HttpStatus.SC_CREATED);
|
responsePayload.setStatusCode(HttpStatus.SC_CREATED);
|
||||||
responsePayload.setMessageFromServer("User password by username: " + credentials.getUsername() +
|
responsePayload.setMessageFromServer("User password by username: " + credentials.getUsername() +
|
||||||
" was successfully changed.");
|
" was successfully changed.");
|
||||||
return Response.status(HttpStatus.SC_CREATED).entity(responsePayload).build();
|
return Response.status(Response.Status.CREATED).entity(responsePayload).build();
|
||||||
} catch (UserStoreException e) {
|
} catch (UserStoreException e) {
|
||||||
log.error(e.getMessage(), e);
|
log.error(e.getMessage(), e);
|
||||||
responsePayload.setStatusCode(HttpStatus.SC_BAD_REQUEST);
|
responsePayload.setStatusCode(HttpStatus.SC_BAD_REQUEST);
|
||||||
responsePayload.setMessageFromServer("Could not change the password.");
|
responsePayload.setMessageFromServer("Could not change the password.");
|
||||||
return Response.status(HttpStatus.SC_BAD_REQUEST).entity(responsePayload).build();
|
return Response.status(Response.Status.BAD_REQUEST).entity(responsePayload).build();
|
||||||
} catch (UnsupportedEncodingException e) {
|
} catch (UnsupportedEncodingException e) {
|
||||||
String errorMsg = "Could not change the password of the user: " + credentials.getUsername() +
|
String errorMsg = "Could not change the password of the user: " + credentials.getUsername() +
|
||||||
". The Character Encoding is not supported.";
|
". The Character Encoding is not supported.";
|
||||||
log.error(errorMsg, e);
|
log.error(errorMsg, e);
|
||||||
throw new MDMAPIException(errorMsg, e);
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMsg).build();
|
||||||
|
} catch (MDMAPIException e) {
|
||||||
|
log.error(e.getErrorMessage(), e);
|
||||||
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getErrorMessage()).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -33,18 +33,16 @@ import org.wso2.carbon.device.mgt.core.app.mgt.ApplicationManagementProviderServ
|
|||||||
import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceInformationManager;
|
import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceInformationManager;
|
||||||
import org.wso2.carbon.device.mgt.core.search.mgt.SearchManagerService;
|
import org.wso2.carbon.device.mgt.core.search.mgt.SearchManagerService;
|
||||||
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
||||||
|
import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService;
|
||||||
import org.wso2.carbon.mdm.api.common.MDMAPIException;
|
import org.wso2.carbon.mdm.api.common.MDMAPIException;
|
||||||
import org.wso2.carbon.ntask.core.TaskManager;
|
|
||||||
import org.wso2.carbon.policy.mgt.common.PolicyMonitoringTaskException;
|
import org.wso2.carbon.policy.mgt.common.PolicyMonitoringTaskException;
|
||||||
import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
|
import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
|
||||||
import org.wso2.carbon.policy.mgt.core.task.TaskScheduleService;
|
import org.wso2.carbon.policy.mgt.core.task.TaskScheduleService;
|
||||||
import org.wso2.carbon.policy.mgt.core.util.PolicyManagementConstants;
|
|
||||||
import org.wso2.carbon.user.api.AuthorizationManager;
|
import org.wso2.carbon.user.api.AuthorizationManager;
|
||||||
import org.wso2.carbon.user.api.UserRealm;
|
import org.wso2.carbon.user.api.UserRealm;
|
||||||
import org.wso2.carbon.user.api.UserStoreException;
|
import org.wso2.carbon.user.api.UserStoreException;
|
||||||
import org.wso2.carbon.user.api.UserStoreManager;
|
import org.wso2.carbon.user.api.UserStoreManager;
|
||||||
import org.wso2.carbon.user.core.service.RealmService;
|
import org.wso2.carbon.user.core.service.RealmService;
|
||||||
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
|
|
||||||
|
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -52,12 +50,11 @@ import java.util.List;
|
|||||||
/**
|
/**
|
||||||
* MDMAPIUtils class provides utility function used by CDM REST-API classes.
|
* MDMAPIUtils class provides utility function used by CDM REST-API classes.
|
||||||
*/
|
*/
|
||||||
public class MDMAPIUtils {
|
public class DeviceMgtAPIUtils {
|
||||||
|
|
||||||
private static final String NOTIFIER_FREQUENCY = "notifierFrequency";
|
|
||||||
public static final MediaType DEFAULT_CONTENT_TYPE = MediaType.APPLICATION_JSON_TYPE;
|
public static final MediaType DEFAULT_CONTENT_TYPE = MediaType.APPLICATION_JSON_TYPE;
|
||||||
|
private static final String NOTIFIER_FREQUENCY = "notifierFrequency";
|
||||||
private static Log log = LogFactory.getLog(MDMAPIUtils.class);
|
private static Log log = LogFactory.getLog(DeviceMgtAPIUtils.class);
|
||||||
|
|
||||||
public static int getNotifierFrequency(TenantConfiguration tenantConfiguration) {
|
public static int getNotifierFrequency(TenantConfiguration tenantConfiguration) {
|
||||||
List<ConfigurationEntry> configEntryList = tenantConfiguration.getConfiguration();
|
List<ConfigurationEntry> configEntryList = tenantConfiguration.getConfiguration();
|
||||||
@ -97,6 +94,18 @@ public class MDMAPIUtils {
|
|||||||
return deviceManagementProviderService;
|
return deviceManagementProviderService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static GroupManagementProviderService getGroupManagementProviderService() {
|
||||||
|
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
||||||
|
GroupManagementProviderService groupManagementProviderService =
|
||||||
|
(GroupManagementProviderService) ctx.getOSGiService(GroupManagementProviderService.class, null);
|
||||||
|
if (groupManagementProviderService == null) {
|
||||||
|
String msg = "Group Management service has not initialized.";
|
||||||
|
log.error(msg);
|
||||||
|
throw new IllegalStateException(msg);
|
||||||
|
}
|
||||||
|
return groupManagementProviderService;
|
||||||
|
}
|
||||||
|
|
||||||
public static int getTenantId(String tenantDomain) throws MDMAPIException {
|
public static int getTenantId(String tenantDomain) throws MDMAPIException {
|
||||||
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
||||||
RealmService realmService = (RealmService) ctx.getOSGiService(RealmService.class, null);
|
RealmService realmService = (RealmService) ctx.getOSGiService(RealmService.class, null);
|
||||||
@ -1,17 +1,17 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
*
|
*
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
* in compliance with the License.
|
* in compliance with the License.
|
||||||
* you may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing,
|
* Unless required by applicable law or agreed to in writing,
|
||||||
* software distributed under the License is distributed on an
|
* software distributed under the License is distributed on an
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
* KIND, either express or implied. See the License for the
|
* KIND, either express or implied. See the License for the
|
||||||
* specific language governing permissions and limitations
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
@ -19,7 +19,7 @@
|
|||||||
package org.wso2.carbon.mdm.util;
|
package org.wso2.carbon.mdm.util;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the constants used by MDM-Admin web application.
|
* Holds the constants used by Device Management Admin web application.
|
||||||
*/
|
*/
|
||||||
public class Constants {
|
public class Constants {
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
(URL) , HTTP method and OAUTH2 authorization scope (not-required).
|
(URL) , HTTP method and OAUTH2 authorization scope (not-required).
|
||||||
When defining dynamic paths for APIs, path variables are denoted by '*' notation.
|
When defining dynamic paths for APIs, path variables are denoted by '*' notation.
|
||||||
For ex:
|
For ex:
|
||||||
Actual API endpoint: mdm-admin/1.0.0/devices/{device-id}
|
Actual API endpoint: devicemgt_admin/1.0.0/devices/{device-id}
|
||||||
URL to be represented here: /devices/*
|
URL to be represented here: /devices/*
|
||||||
NOTE: All the endpoints of the web app should be available in this file. Otherwise
|
NOTE: All the endpoints of the web app should be available in this file. Otherwise
|
||||||
it will result 403 error at the runtime.
|
it will result 403 error at the runtime.
|
||||||
@ -40,7 +40,7 @@
|
|||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>Device Management Admin</name>
|
<name>Device Management Admin</name>
|
||||||
<path>/device-mgt/emm-admin</path>
|
<path>/device-mgt/admin</path>
|
||||||
<url>/</url>
|
<url>/</url>
|
||||||
<method>GET</method>
|
<method>GET</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
@ -54,98 +54,98 @@
|
|||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>Devices</name>
|
<name>Devices</name>
|
||||||
<path>/device-mgt/emm-admin/devices</path>
|
<path>/device-mgt/admin/devices</path>
|
||||||
<url>/</url>
|
<url>/</url>
|
||||||
<method>GET</method>
|
<method>GET</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>Policies</name>
|
<name>Policies</name>
|
||||||
<path>/device-mgt/emm-admin/policies</path>
|
<path>/device-mgt/admin/policies</path>
|
||||||
<url>/</url>
|
<url>/</url>
|
||||||
<method>GET</method>
|
<method>GET</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>Notifications</name>
|
<name>Notifications</name>
|
||||||
<path>/device-mgt/emm-admin/notifications</path>
|
<path>/device-mgt/admin/notifications</path>
|
||||||
<url>/</url>
|
<url>/</url>
|
||||||
<method>GET</method>
|
<method>GET</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>Users</name>
|
<name>Users</name>
|
||||||
<path>/device-mgt/emm-admin/users</path>
|
<path>/device-mgt/admin/users</path>
|
||||||
<url>/</url>
|
<url>/</url>
|
||||||
<method>GET</method>
|
<method>GET</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>Operations</name>
|
<name>Operations</name>
|
||||||
<path>/device-mgt/emm-admin/operations</path>
|
<path>/device-mgt/admin/operations</path>
|
||||||
<url>/</url>
|
<url>/</url>
|
||||||
<method>GET</method>
|
<method>GET</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>Applications</name>
|
<name>Applications</name>
|
||||||
<path>/device-mgt/emm-admin/operations/applications</path>
|
<path>/device-mgt/admin/operations/applications</path>
|
||||||
<url>/</url>
|
<url>/</url>
|
||||||
<method>GET</method>
|
<method>GET</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>Roles</name>
|
<name>Roles</name>
|
||||||
<path>/device-mgt/emm-admin/roles</path>
|
<path>/device-mgt/admin/roles</path>
|
||||||
<url>/</url>
|
<url>/</url>
|
||||||
<method>GET</method>
|
<method>GET</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>Configurations</name>
|
<name>Configurations</name>
|
||||||
<path>/device-mgt/emm-admin/platform-configs</path>
|
<path>/device-mgt/admin/platform-configs</path>
|
||||||
<url>/</url>
|
<url>/</url>
|
||||||
<method>GET</method>
|
<method>GET</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>View Dashboard</name>
|
<name>View Dashboard</name>
|
||||||
<path>/device-mgt/emm-admin/dashboard</path>
|
<path>/device-mgt/admin/dashboard</path>
|
||||||
<url>/</url>
|
<url>/</url>
|
||||||
<method>GET</method>
|
<method>GET</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>List devices</name>
|
<name>List devices</name>
|
||||||
<path>/device-mgt/emm-admin/devices/list</path>
|
<path>/device-mgt/admin/devices/list</path>
|
||||||
<url>/devices</url>
|
<url>/devices</url>
|
||||||
<method>GET</method>
|
<method>GET</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>List devices</name>
|
<name>List devices</name>
|
||||||
<path>/device-mgt/emm-admin/devices/list</path>
|
<path>/device-mgt/admin/devices/list</path>
|
||||||
<url>/devices/types</url>
|
<url>/devices/types</url>
|
||||||
<method>GET</method>
|
<method>GET</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>Add policy</name>
|
<name>Add policy</name>
|
||||||
<path>/device-mgt/emm-admin/policies/add</path>
|
<path>/device-mgt/admin/policies/add</path>
|
||||||
<url>/devices/types</url>
|
<url>/devices/types</url>
|
||||||
<method>GET</method>
|
<method>GET</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>Edit policy</name>
|
<name>Edit policy</name>
|
||||||
<path>/device-mgt/emm-admin/policies/update</path>
|
<path>/device-mgt/admin/policies/update</path>
|
||||||
<url>/devices/types</url>
|
<url>/devices/types</url>
|
||||||
<method>GET</method>
|
<method>GET</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>View device</name>
|
<name>View device</name>
|
||||||
<path>/device-mgt/emm-admin/devices/view</path>
|
<path>/device-mgt/admin/devices/view</path>
|
||||||
<url>/devices/view</url>
|
<url>/devices/view</url>
|
||||||
<method>GET</method>
|
<method>GET</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
@ -167,21 +167,21 @@
|
|||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>View device</name>
|
<name>View device</name>
|
||||||
<path>/device-mgt/emm-admin/devices/view</path>
|
<path>/device-mgt/admin/devices/view</path>
|
||||||
<url>/devices/user/*/*</url>
|
<url>/devices/user/*/*</url>
|
||||||
<method>GET</method>
|
<method>GET</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>List devices</name>
|
<name>List devices</name>
|
||||||
<path>/device-mgt/emm-admin/devices/list</path>
|
<path>/device-mgt/admin/devices/list</path>
|
||||||
<url>/devices/count</url>
|
<url>/devices/count</url>
|
||||||
<method>GET</method>
|
<method>GET</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>List devices</name>
|
<name>List devices</name>
|
||||||
<path>/device-mgt/emm-admin/devices/list</path>
|
<path>/device-mgt/admin/devices/list</path>
|
||||||
<url>/devices/name/*/*</url>
|
<url>/devices/name/*/*</url>
|
||||||
<method>GET</method>
|
<method>GET</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
@ -190,28 +190,28 @@
|
|||||||
<!-- Notification related APIs -->
|
<!-- Notification related APIs -->
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>View notifications</name>
|
<name>View notifications</name>
|
||||||
<path>/device-mgt/emm-admin/notifications/view</path>
|
<path>/device-mgt/admin/notifications/view</path>
|
||||||
<url>/notifications</url>
|
<url>/notifications</url>
|
||||||
<method>GET</method>
|
<method>GET</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>Add notification</name>
|
<name>Add notification</name>
|
||||||
<path>/device-mgt/emm-admin/notifications/add</path>
|
<path>/device-mgt/admin/notifications/add</path>
|
||||||
<url>/notifications</url>
|
<url>/notifications</url>
|
||||||
<method>POST</method>
|
<method>POST</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>Update notification</name>
|
<name>Update notification</name>
|
||||||
<path>/device-mgt/emm-admin/notifications/update</path>
|
<path>/device-mgt/admin/notifications/update</path>
|
||||||
<url>/notifications/*/*</url>
|
<url>/notifications/*/*</url>
|
||||||
<method>PUT</method>
|
<method>PUT</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>View notifications</name>
|
<name>View notifications</name>
|
||||||
<path>/device-mgt/emm-admin/notifications/view</path>
|
<path>/device-mgt/admin/notifications/view</path>
|
||||||
<url>/notifications/*</url>
|
<url>/notifications/*</url>
|
||||||
<method>GET</method>
|
<method>GET</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
@ -220,35 +220,35 @@
|
|||||||
<!-- Operations related APIs -->
|
<!-- Operations related APIs -->
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>View user</name>
|
<name>View user</name>
|
||||||
<path>/device-mgt/emm-admin/users/view</path>
|
<path>/device-mgt/admin/users/view</path>
|
||||||
<url>/operations</url>
|
<url>/operations</url>
|
||||||
<method>GET</method>
|
<method>GET</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>Install application</name>
|
<name>Install application</name>
|
||||||
<path>/device-mgt/emm-admin/operations/applications/install-applications</path>
|
<path>/device-mgt/admin/operations/applications/install-applications</path>
|
||||||
<url>/operations</url>
|
<url>/operations</url>
|
||||||
<method>POST</method>
|
<method>POST</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>Install application</name>
|
<name>Install application</name>
|
||||||
<path>/device-mgt/emm-admin/operations/applications/install-applications</path>
|
<path>/device-mgt/admin/operations/applications/install-applications</path>
|
||||||
<url>/operations/installApp/*</url>
|
<url>/operations/installApp/*</url>
|
||||||
<method>POST</method>
|
<method>POST</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>Uninstall application</name>
|
<name>Uninstall application</name>
|
||||||
<path>/device-mgt/emm-admin/operations/applications/uninstall-applications</path>
|
<path>/device-mgt/admin/operations/applications/uninstall-applications</path>
|
||||||
<url>/operations/uninstallApp/*</url>
|
<url>/operations/uninstallApp/*</url>
|
||||||
<method>POST</method>
|
<method>POST</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>View application</name>
|
<name>View application</name>
|
||||||
<path>/device-mgt/emm-admin/operations/applications/view-applications</path>
|
<path>/device-mgt/admin/operations/applications/view-applications</path>
|
||||||
<url>/operations/*/*/*</url>
|
<url>/operations/*/*/*</url>
|
||||||
<method>GET</method>
|
<method>GET</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
@ -262,21 +262,21 @@
|
|||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>View device</name>
|
<name>View device</name>
|
||||||
<path>/device-mgt/emm-admin/devices/view</path>
|
<path>/device-mgt/admin/devices/view</path>
|
||||||
<url>/operations/*/*/*</url>
|
<url>/operations/*/*/*</url>
|
||||||
<method>GET</method>
|
<method>GET</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>View device</name>
|
<name>View device</name>
|
||||||
<path>/device-mgt/emm-admin/devices/view</path>
|
<path>/device-mgt/admin/devices/view</path>
|
||||||
<url>/operations/*/*</url>
|
<url>/operations/*/*</url>
|
||||||
<method>GET</method>
|
<method>GET</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>View device</name>
|
<name>View device</name>
|
||||||
<path>/device-mgt/emm-admin/devices/view</path>
|
<path>/device-mgt/admin/devices/view</path>
|
||||||
<url>/operations/paginate/*/*</url>
|
<url>/operations/paginate/*/*</url>
|
||||||
<method>GET</method>
|
<method>GET</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
@ -307,14 +307,14 @@
|
|||||||
<!-- Feature related APIs -->
|
<!-- Feature related APIs -->
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>List policies</name>
|
<name>List policies</name>
|
||||||
<path>/device-mgt/emm-admin/policies/list</path>
|
<path>/device-mgt/admin/policies/list</path>
|
||||||
<url>/features/*</url>
|
<url>/features/*</url>
|
||||||
<method>GET</method>
|
<method>GET</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>View device</name>
|
<name>View device</name>
|
||||||
<path>/device-mgt/emm-admin/devices/view</path>
|
<path>/device-mgt/admin/devices/view</path>
|
||||||
<url>/features/*</url>
|
<url>/features/*</url>
|
||||||
<method>GET</method>
|
<method>GET</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
@ -331,63 +331,63 @@
|
|||||||
<path>/device-mgt/user/devices/view</path>
|
<path>/device-mgt/user/devices/view</path>
|
||||||
<url>/features</url>
|
<url>/features</url>
|
||||||
<method>GET</method>
|
<method>GET</method>
|
||||||
<scope>emm_admin</scope>
|
|
||||||
</Permission>
|
</Permission>
|
||||||
<!-- End of Feature related APIs -->
|
<!-- End of Feature related APIs -->
|
||||||
|
|
||||||
<!-- Role related APIs -->
|
<!-- Role related APIs -->
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>List roles</name>
|
<name>List roles</name>
|
||||||
<path>/device-mgt/emm-admin/roles/list</path>
|
<path>/device-mgt/admin/roles/list</path>
|
||||||
<url>/roles</url>
|
<url>/roles</url>
|
||||||
<method>GET</method>
|
<method>GET</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>View user</name>
|
<name>View user</name>
|
||||||
<path>/device-mgt/emm-admin/users/view</path>
|
<path>/device-mgt/admin/users/view</path>
|
||||||
<url>/roles</url>
|
<url>/roles</url>
|
||||||
<method>GET</method>
|
<method>GET</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>Add policy</name>
|
<name>Add policy</name>
|
||||||
<path>/device-mgt/emm-admin/policies/add</path>
|
<path>/device-mgt/admin/policies/add</path>
|
||||||
<url>/roles</url>
|
<url>/roles</url>
|
||||||
<method>GET</method>
|
<method>GET</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>Update policy</name>
|
<name>Update policy</name>
|
||||||
<path>/device-mgt/emm-admin/policies/update</path>
|
<path>/device-mgt/admin/policies/update</path>
|
||||||
<url>/roles</url>
|
<url>/roles</url>
|
||||||
<method>GET</method>
|
<method>GET</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>List roles</name>
|
<name>List roles</name>
|
||||||
<path>/device-mgt/emm-admin/roles/list</path>
|
<path>/device-mgt/admin/roles/list</path>
|
||||||
<url>/roles/permissions</url>
|
<url>/roles/permissions</url>
|
||||||
<method>GET</method>
|
<method>GET</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>List roles</name>
|
<name>List roles</name>
|
||||||
<path>/device-mgt/emm-admin/roles/list</path>
|
<path>/device-mgt/admin/roles/list</path>
|
||||||
<url>/roles/*</url>
|
<url>/roles/*</url>
|
||||||
<method>GET</method>
|
<method>GET</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>Add user</name>
|
<name>Add user</name>
|
||||||
<path>/device-mgt/emm-admin/users/add</path>
|
<path>/device-mgt/admin/users/add</path>
|
||||||
<url>/roles/*</url>
|
<url>/roles/*</url>
|
||||||
<method>GET</method>
|
<method>GET</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>Update role</name>
|
<name>Update role</name>
|
||||||
<path>/device-mgt/emm-admin/roles/update</path>
|
<path>/device-mgt/admin/roles/update</path>
|
||||||
<url>/roles</url>
|
<url>/roles</url>
|
||||||
<method>PUT</method>
|
<method>PUT</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
@ -397,33 +397,33 @@
|
|||||||
<!--<path>/device-mgt/roles/update</path>-->
|
<!--<path>/device-mgt/roles/update</path>-->
|
||||||
<!--<url>/roles/*</url>-->
|
<!--<url>/roles/*</url>-->
|
||||||
<!--<method>PUT</method>-->
|
<!--<method>PUT</method>-->
|
||||||
<!--<scope>emm_admin</scope>-->
|
<!---->
|
||||||
<!--</Permission>-->
|
<!--</Permission>-->
|
||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>Update role</name>
|
<name>Update role</name>
|
||||||
<path>/device-mgt/emm-admin/roles/update</path>
|
<path>/device-mgt/admin/roles/update</path>
|
||||||
<url>/roles/users</url>
|
<url>/roles/users</url>
|
||||||
<method>PUT</method>
|
<method>PUT</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>Add role</name>
|
<name>Add role</name>
|
||||||
<path>/device-mgt/emm-admin/roles/add</path>
|
<path>/device-mgt/admin/roles/add</path>
|
||||||
<url>/roles</url>
|
<url>/roles</url>
|
||||||
<method>POST</method>
|
<method>POST</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>Remove role</name>
|
<name>Remove role</name>
|
||||||
<path>/device-mgt/emm-admin/roles/remove</path>
|
<path>/device-mgt/admin/roles/remove</path>
|
||||||
<url>/roles</url>
|
<url>/roles</url>
|
||||||
<method>DELETE</method>
|
<method>DELETE</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>List roles</name>
|
<name>List roles</name>
|
||||||
<path>/device-mgt/emm-admin/roles/list</path>
|
<path>/device-mgt/admin/roles/list</path>
|
||||||
<url>/roles/count</url>
|
<url>/roles/count</url>
|
||||||
<method>GET</method>
|
<method>GET</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
@ -432,28 +432,28 @@
|
|||||||
<!-- User related APIs -->
|
<!-- User related APIs -->
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>List users</name>
|
<name>List users</name>
|
||||||
<path>/device-mgt/emm-admin/users/list</path>
|
<path>/device-mgt/admin/users/list</path>
|
||||||
<url>/users</url>
|
<url>/users</url>
|
||||||
<method>GET</method>
|
<method>GET</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>Add user</name>
|
<name>Add user</name>
|
||||||
<path>/device-mgt/emm-admin/users/add</path>
|
<path>/device-mgt/admin/users/add</path>
|
||||||
<url>/users</url>
|
<url>/users</url>
|
||||||
<method>POST</method>
|
<method>POST</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>View user</name>
|
<name>View user</name>
|
||||||
<path>/device-mgt/emm-admin/users/view</path>
|
<path>/device-mgt/admin/users/view</path>
|
||||||
<url>/users/view</url>
|
<url>/users/view</url>
|
||||||
<method>GET</method>
|
<method>GET</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>Update user</name>
|
<name>Update user</name>
|
||||||
<path>/device-mgt/emm-admin/users/update</path>
|
<path>/device-mgt/admin/users/update</path>
|
||||||
<url>/users</url>
|
<url>/users</url>
|
||||||
<method>PUT</method>
|
<method>PUT</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
@ -463,40 +463,39 @@
|
|||||||
<path>/login</path>
|
<path>/login</path>
|
||||||
<url>/users/change-password</url>
|
<url>/users/change-password</url>
|
||||||
<method>POST</method>
|
<method>POST</method>
|
||||||
<scope>emm_admin</scope>
|
|
||||||
</Permission>
|
</Permission>
|
||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>Reset password</name>
|
<name>Reset password</name>
|
||||||
<path>/device-mgt/emm-admin/users/password-reset</path>
|
<path>/device-mgt/admin/users/password-reset</path>
|
||||||
<url>/users/reset-password</url>
|
<url>/users/reset-password</url>
|
||||||
<method>POST</method>
|
<method>POST</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>Remove user</name>
|
<name>Remove user</name>
|
||||||
<path>/device-mgt/emm-admin/users/remove</path>
|
<path>/device-mgt/admin/users/remove</path>
|
||||||
<url>/users</url>
|
<url>/users</url>
|
||||||
<method>DELETE</method>
|
<method>DELETE</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>View user</name>
|
<name>View user</name>
|
||||||
<path>/device-mgt/emm-admin/users/view</path>
|
<path>/device-mgt/admin/users/view</path>
|
||||||
<url>/users/roles</url>
|
<url>/users/roles</url>
|
||||||
<method>GET</method>
|
<method>GET</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
|
|
||||||
<!--<Permission>-->
|
<!--<Permission>-->
|
||||||
<!--<name>Get user roles by name</name>-->
|
<!--<name>Get user roles by name</name>-->
|
||||||
<!--<path>/device-mgt/emm-admin/users/view</path>-->
|
<!--<path>/device-mgt/admin/users/view</path>-->
|
||||||
<!--<url>/roles</url>-->
|
<!--<url>/roles</url>-->
|
||||||
<!--<method>GET</method>-->
|
<!--<method>GET</method>-->
|
||||||
<!--</Permission>-->
|
<!--</Permission>-->
|
||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>Add user</name>
|
<name>Add user</name>
|
||||||
<path>/device-mgt/emm-admin/users/add</path>
|
<path>/device-mgt/admin/users/add</path>
|
||||||
<url>/roles</url>
|
<url>/roles</url>
|
||||||
<method>POST</method>
|
<method>POST</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
@ -510,77 +509,77 @@
|
|||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>List devices</name>
|
<name>List devices</name>
|
||||||
<path>/device-mgt/emm-admin/devices/list</path>
|
<path>/device-mgt/admin/devices/list</path>
|
||||||
<url>/users/devices</url>
|
<url>/users/devices</url>
|
||||||
<method>GET</method>
|
<method>GET</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>View user</name>
|
<name>View user</name>
|
||||||
<path>/device-mgt/emm-admin/users/view</path>
|
<path>/device-mgt/admin/users/view</path>
|
||||||
<url>/users/*/*</url>
|
<url>/users/*/*</url>
|
||||||
<method>GET</method>
|
<method>GET</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>List users</name>
|
<name>List users</name>
|
||||||
<path>/device-mgt/emm-admin/users/list</path>
|
<path>/device-mgt/admin/users/list</path>
|
||||||
<url>/users/count</url>
|
<url>/users/count</url>
|
||||||
<method>GET</method>
|
<method>GET</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>List users</name>
|
<name>List users</name>
|
||||||
<path>/device-mgt/emm-admin/users/list</path>
|
<path>/device-mgt/admin/users/list</path>
|
||||||
<url>/users/view-users</url>
|
<url>/users/view-users</url>
|
||||||
<method>GET</method>
|
<method>GET</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>Add role</name>
|
<name>Add role</name>
|
||||||
<path>/device-mgt/emm-admin/roles/add</path>
|
<path>/device-mgt/admin/roles/add</path>
|
||||||
<url>/users/view-users</url>
|
<url>/users/view-users</url>
|
||||||
<method>GET</method>
|
<method>GET</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>Update role</name>
|
<name>Update role</name>
|
||||||
<path>/device-mgt/emm-admin/roles/update</path>
|
<path>/device-mgt/admin/roles/update</path>
|
||||||
<url>/users/view-users</url>
|
<url>/users/view-users</url>
|
||||||
<method>GET</method>
|
<method>GET</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>Add policy</name>
|
<name>Add policy</name>
|
||||||
<path>/device-mgt/emm-admin/policies/add</path>
|
<path>/device-mgt/admin/policies/add</path>
|
||||||
<url>/users/view-users</url>
|
<url>/users/view-users</url>
|
||||||
<method>GET</method>
|
<method>GET</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>Update policy</name>
|
<name>Update policy</name>
|
||||||
<path>/device-mgt/emm-admin/policies/update</path>
|
<path>/device-mgt/admin/policies/update</path>
|
||||||
<url>/users/view-users</url>
|
<url>/users/view-users</url>
|
||||||
<method>GET</method>
|
<method>GET</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>List users</name>
|
<name>List users</name>
|
||||||
<path>/device-mgt/emm-admin/users/list</path>
|
<path>/device-mgt/admin/users/list</path>
|
||||||
<url>/users/users-by-username</url>
|
<url>/users/users-by-username</url>
|
||||||
<method>GET</method>
|
<method>GET</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>List users</name>
|
<name>List users</name>
|
||||||
<path>/device-mgt/emm-admin/users/list</path>
|
<path>/device-mgt/admin/users/list</path>
|
||||||
<url>/users/users-by-username/*</url>
|
<url>/users/users-by-username/*</url>
|
||||||
<method>GET</method>
|
<method>GET</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>Invite user</name>
|
<name>Invite user</name>
|
||||||
<path>/device-mgt/emm-admin/users/invite</path>
|
<path>/device-mgt/admin/users/invite</path>
|
||||||
<url>/users/email-invitation</url>
|
<url>/users/email-invitation</url>
|
||||||
<method>POST</method>
|
<method>POST</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
@ -596,28 +595,28 @@
|
|||||||
<!-- Policy related APIs -->
|
<!-- Policy related APIs -->
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>Add Policy</name>
|
<name>Add Policy</name>
|
||||||
<path>/device-mgt/emm-admin/policies/add</path>
|
<path>/device-mgt/admin/policies/add</path>
|
||||||
<url>/policies/inactive-policy</url>
|
<url>/policies/inactive-policy</url>
|
||||||
<method>POST</method>
|
<method>POST</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>List policies</name>
|
<name>List policies</name>
|
||||||
<path>/device-mgt/emm-admin/policies/list</path>
|
<path>/device-mgt/admin/policies/list</path>
|
||||||
<url>/policies/*/*</url>
|
<url>/policies/*/*</url>
|
||||||
<method>POST</method>
|
<method>POST</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>List policies</name>
|
<name>List policies</name>
|
||||||
<path>/device-mgt/emm-admin/policies/list</path>
|
<path>/device-mgt/admin/policies/list</path>
|
||||||
<url>/policies/*/*/*</url>
|
<url>/policies/*/*/*</url>
|
||||||
<method>GET</method>
|
<method>GET</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>View device</name>
|
<name>View device</name>
|
||||||
<path>/device-mgt/emm-admin/devices/view</path>
|
<path>/device-mgt/admin/devices/view</path>
|
||||||
<url>/policies/*/*/*</url>
|
<url>/policies/*/*/*</url>
|
||||||
<method>GET</method>
|
<method>GET</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
@ -631,119 +630,119 @@
|
|||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>Add policy</name>
|
<name>Add policy</name>
|
||||||
<path>/device-mgt/emm-admin/policies/add</path>
|
<path>/device-mgt/admin/policies/add</path>
|
||||||
<url>/policies/active-policy</url>
|
<url>/policies/active-policy</url>
|
||||||
<method>POST</method>
|
<method>POST</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>Remove policy</name>
|
<name>Remove policy</name>
|
||||||
<path>/device-mgt/emm-admin/policies/remove</path>
|
<path>/device-mgt/admin/policies/remove</path>
|
||||||
<url>/policies/bulk-remove</url>
|
<url>/policies/bulk-remove</url>
|
||||||
<method>POST</method>
|
<method>POST</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>List policies</name>
|
<name>List policies</name>
|
||||||
<path>/device-mgt/emm-admin/policies/list</path>
|
<path>/device-mgt/admin/policies/list</path>
|
||||||
<url>/policies</url>
|
<url>/policies</url>
|
||||||
<method>GET</method>
|
<method>GET</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>List policies</name>
|
<name>List policies</name>
|
||||||
<path>/device-mgt/emm-admin/policies/list</path>
|
<path>/device-mgt/admin/policies/list</path>
|
||||||
<url>/policies/*</url>
|
<url>/policies/*</url>
|
||||||
<method>GET</method>
|
<method>GET</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>Update policy</name>
|
<name>Update policy</name>
|
||||||
<path>/device-mgt/emm-admin/policies/update</path>
|
<path>/device-mgt/admin/policies/update</path>
|
||||||
<url>/policies/*</url>
|
<url>/policies/*</url>
|
||||||
<method>PUT</method>
|
<method>PUT</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>Remove policy</name>
|
<name>Remove policy</name>
|
||||||
<path>/device-mgt/emm-admin/policies/remove</path>
|
<path>/device-mgt/admin/policies/remove</path>
|
||||||
<url>/policies</url>
|
<url>/policies</url>
|
||||||
<method>DELETE</method>
|
<method>DELETE</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>List policies</name>
|
<name>List policies</name>
|
||||||
<path>/device-mgt/emm-admin/policies/list</path>
|
<path>/device-mgt/admin/policies/list</path>
|
||||||
<url>/policies/count</url>
|
<url>/policies/count</url>
|
||||||
<method>GET</method>
|
<method>GET</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>Edit policy</name>
|
<name>Edit policy</name>
|
||||||
<path>/device-mgt/emm-admin/policies/update</path>
|
<path>/device-mgt/admin/policies/update</path>
|
||||||
<url>/policies/priorities</url>
|
<url>/policies/priorities</url>
|
||||||
<method>PUT</method>
|
<method>PUT</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>Edit policy</name>
|
<name>Edit policy</name>
|
||||||
<path>/device-mgt/emm-admin/policies/update</path>
|
<path>/device-mgt/admin/policies/update</path>
|
||||||
<url>/policies/activate</url>
|
<url>/policies/activate</url>
|
||||||
<method>PUT</method>
|
<method>PUT</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>Add policy</name>
|
<name>Add policy</name>
|
||||||
<path>/device-mgt/emm-admin/policies/add</path>
|
<path>/device-mgt/admin/policies/add</path>
|
||||||
<url>/policies/activate</url>
|
<url>/policies/activate</url>
|
||||||
<method>PUT</method>
|
<method>PUT</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>Edit policy</name>
|
<name>Edit policy</name>
|
||||||
<path>/device-mgt/emm-admin/policies/update</path>
|
<path>/device-mgt/admin/policies/update</path>
|
||||||
<url>/policies/inactivate</url>
|
<url>/policies/inactivate</url>
|
||||||
<method>PUT</method>
|
<method>PUT</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>Add policy</name>
|
<name>Add policy</name>
|
||||||
<path>/device-mgt/emm-admin/policies/add</path>
|
<path>/device-mgt/admin/policies/add</path>
|
||||||
<url>/policies/inactivate</url>
|
<url>/policies/inactivate</url>
|
||||||
<method>PUT</method>
|
<method>PUT</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>Edit policy</name>
|
<name>Edit policy</name>
|
||||||
<path>/device-mgt/emm-admin/policies/update</path>
|
<path>/device-mgt/admin/policies/update</path>
|
||||||
<url>/policies/apply-changes</url>
|
<url>/policies/apply-changes</url>
|
||||||
<method>PUT</method>
|
<method>PUT</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>Add policy</name>
|
<name>Add policy</name>
|
||||||
<path>/device-mgt/emm-admin/policies/add</path>
|
<path>/device-mgt/admin/policies/add</path>
|
||||||
<url>/policies/start-task/*</url>
|
<url>/policies/start-task/*</url>
|
||||||
<method>GET</method>
|
<method>GET</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>Add policy</name>
|
<name>Add policy</name>
|
||||||
<path>/device-mgt/emm-admin/policies/add</path>
|
<path>/device-mgt/admin/policies/add</path>
|
||||||
<url>/policies/update-task/*</url>
|
<url>/policies/update-task/*</url>
|
||||||
<method>GET</method>
|
<method>GET</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>Add policy</name>
|
<name>Add policy</name>
|
||||||
<path>/device-mgt/emm-admin/policies/add</path>
|
<path>/device-mgt/admin/policies/add</path>
|
||||||
<url>/policies/stop-task</url>
|
<url>/policies/stop-task</url>
|
||||||
<method>GET</method>
|
<method>GET</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>List policies</name>
|
<name>List policies</name>
|
||||||
<path>/device-mgt/emm-admin/policies/list</path>
|
<path>/device-mgt/admin/policies/list</path>
|
||||||
<url>/policies/*/*</url>
|
<url>/policies/*/*</url>
|
||||||
<method>GET</method>
|
<method>GET</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
@ -752,21 +751,21 @@
|
|||||||
<!-- Profile related APIs -->
|
<!-- Profile related APIs -->
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>Add policy</name>
|
<name>Add policy</name>
|
||||||
<path>/device-mgt/emm-admin/policies/add</path>
|
<path>/device-mgt/admin/policies/add</path>
|
||||||
<url>/profiles</url>
|
<url>/profiles</url>
|
||||||
<method>POST</method>
|
<method>POST</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>Edit policy</name>
|
<name>Edit policy</name>
|
||||||
<path>/device-mgt/emm-admin/policies/update</path>
|
<path>/device-mgt/admin/policies/update</path>
|
||||||
<url>/profiles/*</url>
|
<url>/profiles/*</url>
|
||||||
<method>PUT</method>
|
<method>PUT</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>Remove policy</name>
|
<name>Remove policy</name>
|
||||||
<path>/device-mgt/emm-admin/policies/remove</path>
|
<path>/device-mgt/admin/policies/remove</path>
|
||||||
<url>/profiles/*</url>
|
<url>/profiles/*</url>
|
||||||
<method>DELETE</method>
|
<method>DELETE</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
@ -776,14 +775,14 @@
|
|||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>Device Information</name>
|
<name>Device Information</name>
|
||||||
<path>/device-mgt/emm-admin/information/get</path>
|
<path>/device-mgt/admin/information/get</path>
|
||||||
<url>/information/*/*</url>
|
<url>/information/*/*</url>
|
||||||
<method>GET</method>
|
<method>GET</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>Device Search</name>
|
<name>Device Search</name>
|
||||||
<path>/device-mgt/emm-admin/search</path>
|
<path>/device-mgt/admin/search</path>
|
||||||
<url>/information/*</url>
|
<url>/information/*</url>
|
||||||
<method>GET</method>
|
<method>GET</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
@ -797,35 +796,35 @@
|
|||||||
<!--<path>/device-mgt/license/view</path>-->
|
<!--<path>/device-mgt/license/view</path>-->
|
||||||
<!--<url>/license/*/*</url>-->
|
<!--<url>/license/*/*</url>-->
|
||||||
<!--<method>GET</method>-->
|
<!--<method>GET</method>-->
|
||||||
<!--<scope>emm_admin</scope>-->
|
<!---->
|
||||||
<!--</Permission>-->
|
<!--</Permission>-->
|
||||||
<!--<Permission>-->
|
<!--<Permission>-->
|
||||||
<!--<name>Add license</name>-->
|
<!--<name>Add license</name>-->
|
||||||
<!--<path>/device-mgt/license/add</path>-->
|
<!--<path>/device-mgt/license/add</path>-->
|
||||||
<!--<url>/license</url>-->
|
<!--<url>/license</url>-->
|
||||||
<!--<method>POST</method>-->
|
<!--<method>POST</method>-->
|
||||||
<!--<scope>emm_admin</scope>-->
|
<!---->
|
||||||
<!--</Permission>-->
|
<!--</Permission>-->
|
||||||
<!-- End of License related APIs -->
|
<!-- End of License related APIs -->
|
||||||
|
|
||||||
<!-- Configuration related APIs -->
|
<!-- Configuration related APIs -->
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>View configuration</name>
|
<name>View configuration</name>
|
||||||
<path>/device-mgt/emm-admin/platform-configs/view</path>
|
<path>/device-mgt/admin/platform-configs/view</path>
|
||||||
<url>/configuration</url>
|
<url>/configuration</url>
|
||||||
<method>GET</method>
|
<method>GET</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>Add configuration</name>
|
<name>Add configuration</name>
|
||||||
<path>/device-mgt/emm-admin/platform-configs/add</path>
|
<path>/device-mgt/admin/platform-configs/add</path>
|
||||||
<url>/configuration</url>
|
<url>/configuration</url>
|
||||||
<method>POST</method>
|
<method>POST</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
|
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>Update configuration</name>
|
<name>Update configuration</name>
|
||||||
<path>/device-mgt/emm-admin/platform-configs/modify</path>
|
<path>/device-mgt/admin/platform-configs/modify</path>
|
||||||
<url>/configuration</url>
|
<url>/configuration</url>
|
||||||
<method>PUT</method>
|
<method>PUT</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
@ -838,21 +837,161 @@
|
|||||||
<path>/device-mgt/android/certificate/save</path>
|
<path>/device-mgt/android/certificate/save</path>
|
||||||
<url>/certificates/saveCertificate</url>
|
<url>/certificates/saveCertificate</url>
|
||||||
<method>POST</method>
|
<method>POST</method>
|
||||||
<scope>emm_admin</scope>
|
|
||||||
</Permission>
|
</Permission>
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>get certificate in the database</name>
|
<name>get certificate in the database</name>
|
||||||
<path>/device-mgt/android/certificate/Get</path>
|
<path>/device-mgt/android/certificate/Get</path>
|
||||||
<url>/certificates/*</url>
|
<url>/certificates/*</url>
|
||||||
<method>GET</method>
|
<method>GET</method>
|
||||||
<scope>emm_admin</scope>
|
|
||||||
</Permission>
|
</Permission>
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>get certificate in the database</name>
|
<name>get certificate in the database</name>
|
||||||
<path>/device-mgt/android/certificate/Get</path>
|
<path>/device-mgt/android/certificate/Get</path>
|
||||||
<url>/certificates/*</url>
|
<url>/certificates/*</url>
|
||||||
<method>DELETE</method>
|
<method>DELETE</method>
|
||||||
<scope>emm_admin</scope>
|
|
||||||
</Permission>
|
</Permission>
|
||||||
<!-- End of Certificate related APIs -->
|
<!-- End of Certificate related APIs -->
|
||||||
</PermissionConfiguration>
|
|
||||||
|
<!-- Group related APIs -->
|
||||||
|
<Permission>
|
||||||
|
<name>Group Management</name>
|
||||||
|
<path>/device-mgt/admin/groups</path>
|
||||||
|
<url>/groups</url>
|
||||||
|
<method>POST</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>Group Management</name>
|
||||||
|
<path>/device-mgt/admin/groups</path>
|
||||||
|
<url>/groups/*/*</url>
|
||||||
|
<method>PUT</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>Group Management</name>
|
||||||
|
<path>/device-mgt/admin/groups</path>
|
||||||
|
<url>/groups/*/*</url>
|
||||||
|
<method>DELETE</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>Group Management</name>
|
||||||
|
<path>/device-mgt/admin/groups</path>
|
||||||
|
<url>/groups</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>Group Management</name>
|
||||||
|
<path>/device-mgt/admin/groups</path>
|
||||||
|
<url>/groups/user/*</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>Group Management</name>
|
||||||
|
<path>/device-mgt/admin/groups</path>
|
||||||
|
<url>/groups/*/*</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>Group Management</name>
|
||||||
|
<path>/device-mgt/admin/groups</path>
|
||||||
|
<url>/groups/search</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>Group Management</name>
|
||||||
|
<path>/device-mgt/admin/groups</path>
|
||||||
|
<url>/groups/user/*/all</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>Group Management</name>
|
||||||
|
<path>/device-mgt/admin/groups</path>
|
||||||
|
<url>/groups/user/*/count</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>Group Management</name>
|
||||||
|
<path>/device-mgt/admin/groups</path>
|
||||||
|
<url>/groups/*/*/share</url>
|
||||||
|
<method>PUT</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>Group Management</name>
|
||||||
|
<path>/device-mgt/admin/groups</path>
|
||||||
|
<url>/groups/*/*/unshare</url>
|
||||||
|
<method>PUT</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>Group Management</name>
|
||||||
|
<path>/device-mgt/admin/groups</path>
|
||||||
|
<url>/groups/*/*/share/roles/*/permissions</url>
|
||||||
|
<method>PUT</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>Group Management</name>
|
||||||
|
<path>/device-mgt/admin/groups</path>
|
||||||
|
<url>/groups/*/*/share/roles/*/permissions</url>
|
||||||
|
<method>DELETE</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>Group Management</name>
|
||||||
|
<path>/device-mgt/admin/groups</path>
|
||||||
|
<url>/groups/*/*/share/roles</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>Group Management</name>
|
||||||
|
<path>/device-mgt/admin/groups</path>
|
||||||
|
<url>/groups/*/*/users</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>Group Management</name>
|
||||||
|
<path>/device-mgt/admin/groups</path>
|
||||||
|
<url>/groups/*/*/devices/all</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>Group Management</name>
|
||||||
|
<path>/device-mgt/admin/groups</path>
|
||||||
|
<url>/groups/*/*/devices/count</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>Group Management</name>
|
||||||
|
<path>/device-mgt/admin/groups</path>
|
||||||
|
<url>/groups/*/*/devices/*/*</url>
|
||||||
|
<method>PUT</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>Group Management</name>
|
||||||
|
<path>/device-mgt/admin/groups</path>
|
||||||
|
<url>/groups/*/*/devices/*/*</url>
|
||||||
|
<method>DELETE</method>
|
||||||
|
</Permission>
|
||||||
|
|
||||||
|
<Permission>
|
||||||
|
<name>Group Management</name>
|
||||||
|
<path>/device-mgt/admin/groups</path>
|
||||||
|
<url>/groups/*/*/users/*/permissions</url>
|
||||||
|
<method>GET</method>
|
||||||
|
</Permission>
|
||||||
|
<!-- End of Group related APIs -->
|
||||||
|
|
||||||
|
</PermissionConfiguration>
|
||||||
|
|||||||
@ -17,9 +17,9 @@
|
|||||||
~ under the License.
|
~ under the License.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xmlns:jaxrs="http://cxf.apache.org/jaxrs"
|
xmlns:jaxrs="http://cxf.apache.org/jaxrs"
|
||||||
|
xmlns="http://www.springframework.org/schema/beans"
|
||||||
xsi:schemaLocation="
|
xsi:schemaLocation="
|
||||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||||
http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd">
|
http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd">
|
||||||
@ -51,6 +51,15 @@
|
|||||||
<ref bean="errorHandler"/>
|
<ref bean="errorHandler"/>
|
||||||
</jaxrs:providers>
|
</jaxrs:providers>
|
||||||
</jaxrs:server>
|
</jaxrs:server>
|
||||||
|
<jaxrs:server id="deviceGroupService" address="/groups">
|
||||||
|
<jaxrs:serviceBeans>
|
||||||
|
<ref bean="groupServiceBean"/>
|
||||||
|
</jaxrs:serviceBeans>
|
||||||
|
<jaxrs:providers>
|
||||||
|
<ref bean="jsonProvider"/>
|
||||||
|
<ref bean="errorHandler"/>
|
||||||
|
</jaxrs:providers>
|
||||||
|
</jaxrs:server>
|
||||||
<jaxrs:server id="userService" address="/users">
|
<jaxrs:server id="userService" address="/users">
|
||||||
<jaxrs:serviceBeans>
|
<jaxrs:serviceBeans>
|
||||||
<ref bean="userServiceBean"/>
|
<ref bean="userServiceBean"/>
|
||||||
@ -155,7 +164,8 @@
|
|||||||
</jaxrs:server>
|
</jaxrs:server>
|
||||||
-->
|
-->
|
||||||
<bean id="operationServiceBean" class="org.wso2.carbon.mdm.api.Operation"/>
|
<bean id="operationServiceBean" class="org.wso2.carbon.mdm.api.Operation"/>
|
||||||
<bean id="deviceServiceBean" class="org.wso2.carbon.mdm.api.MobileDevice"/>
|
<bean id="deviceServiceBean" class="org.wso2.carbon.mdm.api.Device"/>
|
||||||
|
<bean id="groupServiceBean" class="org.wso2.carbon.mdm.api.Group"/>
|
||||||
<bean id="userServiceBean" class="org.wso2.carbon.mdm.api.User"/>
|
<bean id="userServiceBean" class="org.wso2.carbon.mdm.api.User"/>
|
||||||
<bean id="roleServiceBean" class="org.wso2.carbon.mdm.api.Role"/>
|
<bean id="roleServiceBean" class="org.wso2.carbon.mdm.api.Role"/>
|
||||||
<bean id="featureServiceBean" class="org.wso2.carbon.mdm.api.Feature"/>
|
<bean id="featureServiceBean" class="org.wso2.carbon.mdm.api.Feature"/>
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!--
|
<!--
|
||||||
~ Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
~ Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
~
|
~
|
||||||
~ WSO2 Inc. licenses this file to you under the Apache License,
|
~ WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
~ Version 2.0 (the "License"); you may not use this file except
|
~ Version 2.0 (the "License"); you may not use this file except
|
||||||
@ -12,14 +12,14 @@
|
|||||||
~ Unless required by applicable law or agreed to in writing,
|
~ Unless required by applicable law or agreed to in writing,
|
||||||
~ software distributed under the License is distributed on an
|
~ software distributed under the License is distributed on an
|
||||||
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
~ KIND, either express or implied. See the License for the
|
~ KIND, either express or implied. See the License for the
|
||||||
~ specific language governing permissions and limitations
|
~ specific language governing permissions and limitations
|
||||||
~ under the License.
|
~ under the License.
|
||||||
-->
|
-->
|
||||||
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
|
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
|
||||||
<display-name>Admin-Webapp</display-name>
|
<display-name>Admin-Webapp</display-name>
|
||||||
<servlet>
|
<servlet>
|
||||||
<description>JAX-WS/JAX-RS MDM Endpoint</description>
|
<description>JAX-WS/JAX-RS Device Management Endpoint</description>
|
||||||
<display-name>JAX-WS/JAX-RS Servlet</display-name>
|
<display-name>JAX-WS/JAX-RS Servlet</display-name>
|
||||||
<servlet-name>CXFServlet</servlet-name>
|
<servlet-name>CXFServlet</servlet-name>
|
||||||
<servlet-class>
|
<servlet-class>
|
||||||
@ -63,7 +63,7 @@
|
|||||||
<!-- Below configuration is used to redirect http requests to https -->
|
<!-- Below configuration is used to redirect http requests to https -->
|
||||||
<security-constraint>
|
<security-constraint>
|
||||||
<web-resource-collection>
|
<web-resource-collection>
|
||||||
<web-resource-name>MDM-Admin</web-resource-name>
|
<web-resource-name>DeviceMgt-Admin</web-resource-name>
|
||||||
<url-pattern>/*</url-pattern>
|
<url-pattern>/*</url-pattern>
|
||||||
</web-resource-collection>
|
</web-resource-collection>
|
||||||
<user-data-constraint>
|
<user-data-constraint>
|
||||||
|
|||||||
@ -35,6 +35,9 @@ import javax.ws.rs.HttpMethod;
|
|||||||
import javax.ws.rs.OPTIONS;
|
import javax.ws.rs.OPTIONS;
|
||||||
import javax.ws.rs.POST;
|
import javax.ws.rs.POST;
|
||||||
import javax.ws.rs.PUT;
|
import javax.ws.rs.PUT;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.PathParam;
|
||||||
|
import javax.ws.rs.QueryParam;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.annotation.Annotation;
|
import java.lang.annotation.Annotation;
|
||||||
import java.lang.reflect.InvocationHandler;
|
import java.lang.reflect.InvocationHandler;
|
||||||
@ -61,7 +64,8 @@ public class AnnotationUtil {
|
|||||||
private static final String PACKAGE_ORG_SPRINGFRAMEWORK = "org.springframework";
|
private static final String PACKAGE_ORG_SPRINGFRAMEWORK = "org.springframework";
|
||||||
public static final String STRING_ARR = "string_arr";
|
public static final String STRING_ARR = "string_arr";
|
||||||
public static final String STRING = "string";
|
public static final String STRING = "string";
|
||||||
private Class<org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.Feature> featureClazz;
|
private Class<org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.Feature>
|
||||||
|
featureAnnotationClazz;
|
||||||
private ClassLoader classLoader;
|
private ClassLoader classLoader;
|
||||||
private ServletContext servletContext;
|
private ServletContext servletContext;
|
||||||
|
|
||||||
@ -108,7 +112,7 @@ public class AnnotationUtil {
|
|||||||
if (deviceTypeAnno != null) {
|
if (deviceTypeAnno != null) {
|
||||||
Method[] deviceTypeMethod = deviceTypeClazz.getMethods();
|
Method[] deviceTypeMethod = deviceTypeClazz.getMethods();
|
||||||
String deviceType = invokeMethod(deviceTypeMethod[0], deviceTypeAnno, STRING);
|
String deviceType = invokeMethod(deviceTypeMethod[0], deviceTypeAnno, STRING);
|
||||||
featureClazz =
|
featureAnnotationClazz =
|
||||||
(Class<org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations
|
(Class<org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations
|
||||||
.Feature>) classLoader.loadClass(
|
.Feature>) classLoader.loadClass(
|
||||||
org.wso2.carbon.device.mgt.extensions.feature.mgt
|
org.wso2.carbon.device.mgt.extensions.feature.mgt
|
||||||
@ -130,80 +134,120 @@ public class AnnotationUtil {
|
|||||||
return features;
|
return features;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Feature> getFeatures(Method[] annotatedMethods) throws Throwable {
|
private List<Feature> getFeatures(Method[] methodsList) throws Throwable {
|
||||||
List<Feature> featureList = new ArrayList<>();
|
List<Feature> featureList = new ArrayList<>();
|
||||||
for (Method method : annotatedMethods) {
|
for (Method currentMethod : methodsList) {
|
||||||
Annotation methodAnnotation = method.getAnnotation(featureClazz);
|
Annotation featureAnnotation = currentMethod.getAnnotation(featureAnnotationClazz);
|
||||||
if (methodAnnotation != null) {
|
if (featureAnnotation != null) {
|
||||||
Annotation[] annotations = method.getDeclaredAnnotations();
|
Feature feature = new Feature();
|
||||||
|
feature = processFeatureAnnotation(feature, currentMethod);
|
||||||
|
Annotation[] annotations = currentMethod.getDeclaredAnnotations();
|
||||||
|
Feature.MetadataEntry metadataEntry = new Feature.MetadataEntry();
|
||||||
|
metadataEntry.setId(-1);
|
||||||
|
Map<String, Object> apiParams = new HashMap<>();
|
||||||
for (int i = 0; i < annotations.length; i++) {
|
for (int i = 0; i < annotations.length; i++) {
|
||||||
if (annotations[i].annotationType().getName().equals(
|
Annotation currentAnnotation = annotations[i];
|
||||||
org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.Feature.class.getName())) {
|
feature = processHttpMethodAnnotation(feature, currentAnnotation);
|
||||||
Feature feature = new Feature();
|
if (currentAnnotation.annotationType().getName().equals(Path.class.getName())) {
|
||||||
Method[] featureAnnoMethods = featureClazz.getMethods();
|
String uri = getPathAnnotationValue(currentMethod);
|
||||||
Annotation featureAnno = method.getAnnotation(featureClazz);
|
apiParams.put("uri", uri);
|
||||||
|
|
||||||
for (int k = 0; k < featureAnnoMethods.length; k++) {
|
|
||||||
switch (featureAnnoMethods[k].getName()) {
|
|
||||||
case "name":
|
|
||||||
feature.setName(invokeMethod(featureAnnoMethods[k], featureAnno, STRING));
|
|
||||||
break;
|
|
||||||
case "code":
|
|
||||||
feature.setCode(invokeMethod(featureAnnoMethods[k], featureAnno, STRING));
|
|
||||||
break;
|
|
||||||
case "description":
|
|
||||||
feature.setDescription(invokeMethod(featureAnnoMethods[k], featureAnno, STRING));
|
|
||||||
break;
|
|
||||||
case "type":
|
|
||||||
feature.setType(invokeMethod(featureAnnoMethods[k], featureAnno, STRING));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//Extracting method with which feature is exposed
|
|
||||||
if (annotations[i].annotationType().getName().equals(GET.class.getName())) {
|
|
||||||
feature.setMethod(HttpMethod.GET);
|
|
||||||
}
|
|
||||||
if (annotations[i].annotationType().getName().equals(POST.class.getName())) {
|
|
||||||
feature.setMethod(HttpMethod.POST);
|
|
||||||
}
|
|
||||||
if (annotations[i].annotationType().getName().equals(OPTIONS.class.getName())) {
|
|
||||||
feature.setMethod(HttpMethod.OPTIONS);
|
|
||||||
}
|
|
||||||
if (annotations[i].annotationType().getName().equals(DELETE.class.getName())) {
|
|
||||||
feature.setMethod(HttpMethod.DELETE);
|
|
||||||
}
|
|
||||||
if (annotations[i].annotationType().getName().equals(PUT.class.getName())) {
|
|
||||||
feature.setMethod(HttpMethod.PUT);
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
Class<FormParam> formParamClazz = (Class<FormParam>) classLoader.loadClass(
|
|
||||||
FormParam.class.getName());
|
|
||||||
Method[] formMethods = formParamClazz.getMethods();
|
|
||||||
//Extract method parameter information and store same as feature meta info
|
|
||||||
List<Feature.MetadataEntry> metaInfoList = new ArrayList<>();
|
|
||||||
Annotation[][] paramAnnotations = method.getParameterAnnotations();
|
|
||||||
for (int j = 0; j < paramAnnotations.length; j++) {
|
|
||||||
for (Annotation anno : paramAnnotations[j]) {
|
|
||||||
if (anno.annotationType().getName().equals(FormParam.class.getName())) {
|
|
||||||
Feature.MetadataEntry metadataEntry = new Feature.MetadataEntry();
|
|
||||||
metadataEntry.setId(j);
|
|
||||||
metadataEntry.setValue(invokeMethod(formMethods[0], anno, STRING));
|
|
||||||
metaInfoList.add(metadataEntry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
feature.setMetadataEntries(metaInfoList);
|
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
log.debug("No Form Param found for class " + featureClazz.getName());
|
|
||||||
}
|
|
||||||
featureList.add(feature);
|
|
||||||
}
|
}
|
||||||
|
apiParams = processParamAnnotations(apiParams, currentMethod);
|
||||||
}
|
}
|
||||||
|
metadataEntry.setValue(apiParams);
|
||||||
|
List<Feature.MetadataEntry> metaInfoList = new ArrayList<>();
|
||||||
|
metaInfoList.add(metadataEntry);
|
||||||
|
feature.setMetadataEntries(metaInfoList);
|
||||||
|
featureList.add(feature);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return featureList;
|
return featureList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Map<String, Object> processParamAnnotations(Map<String, Object> apiParams, Method currentMethod) throws Throwable{
|
||||||
|
try {
|
||||||
|
apiParams.put("pathParams", processParamAnnotations(currentMethod, PathParam.class));
|
||||||
|
apiParams.put("queryParams", processParamAnnotations(currentMethod, QueryParam.class));
|
||||||
|
apiParams.put("formParams", processParamAnnotations(currentMethod, FormParam.class));
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
log.debug("No Form Param found for class " + featureAnnotationClazz.getName());
|
||||||
|
}
|
||||||
|
return apiParams;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<String> processParamAnnotations(Method currentMethod, Class<?> clazz) throws Throwable{
|
||||||
|
List<String> params = new ArrayList<>();
|
||||||
|
try {
|
||||||
|
Class<?> paramClazz = (Class<?>) classLoader.loadClass(clazz.getName());
|
||||||
|
Method[] formMethods = paramClazz.getMethods();
|
||||||
|
//Extract method parameter information and store same as feature meta info
|
||||||
|
Annotation[][] paramAnnotations = currentMethod.getParameterAnnotations();
|
||||||
|
Method valueMethod = formMethods[0];
|
||||||
|
for (int j = 0; j < paramAnnotations.length; j++) {
|
||||||
|
for (Annotation anno : paramAnnotations[j]) {
|
||||||
|
if (anno.annotationType().getName().equals(clazz.getName())) {
|
||||||
|
params.add(invokeMethod(valueMethod, anno, STRING));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
log.debug("No "+ clazz.getName() +" Param found for class " + featureAnnotationClazz.getName());
|
||||||
|
}
|
||||||
|
return params;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Feature processHttpMethodAnnotation(Feature feature, Annotation currentAnnotation) {
|
||||||
|
//Extracting method with which feature is exposed
|
||||||
|
if (currentAnnotation.annotationType().getName().equals(GET.class.getName())) {
|
||||||
|
feature.setMethod(HttpMethod.GET);
|
||||||
|
} else if (currentAnnotation.annotationType().getName().equals(POST.class.getName())) {
|
||||||
|
feature.setMethod(HttpMethod.POST);
|
||||||
|
} else if (currentAnnotation.annotationType().getName().equals(OPTIONS.class.getName())) {
|
||||||
|
feature.setMethod(HttpMethod.OPTIONS);
|
||||||
|
} else if (currentAnnotation.annotationType().getName().equals(DELETE.class.getName())) {
|
||||||
|
feature.setMethod(HttpMethod.DELETE);
|
||||||
|
} else if (currentAnnotation.annotationType().getName().equals(PUT.class.getName())) {
|
||||||
|
feature.setMethod(HttpMethod.PUT);
|
||||||
|
}
|
||||||
|
return feature;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Feature processFeatureAnnotation(Feature feature, Method currentMethod) throws Throwable{
|
||||||
|
Method[] featureAnnoMethods = featureAnnotationClazz.getMethods();
|
||||||
|
Annotation featureAnno = currentMethod.getAnnotation(featureAnnotationClazz);
|
||||||
|
for (int k = 0; k < featureAnnoMethods.length; k++) {
|
||||||
|
switch (featureAnnoMethods[k].getName()) {
|
||||||
|
case "name":
|
||||||
|
feature.setName(invokeMethod(featureAnnoMethods[k], featureAnno, STRING));
|
||||||
|
break;
|
||||||
|
case "code":
|
||||||
|
feature.setCode(invokeMethod(featureAnnoMethods[k], featureAnno, STRING));
|
||||||
|
break;
|
||||||
|
case "description":
|
||||||
|
feature.setDescription(invokeMethod(featureAnnoMethods[k], featureAnno, STRING));
|
||||||
|
break;
|
||||||
|
case "type":
|
||||||
|
feature.setType(invokeMethod(featureAnnoMethods[k], featureAnno, STRING));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return feature;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPathAnnotationValue(Method currentMethod) throws Throwable{
|
||||||
|
String uri = "";
|
||||||
|
try {
|
||||||
|
Class<Path> pathClazz = (Class<Path>) classLoader.loadClass(Path.class.getName());
|
||||||
|
Annotation pathAnnno = currentMethod.getAnnotation(pathClazz);
|
||||||
|
Method[] pathMethods = pathClazz.getMethods();
|
||||||
|
Method valueMethod = pathMethods[0];
|
||||||
|
uri = invokeMethod(valueMethod, pathAnnno, STRING);
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
log.debug("No Path Param found for class " + featureAnnotationClazz.getName());
|
||||||
|
}
|
||||||
|
return uri;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When an annotation and method is passed, this method invokes that executes said method against the annotation
|
* When an annotation and method is passed, this method invokes that executes said method against the annotation
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -25,6 +25,8 @@ var constants = require("/app/modules/constants.js");
|
|||||||
var deviceModule = require("/app/modules/device.js").deviceModule;
|
var deviceModule = require("/app/modules/device.js").deviceModule;
|
||||||
var utility = require("/app/modules/utility.js").utility;
|
var utility = require("/app/modules/utility.js").utility;
|
||||||
var devicemgtProps = require('/app/conf/devicemgt-props.js').config();
|
var devicemgtProps = require('/app/conf/devicemgt-props.js').config();
|
||||||
|
var userModule = require("/app/modules/user.js").userModule;
|
||||||
|
var serviceInvokers = require("/app/modules/backend-service-invoker.js").backendServiceInvoker;
|
||||||
|
|
||||||
var CarbonUtils = Packages.org.wso2.carbon.utils.CarbonUtils;
|
var CarbonUtils = Packages.org.wso2.carbon.utils.CarbonUtils;
|
||||||
var user = session.get(constants.USER_SESSION_KEY);
|
var user = session.get(constants.USER_SESSION_KEY);
|
||||||
@ -159,6 +161,88 @@ if (!user) {
|
|||||||
var deviceType = elements.deviceType;
|
var deviceType = elements.deviceType;
|
||||||
var deviceName = request.getParameter("name");
|
var deviceName = request.getParameter("name");
|
||||||
result = deviceModule.updateDevice(deviceType, deviceId, deviceName);
|
result = deviceModule.updateDevice(deviceType, deviceId, deviceName);
|
||||||
|
} else if (uriMatcher.match("/{context}/api/devices")) {
|
||||||
|
var url = request.getParameter("url");
|
||||||
|
var draw = request.getParameter("draw");
|
||||||
|
var length = request.getParameter("length");
|
||||||
|
var start = request.getParameter("start");
|
||||||
|
var search = request.getParameter("search[value]");
|
||||||
|
var deviceName = request.getParameter("columns[1][search][value]");
|
||||||
|
var owner = request.getParameter("columns[2][search][value]");
|
||||||
|
var status = request.getParameter("columns[3][search][value]");
|
||||||
|
var platform = request.getParameter("columns[4][search][value]");
|
||||||
|
var ownership = request.getParameter("columns[5][search][value]");
|
||||||
|
var targetURL;
|
||||||
|
|
||||||
|
function appendQueryParam (url, queryParam , value) {
|
||||||
|
if (url.indexOf("?") > 0) {
|
||||||
|
return url + "&" + queryParam + "=" + value;
|
||||||
|
}
|
||||||
|
return url + "?" + queryParam + "=" + value;
|
||||||
|
}
|
||||||
|
targetURL = devicemgtProps.httpsURL + request.getParameter("url");
|
||||||
|
targetURL = appendQueryParam(targetURL, "draw", draw);
|
||||||
|
targetURL = appendQueryParam(targetURL, "start", start);
|
||||||
|
targetURL = appendQueryParam(targetURL, "length", length);
|
||||||
|
|
||||||
|
if (search && search !== "") {
|
||||||
|
targetURL = appendQueryParam(targetURL, "search", search);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (deviceName && deviceName !== "") {
|
||||||
|
targetURL = appendQueryParam(targetURL, "device-name", deviceName);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (owner && owner !== "") {
|
||||||
|
targetURL = appendQueryParam(targetURL, "user", owner);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (status && status !== "") {
|
||||||
|
targetURL = appendQueryParam(targetURL, "status", status);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (platform && platform !== "") {
|
||||||
|
targetURL = appendQueryParam(targetURL, "type", platform);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ownership && ownership !== "") {
|
||||||
|
targetURL = appendQueryParam(targetURL, "ownership", ownership);
|
||||||
|
}
|
||||||
|
|
||||||
|
serviceInvokers.XMLHttp.get(
|
||||||
|
targetURL, function (responsePayload) {
|
||||||
|
response.status = 200;
|
||||||
|
result = responsePayload;
|
||||||
|
},
|
||||||
|
function (responsePayload) {
|
||||||
|
response.status = responsePayload.status;
|
||||||
|
result = responsePayload.responseText;
|
||||||
|
});
|
||||||
|
} else if (uriMatcher.match("/{context}/api/devices/")) {
|
||||||
|
if (userModule.isAuthorized("/permission/admin/device-mgt/admin/devices/list")) {
|
||||||
|
result = deviceModule.listDevices();
|
||||||
|
} else {
|
||||||
|
response.sendError(403);
|
||||||
|
}
|
||||||
|
} else if (uriMatcher.match("/{context}/api/devices/{type}/{deviceId}")) {
|
||||||
|
elements = uriMatcher.elements();
|
||||||
|
deviceId = elements.deviceId;
|
||||||
|
type = elements.type;
|
||||||
|
if (userModule.isAuthorized("/permission/admin/device-mgt/admin/devices/list")) {
|
||||||
|
result = deviceModule.viewDevice(type, deviceId);
|
||||||
|
}else {
|
||||||
|
response.sendError(403);
|
||||||
|
}
|
||||||
|
} else if (uriMatcher.match("{context}/api/devices/{type}/{deviceId}/{operation}")) {
|
||||||
|
elements = uriMatcher.elements();
|
||||||
|
deviceId = elements.deviceId;
|
||||||
|
type = elements.type;
|
||||||
|
operation = elements.operation;
|
||||||
|
if (userModule.isAuthorized("/permission/admin/device-mgt/admin/devices/operation")) {
|
||||||
|
result = deviceModule.performOperation(deviceId, operation, [], type);
|
||||||
|
} else {
|
||||||
|
response.sendError(403);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -30,11 +30,13 @@ var result;
|
|||||||
|
|
||||||
if (uriMatcher.match("/{context}/api/invoker/execute/")) {
|
if (uriMatcher.match("/{context}/api/invoker/execute/")) {
|
||||||
var method = request.getContent().actionMethod;
|
var method = request.getContent().actionMethod;
|
||||||
var targetURL = devicemgtProps.httpsURL + request.getContent().actionUrl;
|
var targetURL = getTargetUrl(devicemgtProps.httpsURL, request.getContent().actionUrl);
|
||||||
var payload = request.getContent().actionPayload;
|
var payload = request.getContent().actionPayload;
|
||||||
|
var contentType = request.getHeader(constants.CONTENT_TYPE_IDENTIFIER);
|
||||||
|
var acceptType = request.getHeader(constants.ACCEPT_IDENTIFIER);
|
||||||
if (method == undefined && payload == undefined) {
|
if (method == undefined && payload == undefined) {
|
||||||
method = parse(request.getContent()).actionMethod;
|
method = parse(request.getContent()).actionMethod;
|
||||||
targetURL = devicemgtProps.httpsURL + parse(request.getContent()).actionUrl;
|
targetURL = getTargetUrl(devicemgtProps.httpsURL, parse(request.getContent()).actionUrl);
|
||||||
payload = parse(request.getContent()).actionPayload;
|
payload = parse(request.getContent()).actionPayload;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@ -48,7 +50,9 @@ if (uriMatcher.match("/{context}/api/invoker/execute/")) {
|
|||||||
function (responsePayload) {
|
function (responsePayload) {
|
||||||
response.status = responsePayload.status;
|
response.status = responsePayload.status;
|
||||||
response.content = responsePayload.responseText;
|
response.content = responsePayload.responseText;
|
||||||
});
|
},
|
||||||
|
contentType,
|
||||||
|
acceptType);
|
||||||
break;
|
break;
|
||||||
case constants.HTTP_POST:
|
case constants.HTTP_POST:
|
||||||
var responseData = serviceInvokers.XMLHttp.post(
|
var responseData = serviceInvokers.XMLHttp.post(
|
||||||
@ -59,7 +63,9 @@ if (uriMatcher.match("/{context}/api/invoker/execute/")) {
|
|||||||
function (responsePayload) {
|
function (responsePayload) {
|
||||||
response.status = responsePayload.status;
|
response.status = responsePayload.status;
|
||||||
response.content = responsePayload.responseText;
|
response.content = responsePayload.responseText;
|
||||||
});
|
},
|
||||||
|
contentType,
|
||||||
|
acceptType);
|
||||||
break;
|
break;
|
||||||
case constants.HTTP_PUT:
|
case constants.HTTP_PUT:
|
||||||
var responseData = serviceInvokers.XMLHttp.put(
|
var responseData = serviceInvokers.XMLHttp.put(
|
||||||
@ -70,19 +76,22 @@ if (uriMatcher.match("/{context}/api/invoker/execute/")) {
|
|||||||
function (responsePayload) {
|
function (responsePayload) {
|
||||||
response.status = responsePayload.status;
|
response.status = responsePayload.status;
|
||||||
response.content = responsePayload.responseText;
|
response.content = responsePayload.responseText;
|
||||||
});
|
},
|
||||||
|
contentType,
|
||||||
|
acceptType);
|
||||||
break;
|
break;
|
||||||
case constants.HTTP_DELETE:
|
case constants.HTTP_DELETE:
|
||||||
var responseData =
|
var responseData = serviceInvokers.XMLHttp.delete(
|
||||||
serviceInvokers.XMLHttp.delete(
|
targetURL, function (responsePayload) {
|
||||||
targetURL, function (responsePayload) {
|
response.status = 200;
|
||||||
response.status = 200;
|
response.content = responsePayload;
|
||||||
response.content = responsePayload;
|
},
|
||||||
},
|
function (responsePayload) {
|
||||||
function (responsePayload) {
|
response.status = responsePayload.status;
|
||||||
response.status = responsePayload.status;
|
response.content = responsePayload.responseText;
|
||||||
response.content = responsePayload.responseText;
|
},
|
||||||
});
|
contentType,
|
||||||
|
acceptType);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -90,4 +99,12 @@ if (uriMatcher.match("/{context}/api/invoker/execute/")) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getTargetUrl(serverUrl, actionUrl){
|
||||||
|
if(actionUrl == undefined || actionUrl.lastIndexOf("http", 0) === 0){
|
||||||
|
return actionUrl;
|
||||||
|
} else {
|
||||||
|
return serverUrl + actionUrl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
%>
|
%>
|
||||||
|
|||||||
@ -46,7 +46,6 @@ if (uriMatcher.match("/{context}/api/user/authenticate")) {
|
|||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("User Logged In : " + user);
|
log.debug("User Logged In : " + user);
|
||||||
}
|
}
|
||||||
utility.insertAppPermissions(userModule, "login");
|
|
||||||
apiWrapperUtil.setupAccessTokenPair("password", {
|
apiWrapperUtil.setupAccessTokenPair("password", {
|
||||||
"username": username,
|
"username": username,
|
||||||
"password": password
|
"password": password
|
||||||
@ -69,7 +68,6 @@ if (uriMatcher.match("/{context}/api/user/authenticate")) {
|
|||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("User Logged In : " + user);
|
log.debug("User Logged In : " + user);
|
||||||
}
|
}
|
||||||
utility.insertAppPermissions(userModule, "login");
|
|
||||||
apiWrapperUtil.setupAccessTokenPair("password", {"username": username, "password": password});
|
apiWrapperUtil.setupAccessTokenPair("password", {"username": username, "password": password});
|
||||||
var permissions = userModule.getUIPermissions();
|
var permissions = userModule.getUIPermissions();
|
||||||
if (permissions.VIEW_DASHBOARD) {
|
if (permissions.VIEW_DASHBOARD) {
|
||||||
|
|||||||
@ -20,6 +20,7 @@ var apiWrapperUtil = function () {
|
|||||||
var module = {};
|
var module = {};
|
||||||
var tokenUtil = require("/app/modules/util.js").util;
|
var tokenUtil = require("/app/modules/util.js").util;
|
||||||
var constants = require("/app/modules/constants.js");
|
var constants = require("/app/modules/constants.js");
|
||||||
|
var constants = require("/app/modules/constants.js");
|
||||||
|
|
||||||
module.refreshToken = function () {
|
module.refreshToken = function () {
|
||||||
var tokenPair = session.get(constants.ACCESS_TOKEN_PAIR_IDENTIFIER);
|
var tokenPair = session.get(constants.ACCESS_TOKEN_PAIR_IDENTIFIER);
|
||||||
@ -32,12 +33,12 @@ var apiWrapperUtil = function () {
|
|||||||
var clientData = tokenUtil.getDyanmicCredentials(properties);
|
var clientData = tokenUtil.getDyanmicCredentials(properties);
|
||||||
var encodedClientKeys = tokenUtil.encode(clientData.clientId + ":" + clientData.clientSecret);
|
var encodedClientKeys = tokenUtil.encode(clientData.clientId + ":" + clientData.clientSecret);
|
||||||
session.put(constants.ENCODED_CLIENT_KEYS_IDENTIFIER, encodedClientKeys);
|
session.put(constants.ENCODED_CLIENT_KEYS_IDENTIFIER, encodedClientKeys);
|
||||||
if (type == "password") {
|
if (type == constants.GRANT_TYPE_PASSWORD) {
|
||||||
tokenPair =
|
tokenPair =
|
||||||
tokenUtil.getTokenWithPasswordGrantType(properties.username, encodeURIComponent(properties.password), encodedClientKeys);
|
tokenUtil.getTokenWithPasswordGrantType(properties.username, encodeURIComponent(properties.password), encodedClientKeys);
|
||||||
} else if (type == "saml") {
|
} else if (type == constants.GRANT_TYPE_SAML) {
|
||||||
tokenPair = tokenUtil.
|
tokenPair = tokenUtil.
|
||||||
getTokenWithSAMLGrantType(properties.samlToken, encodedClientKeys, "PRODUCTION");
|
getTokenWithSAMLGrantType(properties.samlToken, encodedClientKeys, "PRODUCTION");
|
||||||
}
|
}
|
||||||
session.put(constants.ACCESS_TOKEN_PAIR_IDENTIFIER, tokenPair);
|
session.put(constants.ACCESS_TOKEN_PAIR_IDENTIFIER, tokenPair);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -54,11 +54,17 @@ var backendServiceInvoker = function () {
|
|||||||
* @param errorCallback a function to be called if en error is reserved.
|
* @param errorCallback a function to be called if en error is reserved.
|
||||||
* @param count a counter which hold the number of recursive execution
|
* @param count a counter which hold the number of recursive execution
|
||||||
*/
|
*/
|
||||||
privateMethods.execute = function (method, url, successCallback, errorCallback, payload, count) {
|
privateMethods.execute = function (method, url, successCallback, errorCallback, payload, count, contentType, acceptType) {
|
||||||
var xmlHttpRequest = new XMLHttpRequest();
|
var xmlHttpRequest = new XMLHttpRequest();
|
||||||
xmlHttpRequest.open(method, url);
|
xmlHttpRequest.open(method, url);
|
||||||
xmlHttpRequest.setRequestHeader(constants.CONTENT_TYPE_IDENTIFIER, constants.APPLICATION_JSON);
|
if(!contentType){
|
||||||
xmlHttpRequest.setRequestHeader(constants.ACCEPT_IDENTIFIER, constants.APPLICATION_JSON);
|
contentType = constants.APPLICATION_JSON;
|
||||||
|
}
|
||||||
|
if(!acceptType){
|
||||||
|
acceptType = constants.APPLICATION_JSON;
|
||||||
|
}
|
||||||
|
xmlHttpRequest.setRequestHeader(constants.CONTENT_TYPE_IDENTIFIER, contentType);
|
||||||
|
xmlHttpRequest.setRequestHeader(constants.ACCEPT_IDENTIFIER, acceptType);
|
||||||
if (IS_OAUTH_ENABLED) {
|
if (IS_OAUTH_ENABLED) {
|
||||||
var accessToken = privateMethods.getAccessToken();
|
var accessToken = privateMethods.getAccessToken();
|
||||||
if (!accessToken) {
|
if (!accessToken) {
|
||||||
@ -98,9 +104,9 @@ var backendServiceInvoker = function () {
|
|||||||
* @param successCallback a function to be called if the respond if successful.
|
* @param successCallback a function to be called if the respond if successful.
|
||||||
* @param errorCallback a function to be called if en error is reserved.
|
* @param errorCallback a function to be called if en error is reserved.
|
||||||
*/
|
*/
|
||||||
privateMethods.initiateXMLHTTPRequest = function (method, url, successCallback, errorCallback, payload) {
|
privateMethods.initiateXMLHTTPRequest = function (method, url, successCallback, errorCallback, payload, contentType, acceptType) {
|
||||||
if (privateMethods.getAccessToken()) {
|
if (privateMethods.getAccessToken()) {
|
||||||
return privateMethods.execute(method, url, successCallback, errorCallback, payload, 0);
|
return privateMethods.execute(method, url, successCallback, errorCallback, payload, 0, contentType, acceptType);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -112,7 +118,7 @@ var backendServiceInvoker = function () {
|
|||||||
* @param successCallback a function to be called if the respond if successful.
|
* @param successCallback a function to be called if the respond if successful.
|
||||||
* @param errorCallback a function to be called if en error is reserved.
|
* @param errorCallback a function to be called if en error is reserved.
|
||||||
*/
|
*/
|
||||||
privateMethods.initiateHTTPClientRequest = function (method, url, successCallback, errorCallback, payload) {
|
privateMethods.initiateHTTPClientRequest = function (method, url, successCallback, errorCallback, payload, contentType, acceptType) {
|
||||||
var HttpClient = Packages.org.apache.commons.httpclient.HttpClient;
|
var HttpClient = Packages.org.apache.commons.httpclient.HttpClient;
|
||||||
var httpMethodObject;
|
var httpMethodObject;
|
||||||
switch (method) {
|
switch (method) {
|
||||||
@ -138,11 +144,11 @@ var backendServiceInvoker = function () {
|
|||||||
var Header = Packages.org.apache.commons.httpclient.Header;
|
var Header = Packages.org.apache.commons.httpclient.Header;
|
||||||
var header = new Header();
|
var header = new Header();
|
||||||
header.setName(constants.CONTENT_TYPE_IDENTIFIER);
|
header.setName(constants.CONTENT_TYPE_IDENTIFIER);
|
||||||
header.setValue(constants.APPLICATION_JSON);
|
header.setValue(contentType);
|
||||||
httpMethodObject.addRequestHeader(header);
|
httpMethodObject.addRequestHeader(header);
|
||||||
header = new Header();
|
header = new Header();
|
||||||
header.setName(constants.ACCEPT_IDENTIFIER);
|
header.setName(constants.ACCEPT_IDENTIFIER);
|
||||||
header.setValue(constants.APPLICATION_JSON);
|
header.setValue(acceptType);
|
||||||
httpMethodObject.addRequestHeader(header);
|
httpMethodObject.addRequestHeader(header);
|
||||||
if (IS_OAUTH_ENABLED) {
|
if (IS_OAUTH_ENABLED) {
|
||||||
var accessToken = privateMethods.getAccessToken();
|
var accessToken = privateMethods.getAccessToken();
|
||||||
@ -226,8 +232,8 @@ var backendServiceInvoker = function () {
|
|||||||
* @param successCallback a function to be called if the respond if successful.
|
* @param successCallback a function to be called if the respond if successful.
|
||||||
* @param errorCallback a function to be called if en error is reserved.
|
* @param errorCallback a function to be called if en error is reserved.
|
||||||
*/
|
*/
|
||||||
publicXMLHTTPInvokers.get = function (url, successCallback, errorCallback) {
|
publicXMLHTTPInvokers.get = function (url, successCallback, errorCallback, contentType, acceptType) {
|
||||||
return privateMethods.initiateXMLHTTPRequest(constants.HTTP_GET, url, successCallback, errorCallback);
|
return privateMethods.initiateXMLHTTPRequest(constants.HTTP_GET, url, successCallback, errorCallback, contentType, acceptType);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -237,8 +243,8 @@ var backendServiceInvoker = function () {
|
|||||||
* @param successCallback a function to be called if the respond if successful.
|
* @param successCallback a function to be called if the respond if successful.
|
||||||
* @param errorCallback a function to be called if en error is reserved.
|
* @param errorCallback a function to be called if en error is reserved.
|
||||||
*/
|
*/
|
||||||
publicXMLHTTPInvokers.post = function (url, payload, successCallback, errorCallback) {
|
publicXMLHTTPInvokers.post = function (url, payload, successCallback, errorCallback, contentType, acceptType) {
|
||||||
return privateMethods.initiateXMLHTTPRequest(constants.HTTP_POST, url, successCallback, errorCallback, payload);
|
return privateMethods.initiateXMLHTTPRequest(constants.HTTP_POST, url, successCallback, errorCallback, payload, contentType, acceptType);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -248,8 +254,8 @@ var backendServiceInvoker = function () {
|
|||||||
* @param successCallback a function to be called if the respond if successful.
|
* @param successCallback a function to be called if the respond if successful.
|
||||||
* @param errorCallback a function to be called if en error is reserved.
|
* @param errorCallback a function to be called if en error is reserved.
|
||||||
*/
|
*/
|
||||||
publicXMLHTTPInvokers.put = function (url, payload, successCallback, errorCallback) {
|
publicXMLHTTPInvokers.put = function (url, payload, successCallback, errorCallback, contentType, acceptType) {
|
||||||
return privateMethods.initiateXMLHTTPRequest(constants.HTTP_PUT, url, successCallback, errorCallback, payload);
|
return privateMethods.initiateXMLHTTPRequest(constants.HTTP_PUT, url, successCallback, errorCallback, payload, contentType, acceptType);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -258,8 +264,8 @@ var backendServiceInvoker = function () {
|
|||||||
* @param successCallback a function to be called if the respond if successful.
|
* @param successCallback a function to be called if the respond if successful.
|
||||||
* @param errorCallback a function to be called if en error is reserved.
|
* @param errorCallback a function to be called if en error is reserved.
|
||||||
*/
|
*/
|
||||||
publicXMLHTTPInvokers.delete = function (url, successCallback, errorCallback) {
|
publicXMLHTTPInvokers.delete = function (url, successCallback, errorCallback, contentType, acceptType) {
|
||||||
return privateMethods.initiateXMLHTTPRequest(constants.HTTP_DELETE, url, successCallback, errorCallback);
|
return privateMethods.initiateXMLHTTPRequest(constants.HTTP_DELETE, url, successCallback, errorCallback, contentType, acceptType);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -281,8 +287,8 @@ var backendServiceInvoker = function () {
|
|||||||
* @param successCallback a function to be called if the respond if successful.
|
* @param successCallback a function to be called if the respond if successful.
|
||||||
* @param errorCallback a function to be called if en error is reserved.
|
* @param errorCallback a function to be called if en error is reserved.
|
||||||
*/
|
*/
|
||||||
publicHTTPClientInvokers.get = function (url, successCallback, errorCallback) {
|
publicHTTPClientInvokers.get = function (url, successCallback, errorCallback, contentType, acceptType) {
|
||||||
return privateMethods.initiateHTTPClientRequest(constants.HTTP_GET, url, successCallback, errorCallback);
|
return privateMethods.initiateHTTPClientRequest(constants.HTTP_GET, url, successCallback, errorCallback, contentType, acceptType);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -292,9 +298,9 @@ var backendServiceInvoker = function () {
|
|||||||
* @param successCallback a function to be called if the respond if successful.
|
* @param successCallback a function to be called if the respond if successful.
|
||||||
* @param errorCallback a function to be called if en error is reserved.
|
* @param errorCallback a function to be called if en error is reserved.
|
||||||
*/
|
*/
|
||||||
publicHTTPClientInvokers.post = function (url, payload, successCallback, errorCallback) {
|
publicHTTPClientInvokers.post = function (url, payload, successCallback, errorCallback, contentType, acceptType) {
|
||||||
return privateMethods.
|
return privateMethods.
|
||||||
initiateHTTPClientRequest(constants.HTTP_POST, url, successCallback, errorCallback, payload);
|
initiateHTTPClientRequest(constants.HTTP_POST, url, successCallback, errorCallback, payload, contentType, acceptType);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -304,8 +310,8 @@ var backendServiceInvoker = function () {
|
|||||||
* @param successCallback a function to be called if the respond if successful.
|
* @param successCallback a function to be called if the respond if successful.
|
||||||
* @param errorCallback a function to be called if en error is reserved.
|
* @param errorCallback a function to be called if en error is reserved.
|
||||||
*/
|
*/
|
||||||
publicHTTPClientInvokers.put = function (url, payload, successCallback, errorCallback) {
|
publicHTTPClientInvokers.put = function (url, payload, successCallback, errorCallback, contentType, acceptType) {
|
||||||
return privateMethods.initiateHTTPClientRequest(constants.HTTP_PUT, url, successCallback, errorCallback, payload);
|
return privateMethods.initiateHTTPClientRequest(constants.HTTP_PUT, url, successCallback, errorCallback, payload, contentType, acceptType);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -314,8 +320,8 @@ var backendServiceInvoker = function () {
|
|||||||
* @param successCallback a function to be called if the respond if successful.
|
* @param successCallback a function to be called if the respond if successful.
|
||||||
* @param errorCallback a function to be called if en error is reserved.
|
* @param errorCallback a function to be called if en error is reserved.
|
||||||
*/
|
*/
|
||||||
publicHTTPClientInvokers.delete = function (url, successCallback, errorCallback) {
|
publicHTTPClientInvokers.delete = function (url, successCallback, errorCallback, contentType, acceptType) {
|
||||||
return privateMethods.initiateHTTPClientRequest(constants.HTTP_DELETE, url, successCallback, errorCallback);
|
return privateMethods.initiateHTTPClientRequest(constants.HTTP_DELETE, url, successCallback, errorCallback, contentType, acceptType);
|
||||||
};
|
};
|
||||||
|
|
||||||
var publicInvokers = {};
|
var publicInvokers = {};
|
||||||
|
|||||||
@ -48,8 +48,8 @@ var LANGUAGE_US = "en_US";
|
|||||||
|
|
||||||
var VENDOR_APPLE = "Apple";
|
var VENDOR_APPLE = "Apple";
|
||||||
var ERRORS = {
|
var ERRORS = {
|
||||||
"USER_NOT_FOUND": "USER_NOT_FOUND"
|
"USER_NOT_FOUND": "USER_NOT_FOUND"
|
||||||
};
|
};
|
||||||
|
|
||||||
var USER_STORES_NOISY_CHAR = "\"";
|
var USER_STORES_NOISY_CHAR = "\"";
|
||||||
var USER_STORES_SPLITTING_CHAR = "\\n";
|
var USER_STORES_SPLITTING_CHAR = "\\n";
|
||||||
@ -70,6 +70,9 @@ var HTTP_POST = "POST";
|
|||||||
var HTTP_PUT = "PUT";
|
var HTTP_PUT = "PUT";
|
||||||
var HTTP_DELETE = "DELETE";
|
var HTTP_DELETE = "DELETE";
|
||||||
|
|
||||||
|
var GRANT_TYPE_PASSWORD = "password";
|
||||||
|
var GRANT_TYPE_SAML = "saml";
|
||||||
|
|
||||||
var MQTT_QUEUE_CONFIG_NAME = "MQTT";
|
var MQTT_QUEUE_CONFIG_NAME = "MQTT";
|
||||||
|
|
||||||
var HTTP_CONFLICT = 409;
|
var HTTP_CONFLICT = 409;
|
||||||
|
|||||||
@ -278,9 +278,10 @@ deviceModule = function () {
|
|||||||
if (device) {
|
if (device) {
|
||||||
var propertiesList = device["properties"];
|
var propertiesList = device["properties"];
|
||||||
var properties = {};
|
var properties = {};
|
||||||
for (var i = 0; i < propertiesList.length; i++) {
|
if (propertiesList){
|
||||||
properties[propertiesList[i]["name"]] =
|
for (var i = 0; i < propertiesList.length; i++) {
|
||||||
propertiesList[i]["value"];
|
properties[propertiesList[i]["name"]] = propertiesList[i]["value"];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
var deviceObject = {};
|
var deviceObject = {};
|
||||||
deviceObject[constants["DEVICE_IDENTIFIER"]] = device["deviceIdentifier"];
|
deviceObject[constants["DEVICE_IDENTIFIER"]] = device["deviceIdentifier"];
|
||||||
|
|||||||
@ -26,7 +26,6 @@ application.put("carbonServer", carbonServer);
|
|||||||
|
|
||||||
var userModule = require("/app/modules/user.js")["userModule"];
|
var userModule = require("/app/modules/user.js")["userModule"];
|
||||||
var utility = require("/app/modules/utility.js")["utility"];
|
var utility = require("/app/modules/utility.js")["utility"];
|
||||||
utility.insertAppPermissions(userModule, "init");
|
|
||||||
|
|
||||||
var permissions = {
|
var permissions = {
|
||||||
'/permission/admin/device-mgt/devices': ['ui.execute'],
|
'/permission/admin/device-mgt/devices': ['ui.execute'],
|
||||||
|
|||||||
@ -20,16 +20,19 @@ var onSuccess;
|
|||||||
var onFail;
|
var onFail;
|
||||||
|
|
||||||
(function () {
|
(function () {
|
||||||
var log = new Log("api/user-api.jag");
|
var log = new Log("/app/modules/login.js");
|
||||||
|
var constants = require("/app/modules/constants.js");
|
||||||
onSuccess = function (context) {
|
onSuccess = function (context) {
|
||||||
|
var properties;
|
||||||
var utility = require("/app/modules/utility.js").utility;
|
var utility = require("/app/modules/utility.js").utility;
|
||||||
var apiWrapperUtil = require("/app/modules/api-wrapper-util.js").apiWrapperUtil;
|
var apiWrapperUtil = require("/app/modules/api-wrapper-util.js").apiWrapperUtil;
|
||||||
var userModule = require("/app/modules/user.js").userModule;
|
if(context.input.samlToken){
|
||||||
|
properties = {samlToken: context.input.samlToken};
|
||||||
utility.insertAppPermissions(userModule, "login");
|
apiWrapperUtil.setupAccessTokenPair(constants.GRANT_TYPE_SAML, properties);
|
||||||
var properties = {username: context.input.username, password: context.input.password};
|
}else{
|
||||||
apiWrapperUtil.setupAccessTokenPair("password", properties);
|
properties = {username: context.input.username, password: context.input.password};
|
||||||
|
apiWrapperUtil.setupAccessTokenPair(constants.GRANT_TYPE_PASSWORD, properties);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
onFail = function (error) {
|
onFail = function (error) {
|
||||||
|
|||||||
@ -21,6 +21,7 @@ var operationModule = function () {
|
|||||||
var utility = require('/app/modules/utility.js').utility;
|
var utility = require('/app/modules/utility.js').utility;
|
||||||
var constants = require('/app/modules/constants.js');
|
var constants = require('/app/modules/constants.js');
|
||||||
var devicemgtProps = require('/app/conf/devicemgt-props.js').config();
|
var devicemgtProps = require('/app/conf/devicemgt-props.js').config();
|
||||||
|
var serviceInvokers = require("/app/modules/backend-service-invoker.js").backendServiceInvoker;
|
||||||
|
|
||||||
var publicMethods = {};
|
var publicMethods = {};
|
||||||
var privateMethods = {};
|
var privateMethods = {};
|
||||||
@ -39,51 +40,46 @@ var operationModule = function () {
|
|||||||
privateMethods.getOperationsFromFeatures = function (deviceType, operationType) {
|
privateMethods.getOperationsFromFeatures = function (deviceType, operationType) {
|
||||||
var url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/features/" + deviceType;
|
var url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/features/" + deviceType;
|
||||||
var featuresList = serviceInvokers.XMLHttp.get(url, function (responsePayload) {
|
var featuresList = serviceInvokers.XMLHttp.get(url, function (responsePayload) {
|
||||||
var features = responsePayload.responseContent;
|
var features = responsePayload;
|
||||||
var featureList = [];
|
var featureList = [];
|
||||||
var feature;
|
var feature;
|
||||||
for (var i = 0; i < features.size(); i++) {
|
for (var i = 0; i < features.length; i++) {
|
||||||
feature = {};
|
feature = {};
|
||||||
if (features.get(i).getType() != operationType) {
|
if (features[i].type != operationType) {
|
||||||
continue;
|
continue;
|
||||||
} else if (features.get(i).getType() == 'monitor') {
|
} else if (features[i].type == 'monitor') {
|
||||||
var analyticStreams = utility.getDeviceTypeConfig(deviceType)["analyticStreams"];
|
var analyticStreams = utility.getDeviceTypeConfig(deviceType)["analyticStreams"];
|
||||||
if (analyticStreams) {
|
if (analyticStreams) {
|
||||||
for (var stream in analyticStreams) {
|
for (var stream in analyticStreams) {
|
||||||
if (analyticStreams[stream].name == features.get(i).getName()) {
|
if (analyticStreams[stream].name == features[i].name) {
|
||||||
feature.ui_unit = analyticStreams[stream].ui_unit;
|
feature.ui_unit = analyticStreams[stream].ui_unit;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
feature["operation"] = new String(features.get(i).getCode());
|
feature["operation"] = features[i].code;
|
||||||
feature["name"] = new String(features.get(i).getName());
|
feature["name"] = features[i].name;
|
||||||
feature["description"] = new String(features.get(i).getDescription());
|
feature["method"] = features[i].method;
|
||||||
feature["deviceType"] = new String(features.get(i).getDeviceType());
|
feature["description"] = features[i].description;
|
||||||
|
feature["deviceType"] = deviceType;
|
||||||
feature["params"] = [];
|
feature["params"] = [];
|
||||||
var metaData = features.get(i).getMetadataEntries();
|
var metaData = features[i].metadataEntries;
|
||||||
if (metaData && metaData != null) {
|
if (metaData) {
|
||||||
for (var j = 0; j < metaData.size(); j++) {
|
for (var j = 0; j < metaData.length; j++) {
|
||||||
feature["params"].push(new String(metaData.get(j).getValue()));
|
feature["params"].push(metaData[j].value);
|
||||||
}
|
}
|
||||||
featureList.push(feature);
|
featureList.push(feature);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return featureList;
|
return featureList;
|
||||||
}
|
}, function (responsePayload) {
|
||||||
,
|
|
||||||
function (responsePayload) {
|
|
||||||
var response = {};
|
var response = {};
|
||||||
response["status"] = "error";
|
response["status"] = "error";
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
return featuresList;
|
return featuresList;
|
||||||
return featureList;
|
|
||||||
} catch (e) {
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
publicMethods.getControlOperations = function (deviceType) {
|
publicMethods.getControlOperations = function (deviceType) {
|
||||||
@ -108,7 +104,6 @@ var operationModule = function () {
|
|||||||
'","protocol":"mqtt", "sessionId":"' + session.getId() + '", "' +
|
'","protocol":"mqtt", "sessionId":"' + session.getId() + '", "' +
|
||||||
constants.AUTHORIZATION_HEADER + '":"' + constants.BEARER_PREFIX +
|
constants.AUTHORIZATION_HEADER + '":"' + constants.BEARER_PREFIX +
|
||||||
getAccessToken(deviceType, user.username, deviceId) + '"}';
|
getAccessToken(deviceType, user.username, deviceId) + '"}';
|
||||||
log.warn("header: " + header);
|
|
||||||
return post(endPoint, params, JSON.parse(header), "json");
|
return post(endPoint, params, JSON.parse(header), "json");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -629,44 +629,43 @@ var userModule = function () {
|
|||||||
|
|
||||||
publicMethods.getUIPermissions = function () {
|
publicMethods.getUIPermissions = function () {
|
||||||
var permissions = {};
|
var permissions = {};
|
||||||
if (publicMethods.isAuthorized("/permission/admin/device-mgt/emm-admin/devices/list") ||
|
if (publicMethods.isAuthorized("/permission/admin/device-mgt/admin/devices/list")) {
|
||||||
publicMethods.isAuthorized("/permission/admin/device-mgt/user/devices/list")) {
|
|
||||||
permissions["LIST_DEVICES"] = true;
|
permissions["LIST_DEVICES"] = true;
|
||||||
}
|
}
|
||||||
if (publicMethods.isAuthorized("/permission/admin/device-mgt/admin/groups/list")) {
|
if (publicMethods.isAuthorized("/permission/admin/device-mgt/admin/groups/list")) {
|
||||||
permissions["LIST_GROUPS"] = true;
|
permissions["LIST_GROUPS"] = true;
|
||||||
}
|
}
|
||||||
if (publicMethods.isAuthorized("/permission/admin/device-mgt/emm-admin/users/list")) {
|
if (publicMethods.isAuthorized("/permission/admin/device-mgt/admin/users/list")) {
|
||||||
permissions["LIST_USERS"] = true;
|
permissions["LIST_USERS"] = true;
|
||||||
}
|
}
|
||||||
if (publicMethods.isAuthorized("/permission/admin/device-mgt/emm-admin/roles/list")) {
|
if (publicMethods.isAuthorized("/permission/admin/device-mgt/admin/roles/list")) {
|
||||||
permissions["LIST_ROLES"] = true;
|
permissions["LIST_ROLES"] = true;
|
||||||
}
|
}
|
||||||
if (publicMethods.isAuthorized("/permission/admin/device-mgt/emm-admin/policies/list")) {
|
if (publicMethods.isAuthorized("/permission/admin/device-mgt/admin/policies/list")) {
|
||||||
permissions["LIST_POLICIES"] = true;
|
permissions["LIST_POLICIES"] = true;
|
||||||
}
|
}
|
||||||
if (publicMethods.isAuthorized("/permission/admin/device-mgt/emm-admin/groups/add")) {
|
if (publicMethods.isAuthorized("/permission/admin/device-mgt/admin/groups/add")) {
|
||||||
permissions["ADD_GROUP"] = true;
|
permissions["ADD_GROUP"] = true;
|
||||||
}
|
}
|
||||||
if (publicMethods.isAuthorized("/permission/admin/device-mgt/emm-admin/users/add")) {
|
if (publicMethods.isAuthorized("/permission/admin/device-mgt/admin/users/add")) {
|
||||||
permissions["ADD_USER"] = true;
|
permissions["ADD_USER"] = true;
|
||||||
}
|
}
|
||||||
if (publicMethods.isAuthorized("/permission/admin/device-mgt/emm-admin/users/remove")) {
|
if (publicMethods.isAuthorized("/permission/admin/device-mgt/admin/users/remove")) {
|
||||||
permissions["REMOVE_USER"] = true;
|
permissions["REMOVE_USER"] = true;
|
||||||
}
|
}
|
||||||
if (publicMethods.isAuthorized("/permission/admin/device-mgt/emm-admin/roles/add")) {
|
if (publicMethods.isAuthorized("/permission/admin/device-mgt/admin/roles/add")) {
|
||||||
permissions["ADD_ROLE"] = true;
|
permissions["ADD_ROLE"] = true;
|
||||||
}
|
}
|
||||||
if (publicMethods.isAuthorized("/permission/admin/device-mgt/emm-admin/policies/add")) {
|
if (publicMethods.isAuthorized("/permission/admin/device-mgt/admin/policies/add")) {
|
||||||
permissions["ADD_POLICY"] = true;
|
permissions["ADD_POLICY"] = true;
|
||||||
}
|
}
|
||||||
if (publicMethods.isAuthorized("/permission/admin/device-mgt/emm-admin/policies/priority")) {
|
if (publicMethods.isAuthorized("/permission/admin/device-mgt/admin/policies/priority")) {
|
||||||
permissions["CHANGE_POLICY_PRIORITY"] = true;
|
permissions["CHANGE_POLICY_PRIORITY"] = true;
|
||||||
}
|
}
|
||||||
if (publicMethods.isAuthorized("/permission/admin/device-mgt/emm-admin/dashboard/view")) {
|
if (publicMethods.isAuthorized("/permission/admin/device-mgt/admin/dashboard/view")) {
|
||||||
permissions["VIEW_DASHBOARD"] = true;
|
permissions["VIEW_DASHBOARD"] = true;
|
||||||
}
|
}
|
||||||
if (publicMethods.isAuthorized("/permission/admin/device-mgt/emm-admin/platform-configs/view")) {
|
if (publicMethods.isAuthorized("/permission/admin/device-mgt/admin/platform-configs/view")) {
|
||||||
permissions["TENANT_CONFIGURATION"] = true;
|
permissions["TENANT_CONFIGURATION"] = true;
|
||||||
}
|
}
|
||||||
if (publicMethods.isAuthorized("/permission/admin/device-mgt/user/devices/list")) {
|
if (publicMethods.isAuthorized("/permission/admin/device-mgt/user/devices/list")) {
|
||||||
|
|||||||
@ -17,6 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
var util = function () {
|
var util = function () {
|
||||||
|
var log = new Log("/app/modules/util.js");
|
||||||
var module = {};
|
var module = {};
|
||||||
var Base64 = Packages.org.apache.commons.codec.binary.Base64;
|
var Base64 = Packages.org.apache.commons.codec.binary.Base64;
|
||||||
var String = Packages.java.lang.String;
|
var String = Packages.java.lang.String;
|
||||||
@ -123,7 +124,7 @@ var util = function () {
|
|||||||
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||||
xhr.setRequestHeader("Authorization", "Basic " + clientKeys);
|
xhr.setRequestHeader("Authorization", "Basic " + clientKeys);
|
||||||
xhr.send("grant_type=urn:ietf:params:oauth:grant-type:saml2-bearer&assertion=" +
|
xhr.send("grant_type=urn:ietf:params:oauth:grant-type:saml2-bearer&assertion=" +
|
||||||
encodeURIComponent(encodedExtractedAssertion) + "&scope=" + "PRODUCTION");
|
encodeURIComponent(encodedExtractedAssertion) + "&scope=" + "PRODUCTION");
|
||||||
var tokenPair = {};
|
var tokenPair = {};
|
||||||
if (xhr.status == 200) {
|
if (xhr.status == 200) {
|
||||||
var data = parse(xhr.responseText);
|
var data = parse(xhr.responseText);
|
||||||
|
|||||||
@ -61,159 +61,6 @@ utility = function () {
|
|||||||
return getOsgiService("org.wso2.carbon.policy.mgt.core.PolicyManagerService");
|
return getOsgiService("org.wso2.carbon.policy.mgt.core.PolicyManagerService");
|
||||||
};
|
};
|
||||||
|
|
||||||
publicMethods.insertAppPermissions = function (userModule, type) {
|
|
||||||
// Below are the 2 types of users:- Normal users and Admins
|
|
||||||
userModule.addPermissions([{
|
|
||||||
key: "admin",
|
|
||||||
name: "Device Management Admin"
|
|
||||||
}], "device-mgt", type);
|
|
||||||
userModule.addPermissions([{
|
|
||||||
key: "user",
|
|
||||||
name: "Device Management User"
|
|
||||||
}], "device-mgt", type);
|
|
||||||
|
|
||||||
// adding permission definitions for device-mgt/admin
|
|
||||||
userModule.addPermissions([{
|
|
||||||
key: "dashboard",
|
|
||||||
name: "Dashboard"
|
|
||||||
}], "device-mgt/admin", type);
|
|
||||||
userModule.addPermissions([{
|
|
||||||
key: "dashboard/view",
|
|
||||||
name: "View Dashboard"
|
|
||||||
}], "device-mgt/admin", type);
|
|
||||||
|
|
||||||
userModule.addPermissions([{
|
|
||||||
key: "devices",
|
|
||||||
name: "Devices"
|
|
||||||
}], "device-mgt/admin", type);
|
|
||||||
userModule.addPermissions([{
|
|
||||||
key: "devices/list",
|
|
||||||
name: "List All Devices"
|
|
||||||
}], "device-mgt/admin", type);
|
|
||||||
userModule.addPermissions([{
|
|
||||||
key: "devices/add",
|
|
||||||
name: "Add Device"
|
|
||||||
}], "device-mgt/admin", type);
|
|
||||||
userModule.addPermissions([{
|
|
||||||
key: "devices/edit",
|
|
||||||
name: "Edit Device"
|
|
||||||
}], "device-mgt/admin", type);
|
|
||||||
userModule.addPermissions([{
|
|
||||||
key: "devices/remove",
|
|
||||||
name: "Remove Device"
|
|
||||||
}], "device-mgt/admin", type);
|
|
||||||
userModule.addPermissions([{
|
|
||||||
key: "groups",
|
|
||||||
name: "Groups"
|
|
||||||
}], "device-mgt/admin", type);
|
|
||||||
userModule.addPermissions([{
|
|
||||||
key: "groups/list",
|
|
||||||
name: "List All Groups"
|
|
||||||
}], "device-mgt/admin", type);
|
|
||||||
userModule.addPermissions([{
|
|
||||||
key: "groups/add",
|
|
||||||
name: "Add Group"
|
|
||||||
}], "device-mgt/admin", type);
|
|
||||||
userModule.addPermissions([{
|
|
||||||
key: "devices/operation",
|
|
||||||
name: "Perform Operation on Any Device"
|
|
||||||
}], "device-mgt/admin", type);
|
|
||||||
|
|
||||||
userModule.addPermissions([{key: "users", name: "Users"}], "device-mgt/admin", type);
|
|
||||||
userModule.addPermissions([{
|
|
||||||
key: "users/add",
|
|
||||||
name: "Add New Users"
|
|
||||||
}], "device-mgt/admin", type);
|
|
||||||
userModule.addPermissions([{
|
|
||||||
key: "users/invite",
|
|
||||||
name: "Invite Users"
|
|
||||||
}], "device-mgt/admin", type);
|
|
||||||
userModule.addPermissions([{
|
|
||||||
key: "users/list",
|
|
||||||
name: "List Users"
|
|
||||||
}], "device-mgt/admin", type);
|
|
||||||
userModule.addPermissions([{
|
|
||||||
key: "users/update",
|
|
||||||
name: "Update Users"
|
|
||||||
}], "device-mgt/admin", type);
|
|
||||||
userModule.addPermissions([{
|
|
||||||
key: "users/remove",
|
|
||||||
name: "Remove Users"
|
|
||||||
}], "device-mgt/admin", type);
|
|
||||||
userModule.addPermissions([{
|
|
||||||
key: "users/reset-password",
|
|
||||||
name: "Reset User Passwords"
|
|
||||||
}], "device-mgt/admin", type);
|
|
||||||
|
|
||||||
userModule.addPermissions([{key: "roles", name: "Roles"}], "device-mgt/admin", type);
|
|
||||||
userModule.addPermissions([{
|
|
||||||
key: "roles/add",
|
|
||||||
name: "Add New Roles"
|
|
||||||
}], "device-mgt/admin", type);
|
|
||||||
userModule.addPermissions([{
|
|
||||||
key: "roles/invite",
|
|
||||||
name: "Invite Roles"
|
|
||||||
}], "device-mgt/admin", type);
|
|
||||||
userModule.addPermissions([{
|
|
||||||
key: "roles/list",
|
|
||||||
name: "List Roles"
|
|
||||||
}], "device-mgt/admin", type);
|
|
||||||
userModule.addPermissions([{
|
|
||||||
key: "roles/remove",
|
|
||||||
name: "Remove Roles"
|
|
||||||
}], "device-mgt/admin", type);
|
|
||||||
userModule.addPermissions([{
|
|
||||||
key: "roles/permission",
|
|
||||||
name: "Update Role Permission"
|
|
||||||
}], "device-mgt/admin", type);
|
|
||||||
|
|
||||||
|
|
||||||
userModule.addPermissions([{
|
|
||||||
key: "policies",
|
|
||||||
name: "Policy"
|
|
||||||
}], "device-mgt/admin", type);
|
|
||||||
userModule.addPermissions([{
|
|
||||||
key: "policies/add",
|
|
||||||
name: "Add Policy"
|
|
||||||
}], "device-mgt/admin", type);
|
|
||||||
userModule.addPermissions([{
|
|
||||||
key: "policies/list",
|
|
||||||
name: "List Policy"
|
|
||||||
}], "device-mgt/admin", type);
|
|
||||||
userModule.addPermissions([{
|
|
||||||
key: "policies/edit",
|
|
||||||
name: "Edit Policy"
|
|
||||||
}], "device-mgt/admin", type);
|
|
||||||
userModule.addPermissions([{
|
|
||||||
key: "policies/remove",
|
|
||||||
name: "Remove Policy"
|
|
||||||
}], "device-mgt/admin", type);
|
|
||||||
userModule.addPermissions([{
|
|
||||||
key: "policies/priority",
|
|
||||||
name: "Policy Priority"
|
|
||||||
}], "device-mgt/admin", type);
|
|
||||||
|
|
||||||
// adding permission definitions for device-mgt/user
|
|
||||||
userModule.addPermissions([{key: "devices", name: "Devices"}], "device-mgt/user", type);
|
|
||||||
userModule.addPermissions([{
|
|
||||||
key: "devices/list",
|
|
||||||
name: "List Individual Devices"
|
|
||||||
}], "device-mgt/user", type);
|
|
||||||
userModule.addPermissions([{
|
|
||||||
key: "devices/operation",
|
|
||||||
name: "Perform Operation on an Individual Device"
|
|
||||||
}], "device-mgt/user", type);
|
|
||||||
|
|
||||||
userModule.addPermissions([{
|
|
||||||
key: "platform-configs",
|
|
||||||
name: "Platform Configurations"
|
|
||||||
}], "device-mgt/admin", type);
|
|
||||||
userModule.addPermissions([{
|
|
||||||
key: "platform-configs/view",
|
|
||||||
name: "View Configurations"
|
|
||||||
}], "device-mgt/admin", type);
|
|
||||||
};
|
|
||||||
|
|
||||||
publicMethods.getIoTServerConfig = function (configName) {
|
publicMethods.getIoTServerConfig = function (configName) {
|
||||||
var path = "/config/iot-config.json";
|
var path = "/config/iot-config.json";
|
||||||
var file = new File(path);
|
var file = new File(path);
|
||||||
|
|||||||
@ -61,7 +61,7 @@
|
|||||||
<div>
|
<div>
|
||||||
{{unit "cdmf.unit.device.operation-mod"}}
|
{{unit "cdmf.unit.device.operation-mod"}}
|
||||||
{{#if deviceCount}}
|
{{#if deviceCount}}
|
||||||
<span id="permission" data-permission="{{{permissions}}}"></span>
|
<span id="permission" data-permission="{{permissions.list}}"></span>
|
||||||
<div id="loading-content" class="col-centered">
|
<div id="loading-content" class="col-centered">
|
||||||
<i class="fw fw-settings fw-spin fw-2x"></i>
|
<i class="fw fw-settings fw-spin fw-2x"></i>
|
||||||
|
|
||||||
@ -324,7 +324,7 @@
|
|||||||
{{/zone}}
|
{{/zone}}
|
||||||
|
|
||||||
{{#zone "bottomJs"}}
|
{{#zone "bottomJs"}}
|
||||||
<script id="device-listing" data-current-user="{{currentUser.username}}"
|
<script id="device-listing" data-current-user="{{currentUser.username}}" data-device-types="{{deviceTypes}}"
|
||||||
data-image-resource="{{@app.context}}/public/cdmf.unit.device.type."
|
data-image-resource="{{@app.context}}/public/cdmf.unit.device.type."
|
||||||
src="{{@page.publicUri}}/templates/listing.hbs"
|
src="{{@page.publicUri}}/templates/listing.hbs"
|
||||||
type="text/x-handlebars-template"></script>
|
type="text/x-handlebars-template"></script>
|
||||||
|
|||||||
@ -31,25 +31,13 @@ function onRequest(context) {
|
|||||||
page.groupName = groupName;
|
page.groupName = groupName;
|
||||||
}
|
}
|
||||||
page.title = title;
|
page.title = title;
|
||||||
page.permissions = {};
|
|
||||||
var currentUser = session.get(constants.USER_SESSION_KEY);
|
var currentUser = session.get(constants.USER_SESSION_KEY);
|
||||||
var permissions = [];
|
|
||||||
if (currentUser) {
|
if (currentUser) {
|
||||||
if (userModule.isAuthorized("/permission/admin/device-mgt/admin/devices/list")) {
|
page.permissions = {};
|
||||||
permissions.push("LIST_DEVICES");
|
page.permissions.list = stringify(userModule.getUIPermissions());
|
||||||
} else if (userModule.isAuthorized("/permission/admin/device-mgt/user/devices/list")) {
|
|
||||||
permissions.push("LIST_OWN_DEVICES");
|
|
||||||
} else if (userModule.isAuthorized("/permission/admin/device-mgt/emm-admin/policies/list")) {
|
|
||||||
permissions.push("LIST_POLICIES");
|
|
||||||
}
|
|
||||||
if (userModule.isAuthorized("/permission/admin/device-mgt/admin/devices/add")) {
|
if (userModule.isAuthorized("/permission/admin/device-mgt/admin/devices/add")) {
|
||||||
permissions.enroll = true;
|
permissions.enroll = true;
|
||||||
}
|
}
|
||||||
if (userModule.isAuthorized("/permission/admin/device-mgt/admin/devices/remove")) {
|
|
||||||
permissions.push("REMOVE_DEVICE");
|
|
||||||
}
|
|
||||||
|
|
||||||
page.permissions.list = permissions;
|
|
||||||
page.currentUser = currentUser;
|
page.currentUser = currentUser;
|
||||||
var deviceCount = 0;
|
var deviceCount = 0;
|
||||||
if (groupName && groupOwner) {
|
if (groupName && groupOwner) {
|
||||||
@ -64,15 +52,17 @@ function onRequest(context) {
|
|||||||
var utility = require("/app/modules/utility.js").utility;
|
var utility = require("/app/modules/utility.js").utility;
|
||||||
var data = deviceModule.getDeviceTypes();
|
var data = deviceModule.getDeviceTypes();
|
||||||
var deviceTypes = [];
|
var deviceTypes = [];
|
||||||
if (data.data) {
|
if (data) {
|
||||||
for (var i = 0; i < data.data.length; i++) {
|
for (var i = 0; i < data.length; i++) {
|
||||||
|
var deviceType = utility.getDeviceTypeConfig(data[i].name).deviceType;
|
||||||
deviceTypes.push({
|
deviceTypes.push({
|
||||||
"type": data.data[i].name,
|
"type": data[i].name,
|
||||||
"category": utility.getDeviceTypeConfig(data.data[i].name).deviceType.category
|
"category": deviceType.category,
|
||||||
});
|
"label": deviceType.label
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
page.deviceTypes = deviceTypes;
|
page.deviceTypes = stringify(deviceTypes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return page;
|
return page;
|
||||||
|
|||||||
@ -72,8 +72,10 @@ $(document).ready(function () {
|
|||||||
|
|
||||||
var i;
|
var i;
|
||||||
var permissionList = $("#permission").data("permission");
|
var permissionList = $("#permission").data("permission");
|
||||||
for (i = 0; i < permissionList.length; i++) {
|
for (var key in permissionList) {
|
||||||
$.setPermission(permissionList[i]);
|
if (permissionList.hasOwnProperty(key)) {
|
||||||
|
$.setPermission(key);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* for device list sorting drop down */
|
/* for device list sorting drop down */
|
||||||
@ -171,7 +173,7 @@ function loadDevices(searchType, searchParam){
|
|||||||
serviceURL = "/devicemgt_admin/devices";
|
serviceURL = "/devicemgt_admin/devices";
|
||||||
} else if ($.hasPermission("LIST_OWN_DEVICES")) {
|
} else if ($.hasPermission("LIST_OWN_DEVICES")) {
|
||||||
//Get authenticated users devices
|
//Get authenticated users devices
|
||||||
serviceURL = "/devicemgt_admin/users/devices?username="+currentUser;
|
serviceURL = "/devicemgt_admin/users/devices?username=" + currentUser;
|
||||||
} else {
|
} else {
|
||||||
$("#loading-content").remove();
|
$("#loading-content").remove();
|
||||||
$('#device-table').addClass('hidden');
|
$('#device-table').addClass('hidden');
|
||||||
@ -181,8 +183,11 @@ function loadDevices(searchType, searchParam){
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getPropertyValue(deviceProperties, propertyName) {
|
function getPropertyValue(deviceProperties, propertyName) {
|
||||||
|
if (!deviceProperties) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
var property;
|
var property;
|
||||||
for (var i =0; i < deviceProperties.length; i++) {
|
for (var i = 0; i < deviceProperties.length; i++) {
|
||||||
property = deviceProperties[i];
|
property = deviceProperties[i];
|
||||||
if (property.name == propertyName) {
|
if (property.name == propertyName) {
|
||||||
return property.value;
|
return property.value;
|
||||||
@ -191,6 +196,16 @@ function loadDevices(searchType, searchParam){
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getDeviceTypeLabel(type){
|
||||||
|
var deviceTypes = deviceListing.data("deviceTypes");
|
||||||
|
for (var i = 0; i < deviceTypes.length; i++){
|
||||||
|
if (deviceTypes[i].type == type){
|
||||||
|
return deviceTypes[i].label;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
$('#device-grid').datatables_extended ({
|
$('#device-grid').datatables_extended ({
|
||||||
serverSide: true,
|
serverSide: true,
|
||||||
processing: false,
|
processing: false,
|
||||||
@ -242,7 +257,10 @@ function loadDevices(searchType, searchParam){
|
|||||||
}
|
}
|
||||||
return html;
|
return html;
|
||||||
}},
|
}},
|
||||||
{ targets: 4, data: 'type' , className: 'fade-edge remove-padding-top' },
|
{ targets: 4, data: 'type' , className: 'fade-edge remove-padding-top' ,
|
||||||
|
render: function ( status, type, row, meta ) {
|
||||||
|
return getDeviceTypeLabel(row.type);
|
||||||
|
}},
|
||||||
{ targets: 5, data: 'enrolmentInfo.ownership' , className: 'fade-edge remove-padding-top' },
|
{ targets: 5, data: 'enrolmentInfo.ownership' , className: 'fade-edge remove-padding-top' },
|
||||||
{ targets: 6, data: 'enrolmentInfo.status' , className: 'text-right content-fill text-left-on-grid-view no-wrap' ,
|
{ targets: 6, data: 'enrolmentInfo.status' , className: 'text-right content-fill text-left-on-grid-view no-wrap' ,
|
||||||
render: function ( status, type, row, meta ) {
|
render: function ( status, type, row, meta ) {
|
||||||
|
|||||||
@ -22,33 +22,42 @@ var invokerUtil = function () {
|
|||||||
|
|
||||||
var END_POINT = window.location.origin+"/devicemgt/api/invoker/execute/";
|
var END_POINT = window.location.origin+"/devicemgt/api/invoker/execute/";
|
||||||
|
|
||||||
module.get = function (url, successCallback, errorCallback) {
|
module.get = function (url, successCallback, errorCallback, contentType, acceptType) {
|
||||||
var payload = null;
|
var payload = null;
|
||||||
execute("GET", url, payload, successCallback, errorCallback);
|
execute("GET", url, payload, successCallback, errorCallback, contentType, acceptType);
|
||||||
};
|
};
|
||||||
module.post = function (url, payload, successCallback, errorCallback) {
|
module.post = function (url, payload, successCallback, errorCallback, contentType, acceptType) {
|
||||||
execute("POST", url, payload, successCallback, errorCallback);
|
execute("POST", url, payload, successCallback, errorCallback, contentType, acceptType);
|
||||||
};
|
};
|
||||||
module.put = function (url, payload, successCallback, errorCallback) {
|
module.put = function (url, payload, successCallback, errorCallback, contentType, acceptType) {
|
||||||
execute("PUT", url, payload, successCallback, errorCallback);
|
execute("PUT", url, payload, successCallback, errorCallback, contentType, acceptType);
|
||||||
};
|
};
|
||||||
module.delete = function (url, successCallback, errorCallback) {
|
module.delete = function (url, successCallback, errorCallback, contentType, acceptType) {
|
||||||
var payload = null;
|
var payload = null;
|
||||||
execute("DELETE", url, payload, successCallback, errorCallback);
|
execute("DELETE", url, payload, successCallback, errorCallback, contentType, acceptType);
|
||||||
};
|
};
|
||||||
function execute (methoad, url, payload, successCallback, errorCallback) {
|
function execute (methoad, url, payload, successCallback, errorCallback, contentType, acceptType) {
|
||||||
|
if(contentType == undefined){
|
||||||
|
contentType = "application/json";
|
||||||
|
}
|
||||||
|
if(acceptType == undefined){
|
||||||
|
acceptType = "application/json";
|
||||||
|
}
|
||||||
var data = {
|
var data = {
|
||||||
url: END_POINT,
|
url: END_POINT,
|
||||||
type: "POST",
|
type: "POST",
|
||||||
contentType: "application/json",
|
contentType: contentType,
|
||||||
accept: "application/json",
|
accept: acceptType,
|
||||||
success: successCallback
|
success: successCallback
|
||||||
};
|
};
|
||||||
console.log(data);
|
console.log(data);
|
||||||
var paramValue = {};
|
var paramValue = {};
|
||||||
paramValue.actionMethod = methoad;
|
paramValue.actionMethod = methoad;
|
||||||
paramValue.actionUrl = url;
|
paramValue.actionUrl = url;
|
||||||
paramValue.actionPayload = JSON.stringify(payload);
|
paramValue.actionPayload = payload;
|
||||||
|
if(contentType == "application/json"){
|
||||||
|
paramValue.actionPayload = JSON.stringify(payload);
|
||||||
|
}
|
||||||
data.data = JSON.stringify(paramValue);
|
data.data = JSON.stringify(paramValue);
|
||||||
$.ajax(data).fail(function (jqXHR) {
|
$.ajax(data).fail(function (jqXHR) {
|
||||||
if (jqXHR.status == "401") {
|
if (jqXHR.status == "401") {
|
||||||
|
|||||||
@ -56,7 +56,7 @@ var module = {};
|
|||||||
cachedAuthModuleConfigs = authModuleConfigs;
|
cachedAuthModuleConfigs = authModuleConfigs;
|
||||||
} else {
|
} else {
|
||||||
log.error("Cannot find User module configurations in application configuration file '"
|
log.error("Cannot find User module configurations in application configuration file '"
|
||||||
+ constants.FILE_APP_CONF + "'.");
|
+ constants.FILE_APP_CONF + "'.");
|
||||||
cachedAuthModuleConfigs = {};
|
cachedAuthModuleConfigs = {};
|
||||||
}
|
}
|
||||||
return cachedAuthModuleConfigs;
|
return cachedAuthModuleConfigs;
|
||||||
@ -85,7 +85,7 @@ var module = {};
|
|||||||
return (rv) ? rv : {};
|
return (rv) ? rv : {};
|
||||||
} else {
|
} else {
|
||||||
log.error("Cannot find login configurations in Auth module configurations in "
|
log.error("Cannot find login configurations in Auth module configurations in "
|
||||||
+ "application configuration file '" + constants.FILE_APP_CONF + "'.");
|
+ "application configuration file '" + constants.FILE_APP_CONF + "'.");
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -113,7 +113,7 @@ var module = {};
|
|||||||
return (rv) ? rv : {};
|
return (rv) ? rv : {};
|
||||||
} else {
|
} else {
|
||||||
log.error("Cannot find logout configurations in Auth module configurations in "
|
log.error("Cannot find logout configurations in Auth module configurations in "
|
||||||
+ "application configuration file '" + constants.FILE_APP_CONF + "'.");
|
+ "application configuration file '" + constants.FILE_APP_CONF + "'.");
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -133,7 +133,7 @@ var module = {};
|
|||||||
cachedSsoConfigs = ssoConfigs;
|
cachedSsoConfigs = ssoConfigs;
|
||||||
} else {
|
} else {
|
||||||
log.error("Cannot find SSO configurations in Auth module configurations in application "
|
log.error("Cannot find SSO configurations in Auth module configurations in application "
|
||||||
+ "configuration file '" + constants.FILE_APP_CONF + "'.");
|
+ "configuration file '" + constants.FILE_APP_CONF + "'.");
|
||||||
cachedSsoConfigs = {};
|
cachedSsoConfigs = {};
|
||||||
}
|
}
|
||||||
return cachedSsoConfigs;
|
return cachedSsoConfigs;
|
||||||
@ -156,13 +156,13 @@ var module = {};
|
|||||||
if (operation == OPERATION_LOGIN) {
|
if (operation == OPERATION_LOGIN) {
|
||||||
configs = getLoginConfigurations(event);
|
configs = getLoginConfigurations(event);
|
||||||
pageFullName = (event == EVENT_SUCCESS) ?
|
pageFullName = (event == EVENT_SUCCESS) ?
|
||||||
configs[constants.APP_CONF_AUTH_MODULE_LOGIN_ON_SUCCESS_PAGE] :
|
configs[constants.APP_CONF_AUTH_MODULE_LOGIN_ON_SUCCESS_PAGE] :
|
||||||
configs[constants.APP_CONF_AUTH_MODULE_LOGIN_ON_FAIL_PAGE];
|
configs[constants.APP_CONF_AUTH_MODULE_LOGIN_ON_FAIL_PAGE];
|
||||||
} else {
|
} else {
|
||||||
configs = getLogoutConfigurations(event);
|
configs = getLogoutConfigurations(event);
|
||||||
pageFullName = (event == EVENT_SUCCESS) ?
|
pageFullName = (event == EVENT_SUCCESS) ?
|
||||||
configs[constants.APP_CONF_AUTH_MODULE_LOGOUT_ON_SUCCESS_PAGE] :
|
configs[constants.APP_CONF_AUTH_MODULE_LOGOUT_ON_SUCCESS_PAGE] :
|
||||||
configs[constants.APP_CONF_AUTH_MODULE_LOGOUT_ON_FAIL_PAGE];
|
configs[constants.APP_CONF_AUTH_MODULE_LOGOUT_ON_FAIL_PAGE];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pageFullName) {
|
if (pageFullName) {
|
||||||
@ -173,13 +173,13 @@ var module = {};
|
|||||||
return page.definition[constants.PAGE_DEFINITION_URI];
|
return page.definition[constants.PAGE_DEFINITION_URI];
|
||||||
}
|
}
|
||||||
log.warn("Page '" + pageFullName + "' mentioned in Auth module configurations in "
|
log.warn("Page '" + pageFullName + "' mentioned in Auth module configurations in "
|
||||||
+ "application configuration file '" + constants.FILE_APP_CONF
|
+ "application configuration file '" + constants.FILE_APP_CONF
|
||||||
+ "' is disabled.");
|
+ "' is disabled.");
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
log.error("Page '" + pageFullName + "' mentioned in Auth module configurations in "
|
log.error("Page '" + pageFullName + "' mentioned in Auth module configurations in "
|
||||||
+ "application configuration file '" + constants.FILE_APP_CONF
|
+ "application configuration file '" + constants.FILE_APP_CONF
|
||||||
+ "' does not exists.");
|
+ "' does not exists.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return "/";
|
return "/";
|
||||||
@ -207,13 +207,13 @@ var module = {};
|
|||||||
if (operation == OPERATION_LOGIN) {
|
if (operation == OPERATION_LOGIN) {
|
||||||
configs = getLoginConfigurations(event);
|
configs = getLoginConfigurations(event);
|
||||||
scriptFilePath = (event == EVENT_SUCCESS) ?
|
scriptFilePath = (event == EVENT_SUCCESS) ?
|
||||||
configs[constants.APP_CONF_AUTH_MODULE_LOGIN_ON_SUCCESS_SCRIPT] :
|
configs[constants.APP_CONF_AUTH_MODULE_LOGIN_ON_SUCCESS_SCRIPT] :
|
||||||
configs[constants.APP_CONF_AUTH_MODULE_LOGIN_ON_FAIL_SCRIPT];
|
configs[constants.APP_CONF_AUTH_MODULE_LOGIN_ON_FAIL_SCRIPT];
|
||||||
} else {
|
} else {
|
||||||
configs = getLogoutConfigurations(event);
|
configs = getLogoutConfigurations(event);
|
||||||
scriptFilePath = (event == EVENT_SUCCESS) ?
|
scriptFilePath = (event == EVENT_SUCCESS) ?
|
||||||
configs[constants.APP_CONF_AUTH_MODULE_LOGOUT_ON_SUCCESS_SCRIPT] :
|
configs[constants.APP_CONF_AUTH_MODULE_LOGOUT_ON_SUCCESS_SCRIPT] :
|
||||||
configs[constants.APP_CONF_AUTH_MODULE_LOGOUT_ON_FAIL_SCRIPT];
|
configs[constants.APP_CONF_AUTH_MODULE_LOGOUT_ON_FAIL_SCRIPT];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!scriptFilePath || (scriptFilePath.length == 0)) {
|
if (!scriptFilePath || (scriptFilePath.length == 0)) {
|
||||||
@ -222,8 +222,8 @@ var module = {};
|
|||||||
var scriptFile = new File(scriptFilePath);
|
var scriptFile = new File(scriptFilePath);
|
||||||
if (!scriptFile.isExists() || scriptFile.isDirectory()) {
|
if (!scriptFile.isExists() || scriptFile.isDirectory()) {
|
||||||
log.error("Script '" + scriptFilePath + "' mentioned in Auth module configurations in "
|
log.error("Script '" + scriptFilePath + "' mentioned in Auth module configurations in "
|
||||||
+ "application configuration file '" + constants.FILE_APP_CONF
|
+ "application configuration file '" + constants.FILE_APP_CONF
|
||||||
+ "' does not exists.");
|
+ "' does not exists.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -265,7 +265,7 @@ var module = {};
|
|||||||
} else {
|
} else {
|
||||||
// event == EVENT_FAIL
|
// event == EVENT_FAIL
|
||||||
redirectUri = getRedirectUri(operation, EVENT_FAIL) + "?error=" + scriptArgument.message
|
redirectUri = getRedirectUri(operation, EVENT_FAIL) + "?error=" + scriptArgument.message
|
||||||
+ "&" + constants.URL_PARAM_REFERER + "=" + getRelayState(operation);
|
+ "&" + constants.URL_PARAM_REFERER + "=" + getRelayState(operation);
|
||||||
}
|
}
|
||||||
response.sendRedirect(encodeURI(module.getAppContext() + redirectUri));
|
response.sendRedirect(encodeURI(module.getAppContext() + redirectUri));
|
||||||
}
|
}
|
||||||
@ -276,8 +276,8 @@ var module = {};
|
|||||||
var identityProviderUrl = ssoConfigs[constants.APP_CONF_AUTH_MODULE_SSO_IDENTITY_PROVIDER_URL];
|
var identityProviderUrl = ssoConfigs[constants.APP_CONF_AUTH_MODULE_SSO_IDENTITY_PROVIDER_URL];
|
||||||
if (!identityProviderUrl || (identityProviderUrl.length == 0)) {
|
if (!identityProviderUrl || (identityProviderUrl.length == 0)) {
|
||||||
var msg = "Identity Provider URL is not given in SSO configurations in Auth module "
|
var msg = "Identity Provider URL is not given in SSO configurations in Auth module "
|
||||||
+ "configurations in application configuration file '"
|
+ "configurations in application configuration file '"
|
||||||
+ constants.FILE_APP_CONF + "'.";
|
+ constants.FILE_APP_CONF + "'.";
|
||||||
log.error(msg);
|
log.error(msg);
|
||||||
response.sendError(500, msg);
|
response.sendError(500, msg);
|
||||||
return null;
|
return null;
|
||||||
@ -286,7 +286,7 @@ var module = {};
|
|||||||
var issuer = ssoConfigs[constants.APP_CONF_AUTH_MODULE_SSO_ISSUER];
|
var issuer = ssoConfigs[constants.APP_CONF_AUTH_MODULE_SSO_ISSUER];
|
||||||
if (!issuer || (issuer.length == 0)) {
|
if (!issuer || (issuer.length == 0)) {
|
||||||
var msg = "Issuer is not given in SSO configurations in Auth module configurations in "
|
var msg = "Issuer is not given in SSO configurations in Auth module configurations in "
|
||||||
+ "application configuration file '" + constants.FILE_APP_CONF + "'.";
|
+ "application configuration file '" + constants.FILE_APP_CONF + "'.";
|
||||||
log.error(msg);
|
log.error(msg);
|
||||||
response.sendError(500, msg);
|
response.sendError(500, msg);
|
||||||
return null;
|
return null;
|
||||||
@ -316,8 +316,8 @@ var module = {};
|
|||||||
var identityProviderUrl = ssoConfigs[constants.APP_CONF_AUTH_MODULE_SSO_IDENTITY_PROVIDER_URL];
|
var identityProviderUrl = ssoConfigs[constants.APP_CONF_AUTH_MODULE_SSO_IDENTITY_PROVIDER_URL];
|
||||||
if (!identityProviderUrl || (identityProviderUrl.length == 0)) {
|
if (!identityProviderUrl || (identityProviderUrl.length == 0)) {
|
||||||
var msg = "Identity Provider URL is not given in SSO configurations in Auth module "
|
var msg = "Identity Provider URL is not given in SSO configurations in Auth module "
|
||||||
+ "configurations in application configuration file '"
|
+ "configurations in application configuration file '"
|
||||||
+ constants.FILE_APP_CONF + "'.";
|
+ constants.FILE_APP_CONF + "'.";
|
||||||
log.error(msg);
|
log.error(msg);
|
||||||
response.sendError(500, msg);
|
response.sendError(500, msg);
|
||||||
return null;
|
return null;
|
||||||
@ -331,7 +331,7 @@ var module = {};
|
|||||||
var issuer = ssoConfigs[constants.APP_CONF_AUTH_MODULE_SSO_ISSUER];
|
var issuer = ssoConfigs[constants.APP_CONF_AUTH_MODULE_SSO_ISSUER];
|
||||||
if (!issuer || (issuer.length == 0)) {
|
if (!issuer || (issuer.length == 0)) {
|
||||||
var msg = "Issuer is not given in SSO configurations in Auth module configurations in "
|
var msg = "Issuer is not given in SSO configurations in Auth module configurations in "
|
||||||
+ "application configuration file '" + constants.FILE_APP_CONF + "'.";
|
+ "application configuration file '" + constants.FILE_APP_CONF + "'.";
|
||||||
log.error(msg);
|
log.error(msg);
|
||||||
response.sendError(500, msg);
|
response.sendError(500, msg);
|
||||||
return null;
|
return null;
|
||||||
@ -341,10 +341,10 @@ var module = {};
|
|||||||
try {
|
try {
|
||||||
var ssoClient = require("sso").client;
|
var ssoClient = require("sso").client;
|
||||||
encodedSAMLAuthRequest = ssoClient.getEncodedSAMLLogoutRequest(username,
|
encodedSAMLAuthRequest = ssoClient.getEncodedSAMLLogoutRequest(username,
|
||||||
ssoSessionIndex, issuer);
|
ssoSessionIndex, issuer);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log.error("Cannot create SAML logout authorization token for user '" + username
|
log.error("Cannot create SAML logout authorization token for user '" + username
|
||||||
+ "' with issuer '" + issuer + "'.");
|
+ "' with issuer '" + issuer + "'.");
|
||||||
log.error(e.message, e);
|
log.error(e.message, e);
|
||||||
response.sendError(500, e.message);
|
response.sendError(500, e.message);
|
||||||
return null;
|
return null;
|
||||||
@ -446,17 +446,17 @@ var module = {};
|
|||||||
intermediatePage = utils.getFurthestChild(intermediatePage);
|
intermediatePage = utils.getFurthestChild(intermediatePage);
|
||||||
if (!intermediatePage.disabled) {
|
if (!intermediatePage.disabled) {
|
||||||
renderer.renderUiComponent(intermediatePage, requestParams, renderingContext,
|
renderer.renderUiComponent(intermediatePage, requestParams, renderingContext,
|
||||||
lookupTable, response);
|
lookupTable, response);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
log.warn("Intermediate page '" + intermediatePageName + " mentioned in Auth module "
|
log.warn("Intermediate page '" + intermediatePageName + " mentioned in Auth module "
|
||||||
+ "configurations in application configuration file '"
|
+ "configurations in application configuration file '"
|
||||||
+ constants.FILE_APP_CONF + "' is disabled.");
|
+ constants.FILE_APP_CONF + "' is disabled.");
|
||||||
} else {
|
} else {
|
||||||
log.error("Intermediate page '" + intermediatePageName
|
log.error("Intermediate page '" + intermediatePageName
|
||||||
+ " mentioned in Auth module "
|
+ " mentioned in Auth module "
|
||||||
+ "configurations in application configuration file '"
|
+ "configurations in application configuration file '"
|
||||||
+ constants.FILE_APP_CONF + "' does not exists.");
|
+ constants.FILE_APP_CONF + "' does not exists.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -528,13 +528,13 @@ var module = {};
|
|||||||
* string}}
|
* string}}
|
||||||
*/
|
*/
|
||||||
var ssoSession = ssoClient.decodeSAMLLoginResponse(samlResponseObj, samlResponse,
|
var ssoSession = ssoClient.decodeSAMLLoginResponse(samlResponseObj, samlResponse,
|
||||||
session.getId());
|
session.getId());
|
||||||
if (ssoSession.sessionId) {
|
if (ssoSession.sessionId) {
|
||||||
var ssoSessions = getSsoSessions();
|
var ssoSessions = getSsoSessions();
|
||||||
ssoSessions[ssoSession.sessionId] = ssoSession;
|
ssoSessions[ssoSession.sessionId] = ssoSession;
|
||||||
var carbonUser = (require("carbon")).server.tenantUser(ssoSession.loggedInUser);
|
var carbonUser = (require("carbon")).server.tenantUser(ssoSession.loggedInUser);
|
||||||
utils.setCurrentUser(carbonUser.username, carbonUser.domain, carbonUser.tenantId);
|
utils.setCurrentUser(carbonUser.username, carbonUser.domain, carbonUser.tenantId);
|
||||||
var scriptArgument = {input: {}, user: module.getCurrentUser()};
|
var scriptArgument = {input: {samlToken: ssoSession.samlToken}, user: module.getCurrentUser()};
|
||||||
handleEvent(OPERATION_LOGIN, EVENT_SUCCESS, scriptArgument);
|
handleEvent(OPERATION_LOGIN, EVENT_SUCCESS, scriptArgument);
|
||||||
} else {
|
} else {
|
||||||
var msg = "Cannot decode SAML login response.";
|
var msg = "Cannot decode SAML login response.";
|
||||||
|
|||||||
@ -90,10 +90,6 @@
|
|||||||
<groupId>commons-lang.wso2</groupId>
|
<groupId>commons-lang.wso2</groupId>
|
||||||
<artifactId>commons-lang</artifactId>
|
<artifactId>commons-lang</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.wso2.carbon.analytics</groupId>
|
|
||||||
<artifactId>org.wso2.carbon.analytics.api</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.wso2.carbon.registry</groupId>
|
<groupId>org.wso2.carbon.registry</groupId>
|
||||||
<artifactId>org.wso2.carbon.registry.indexing</artifactId>
|
<artifactId>org.wso2.carbon.registry.indexing</artifactId>
|
||||||
|
|||||||
@ -18,13 +18,6 @@
|
|||||||
|
|
||||||
package org.wso2.carbon.identity.jwt.client.extension;
|
package org.wso2.carbon.identity.jwt.client.extension;
|
||||||
|
|
||||||
import com.nimbusds.jose.JOSEException;
|
|
||||||
import com.nimbusds.jose.JWSAlgorithm;
|
|
||||||
import com.nimbusds.jose.JWSHeader;
|
|
||||||
import com.nimbusds.jose.JWSSigner;
|
|
||||||
import com.nimbusds.jose.crypto.RSASSASigner;
|
|
||||||
import com.nimbusds.jwt.JWTClaimsSet;
|
|
||||||
import com.nimbusds.jwt.SignedJWT;
|
|
||||||
import org.apache.commons.codec.binary.Base64;
|
import org.apache.commons.codec.binary.Base64;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
@ -36,32 +29,21 @@ import org.apache.http.client.methods.HttpPost;
|
|||||||
import org.apache.http.message.BasicNameValuePair;
|
import org.apache.http.message.BasicNameValuePair;
|
||||||
import org.json.simple.JSONObject;
|
import org.json.simple.JSONObject;
|
||||||
import org.json.simple.parser.JSONParser;
|
import org.json.simple.parser.JSONParser;
|
||||||
import org.json.simple.parser.ParseException;
|
import org.json.simple.parser.ParseException;;
|
||||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
|
||||||
import org.wso2.carbon.core.util.KeyStoreManager;
|
|
||||||
import org.wso2.carbon.identity.jwt.client.extension.constant.JWTConstants;
|
import org.wso2.carbon.identity.jwt.client.extension.constant.JWTConstants;
|
||||||
import org.wso2.carbon.identity.jwt.client.extension.dto.AccessTokenInfo;
|
import org.wso2.carbon.identity.jwt.client.extension.dto.AccessTokenInfo;
|
||||||
import org.wso2.carbon.identity.jwt.client.extension.dto.JWTConfig;
|
import org.wso2.carbon.identity.jwt.client.extension.dto.JWTConfig;
|
||||||
import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientException;
|
import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientException;
|
||||||
import org.wso2.carbon.identity.jwt.client.extension.util.JWTClientUtil;
|
import org.wso2.carbon.identity.jwt.client.extension.util.JWTClientUtil;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URI;
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.security.KeyManagementException;
|
import java.security.KeyManagementException;
|
||||||
import java.security.KeyStore;
|
|
||||||
import java.security.KeyStoreException;
|
import java.security.KeyStoreException;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.security.UnrecoverableKeyException;
|
|
||||||
import java.security.cert.CertificateException;
|
|
||||||
import java.security.interfaces.RSAPrivateKey;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* this class represents an implementation of Token Client which is based on JWT
|
* this class represents an implementation of Token Client which is based on JWT
|
||||||
@ -69,12 +51,6 @@ import java.util.Random;
|
|||||||
public class JWTClient {
|
public class JWTClient {
|
||||||
|
|
||||||
private static Log log = LogFactory.getLog(JWTClient.class);
|
private static Log log = LogFactory.getLog(JWTClient.class);
|
||||||
private static final String JWT_GRANT_TYPE = "urn:ietf:params:oauth:grant-type:jwt-bearer";
|
|
||||||
private static final String GRANT_TYPE_PARAM_NAME = "grant_type";
|
|
||||||
private static final String REFRESH_TOKEN_GRANT_TYPE = "refresh_token";
|
|
||||||
private static final String REFRESH_TOKEN_GRANT_TYPE_PARAM_NAME = "refresh_token";
|
|
||||||
private static final String JWT_PARAM_NAME = "assertion";
|
|
||||||
private static final String SCOPE_PARAM_NAME = "scope";
|
|
||||||
private JWTConfig jwtConfig;
|
private JWTConfig jwtConfig;
|
||||||
|
|
||||||
public JWTClient(JWTConfig jwtConfig) {
|
public JWTClient(JWTConfig jwtConfig) {
|
||||||
@ -87,13 +63,13 @@ public class JWTClient {
|
|||||||
public AccessTokenInfo getAccessToken(String consumerKey, String consumerSecret, String username, String scopes)
|
public AccessTokenInfo getAccessToken(String consumerKey, String consumerSecret, String username, String scopes)
|
||||||
throws JWTClientException {
|
throws JWTClientException {
|
||||||
List<NameValuePair> params = new ArrayList<>();
|
List<NameValuePair> params = new ArrayList<>();
|
||||||
params.add(new BasicNameValuePair(GRANT_TYPE_PARAM_NAME, JWT_GRANT_TYPE));
|
params.add(new BasicNameValuePair(JWTConstants.GRANT_TYPE_PARAM_NAME, JWTConstants.JWT_GRANT_TYPE));
|
||||||
String assertion = generateSignedJWTAssertion(username);
|
String assertion = JWTClientUtil.generateSignedJWTAssertion(username, jwtConfig);
|
||||||
if (assertion == null) {
|
if (assertion == null) {
|
||||||
throw new JWTClientException("JWT is not configured properly for user : " + username);
|
throw new JWTClientException("JWT is not configured properly for user : " + username);
|
||||||
}
|
}
|
||||||
params.add(new BasicNameValuePair(JWT_PARAM_NAME, assertion));
|
params.add(new BasicNameValuePair(JWTConstants.JWT_PARAM_NAME, assertion));
|
||||||
params.add(new BasicNameValuePair(SCOPE_PARAM_NAME, scopes));
|
params.add(new BasicNameValuePair(JWTConstants.SCOPE_PARAM_NAME, scopes));
|
||||||
return getTokenInfo(params, consumerKey, consumerSecret);
|
return getTokenInfo(params, consumerKey, consumerSecret);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,9 +80,9 @@ public class JWTClient {
|
|||||||
String consumerKey, String consumerSecret)
|
String consumerKey, String consumerSecret)
|
||||||
throws JWTClientException {
|
throws JWTClientException {
|
||||||
List<NameValuePair> params = new ArrayList<>();
|
List<NameValuePair> params = new ArrayList<>();
|
||||||
params.add(new BasicNameValuePair(GRANT_TYPE_PARAM_NAME, REFRESH_TOKEN_GRANT_TYPE));
|
params.add(new BasicNameValuePair(JWTConstants.GRANT_TYPE_PARAM_NAME, JWTConstants.REFRESH_TOKEN_GRANT_TYPE));
|
||||||
params.add(new BasicNameValuePair(REFRESH_TOKEN_GRANT_TYPE_PARAM_NAME, refreshToken));
|
params.add(new BasicNameValuePair(JWTConstants.REFRESH_TOKEN_GRANT_TYPE_PARAM_NAME, refreshToken));
|
||||||
params.add(new BasicNameValuePair(SCOPE_PARAM_NAME, scopes));
|
params.add(new BasicNameValuePair(JWTConstants.SCOPE_PARAM_NAME, scopes));
|
||||||
return getTokenInfo(params, consumerKey, consumerSecret);
|
return getTokenInfo(params, consumerKey, consumerSecret);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,10 +108,10 @@ public class JWTClient {
|
|||||||
JSONParser jsonParser = new JSONParser();
|
JSONParser jsonParser = new JSONParser();
|
||||||
JSONObject jsonObject = (JSONObject) jsonParser.parse(response);
|
JSONObject jsonObject = (JSONObject) jsonParser.parse(response);
|
||||||
AccessTokenInfo accessTokenInfo = new AccessTokenInfo();
|
AccessTokenInfo accessTokenInfo = new AccessTokenInfo();
|
||||||
accessTokenInfo.setAccess_token((String) jsonObject.get(JWTConstants.OAUTH_ACCESS_TOKEN));
|
accessTokenInfo.setAccessToken((String) jsonObject.get(JWTConstants.ACCESS_TOKEN_GRANT_TYPE_PARAM_NAME));
|
||||||
accessTokenInfo.setRefresh_token((String) jsonObject.get(JWTConstants.OAUTH_REFRESH_TOKEN));
|
accessTokenInfo.setRefreshToken((String) jsonObject.get(JWTConstants.REFRESH_TOKEN_GRANT_TYPE_PARAM_NAME));
|
||||||
accessTokenInfo.setExpires_in((Long) jsonObject.get(JWTConstants.OAUTH_EXPIRES_IN));
|
accessTokenInfo.setExpiresIn((Long) jsonObject.get(JWTConstants.OAUTH_EXPIRES_IN));
|
||||||
accessTokenInfo.setToken_type((String) jsonObject.get(JWTConstants.OAUTH_TOKEN_TYPE));
|
accessTokenInfo.setTokenType((String) jsonObject.get(JWTConstants.OAUTH_TOKEN_TYPE));
|
||||||
return accessTokenInfo;
|
return accessTokenInfo;
|
||||||
} catch (MalformedURLException e) {
|
} catch (MalformedURLException e) {
|
||||||
throw new JWTClientException("Invalid URL for token endpoint " + jwtConfig.getTokenEndpoint(), e);
|
throw new JWTClientException("Invalid URL for token endpoint " + jwtConfig.getTokenEndpoint(), e);
|
||||||
@ -156,92 +132,7 @@ public class JWTClient {
|
|||||||
return new String(Base64.encodeBase64((consumerKey + ":" + consumerSecret).getBytes()));
|
return new String(Base64.encodeBase64((consumerKey + ":" + consumerSecret).getBytes()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public String generateSignedJWTAssertion(String username) throws JWTClientException {
|
|
||||||
try {
|
|
||||||
String subject = username;
|
|
||||||
long currentTimeMillis = System.currentTimeMillis();
|
|
||||||
// add the skew between servers
|
|
||||||
String iss = jwtConfig.getIssuer();
|
|
||||||
if (iss == null || iss.isEmpty()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
currentTimeMillis += jwtConfig.getSkew();
|
|
||||||
long iat = currentTimeMillis + jwtConfig.getIssuedInternal() * 60 * 1000;
|
|
||||||
long exp = currentTimeMillis + jwtConfig.getExpirationTime() * 60 * 1000;
|
|
||||||
long nbf = currentTimeMillis + jwtConfig.getValidityPeriodFromCurrentTime() * 60 * 1000;
|
|
||||||
String jti = jwtConfig.getJti();
|
|
||||||
if (jti == null) {
|
|
||||||
String defaultTokenId = currentTimeMillis + "" + new Random().nextInt();
|
|
||||||
jti = defaultTokenId;
|
|
||||||
}
|
|
||||||
List<String> aud = jwtConfig.getAudiences();
|
|
||||||
//set up the basic claims
|
|
||||||
JWTClaimsSet claimsSet = new JWTClaimsSet();
|
|
||||||
claimsSet.setIssueTime(new Date(iat));
|
|
||||||
claimsSet.setExpirationTime(new Date(exp));
|
|
||||||
claimsSet.setIssuer(iss);
|
|
||||||
claimsSet.setSubject(username);
|
|
||||||
claimsSet.setNotBeforeTime(new Date(nbf));
|
|
||||||
claimsSet.setJWTID(jti);
|
|
||||||
claimsSet.setAudience(aud);
|
|
||||||
|
|
||||||
// get Keystore params
|
|
||||||
String keyStorePath = jwtConfig.getKeyStorePath();
|
|
||||||
String privateKeyAlias = jwtConfig.getPrivateKeyAlias();
|
|
||||||
String privateKeyPassword = jwtConfig.getPrivateKeyPassword();
|
|
||||||
KeyStore keyStore;
|
|
||||||
RSAPrivateKey rsaPrivateKey;
|
|
||||||
if (keyStorePath != null && !keyStorePath.isEmpty()) {
|
|
||||||
String keyStorePassword = jwtConfig.getKeyStorePassword();
|
|
||||||
keyStore = loadKeyStore(new File(keyStorePath), keyStorePassword, "JKS");
|
|
||||||
rsaPrivateKey = (RSAPrivateKey) keyStore.getKey(privateKeyAlias, privateKeyPassword.toCharArray());
|
|
||||||
} else {
|
|
||||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
||||||
KeyStoreManager tenantKeyStoreManager = KeyStoreManager.getInstance(tenantId);
|
|
||||||
rsaPrivateKey = (RSAPrivateKey) tenantKeyStoreManager.getDefaultPrivateKey();
|
|
||||||
}
|
|
||||||
JWSSigner signer = new RSASSASigner(rsaPrivateKey);
|
|
||||||
SignedJWT signedJWT = new SignedJWT(new JWSHeader(JWSAlgorithm.RS256), claimsSet);
|
|
||||||
signedJWT.sign(signer);
|
|
||||||
String assertion = signedJWT.serialize();
|
|
||||||
return assertion;
|
|
||||||
} catch (KeyStoreException e) {
|
|
||||||
throw new JWTClientException("Failed loading the keystore.", e);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new JWTClientException("Failed parsing the keystore file.", e);
|
|
||||||
} catch (NoSuchAlgorithmException e) {
|
|
||||||
throw new JWTClientException("No such algorithm found RS256.", e);
|
|
||||||
} catch (CertificateException e) {
|
|
||||||
throw new JWTClientException("Failed loading the certificate from the keystore.", e);
|
|
||||||
} catch (UnrecoverableKeyException e) {
|
|
||||||
throw new JWTClientException("Failed loading the keys from the keystore.", e);
|
|
||||||
} catch (JOSEException e) {
|
|
||||||
throw new JWTClientException(e);
|
|
||||||
} catch (Exception e) {
|
|
||||||
//This is thrown when loading default private key.
|
|
||||||
throw new JWTClientException("Failed loading the private key.", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private KeyStore loadKeyStore(final File keystoreFile, final String password, final String keyStoreType)
|
|
||||||
throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException {
|
|
||||||
if (null == keystoreFile) {
|
|
||||||
throw new IllegalArgumentException("Keystore url may not be null");
|
|
||||||
}
|
|
||||||
URI keystoreUri = keystoreFile.toURI();
|
|
||||||
URL keystoreUrl = keystoreUri.toURL();
|
|
||||||
KeyStore keystore = KeyStore.getInstance(keyStoreType);
|
|
||||||
InputStream is = null;
|
|
||||||
try {
|
|
||||||
is = keystoreUrl.openStream();
|
|
||||||
keystore.load(is, null == password ? null : password.toCharArray());
|
|
||||||
} finally {
|
|
||||||
if (null != is) {
|
|
||||||
is.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return keystore;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -21,8 +21,15 @@ package org.wso2.carbon.identity.jwt.client.extension.constant;
|
|||||||
* This holds the constants related JWT client component.
|
* This holds the constants related JWT client component.
|
||||||
*/
|
*/
|
||||||
public class JWTConstants {
|
public class JWTConstants {
|
||||||
public static final String OAUTH_ACCESS_TOKEN = "access_token";
|
|
||||||
public static final String OAUTH_REFRESH_TOKEN = "refresh_token";
|
|
||||||
public static final String OAUTH_EXPIRES_IN = "expires_in";
|
public static final String OAUTH_EXPIRES_IN = "expires_in";
|
||||||
public static final String OAUTH_TOKEN_TYPE = "token_type";
|
public static final String OAUTH_TOKEN_TYPE = "token_type";
|
||||||
|
public static final String JWT_GRANT_TYPE = "urn:ietf:params:oauth:grant-type:jwt-bearer";
|
||||||
|
public static final String GRANT_TYPE_PARAM_NAME = "grant_type";
|
||||||
|
public static final String REFRESH_TOKEN_GRANT_TYPE = "refresh_token";
|
||||||
|
public static final String REFRESH_TOKEN_GRANT_TYPE_PARAM_NAME = "refresh_token";
|
||||||
|
public static final String ACCESS_TOKEN_GRANT_TYPE_PARAM_NAME = "access_token";
|
||||||
|
public static final String JWT_PARAM_NAME = "assertion";
|
||||||
|
public static final String SCOPE_PARAM_NAME = "scope";
|
||||||
|
public static final String DEFAULT_JWT_CLIENT = "default-jwt-client";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -23,40 +23,40 @@ package org.wso2.carbon.identity.jwt.client.extension.dto;
|
|||||||
*/
|
*/
|
||||||
public class AccessTokenInfo {
|
public class AccessTokenInfo {
|
||||||
|
|
||||||
private String token_type;
|
private String tokenType;
|
||||||
private long expires_in;
|
private long expiresIn;
|
||||||
private String refresh_token;
|
private String refreshToken;
|
||||||
private String access_token;
|
private String accessToken;
|
||||||
|
|
||||||
public String getToken_type() {
|
public String getTokenType() {
|
||||||
return token_type;
|
return tokenType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setToken_type(String token_type) {
|
public void setTokenType(String tokenType) {
|
||||||
this.token_type = token_type;
|
this.tokenType = tokenType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getExpires_in() {
|
public long getExpiresIn() {
|
||||||
return expires_in;
|
return expiresIn;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setExpires_in(long expres_in) {
|
public void setExpiresIn(long expiresIn) {
|
||||||
this.expires_in = expres_in;
|
this.expiresIn = expiresIn;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getRefresh_token() {
|
public String getRefreshToken() {
|
||||||
return refresh_token;
|
return refreshToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRefresh_token(String refresh_token) {
|
public void setRefreshToken(String refreshToken) {
|
||||||
this.refresh_token = refresh_token;
|
this.refreshToken = refreshToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getAccess_token() {
|
public String getAccessToken() {
|
||||||
return access_token;
|
return accessToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAccess_token(String access_token) {
|
public void setAccessToken(String accessToken) {
|
||||||
this.access_token = access_token;
|
this.accessToken = accessToken;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,7 +20,11 @@ package org.wso2.carbon.identity.jwt.client.extension.internal;
|
|||||||
|
|
||||||
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.osgi.framework.BundleContext;
|
||||||
import org.osgi.service.component.ComponentContext;
|
import org.osgi.service.component.ComponentContext;
|
||||||
|
import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientConfigurationException;
|
||||||
|
import org.wso2.carbon.identity.jwt.client.extension.service.JWTClientManagerService;
|
||||||
|
import org.wso2.carbon.identity.jwt.client.extension.service.JWTClientManagerServiceImpl;
|
||||||
import org.wso2.carbon.identity.jwt.client.extension.util.JWTClientUtil;
|
import org.wso2.carbon.identity.jwt.client.extension.util.JWTClientUtil;
|
||||||
import org.wso2.carbon.registry.core.exceptions.RegistryException;
|
import org.wso2.carbon.registry.core.exceptions.RegistryException;
|
||||||
import org.wso2.carbon.registry.core.service.RegistryService;
|
import org.wso2.carbon.registry.core.service.RegistryService;
|
||||||
@ -66,11 +70,16 @@ public class JWTClientExtensionServiceComponent {
|
|||||||
log.debug("Initializing jwt extension bundle");
|
log.debug("Initializing jwt extension bundle");
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
JWTClientUtil.initialize();
|
JWTClientManagerService jwtClientManagerService = new JWTClientManagerServiceImpl();
|
||||||
|
JWTClientUtil.initialize(jwtClientManagerService);
|
||||||
|
BundleContext bundleContext = componentContext.getBundleContext();
|
||||||
|
bundleContext.registerService(JWTClientManagerService.class.getName(), jwtClientManagerService, null);
|
||||||
} catch (RegistryException e) {
|
} catch (RegistryException e) {
|
||||||
log.error("Failed loading the jwt config from registry.", e);
|
log.error("Failed loading the jwt config from registry.", e);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.error("Failed loading the jwt config from the file system.", e);
|
log.error("Failed loading the jwt config from the file system.", e);
|
||||||
|
} catch (JWTClientConfigurationException e) {
|
||||||
|
log.error("Failed to set default jwt configurations.", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.wso2.carbon.identity.jwt.client.extension.service;
|
||||||
|
|
||||||
|
import org.wso2.carbon.identity.jwt.client.extension.JWTClient;
|
||||||
|
import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientConfigurationException;
|
||||||
|
import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientException;
|
||||||
|
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is the JWTClientManagerServiceImpl Service that can be used to have JWT Client for tenant specific.
|
||||||
|
*/
|
||||||
|
public interface JWTClientManagerService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This return the jwt based token client to generate token for the tenant.
|
||||||
|
* @return JWTClient that can be used to generate token.
|
||||||
|
* @throws JWTClientException when the JWT Client creation fails
|
||||||
|
*/
|
||||||
|
JWTClient getJWTClient() throws JWTClientException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This will set the default JWT Client that will be used if there is any available for tenants.
|
||||||
|
* @param properties required to configure jwt client.
|
||||||
|
* @throws JWTClientConfigurationException throws when the configuration is invalid.
|
||||||
|
*/
|
||||||
|
void setDefaultJWTClient(Properties properties) throws JWTClientConfigurationException;
|
||||||
|
}
|
||||||
@ -16,12 +16,15 @@
|
|||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.wso2.carbon.identity.jwt.client.extension;
|
package org.wso2.carbon.identity.jwt.client.extension.service;
|
||||||
|
|
||||||
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.wso2.carbon.base.MultitenantConstants;
|
||||||
import org.wso2.carbon.context.CarbonContext;
|
import org.wso2.carbon.context.CarbonContext;
|
||||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||||
|
import org.wso2.carbon.identity.jwt.client.extension.JWTClient;
|
||||||
|
import org.wso2.carbon.identity.jwt.client.extension.constant.JWTConstants;
|
||||||
import org.wso2.carbon.identity.jwt.client.extension.dto.JWTConfig;
|
import org.wso2.carbon.identity.jwt.client.extension.dto.JWTConfig;
|
||||||
import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientAlreadyExistsException;
|
import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientAlreadyExistsException;
|
||||||
import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientConfigurationException;
|
import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientConfigurationException;
|
||||||
@ -36,42 +39,44 @@ import java.util.Properties;
|
|||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This creates JWT Client for each tenant.
|
* This creates JWT Client for each tenant and implements the JWTClientManagerService interface.
|
||||||
*/
|
*/
|
||||||
public class JWTClientManager {
|
public class JWTClientManagerServiceImpl implements JWTClientManagerService{
|
||||||
|
|
||||||
private static Map<String, JWTClient> jwtClientMap;
|
private static Map<String, JWTClient> jwtClientMap;
|
||||||
private static JWTClientManager jwtClientCreator;
|
private static final Log log = LogFactory.getLog(JWTClientManagerServiceImpl.class);
|
||||||
private static final Log log = LogFactory.getLog(JWTClientManager.class);
|
|
||||||
private static final String TENANT_JWT_CONFIG_LOCATION = "/jwt-config/jwt.properties";
|
private static final String TENANT_JWT_CONFIG_LOCATION = "/jwt-config/jwt.properties";
|
||||||
|
private static JWTClient defaultJWTClient;
|
||||||
|
|
||||||
public static JWTClientManager getInstance() {
|
|
||||||
if (jwtClientCreator == null) {
|
|
||||||
synchronized (JWTClientManager.class) {
|
|
||||||
if (jwtClientCreator == null) {
|
|
||||||
jwtClientCreator = new JWTClientManager();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return jwtClientCreator;
|
|
||||||
}
|
|
||||||
|
|
||||||
private JWTClientManager() {
|
public JWTClientManagerServiceImpl() {
|
||||||
jwtClientMap = new ConcurrentHashMap<>();
|
jwtClientMap = new ConcurrentHashMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* this return the jwt based token client to generate token for the tenant.
|
* this return the jwt based token client to generate token for the tenant.
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public JWTClient getJWTClient() throws JWTClientException {
|
public JWTClient getJWTClient() throws JWTClientException {
|
||||||
String tenantDomain = CarbonContext.getThreadLocalCarbonContext().getTenantDomain();
|
String tenantDomain = CarbonContext.getThreadLocalCarbonContext().getTenantDomain();
|
||||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
||||||
|
if (tenantId == -1) {
|
||||||
|
throw new JWTClientException("Invalid tenant domain :" + tenantDomain);
|
||||||
|
}
|
||||||
//Get jwt client which has been registered for the tenant.
|
//Get jwt client which has been registered for the tenant.
|
||||||
JWTClient jwtClient = getJWTClient(tenantDomain);
|
JWTClient jwtClient = getJWTClient(tenantDomain);
|
||||||
if (jwtClient == null) {
|
if (jwtClient == null) {
|
||||||
//Create new jwt client for the tenant.
|
//Create a new jwt client for the tenant.
|
||||||
try {
|
try {
|
||||||
JWTConfig jwtConfig = new JWTConfig(getJWTConfig(tenantId));
|
Properties properties = getJWTConfigProperties(tenantId);
|
||||||
|
if (properties == null) {
|
||||||
|
if (defaultJWTClient != null) {
|
||||||
|
return defaultJWTClient;
|
||||||
|
} else {
|
||||||
|
throw new JWTClientException("JWT Configuration is not available for tenant " + tenantDomain);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
JWTConfig jwtConfig = new JWTConfig(properties);
|
||||||
jwtClient = new JWTClient(jwtConfig);
|
jwtClient = new JWTClient(jwtConfig);
|
||||||
addJWTClient(tenantDomain, jwtClient);
|
addJWTClient(tenantDomain, jwtClient);
|
||||||
} catch (JWTClientAlreadyExistsException e) {
|
} catch (JWTClientAlreadyExistsException e) {
|
||||||
@ -85,6 +90,31 @@ public class JWTClientManager {
|
|||||||
return jwtClient;
|
return jwtClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This will set the default JWT Client that will be used if there is any available for tenants.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void setDefaultJWTClient(Properties properties) throws JWTClientConfigurationException {
|
||||||
|
if (properties == null) {
|
||||||
|
throw new JWTClientConfigurationException("Failed to load jwt configuration for super tenant.");
|
||||||
|
}
|
||||||
|
String defaultJWTClientMode = properties.getProperty(JWTConstants.DEFAULT_JWT_CLIENT);
|
||||||
|
boolean isDefaultJwtClient = false;
|
||||||
|
if (defaultJWTClientMode != null && !defaultJWTClientMode.isEmpty()) {
|
||||||
|
isDefaultJwtClient = Boolean.parseBoolean(defaultJWTClientMode);
|
||||||
|
}
|
||||||
|
if (isDefaultJwtClient) {
|
||||||
|
try {
|
||||||
|
JWTConfig jwtConfig = new JWTConfig(properties);
|
||||||
|
defaultJWTClient = new JWTClient(jwtConfig);
|
||||||
|
addJWTClient(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, defaultJWTClient);
|
||||||
|
} catch (JWTClientAlreadyExistsException e) {
|
||||||
|
log.warn("Attempting to register a jwt client for the super tenant" +
|
||||||
|
" when one already exists. Returning existing jwt client");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch the jwt client which has been registered under the tenant domain.
|
* Fetch the jwt client which has been registered under the tenant domain.
|
||||||
*
|
*
|
||||||
@ -106,23 +136,25 @@ public class JWTClientManager {
|
|||||||
* @throws JWTClientAlreadyExistsException - If a jwt client has already been registered under the tenantdomain
|
* @throws JWTClientAlreadyExistsException - If a jwt client has already been registered under the tenantdomain
|
||||||
*/
|
*/
|
||||||
private void addJWTClient(String tenantDomain, JWTClient jwtClient) throws JWTClientAlreadyExistsException {
|
private void addJWTClient(String tenantDomain, JWTClient jwtClient) throws JWTClientAlreadyExistsException {
|
||||||
if (jwtClientMap.containsKey(tenantDomain)) {
|
synchronized (jwtClientMap) {
|
||||||
throw new JWTClientAlreadyExistsException("A jwt client has already been created for the tenant " + tenantDomain);
|
if (jwtClientMap.containsKey(tenantDomain)) {
|
||||||
|
throw new JWTClientAlreadyExistsException(
|
||||||
|
"A jwt client has already been created for the tenant " + tenantDomain);
|
||||||
|
}
|
||||||
|
jwtClientMap.put(tenantDomain, jwtClient);
|
||||||
}
|
}
|
||||||
jwtClientMap.put(tenantDomain, jwtClient);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve JWT configs from registry.
|
* Retrieve JWT configs from registry.
|
||||||
*/
|
*/
|
||||||
private Properties getJWTConfig(int tenantId) throws JWTClientConfigurationException {
|
private Properties getJWTConfigProperties(int tenantId) throws JWTClientConfigurationException {
|
||||||
try {
|
try {
|
||||||
Resource config = JWTClientUtil.getConfigRegistryResourceContent(tenantId, TENANT_JWT_CONFIG_LOCATION);
|
Resource config = JWTClientUtil.getConfigRegistryResourceContent(tenantId, TENANT_JWT_CONFIG_LOCATION);
|
||||||
Properties properties = new Properties();
|
Properties properties = null;
|
||||||
if(config != null) {
|
if (config != null) {
|
||||||
|
properties = new Properties();
|
||||||
properties.load(config.getContentStream());
|
properties.load(config.getContentStream());
|
||||||
} else {
|
|
||||||
throw new JWTClientConfigurationException("Failed to load jwt configuration for tenant id : " + tenantId);
|
|
||||||
}
|
}
|
||||||
return properties;
|
return properties;
|
||||||
} catch (RegistryException e) {
|
} catch (RegistryException e) {
|
||||||
@ -17,7 +17,13 @@
|
|||||||
*/
|
*/
|
||||||
package org.wso2.carbon.identity.jwt.client.extension.util;
|
package org.wso2.carbon.identity.jwt.client.extension.util;
|
||||||
|
|
||||||
import org.apache.commons.io.FileUtils;
|
import com.nimbusds.jose.JOSEException;
|
||||||
|
import com.nimbusds.jose.JWSAlgorithm;
|
||||||
|
import com.nimbusds.jose.JWSHeader;
|
||||||
|
import com.nimbusds.jose.JWSSigner;
|
||||||
|
import com.nimbusds.jose.crypto.RSASSASigner;
|
||||||
|
import com.nimbusds.jwt.JWTClaimsSet;
|
||||||
|
import com.nimbusds.jwt.SignedJWT;
|
||||||
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.apache.http.HttpResponse;
|
import org.apache.http.HttpResponse;
|
||||||
@ -27,8 +33,12 @@ import org.apache.http.conn.ssl.SSLContextBuilder;
|
|||||||
import org.apache.http.conn.ssl.TrustSelfSignedStrategy;
|
import org.apache.http.conn.ssl.TrustSelfSignedStrategy;
|
||||||
import org.apache.http.impl.client.HttpClients;
|
import org.apache.http.impl.client.HttpClients;
|
||||||
import org.apache.http.util.EntityUtils;
|
import org.apache.http.util.EntityUtils;
|
||||||
import org.wso2.carbon.base.MultitenantConstants;
|
|
||||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||||
|
import org.wso2.carbon.core.util.KeyStoreManager;
|
||||||
|
import org.wso2.carbon.identity.jwt.client.extension.service.JWTClientManagerService;
|
||||||
|
import org.wso2.carbon.identity.jwt.client.extension.dto.JWTConfig;
|
||||||
|
import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientConfigurationException;
|
||||||
|
import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientException;
|
||||||
import org.wso2.carbon.identity.jwt.client.extension.internal.JWTClientExtensionDataHolder;
|
import org.wso2.carbon.identity.jwt.client.extension.internal.JWTClientExtensionDataHolder;
|
||||||
import org.wso2.carbon.registry.core.Registry;
|
import org.wso2.carbon.registry.core.Registry;
|
||||||
import org.wso2.carbon.registry.core.Resource;
|
import org.wso2.carbon.registry.core.Resource;
|
||||||
@ -36,13 +46,25 @@ import org.wso2.carbon.registry.core.exceptions.RegistryException;
|
|||||||
import org.wso2.carbon.registry.core.service.RegistryService;
|
import org.wso2.carbon.registry.core.service.RegistryService;
|
||||||
import org.wso2.carbon.registry.core.service.TenantRegistryLoader;
|
import org.wso2.carbon.registry.core.service.TenantRegistryLoader;
|
||||||
import org.wso2.carbon.utils.CarbonUtils;
|
import org.wso2.carbon.utils.CarbonUtils;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.URL;
|
||||||
import java.security.KeyManagementException;
|
import java.security.KeyManagementException;
|
||||||
|
import java.security.KeyStore;
|
||||||
import java.security.KeyStoreException;
|
import java.security.KeyStoreException;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.security.UnrecoverableKeyException;
|
||||||
|
import java.security.cert.CertificateException;
|
||||||
|
import java.security.interfaces.RSAPrivateKey;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Properties;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is the utility class that is used for JWT Client.
|
* This is the utility class that is used for JWT Client.
|
||||||
@ -55,8 +77,10 @@ public class JWTClientUtil {
|
|||||||
private static final String JWT_CONFIG_FILE_NAME = "jwt.properties";
|
private static final String JWT_CONFIG_FILE_NAME = "jwt.properties";
|
||||||
private static final String SUPERTENANT_JWT_CONFIG_LOCATION =
|
private static final String SUPERTENANT_JWT_CONFIG_LOCATION =
|
||||||
CarbonUtils.getEtcCarbonConfigDirPath() + File.separator + JWT_CONFIG_FILE_NAME;
|
CarbonUtils.getEtcCarbonConfigDirPath() + File.separator + JWT_CONFIG_FILE_NAME;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a http client instance
|
* Return a http client instance
|
||||||
|
*
|
||||||
* @param protocol- service endpoint protocol http/https
|
* @param protocol- service endpoint protocol http/https
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@ -96,12 +120,14 @@ public class JWTClientUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void initialize() throws RegistryException, IOException {
|
public static void initialize(JWTClientManagerService jwtClientManagerService)
|
||||||
Resource resource = getConfigRegistryResourceContent(MultitenantConstants.SUPER_TENANT_ID, TENANT_JWT_CONFIG_LOCATION);
|
throws RegistryException, IOException, JWTClientConfigurationException {
|
||||||
if (resource == null) {
|
File configFile = new File(SUPERTENANT_JWT_CONFIG_LOCATION);
|
||||||
File configFile = new File(SUPERTENANT_JWT_CONFIG_LOCATION);
|
if (configFile.exists()) {
|
||||||
String contents = FileUtils.readFileToString(configFile, "UTF-8");
|
InputStream propertyStream = configFile.toURI().toURL().openStream();
|
||||||
addJWTConfigResourceToRegistry(MultitenantConstants.SUPER_TENANT_ID, contents);
|
Properties properties = new Properties();
|
||||||
|
properties.load(propertyStream);
|
||||||
|
jwtClientManagerService.setDefaultJWTClient(properties);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,7 +162,7 @@ public class JWTClientUtil {
|
|||||||
/**
|
/**
|
||||||
* Get the jwt details from the registry for tenants.
|
* Get the jwt details from the registry for tenants.
|
||||||
*
|
*
|
||||||
* @param tenantId for accesing tenant space.
|
* @param tenantId for accesing tenant space.
|
||||||
* @return the config for tenant
|
* @return the config for tenant
|
||||||
* @throws RegistryException
|
* @throws RegistryException
|
||||||
*/
|
*/
|
||||||
@ -161,8 +187,96 @@ public class JWTClientUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void loadTenantRegistry(int tenantId) throws RegistryException {
|
private static void loadTenantRegistry(int tenantId) throws RegistryException {
|
||||||
TenantRegistryLoader tenantRegistryLoader = JWTClientExtensionDataHolder.getInstance().getTenantRegistryLoader();
|
TenantRegistryLoader tenantRegistryLoader =
|
||||||
|
JWTClientExtensionDataHolder.getInstance().getTenantRegistryLoader();
|
||||||
JWTClientExtensionDataHolder.getInstance().getIndexLoaderService().loadTenantIndex(tenantId);
|
JWTClientExtensionDataHolder.getInstance().getIndexLoaderService().loadTenantIndex(tenantId);
|
||||||
tenantRegistryLoader.loadTenantRegistry(tenantId);
|
tenantRegistryLoader.loadTenantRegistry(tenantId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String generateSignedJWTAssertion(String username, JWTConfig jwtConfig) throws JWTClientException {
|
||||||
|
try {
|
||||||
|
String subject = username;
|
||||||
|
long currentTimeMillis = System.currentTimeMillis();
|
||||||
|
// add the skew between servers
|
||||||
|
String iss = jwtConfig.getIssuer();
|
||||||
|
if (iss == null || iss.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
currentTimeMillis += jwtConfig.getSkew();
|
||||||
|
long iat = currentTimeMillis + jwtConfig.getIssuedInternal() * 60 * 1000;
|
||||||
|
long exp = currentTimeMillis + jwtConfig.getExpirationTime() * 60 * 1000;
|
||||||
|
long nbf = currentTimeMillis + jwtConfig.getValidityPeriodFromCurrentTime() * 60 * 1000;
|
||||||
|
String jti = jwtConfig.getJti();
|
||||||
|
if (jti == null) {
|
||||||
|
String defaultTokenId = currentTimeMillis + "" + new Random().nextInt();
|
||||||
|
jti = defaultTokenId;
|
||||||
|
}
|
||||||
|
List<String> aud = jwtConfig.getAudiences();
|
||||||
|
//set up the basic claims
|
||||||
|
JWTClaimsSet claimsSet = new JWTClaimsSet();
|
||||||
|
claimsSet.setIssueTime(new Date(iat));
|
||||||
|
claimsSet.setExpirationTime(new Date(exp));
|
||||||
|
claimsSet.setIssuer(iss);
|
||||||
|
claimsSet.setSubject(username);
|
||||||
|
claimsSet.setNotBeforeTime(new Date(nbf));
|
||||||
|
claimsSet.setJWTID(jti);
|
||||||
|
claimsSet.setAudience(aud);
|
||||||
|
|
||||||
|
// get Keystore params
|
||||||
|
String keyStorePath = jwtConfig.getKeyStorePath();
|
||||||
|
String privateKeyAlias = jwtConfig.getPrivateKeyAlias();
|
||||||
|
String privateKeyPassword = jwtConfig.getPrivateKeyPassword();
|
||||||
|
KeyStore keyStore;
|
||||||
|
RSAPrivateKey rsaPrivateKey;
|
||||||
|
if (keyStorePath != null && !keyStorePath.isEmpty()) {
|
||||||
|
String keyStorePassword = jwtConfig.getKeyStorePassword();
|
||||||
|
keyStore = loadKeyStore(new File(keyStorePath), keyStorePassword, "JKS");
|
||||||
|
rsaPrivateKey = (RSAPrivateKey) keyStore.getKey(privateKeyAlias, privateKeyPassword.toCharArray());
|
||||||
|
} else {
|
||||||
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
||||||
|
KeyStoreManager tenantKeyStoreManager = KeyStoreManager.getInstance(tenantId);
|
||||||
|
rsaPrivateKey = (RSAPrivateKey) tenantKeyStoreManager.getDefaultPrivateKey();
|
||||||
|
}
|
||||||
|
JWSSigner signer = new RSASSASigner(rsaPrivateKey);
|
||||||
|
SignedJWT signedJWT = new SignedJWT(new JWSHeader(JWSAlgorithm.RS256), claimsSet);
|
||||||
|
signedJWT.sign(signer);
|
||||||
|
String assertion = signedJWT.serialize();
|
||||||
|
return assertion;
|
||||||
|
} catch (KeyStoreException e) {
|
||||||
|
throw new JWTClientException("Failed loading the keystore.", e);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new JWTClientException("Failed parsing the keystore file.", e);
|
||||||
|
} catch (NoSuchAlgorithmException e) {
|
||||||
|
throw new JWTClientException("No such algorithm found RS256.", e);
|
||||||
|
} catch (CertificateException e) {
|
||||||
|
throw new JWTClientException("Failed loading the certificate from the keystore.", e);
|
||||||
|
} catch (UnrecoverableKeyException e) {
|
||||||
|
throw new JWTClientException("Failed loading the keys from the keystore.", e);
|
||||||
|
} catch (JOSEException e) {
|
||||||
|
throw new JWTClientException(e);
|
||||||
|
} catch (Exception e) {
|
||||||
|
//This is thrown when loading default private key.
|
||||||
|
throw new JWTClientException("Failed loading the private key.", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static KeyStore loadKeyStore(final File keystoreFile, final String password, final String keyStoreType)
|
||||||
|
throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException {
|
||||||
|
if (null == keystoreFile) {
|
||||||
|
throw new IllegalArgumentException("Keystore url may not be null");
|
||||||
|
}
|
||||||
|
URI keystoreUri = keystoreFile.toURI();
|
||||||
|
URL keystoreUrl = keystoreUri.toURL();
|
||||||
|
KeyStore keystore = KeyStore.getInstance(keyStoreType);
|
||||||
|
InputStream is = null;
|
||||||
|
try {
|
||||||
|
is = keystoreUrl.openStream();
|
||||||
|
keystore.load(is, null == password ? null : password.toCharArray());
|
||||||
|
} finally {
|
||||||
|
if (null != is) {
|
||||||
|
is.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return keystore;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -45,8 +45,6 @@ public class WebappAuthenticationValve extends CarbonTomcatValve {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
WebappAuthenticator authenticator = WebappAuthenticatorFactory.getAuthenticator(request);
|
WebappAuthenticator authenticator = WebappAuthenticatorFactory.getAuthenticator(request);
|
||||||
if (authenticator == null) {
|
if (authenticator == null) {
|
||||||
String msg = "Failed to load an appropriate authenticator to authenticate the request";
|
String msg = "Failed to load an appropriate authenticator to authenticate the request";
|
||||||
|
|||||||
@ -59,7 +59,7 @@
|
|||||||
<outputDirectory>
|
<outputDirectory>
|
||||||
${project.build.directory}/maven-shared-archive-resources/webapps
|
${project.build.directory}/maven-shared-archive-resources/webapps
|
||||||
</outputDirectory>
|
</outputDirectory>
|
||||||
<destFileName>mdm-admin.war</destFileName>
|
<destFileName>devicemgt_admin.war</destFileName>
|
||||||
</artifactItem>
|
</artifactItem>
|
||||||
</artifactItems>
|
</artifactItems>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
instructions.configure = \
|
instructions.configure = \
|
||||||
org.eclipse.equinox.p2.touchpoint.natives.mkdir(path:${installFolder}/../../deployment/server/webapps/);\
|
org.eclipse.equinox.p2.touchpoint.natives.mkdir(path:${installFolder}/../../deployment/server/webapps/);\
|
||||||
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.api_${feature.version}/webapps/mdm-admin.war,target:${installFolder}/../../deployment/server/webapps/mdm-admin.war,overwrite:true);\
|
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.api_${feature.version}/webapps/devicemgt_admin.war,target:${installFolder}/../../deployment/server/webapps/devicemgt_admin.war,overwrite:true);\
|
||||||
@ -1,18 +1,18 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<!--
|
<!--
|
||||||
~ Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
~ Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
~
|
~
|
||||||
~ WSO2 Inc. licenses this file to you under the Apache License,
|
~ WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
~ Version 2.0 (the "License"); you may not use this file except
|
~ Version 2.0 (the "License"); you may not use this file except
|
||||||
~ in compliance with the License.
|
~ in compliance with the License.
|
||||||
~ you may obtain a copy of the License at
|
~ You may obtain a copy of the License at
|
||||||
~
|
~
|
||||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||||
~
|
~
|
||||||
~ Unless required by applicable law or agreed to in writing,
|
~ Unless required by applicable law or agreed to in writing,
|
||||||
~ software distributed under the License is distributed on an
|
~ software distributed under the License is distributed on an
|
||||||
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
~ KIND, either express or implied. See the License for the
|
~ KIND, either express or implied. See the License for the
|
||||||
~ specific language governing permissions and limitations
|
~ specific language governing permissions and limitations
|
||||||
~ under the License.
|
~ under the License.
|
||||||
-->
|
-->
|
||||||
@ -44,6 +44,11 @@
|
|||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<artifactId>org.wso2.carbon.device.mgt.common</artifactId>
|
<artifactId>org.wso2.carbon.device.mgt.common</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.device.mgt.api.feature</artifactId>
|
||||||
|
<type>zip</type>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.wso2.carbon.commons</groupId>
|
<groupId>org.wso2.carbon.commons</groupId>
|
||||||
<artifactId>org.wso2.carbon.email.verification</artifactId>
|
<artifactId>org.wso2.carbon.email.verification</artifactId>
|
||||||
@ -97,6 +102,11 @@
|
|||||||
<propertyDef>org.eclipse.equinox.p2.type.group:false</propertyDef>
|
<propertyDef>org.eclipse.equinox.p2.type.group:false</propertyDef>
|
||||||
</properties>
|
</properties>
|
||||||
</adviceFile>
|
</adviceFile>
|
||||||
|
<includedFeatures>
|
||||||
|
<includedFeatureDef>
|
||||||
|
org.wso2.carbon.devicemgt:org.wso2.carbon.device.mgt.api.feature:${carbon.device.mgt.version}
|
||||||
|
</includedFeatureDef>
|
||||||
|
</includedFeatures>
|
||||||
<bundles>
|
<bundles>
|
||||||
<bundleDef>
|
<bundleDef>
|
||||||
org.wso2.carbon.devicemgt:org.wso2.carbon.device.mgt.core:${carbon.device.mgt.version}
|
org.wso2.carbon.devicemgt:org.wso2.carbon.device.mgt.core:${carbon.device.mgt.version}
|
||||||
|
|||||||
@ -1,21 +1,21 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!--
|
<!--
|
||||||
~ Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
~ Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
~
|
~
|
||||||
~ WSO2 Inc. licenses this file to you under the Apache License,
|
~ WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
~ Version 2.0 (the "License"); you may not use this file except
|
~ Version 2.0 (the "License"); you may not use this file except
|
||||||
~ in compliance with the License.
|
~ in compliance with the License.
|
||||||
~ You may obtain a copy of the License at
|
~ You may obtain a copy of the License at
|
||||||
~
|
~
|
||||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||||
~
|
~
|
||||||
~ Unless required by applicable law or agreed to in writing,
|
~ Unless required by applicable law or agreed to in writing,
|
||||||
~ software distributed under the License is distributed on an
|
~ software distributed under the License is distributed on an
|
||||||
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
~ KIND, either express or implied. See the License for the
|
~ KIND, either express or implied. See the License for the
|
||||||
~ specific language governing permissions and limitations
|
~ specific language governing permissions and limitations
|
||||||
~ under the License.
|
~ under the License.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
|
||||||
|
|||||||
@ -1,44 +0,0 @@
|
|||||||
<!--
|
|
||||||
~ Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
||||||
~
|
|
||||||
~ WSO2 Inc. licenses this file to you under the Apache License,
|
|
||||||
~ Version 2.0 (the "License"); you may not use this file except
|
|
||||||
~ in compliance with the License.
|
|
||||||
~ You may obtain a copy of the License at
|
|
||||||
~
|
|
||||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
~
|
|
||||||
~ Unless required by applicable law or agreed to in writing,
|
|
||||||
~ software distributed under the License is distributed on an
|
|
||||||
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
~ KIND, either express or implied. See the License for the
|
|
||||||
~ specific language governing permissions and limitations
|
|
||||||
~ under the License.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<IdentityProvider>
|
|
||||||
<IdentityProviderName>CDMF_DEFAULT_IDP</IdentityProviderName>
|
|
||||||
<DisplayName>CDMF_DEFAULT_IDP</DisplayName>
|
|
||||||
<IdentityProviderDescription></IdentityProviderDescription>
|
|
||||||
<Alias>https://localhost:9443/oauth2/token</Alias>
|
|
||||||
<IsPrimary>true</IsPrimary>
|
|
||||||
<IsFederationHub></IsFederationHub>
|
|
||||||
<HomeRealmId></HomeRealmId>
|
|
||||||
<ProvisioningRole></ProvisioningRole>
|
|
||||||
<FederatedAuthenticatorConfigs></FederatedAuthenticatorConfigs>
|
|
||||||
<DefaultAuthenticatorConfig>
|
|
||||||
</DefaultAuthenticatorConfig>
|
|
||||||
<ProvisioningConnectorConfigs>
|
|
||||||
<!--<ProvisioningConnectorConfig>
|
|
||||||
<ProvisioningProperties>
|
|
||||||
</ProvisioningProperties>
|
|
||||||
</ProvisioningConnectorConfig>-->
|
|
||||||
</ProvisioningConnectorConfigs>
|
|
||||||
<!--<DefaultProvisioningConnectorConfig></DefaultProvisioningConnectorConfig>-->
|
|
||||||
<ClaimConfig></ClaimConfig>
|
|
||||||
<Certificate>
|
|
||||||
MIIFkzCCA3sCBAKkVfcwDQYJKoZIhvcNAQEFBQAwgY0xCzAJBgNVBAYTAlNMMRAwDgYDVQQIEwdXZXN0ZXJuMRAwDgYDVQQHEwdDb2xvbWJvMQ0wCwYDVQQKEwRXU08yMRQwEgYDVQQLEwtFbmdpbmVlcmluZzESMBAGA1UEAxMJbG9jYWxob3N0MSEwHwYJKoZIhvcNAQkBFhJpb3RzZXJ2ZXJAd3NvMi5jb20wHhcNMTUxMjE3MTMxMTA0WhcNMTcxMjE2MTMxMTA0WjCBjTELMAkGA1UEBhMCU0wxEDAOBgNVBAgTB1dlc3Rlcm4xEDAOBgNVBAcTB0NvbG9tYm8xDTALBgNVBAoTBFdTTzIxFDASBgNVBAsTC0VuZ2luZWVyaW5nMRIwEAYDVQQDEwlsb2NhbGhvc3QxITAfBgkqhkiG9w0BCQEWEmlvdHNlcnZlckB3c28yLmNvbTCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBALkiGVQ9tZOKIi/gD/toV+enq+neqOBGYQ8Fq/ABOWnK2QpGWm81+Rets5GbQ6W//D8C5TOBGqK7z+LAgdmILr1XLkvrXWoan0GPdDJ1wpc2/6XDZvM5f7Y8cmRqVPJv7AF+ImgF9dqv97gYCiujy+nNHd5Nk/60pco2LBV5SyLqqrzKXEnSGrS4zoYWpPeJ9YrXPEkW7A6AxTQK0yU9Ej4TktgafbTueythrLomKiZJj4wPxm2lA2lAZscDdws9NWrI5z/LUVLbUMxrY10Nig1liX5b1mrUk5bb1d2tqwkPrpRILKoOBJtI674SQS3GziiUiCJGIO/EGGRn1AJsC/SvnnEez3WKY/DgJ6102MWK/yWtY8NYHUX2anwMBS7UpT5A4BXdsfBz3R+iPF99FxdAGGsS4GQuuPocZaycLqoPCxpTSSxBsKMUcKpn3yaiQRd6uDuiTNt7odDOQj0Tno7uokh/HILgbzvj9EExDOsdwLVvqYmUHBPeLmiICWXfi4kyH/twPOZtV9eVnfWYx5Kwg+2Y4fIb3q4ABr0hzxaMYHQo6NOukSH1BcdAWiQIXbSFFaTZD8p6OfiZpHcQ59HT/Z8GBlCFL2xkYJFmOhXI/Cu+xrcwqEIInv7d8w3eiNQ7MneomEptLbBk9+kMsP0ubo34oOGHR9qk3Lj580c/AgMBAAEwDQYJKoZIhvcNAQEFBQADggIBADw70g2/wrgzrAM8OXBlthGbCEaXZpKwq9IJN0qu+/l+PNwF7csQhj+qW+zMrWaH1DGWJroaei1+NFFrj/pvp61rF/ZeTPGVJd7puCq++SevqIrzKyAEBtwtpXmcFhBpV/FrQAv3ODOJ3bN2wSRPZHUvARTBB3RaUI06g1jCaBzjDEGoMfSxdr5/Ty2WxTI9u9RlIs3Q52AiOmROtLPiEQZQIqfNO3cxCEWojHxPqVEZA/kQYy+rryj4H0zzSrj7QFlQhsMDw5j8bv9AcvTEGmwp29avsgnceDWinI6lwtd8zqh0ZW9QJdH0BRNCM/EkTlTUHeEg04/sOgOrlWcvEfVxDqNEtbUzU9UFxl0lkQkuRn1UdxZlvhWaFnel5iRC9b7OZvi2mkVujLyxEWlJB1tuyMLQxu6PfabBVODP5V8/+uyiiK/gwrB5rYl8RHxGoznJnI1Y3HVzKlA849CrMBaY5vnhE03cNja7QroPzLmmuXBLk2LbI1lu5nJAqKpBUPMI/IU3pF4Q7VTD2ZANI+ktGgGlM8AK4OJHWOhj8W289pWTHVjG8syPLTsaYkhgLjzZl/g9cUwn/96NJNvzd3dkT+7VgE+BJOLofq25CjZcN1M7MhWdl3vbWNj9vzL0+FCnwca8UecfvFS39PIekIvqbtP+Gw8NiYOUGIllZ0JH
|
|
||||||
</Certificate>
|
|
||||||
<PermissionAndRoleConfig></PermissionAndRoleConfig>
|
|
||||||
<JustInTimeProvisioningConfig></JustInTimeProvisioningConfig>
|
|
||||||
</IdentityProvider>
|
|
||||||
@ -41,7 +41,7 @@ skew=0
|
|||||||
#jti=token123
|
#jti=token123
|
||||||
|
|
||||||
#KeyStore to cryptographic credentials
|
#KeyStore to cryptographic credentials
|
||||||
#KeyStore=src/main/resources/wso2carbon.jks
|
#KeyStore=repository/resources/security/wso2carbon.jks
|
||||||
|
|
||||||
#Password of the KeyStore
|
#Password of the KeyStore
|
||||||
#KeyStorePassword=wso2carbon
|
#KeyStorePassword=wso2carbon
|
||||||
@ -52,3 +52,6 @@ skew=0
|
|||||||
#Private key password to retrieve the private key used to sign
|
#Private key password to retrieve the private key used to sign
|
||||||
#AuthnRequest and LogoutRequest messages
|
#AuthnRequest and LogoutRequest messages
|
||||||
#PrivateKeyPassword=wso2carbon
|
#PrivateKeyPassword=wso2carbon
|
||||||
|
|
||||||
|
#this will be used as the default IDP config if there isn't any config available for tenants.
|
||||||
|
default-jwt-client=true
|
||||||
|
|||||||
@ -1,3 +1,2 @@
|
|||||||
instructions.configure = \
|
instructions.configure = \
|
||||||
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.identity.jwt.client.extension_${feature.version}/jwt.properties,target:${installFolder}/../../conf/etc/jwt.properties,overwrite:true);\
|
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.identity.jwt.client.extension_${feature.version}/jwt.properties,target:${installFolder}/../../conf/etc/jwt.properties,overwrite:true);\
|
||||||
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.identity.jwt.client.extension_${feature.version}/CDMF_DEFAULT_IDP.xml,target:${installFolder}/../../conf/identity/identity-providers/CDMF_DEFAULT_IDP.xml,overwrite:true);\
|
|
||||||
|
|||||||
17
pom.xml
17
pom.xml
@ -280,6 +280,12 @@
|
|||||||
<type>zip</type>
|
<type>zip</type>
|
||||||
<version>${carbon.device.mgt.version}</version>
|
<version>${carbon.device.mgt.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.device.mgt.api.feature</artifactId>
|
||||||
|
<type>zip</type>
|
||||||
|
<version>${carbon.device.mgt.version}</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<artifactId>org.wso2.carbon.device.mgt.ui.feature</artifactId>
|
<artifactId>org.wso2.carbon.device.mgt.ui.feature</artifactId>
|
||||||
@ -1390,13 +1396,6 @@
|
|||||||
<version>${carbon.analytics.common.version}</version>
|
<version>${carbon.analytics.common.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Carbon Analytics -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.wso2.carbon.analytics</groupId>
|
|
||||||
<artifactId>org.wso2.carbon.analytics.api</artifactId>
|
|
||||||
<version>${carbon.analytics.version}</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- Carbon Registry -->
|
<!-- Carbon Registry -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.wso2.carbon.registry</groupId>
|
<groupId>org.wso2.carbon.registry</groupId>
|
||||||
@ -1749,10 +1748,6 @@
|
|||||||
<carbon.analytics.common.version>5.0.11</carbon.analytics.common.version>
|
<carbon.analytics.common.version>5.0.11</carbon.analytics.common.version>
|
||||||
<carbon.analytics.common.version.range>[5.0.11,6.0.0)</carbon.analytics.common.version.range>
|
<carbon.analytics.common.version.range>[5.0.11,6.0.0)</carbon.analytics.common.version.range>
|
||||||
|
|
||||||
<!-- Carbon Analytics -->
|
|
||||||
<carbon.analytics.version>1.0.5</carbon.analytics.version>
|
|
||||||
<carbon.analytics.version.range>[1.0.5,2.0.0]</carbon.analytics.version.range>
|
|
||||||
|
|
||||||
<!-- Carbon Registry -->
|
<!-- Carbon Registry -->
|
||||||
<carbon.registry.version>4.4.8</carbon.registry.version>
|
<carbon.registry.version>4.4.8</carbon.registry.version>
|
||||||
<carbon.registry.imp.pkg.version.range>[4.4.8, 5.0.0)</carbon.registry.imp.pkg.version.range>
|
<carbon.registry.imp.pkg.version.range>[4.4.8, 5.0.0)</carbon.registry.imp.pkg.version.range>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user