Sync with master

apim420
Pasindu Rupasinghe 11 months ago
commit 6a12911487

@ -22,7 +22,7 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>grafana-mgt</artifactId>
<version>5.0.35-SNAPSHOT</version>
<version>5.0.38-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>grafana-mgt</artifactId>
<version>5.0.35-SNAPSHOT</version>
<version>5.0.38-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>grafana-mgt</artifactId>
<version>5.0.35-SNAPSHOT</version>
<version>5.0.38-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>analytics-mgt</artifactId>
<version>5.0.35-SNAPSHOT</version>
<version>5.0.38-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -21,7 +21,7 @@
<parent>
<artifactId>io.entgra.device.mgt.core.parent</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.35-SNAPSHOT</version>
<version>5.0.38-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

@ -20,7 +20,7 @@
<parent>
<artifactId>apimgt-extensions</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.35-SNAPSHOT</version>
<version>5.0.38-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

@ -22,7 +22,7 @@
<parent>
<artifactId>apimgt-extensions</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.35-SNAPSHOT</version>
<version>5.0.38-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -21,7 +21,7 @@
<parent>
<artifactId>apimgt-extensions</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.35-SNAPSHOT</version>
<version>5.0.38-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<artifactId>apimgt-extensions</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.35-SNAPSHOT</version>
<version>5.0.38-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<artifactId>apimgt-extensions</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.35-SNAPSHOT</version>
<version>5.0.38-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
@ -78,6 +78,10 @@
<artifactId>okhttp</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.user.api</artifactId>
</dependency>
</dependencies>
<build>
@ -108,23 +112,20 @@
io.entgra.device.mgt.core.apimgt.extension.rest.api.*
</Export-Package>
<Import-Package>
com.google.gson;version="[2.9,3)",
io.entgra.device.mgt.core.apimgt.extension.rest.api,
io.entgra.device.mgt.core.apimgt.extension.rest.api.dto,
io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo,
io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions,
io.entgra.device.mgt.core.apimgt.extension.rest.api.util,
javax.net.ssl,okhttp3;version="[4.9,5)",
org.apache.commons.lang;version="[2.6,3)",
org.apache.commons.logging;version="[1.2,2)",
org.apache.commons.ssl;version="[3.1,4)",
org.json;version="[3.0,4)",
org.osgi.framework.*;version="${imp.package.version.osgi.framework}",
org.osgi.service.*;version="${imp.package.version.osgi.service}",
org.wso2.carbon.apimgt.api.model;version="[9.28,10)",
org.wso2.carbon.apimgt.impl;version="[9.28,10)",
org.wso2.carbon.apimgt.impl.internal;version="[9.28,10)",
org.wso2.carbon.base;version="[1.0,2)"
org.wso2.carbon.core;version="4.6",
org.wso2.carbon.core.util;version="4.6",
org.apache.commons.ssl,
org.wso2.carbon.apimgt.api.model,
okhttp3.*,
org.wso2.carbon.apimgt.impl;version="${carbon.api.mgt.version.range}",
org.wso2.carbon.apimgt.impl.utils;version="${carbon.api.mgt.version.range}",
org.wso2.carbon.apimgt.impl.internal;version="${carbon.api.mgt.version.range}",
org.json,
org.wso2.carbon.user.api,
org.wso2.carbon.context;version="4.6",
org.wso2.carbon.utils.*
</Import-Package>
</instructions>
</configuration>

@ -28,8 +28,10 @@ import okhttp3.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.json.JSONObject;
import org.wso2.carbon.apimgt.impl.APIConstants;
import org.wso2.carbon.apimgt.impl.APIManagerConfiguration;
import org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import java.io.IOException;
@ -44,12 +46,12 @@ public class APIApplicationServicesImpl implements APIApplicationServices {
getAPIManagerConfigurationService().getAPIManagerConfiguration();
@Override
public APIApplicationKey createAndRetrieveApplicationCredentials(String clientName, String grantType)
throws APIServicesException {
public APIApplicationKey createAndRetrieveApplicationCredentials(String clientName, String grantType) throws APIServicesException {
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
String serverUser = getScopePublishUserName(tenantDomain);
String serverPassword = getScopePublishUserPassword(tenantDomain);
String applicationEndpoint = config.getFirstProperty(Constants.DCR_END_POINT);
String serverUser = config.getFirstProperty(Constants.SERVER_USER);
String serverPassword = config.getFirstProperty(Constants.SERVER_PASSWORD);
JSONObject jsonObject = new JSONObject();
jsonObject.put("callbackUrl", Constants.EMPTY_STRING);
@ -64,9 +66,11 @@ public class APIApplicationServicesImpl implements APIApplicationServices {
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Credentials.basic(serverUser, serverPassword))
.post(requestBody)
.build();
try {
Response response = client.newCall(request).execute();
return gson.fromJson(response.body().string(), APIApplicationKey.class);
try (Response response = client.newCall(request).execute()) {
return gson.fromJson(response.body().string(), APIApplicationKey.class);
}
} catch (IOException e) {
msg = "Error occurred while processing the response";
log.error(msg, e);
@ -107,8 +111,9 @@ public class APIApplicationServicesImpl implements APIApplicationServices {
public AccessTokenInfo generateAccessTokenFromRegisteredApplication(String consumerKey, String consumerSecret)
throws APIServicesException {
String userName = config.getFirstProperty(Constants.SERVER_USER);
String userPassword = config.getFirstProperty(Constants.SERVER_PASSWORD);
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
String userName = getScopePublishUserName(tenantDomain);
String userPassword = getScopePublishUserPassword(tenantDomain);
JSONObject params = new JSONObject();
params.put(Constants.GRANT_TYPE_PARAM_NAME, Constants.PASSWORD_GRANT_TYPE);
@ -119,9 +124,8 @@ public class APIApplicationServicesImpl implements APIApplicationServices {
}
@Override
public AccessTokenInfo generateAccessTokenFromRefreshToken(String refreshToken, String consumerKey, String consumerSecret)
throws APIServicesException {
public AccessTokenInfo generateAccessTokenFromRefreshToken(String refreshToken, String consumerKey,
String consumerSecret) throws APIServicesException {
JSONObject params = new JSONObject();
params.put(Constants.GRANT_TYPE_PARAM_NAME, Constants.REFRESH_TOKEN_GRANT_TYPE);
params.put(Constants.REFRESH_TOKEN_GRANT_TYPE_PARAM_NAME, refreshToken);
@ -150,4 +154,20 @@ public class APIApplicationServicesImpl implements APIApplicationServices {
throw new APIServicesException(e);
}
}
private String getScopePublishUserName(String tenantDomain) {
if(APIConstants.SUPER_TENANT_DOMAIN.equals(tenantDomain)) {
return config.getFirstProperty(Constants.SERVER_USER);
} else {
return Constants.SCOPE_PUBLISH_RESERVED_USER_NAME + "@" + tenantDomain;
}
}
private String getScopePublishUserPassword(String tenantDomain) {
if(APIConstants.SUPER_TENANT_DOMAIN.equals(tenantDomain)) {
return config.getFirstProperty(Constants.SERVER_PASSWORD);
} else {
return Constants.SCOPE_PUBLISH_RESERVED_USER_PASSWORD;
}
}
}

@ -41,6 +41,9 @@ public interface PublisherRESTAPIServices {
boolean updateSharedScope(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, Scope scope)
throws APIServicesException, BadRequestException, UnexpectedResponseException;
boolean deleteSharedScope(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, Scope scope)
throws APIServicesException, BadRequestException, UnexpectedResponseException;
APIInfo getApi(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, String apiUuid)
throws APIServicesException, BadRequestException, UnexpectedResponseException;

@ -79,6 +79,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
throw new BadRequestException(msg);
} else {
String msg = "Response : " + response.code() + response.body();
log.error(msg);
throw new UnexpectedResponseException(msg);
}
} catch (IOException e) {
@ -123,6 +124,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
return false;
} else {
String msg = "Response : " + response.code() + response.body();
log.error(msg);
throw new UnexpectedResponseException(msg);
}
} catch (IOException e) {
@ -177,6 +179,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
throw new BadRequestException(msg);
} else {
String msg = "Response : " + response.code() + response.message();
log.error(msg);
throw new UnexpectedResponseException(msg);
}
} catch (IOException e) {
@ -231,6 +234,61 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
throw new BadRequestException(msg);
} else {
String msg = "Response : " + response.code() + response.body();
log.error(msg);
throw new UnexpectedResponseException(msg);
}
} catch (IOException e) {
String msg = "Error occurred while processing the response";
log.error(msg, e);
throw new APIServicesException(msg, e);
}
}
@Override
public boolean deleteSharedScope(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, Scope scope)
throws APIServicesException, BadRequestException, UnexpectedResponseException {
String updateScopeUrl = endPointPrefix + Constants.SCOPE_API_ENDPOINT + scope.getId();
JSONArray bindings = new JSONArray();
if (scope.getBindings() != null) {
for (String str : scope.getBindings()) {
bindings.put(str);
}
}
JSONObject payload = new JSONObject();
payload.put("name", (scope.getName() != null ? scope.getName() : ""));
payload.put("displayName", (scope.getDisplayName() != null ? scope.getDisplayName() : ""));
payload.put("description", (scope.getDescription() != null ? scope.getDescription() : ""));
payload.put("bindings", (bindings != null ? bindings : ""));
payload.put("usageCount", (scope.getUsageCount() != 0 ? scope.getUsageCount() : 0));
RequestBody requestBody = RequestBody.create(JSON, payload.toString());
Request request = new Request.Builder()
.url(updateScopeUrl)
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
+ accessTokenInfo.getAccess_token())
.delete(requestBody)
.build();
try {
Response response = client.newCall(request).execute();
if (HttpStatus.SC_OK == response.code()) {
return true;
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
AccessTokenInfo refreshedAccessToken = apiApplicationServices.
generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(),
apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret());
//TODO: max attempt count
return deleteSharedScope(apiApplicationKey, refreshedAccessToken, scope);
} else if (HttpStatus.SC_BAD_REQUEST == response.code()) {
String msg = "Bad Request, Invalid scope object";
log.error(msg);
throw new BadRequestException(msg);
} else {
String msg = "Response : " + response.code() + response.body();
log.error(msg);
throw new UnexpectedResponseException(msg);
}
} catch (IOException e) {
@ -269,6 +327,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
throw new BadRequestException(msg);
} else {
String msg = "Response : " + response.code() + response.body();
log.error(msg);
throw new UnexpectedResponseException(msg);
}
} catch (IOException e) {
@ -308,6 +367,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
throw new BadRequestException(msg);
} else {
String msg = "Response : " + response.code() + response.body();
log.error(msg);
throw new UnexpectedResponseException(msg);
}
} catch (IOException e) {
@ -447,6 +507,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
throw new BadRequestException(msg);
} else {
String msg = "Response status : " + response.code() + " Response message : " + response.message();
log.error(msg);
throw new UnexpectedResponseException(msg);
}
} catch (IOException e) {
@ -586,6 +647,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
throw new BadRequestException(msg);
} else {
String msg = "Response : " + response.code() + response.body();
log.error(msg);
throw new UnexpectedResponseException(msg);
}
} catch (IOException e) {
@ -632,6 +694,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
throw new BadRequestException(msg);
} else {
String msg = "Response : " + response.code() + response.body();
log.error(msg);
throw new UnexpectedResponseException(msg);
}
} catch (IOException e) {
@ -673,6 +736,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
throw new BadRequestException(msg);
} else {
String msg = "Response : " + response.code() + response.body();
log.error(msg);
throw new UnexpectedResponseException(msg);
}
} catch (IOException e) {
@ -720,6 +784,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
throw new BadRequestException(msg);
} else {
String msg = "Response : " + response.code() + response.body();
log.error(msg);
throw new UnexpectedResponseException(msg);
}
} catch (IOException e) {
@ -761,6 +826,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
throw new BadRequestException(msg);
} else {
String msg = "Response : " + response.code() + response.body();
log.error(msg);
throw new UnexpectedResponseException(msg);
}
} catch (IOException e) {
@ -804,6 +870,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
throw new BadRequestException(msg);
} else {
String msg = "Response : " + response.code() + response.body();
log.error(msg);
throw new UnexpectedResponseException(msg);
}
} catch (IOException e) {
@ -846,6 +913,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
throw new BadRequestException(msg);
} else {
String msg = "Response : " + response.code() + response.body();
log.error(msg);
throw new UnexpectedResponseException(msg);
}
} catch (IOException e) {
@ -889,6 +957,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
throw new BadRequestException(msg);
} else {
String msg = "Response : " + response.code() + response.body();
log.error(msg);
throw new UnexpectedResponseException(msg);
}
} catch (IOException e) {
@ -939,6 +1008,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
throw new BadRequestException(msg);
} else {
String msg = "Response : " + response.code() + response.body();
log.error(msg);
throw new UnexpectedResponseException(msg);
}
} catch (IOException e) {
@ -990,6 +1060,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
throw new BadRequestException(msg);
} else {
String msg = "Response : " + response.code() + response.body();
log.error(msg);
throw new UnexpectedResponseException(msg);
}
} catch (IOException e) {
@ -1031,6 +1102,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
throw new BadRequestException(msg);
} else {
String msg = "Response : " + response.code() + response.body();
log.error(msg);
throw new UnexpectedResponseException(msg);
}
} catch (IOException e) {
@ -1071,6 +1143,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
throw new BadRequestException(msg);
} else {
String msg = "Response : " + response.code() + response.body();
log.error(msg);
throw new UnexpectedResponseException(msg);
}
} catch (IOException e) {
@ -1111,6 +1184,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
throw new BadRequestException(msg);
} else {
String msg = "Response : " + response.code() + response.body();
log.error(msg);
throw new UnexpectedResponseException(msg);
}
} catch (IOException e) {
@ -1162,6 +1236,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
throw new BadRequestException(msg);
} else {
String msg = "Response : " + response.code() + response.body();
log.error(msg);
throw new UnexpectedResponseException(msg);
}
} catch (IOException e) {
@ -1208,6 +1283,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
throw new BadRequestException(msg);
} else {
String msg = "Response : " + response.code() + response.body();
log.error(msg);
throw new UnexpectedResponseException(msg);
}
} catch (IOException e) {

@ -72,6 +72,8 @@ public final class Constants {
public static final String SUBSCRIPTION_API = "/api/am/devportal/v3/subscriptions";
public static final String DEV_PORTAL_API = "/api/am/devportal/v3/apis?limit=1000";
public static final String KEY_MANAGERS_API = "/api/am/devportal/v3/key-managers";
public static final String SCOPE_PUBLISH_RESERVED_USER_NAME = "scope_publish_reserved_user";
public static final String SCOPE_PUBLISH_RESERVED_USER_PASSWORD = "&gKfyE8E4rUY4Q";
public static final String ADMIN_ROLE_KEY = "admin";
public static final String PERM_SCOPE_MAPPING_META_KEY = "perm-scope-mapping";
}

@ -22,6 +22,8 @@ import io.entgra.device.mgt.core.apimgt.extension.rest.api.APIApplicationService
import io.entgra.device.mgt.core.apimgt.extension.rest.api.APIApplicationServicesImpl;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.ConsumerRESTAPIServices;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.ConsumerRESTAPIServicesImpl;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.PublisherRESTAPIServices;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.PublisherRESTAPIServicesImpl;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.osgi.framework.BundleContext;
@ -32,9 +34,9 @@ import org.wso2.carbon.apimgt.impl.APIManagerConfigurationService;
@Component(
name = "io.entgra.device.mgt.core.apimgt.extension.rest.api.internal.PublisherRESTAPIServiceComponent",
immediate = true)
public class PublisherRESTAPIServiceComponent {
public class APIManagerServiceComponent {
private static final Log log = LogFactory.getLog(PublisherRESTAPIServiceComponent.class);
private static Log log = LogFactory.getLog(APIManagerServiceComponent.class);
@Activate
protected void activate(ComponentContext componentContext) {
@ -46,11 +48,15 @@ public class PublisherRESTAPIServiceComponent {
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
bundleContext.registerService(APIApplicationServices.class.getName(), apiApplicationServices, null);
PublisherRESTAPIDataHolder.getInstance().setApiApplicationServices(apiApplicationServices);
APIManagerServiceDataHolder.getInstance().setApiApplicationServices(apiApplicationServices);
PublisherRESTAPIServices publisherRESTAPIServices = new PublisherRESTAPIServicesImpl();
bundleContext.registerService(PublisherRESTAPIServices.class.getName(), publisherRESTAPIServices, null);
APIManagerServiceDataHolder.getInstance().setPublisherRESTAPIServices(publisherRESTAPIServices);
ConsumerRESTAPIServices consumerRESTAPIServices = new ConsumerRESTAPIServicesImpl();
bundleContext.registerService(ConsumerRESTAPIServices.class.getName(), consumerRESTAPIServices, null);
PublisherRESTAPIDataHolder.getInstance().setConsumerRESTAPIServices(consumerRESTAPIServices);
APIManagerServiceDataHolder.getInstance().setConsumerRESTAPIServices(consumerRESTAPIServices);
if (log.isDebugEnabled()) {
log.debug("API Application bundle has been successfully initialized");
@ -74,13 +80,13 @@ public class PublisherRESTAPIServiceComponent {
if (log.isDebugEnabled()) {
log.debug("Setting API Manager Configuration Service");
}
PublisherRESTAPIDataHolder.getInstance().setAPIManagerConfiguration(apiManagerConfigurationService);
APIManagerServiceDataHolder.getInstance().setAPIManagerConfiguration(apiManagerConfigurationService);
}
protected void unsetAPIManagerConfigurationService(APIManagerConfigurationService apiManagerConfigurationService) {
if (log.isDebugEnabled()) {
log.debug("Unsetting API Manager Configuration Service");
}
PublisherRESTAPIDataHolder.getInstance().setAPIManagerConfiguration(null);
APIManagerServiceDataHolder.getInstance().setAPIManagerConfiguration(null);
}
}

@ -19,22 +19,28 @@
package io.entgra.device.mgt.core.apimgt.extension.rest.api.internal;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.APIApplicationServices;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.PublisherRESTAPIServices;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.ConsumerRESTAPIServices;
import org.wso2.carbon.apimgt.impl.APIManagerConfigurationService;
import org.wso2.carbon.user.core.service.RealmService;
import org.wso2.carbon.user.core.tenant.TenantManager;
public class PublisherRESTAPIDataHolder {
public class APIManagerServiceDataHolder {
private APIApplicationServices apiApplicationServices;
private APIManagerConfigurationService apiManagerConfigurationService;
private PublisherRESTAPIServices publisherRESTAPIServices;
private RealmService realmService;
private TenantManager tenantManager;
private ConsumerRESTAPIServices consumerRESTAPIServices;
private static APIManagerServiceDataHolder thisInstance = new APIManagerServiceDataHolder();
private static PublisherRESTAPIDataHolder thisInstance = new PublisherRESTAPIDataHolder();
private ConsumerRESTAPIServices consumerRESTAPIServices;
private PublisherRESTAPIDataHolder() {
private APIManagerServiceDataHolder() {
}
static PublisherRESTAPIDataHolder getInstance() {
static APIManagerServiceDataHolder getInstance() {
return thisInstance;
}
@ -57,6 +63,38 @@ public class PublisherRESTAPIDataHolder {
return apiManagerConfigurationService;
}
public PublisherRESTAPIServices getPublisherRESTAPIServices() {
return publisherRESTAPIServices;
}
public void setPublisherRESTAPIServices(PublisherRESTAPIServices publisherRESTAPIServices) {
this.publisherRESTAPIServices = publisherRESTAPIServices;
}
public RealmService getRealmService() {
if (realmService == null) {
throw new IllegalStateException("Realm service is not initialized properly");
}
return realmService;
}
public void setRealmService(RealmService realmService) {
this.realmService = realmService;
this.setTenantManager(realmService);
}
public TenantManager getTenantManager() {
return tenantManager;
}
private void setTenantManager(RealmService realmService) {
if (realmService == null) {
throw new IllegalStateException("Realm service is not initialized properly");
}
this.tenantManager = realmService.getTenantManager();
}
public ConsumerRESTAPIServices getConsumerRESTAPIServices() {
return consumerRESTAPIServices;
}
@ -64,5 +102,4 @@ public class PublisherRESTAPIDataHolder {
public void setConsumerRESTAPIServices(ConsumerRESTAPIServices consumerRESTAPIServices) {
this.consumerRESTAPIServices = consumerRESTAPIServices;
}
}

@ -0,0 +1,91 @@
/*
* Copyright (c) 2018 - 2024, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. 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 io.entgra.device.mgt.core.apimgt.extension.rest.api.util;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.constants.Constants;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.APIServicesException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.user.api.UserStoreException;
import org.wso2.carbon.user.api.UserStoreManager;
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
import org.wso2.carbon.utils.multitenancy.MultitenantUtils;
/**
* This class contains utility methods needed for API publishing
*/
public class APIPublisherUtils {
private static final Log log = LogFactory.getLog(APIPublisherUtils.class);
/**
* This method will create the temporary user created to publish scopes to the sub tenant space.
* @param tenantDomain sub tenant domain from which the user will be created
* @throws APIServicesException if the user was unable to be created
*/
public static void createScopePublishUserIfNotExists(String tenantDomain) throws APIServicesException {
if (!MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) {
try {
UserStoreManager userStoreManager =
PrivilegedCarbonContext.getThreadLocalCarbonContext().getUserRealm().getUserStoreManager();
if (!userStoreManager.isExistingUser(MultitenantUtils.getTenantAwareUsername(Constants.SCOPE_PUBLISH_RESERVED_USER_NAME))) {
if (log.isDebugEnabled()) {
log.debug("Creating scope publish user '" + Constants.SCOPE_PUBLISH_RESERVED_USER_NAME + "' in '" +
tenantDomain + "' tenant domain.");
}
String[] roles = {Constants.ADMIN_ROLE_KEY};
userStoreManager.addUser(
MultitenantUtils.getTenantAwareUsername(Constants.SCOPE_PUBLISH_RESERVED_USER_NAME),
Constants.SCOPE_PUBLISH_RESERVED_USER_PASSWORD,
roles,
null,
""
);
}
} catch (UserStoreException e) {
String msg = "Error occurred while creating scope publishing user in tenant: '" + tenantDomain + "'.";
log.error(msg);
throw new APIServicesException(msg, e);
}
}
}
/**
* This method will delete the temporary user created to publish scopes to the sub tenant space.
* @param tenantDomain sub tenant domain from which the scope publish user will be removed from
*/
public static void removeScopePublishUserIfExists(String tenantDomain) {
if (!MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) {
try {
UserStoreManager userStoreManager =
PrivilegedCarbonContext.getThreadLocalCarbonContext().getUserRealm().getUserStoreManager();
if (userStoreManager.isExistingUser(MultitenantUtils.getTenantAwareUsername(Constants.SCOPE_PUBLISH_RESERVED_USER_NAME))) {
if (log.isDebugEnabled()) {
log.debug("Deleting scope publish user '" + Constants.SCOPE_PUBLISH_RESERVED_USER_NAME + "' from '" +
tenantDomain + "' tenant domain.");
}
userStoreManager.deleteUser(MultitenantUtils.getTenantAwareUsername(Constants.SCOPE_PUBLISH_RESERVED_USER_NAME));
}
} catch(UserStoreException e){
String msg = "Error occurred while deleting scope publishing user from tenant: '" + tenantDomain + "'.";
log.error(msg);
}
}
}
}

@ -21,7 +21,7 @@
<parent>
<artifactId>apimgt-extensions</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.35-SNAPSHOT</version>
<version>5.0.38-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

@ -21,7 +21,7 @@
<parent>
<artifactId>apimgt-extensions</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.35-SNAPSHOT</version>
<version>5.0.38-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<artifactId>apimgt-extensions</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.35-SNAPSHOT</version>
<version>5.0.38-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -39,7 +39,7 @@ public interface APIPublisherService {
/**
* Add default scopes defined in the cdm-config.xml
*/
void addDefaultScopesIfNotExist();
void addDefaultScopesIfNotExist() throws APIManagerPublisherException;
/**
* If the permissions are in the permission list, identify the relevant scopes of the supplied permission list

@ -18,18 +18,24 @@
package io.entgra.device.mgt.core.apimgt.webapp.publisher;
import com.google.gson.Gson;
import io.entgra.device.mgt.core.apimgt.annotations.Scopes;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.APIApplicationServices;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.APIApplicationServicesImpl;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.PublisherRESTAPIServices;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.PublisherRESTAPIServicesImpl;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.constants.Constants;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIApplicationKey;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo.*;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo.APIInfo;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo.APIRevision;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo.APIRevisionDeployment;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo.CORSConfiguration;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo.Documentation;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo.Mediation;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo.MediationPolicy;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo.Operations;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo.Scope;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.AccessTokenInfo;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.APIServicesException;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.BadRequestException;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.UnexpectedResponseException;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.util.APIPublisherUtils;
import io.entgra.device.mgt.core.apimgt.webapp.publisher.config.WebappPublisherConfig;
import io.entgra.device.mgt.core.apimgt.webapp.publisher.dto.ApiScope;
import io.entgra.device.mgt.core.apimgt.webapp.publisher.dto.ApiUriTemplate;
@ -43,7 +49,6 @@ import io.entgra.device.mgt.core.device.mgt.core.config.permission.ScopeMapping;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.json.JSONArray;
import org.json.JSONObject;
import org.wso2.carbon.CarbonConstants;
import org.wso2.carbon.apimgt.api.APIManagementException;
@ -62,6 +67,7 @@ import org.wso2.carbon.user.core.tenant.Tenant;
import org.wso2.carbon.user.core.tenant.TenantSearchResult;
import org.wso2.carbon.utils.CarbonUtils;
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
import org.wso2.carbon.utils.multitenancy.MultitenantUtils;
import java.io.BufferedReader;
import java.io.File;
@ -100,21 +106,10 @@ public class APIPublisherServiceImpl implements APIPublisherService {
RealmService realmService = (RealmService) PrivilegedCarbonContext.getThreadLocalCarbonContext()
.getOSGiService(RealmService.class, null);
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
APIApplicationServices apiApplicationServices = APIPublisherDataHolder.getInstance().getApiApplicationServices();
PublisherRESTAPIServices publisherRESTAPIServices = APIPublisherDataHolder.getInstance().getPublisherRESTAPIServices();
APIApplicationKey apiApplicationKey;
AccessTokenInfo accessTokenInfo;
try {
apiApplicationKey = apiApplicationServices.createAndRetrieveApplicationCredentials(
"ClientForPublisherRestCalls",
"client_credentials password refresh_token"
);
accessTokenInfo = apiApplicationServices.generateAccessTokenFromRegisteredApplication(
apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret());
} catch (APIServicesException e) {
String errorMsg = "Error occurred while generating the API application";
log.error(errorMsg, e);
throw new APIManagerPublisherException(e);
}
try {
boolean tenantFound = false;
@ -149,6 +144,19 @@ public class APIPublisherServiceImpl implements APIPublisherService {
PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(apiConfig.getOwner());
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
try {
APIPublisherUtils.createScopePublishUserIfNotExists(tenantDomain);
apiApplicationKey = apiApplicationServices.createAndRetrieveApplicationCredentials(
"ClientForPublisherRestCalls",
"client_credentials password refresh_token");
accessTokenInfo = apiApplicationServices.generateAccessTokenFromRegisteredApplication(
apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret());
} catch (APIServicesException e) {
String errorMsg = "Error occurred while generating the API application";
log.error(errorMsg, e);
throw new APIManagerPublisherException(e);
}
try {
apiConfig.setOwner(APIUtil.getTenantAdminUserName(tenantDomain));
apiConfig.setTenantDomain(tenantDomain);
@ -156,7 +164,6 @@ public class APIPublisherServiceImpl implements APIPublisherService {
APIIdentifier apiIdentifier = new APIIdentifier(APIUtil.replaceEmailDomain(apiConfig.getOwner()),
apiConfig.getName(), apiConfig.getVersion());
PublisherRESTAPIServices publisherRESTAPIServices = new PublisherRESTAPIServicesImpl();
APIInfo[] apiList = publisherRESTAPIServices.getApis(apiApplicationKey, accessTokenInfo);
boolean apiFound = false;
for (int i = 0; i < apiList.length; i++) {
@ -378,6 +385,7 @@ public class APIPublisherServiceImpl implements APIPublisherService {
log.error(msg, e);
throw new APIManagerPublisherException(e);
} finally {
APIPublisherUtils.removeScopePublishUserIfExists(tenantDomain);
PrivilegedCarbonContext.endTenantFlow();
}
}
@ -417,39 +425,55 @@ public class APIPublisherServiceImpl implements APIPublisherService {
}
}
public void addDefaultScopesIfNotExist() {
@Override
public void addDefaultScopesIfNotExist() throws APIManagerPublisherException {
WebappPublisherConfig config = WebappPublisherConfig.getInstance();
List<String> tenants = new ArrayList<>(Collections.singletonList(APIConstants.SUPER_TENANT_DOMAIN));
tenants.addAll(config.getTenants().getTenant());
DeviceManagementConfig deviceManagementConfig = DeviceConfigurationManager.getInstance().getDeviceManagementConfig();
DefaultPermissions defaultPermissions = deviceManagementConfig.getDefaultPermissions();
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
try {
APIApplicationKey apiApplicationKey = apiApplicationServices.createAndRetrieveApplicationCredentials(
"ClientForPublisherRestCalls",
"client_credentials password refresh_token"
);
AccessTokenInfo accessTokenInfo =
apiApplicationServices.generateAccessTokenFromRegisteredApplication(
apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret());
APIApplicationServices apiApplicationServices = APIPublisherDataHolder.getInstance().getApiApplicationServices();
PublisherRESTAPIServices publisherRESTAPIServices = APIPublisherDataHolder.getInstance().getPublisherRESTAPIServices();
PublisherRESTAPIServices publisherRESTAPIServices = new PublisherRESTAPIServicesImpl();
for (String tenantDomain : tenants) {
try {
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain, true);
Scope scope = new Scope();
for (DefaultPermission defaultPermission: defaultPermissions.getDefaultPermissions()) {
if (!publisherRESTAPIServices.isSharedScopeNameExists(apiApplicationKey, accessTokenInfo,
defaultPermission.getScopeMapping().getKey())) {
ScopeMapping scopeMapping = defaultPermission.getScopeMapping();
APIPublisherUtils.createScopePublishUserIfNotExists(tenantDomain);
APIApplicationKey apiApplicationKey =
apiApplicationServices.createAndRetrieveApplicationCredentials(
"ClientForPublisherRestCalls", "client_credentials password refresh_token"
);
AccessTokenInfo accessTokenInfo =
apiApplicationServices.generateAccessTokenFromRegisteredApplication(
apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret());
List<String> bindings = new ArrayList<>(
Arrays.asList(scopeMapping.getDefaultRoles().split(",")));
bindings.add(ADMIN_ROLE_KEY);
scope.setName(scopeMapping.getKey());
scope.setDescription(scopeMapping.getName());
scope.setDisplayName(scopeMapping.getName());
scope.setBindings(bindings);
publisherRESTAPIServices.addNewSharedScope(apiApplicationKey, accessTokenInfo, scope);
Scope scope = new Scope();
for (DefaultPermission defaultPermission : defaultPermissions.getDefaultPermissions()) {
if (!publisherRESTAPIServices.isSharedScopeNameExists(apiApplicationKey, accessTokenInfo,
defaultPermission.getScopeMapping().getKey())) {
ScopeMapping scopeMapping = defaultPermission.getScopeMapping();
List<String> bindings = new ArrayList<>(
Arrays.asList(scopeMapping.getDefaultRoles().split(",")));
bindings.add(ADMIN_ROLE_KEY);
scope.setName(scopeMapping.getKey());
scope.setDescription(scopeMapping.getName());
scope.setDisplayName(scopeMapping.getName());
scope.setBindings(bindings);
publisherRESTAPIServices.addNewSharedScope(apiApplicationKey, accessTokenInfo, scope);
}
}
} catch (BadRequestException | UnexpectedResponseException | APIServicesException e) {
String errorMsg = "Error occurred while adding default scopes";
log.error(errorMsg, e);
throw new APIManagerPublisherException(e);
} finally {
APIPublisherUtils.removeScopePublishUserIfExists(tenantDomain);
PrivilegedCarbonContext.endTenantFlow();
}
} catch (BadRequestException | UnexpectedResponseException | APIServicesException e) {
log.error("Error occurred while adding default scopes");
}
}
@ -462,31 +486,32 @@ public class APIPublisherServiceImpl implements APIPublisherService {
List<String> tenants = new ArrayList<>(Collections.singletonList(APIConstants.SUPER_TENANT_DOMAIN));
tenants.addAll(config.getTenants().getTenant());
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
APIApplicationServices apiApplicationServices = APIPublisherDataHolder.getInstance().getApiApplicationServices();
PublisherRESTAPIServices publisherRESTAPIServices = APIPublisherDataHolder.getInstance().getPublisherRESTAPIServices();
APIApplicationKey apiApplicationKey;
AccessTokenInfo accessTokenInfo;
try {
apiApplicationKey = apiApplicationServices.createAndRetrieveApplicationCredentials(
"ClientForPublisherRestCalls",
"client_credentials password refresh_token"
);
accessTokenInfo = apiApplicationServices.generateAccessTokenFromRegisteredApplication(
apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret());
} catch (APIServicesException e) {
String errorMsg = "Error occurred while generating the API application";
log.error(errorMsg, e);
throw new APIManagerPublisherException(e);
}
UserStoreManager userStoreManager;
String fileName = null;
try {
for (String tenantDomain : tenants) {
for (String tenantDomain : tenants) {
try {
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain, true);
PublisherRESTAPIServices publisherRESTAPIServices = new PublisherRESTAPIServicesImpl();
try {
APIPublisherUtils.createScopePublishUserIfNotExists(tenantDomain);
apiApplicationKey = apiApplicationServices.createAndRetrieveApplicationCredentials("ClientForPublisherRestCalls",
"client_credentials password refresh_token");
accessTokenInfo = apiApplicationServices.generateAccessTokenFromRegisteredApplication(
apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret());
} catch (APIServicesException e) {
String errorMsg = "Error occurred while generating the API application";
log.error(errorMsg, e);
throw new APIManagerPublisherException(e);
}
try {
String fileName =
fileName =
CarbonUtils.getCarbonConfigDirPath() + File.separator + "etc"
+ File.separator + tenantDomain + ".csv";
try {
@ -576,33 +601,39 @@ public class APIPublisherServiceImpl implements APIPublisherService {
}
}
}
} catch (IOException | DirectoryIteratorException ex) {
log.error("failed to read scopes from file.", ex);
} catch (IOException | DirectoryIteratorException e) {
String errorMsg = "Failed to read scopes from file: '" + fileName + "'.";
log.error(errorMsg, e);
throw new APIManagerPublisherException(e);
}
} catch (APIServicesException e) {
String errorMsg = "Error while processing Publisher REST API response";
log.error(errorMsg, e);
throw new APIManagerPublisherException(e);
} catch (BadRequestException e) {
String errorMsg = "Error while calling Publisher REST APIs";
log.error(errorMsg, e);
throw new APIManagerPublisherException(e);
} catch (UnexpectedResponseException e) {
String errorMsg = "Unexpected response from the server";
log.error(errorMsg, e);
throw new APIManagerPublisherException(e);
} finally {
APIPublisherUtils.removeScopePublishUserIfExists(tenantDomain);
PrivilegedCarbonContext.endTenantFlow();
}
} catch (APIServicesException e) {
String errorMsg = "Error while processing Publisher REST API response";
log.error(errorMsg, e);
throw new APIManagerPublisherException(e);
} catch (BadRequestException e) {
String errorMsg = "Error while calling Publisher REST APIs";
log.error(errorMsg, e);
throw new APIManagerPublisherException(e);
} catch (UnexpectedResponseException e) {
String errorMsg = "Unexpected response from the server";
log.error(errorMsg, e);
throw new APIManagerPublisherException(e);
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
}
@Override
public void updateScopeRoleMapping(String roleName, String[] permissions, String[] removedPermissions) throws APIManagerPublisherException {
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
APIApplicationServices apiApplicationServices = APIPublisherDataHolder.getInstance().getApiApplicationServices();
PublisherRESTAPIServices publisherRESTAPIServices = APIPublisherDataHolder.getInstance().getPublisherRESTAPIServices();
APIApplicationKey apiApplicationKey;
AccessTokenInfo accessTokenInfo;
try {
APIPublisherUtils.createScopePublishUserIfNotExists(tenantDomain);
apiApplicationKey = apiApplicationServices.createAndRetrieveApplicationCredentials(
"ClientForPublisherRestCalls",
"client_credentials password refresh_token"
@ -616,7 +647,7 @@ public class APIPublisherServiceImpl implements APIPublisherService {
}
try {
PublisherRESTAPIServices publisherRESTAPIServices = new PublisherRESTAPIServicesImpl();
Scope[] scopeList = publisherRESTAPIServices.getScopes(apiApplicationKey, accessTokenInfo);
Map<String, String> permScopeMap = APIPublisherDataHolder.getInstance().getPermScopeMapping();
@ -646,6 +677,8 @@ public class APIPublisherServiceImpl implements APIPublisherService {
String errorMsg = "Unexpected response from the server";
log.error(errorMsg, e);
throw new APIManagerPublisherException(errorMsg, e);
} finally {
APIPublisherUtils.removeScopePublishUserIfExists(tenantDomain);
}
}

@ -17,6 +17,8 @@
*/
package io.entgra.device.mgt.core.apimgt.webapp.publisher.internal;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.APIApplicationServices;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.PublisherRESTAPIServices;
import io.entgra.device.mgt.core.apimgt.webapp.publisher.APIConfig;
import io.entgra.device.mgt.core.apimgt.webapp.publisher.APIPublisherService;
import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.MetadataManagementService;
@ -44,7 +46,8 @@ public class APIPublisherDataHolder {
private boolean isServerStarted;
private Stack<APIConfig> unpublishedApis = new Stack<>();
private Map<String, String> permScopeMapping;
private APIApplicationServices apiApplicationServices;
private PublisherRESTAPIServices publisherRESTAPIServices;
private MetadataManagementService metadataManagementService;
private static APIPublisherDataHolder thisInstance = new APIPublisherDataHolder();
@ -145,9 +148,29 @@ public class APIPublisherDataHolder {
this.unpublishedApis = unpublishedApis;
}
public Map<String, String> getPermScopeMapping() {return permScopeMapping;}
public Map<String, String> getPermScopeMapping() {
return permScopeMapping;
}
public void setPermScopeMapping(Map<String, String> permScopeMapping) {
this.permScopeMapping = permScopeMapping;
}
public APIApplicationServices getApiApplicationServices() {
return apiApplicationServices;
}
public void setPermScopeMapping(Map<String, String> permScopeMapping) {this.permScopeMapping = permScopeMapping;}
public void setApiApplicationServices(APIApplicationServices apiApplicationServices) {
this.apiApplicationServices = apiApplicationServices;
}
public PublisherRESTAPIServices getPublisherRESTAPIServices() {
return publisherRESTAPIServices;
}
public void setPublisherRESTAPIServices(PublisherRESTAPIServices publisherRESTAPIServices) {
this.publisherRESTAPIServices = publisherRESTAPIServices;
}
public MetadataManagementService getMetadataManagementService() {
return metadataManagementService;

@ -17,6 +17,8 @@
*/
package io.entgra.device.mgt.core.apimgt.webapp.publisher.internal;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.APIApplicationServices;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.PublisherRESTAPIServices;
import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.MetadataManagementService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@ -120,6 +122,46 @@ public class APIPublisherServiceComponent {
APIPublisherDataHolder.getInstance().setRegistryService(null);
}
@Reference(
name = "APIM.application.service",
service = io.entgra.device.mgt.core.apimgt.extension.rest.api.APIApplicationServices.class,
cardinality = ReferenceCardinality.MANDATORY,
policy = ReferencePolicy.DYNAMIC,
unbind = "unsetAPIApplicationServices")
protected void setAPIApplicationServices(APIApplicationServices apiApplicationServices) {
if (log.isDebugEnabled()) {
log.debug("Setting DCR REST API Service");
}
APIPublisherDataHolder.getInstance().setApiApplicationServices(apiApplicationServices);
}
protected void unsetAPIApplicationServices(APIApplicationServices apiApplicationServices) {
if (log.isDebugEnabled()) {
log.debug("Unsetting DCR REST API Service");
}
APIPublisherDataHolder.getInstance().setApiApplicationServices(null);
}
@Reference(
name = "APIM.publisher.service",
service = io.entgra.device.mgt.core.apimgt.extension.rest.api.PublisherRESTAPIServices.class,
cardinality = ReferenceCardinality.MANDATORY,
policy = ReferencePolicy.DYNAMIC,
unbind = "unsetPublisherRESTAPIServices")
protected void setPublisherRESTAPIServices(PublisherRESTAPIServices publisherRESTAPIServices) {
if (log.isDebugEnabled()) {
log.debug("Setting APIM Publisher REST API Service");
}
APIPublisherDataHolder.getInstance().setPublisherRESTAPIServices(publisherRESTAPIServices);
}
protected void unsetPublisherRESTAPIServices(PublisherRESTAPIServices publisherRESTAPIServices) {
if (log.isDebugEnabled()) {
log.debug("Unsetting APIM Publisher REST API Service");
}
APIPublisherDataHolder.getInstance().setPublisherRESTAPIServices(null);
}
@Reference(
name = "io.entgra.meta.mgt",
service = io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.MetadataManagementService.class,

@ -22,7 +22,7 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>io.entgra.device.mgt.core.parent</artifactId>
<version>5.0.35-SNAPSHOT</version>
<version>5.0.38-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

@ -21,7 +21,7 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>application-mgt</artifactId>
<version>5.0.35-SNAPSHOT</version>
<version>5.0.38-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -21,7 +21,7 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>application-mgt</artifactId>
<version>5.0.35-SNAPSHOT</version>
<version>5.0.38-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>io.entgra.device.mgt.core.parent</artifactId>
<version>5.0.35-SNAPSHOT</version>
<version>5.0.38-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<artifactId>certificate-mgt</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.35-SNAPSHOT</version>
<version>5.0.38-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<artifactId>certificate-mgt</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.35-SNAPSHOT</version>
<version>5.0.38-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -21,7 +21,7 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>certificate-mgt</artifactId>
<version>5.0.35-SNAPSHOT</version>
<version>5.0.38-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>io.entgra.device.mgt.core.parent</artifactId>
<version>5.0.35-SNAPSHOT</version>
<version>5.0.38-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<artifactId>device-mgt-extensions</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.35-SNAPSHOT</version>
<version>5.0.38-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<artifactId>device-mgt-extensions</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.35-SNAPSHOT</version>
<version>5.0.38-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -21,7 +21,7 @@
<parent>
<artifactId>device-mgt-extensions</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.35-SNAPSHOT</version>
<version>5.0.38-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<artifactId>device-mgt-extensions</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.35-SNAPSHOT</version>
<version>5.0.38-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<artifactId>device-mgt-extensions</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.35-SNAPSHOT</version>
<version>5.0.38-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<artifactId>device-mgt-extensions</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.35-SNAPSHOT</version>
<version>5.0.38-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<artifactId>device-mgt-extensions</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.35-SNAPSHOT</version>
<version>5.0.38-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<artifactId>device-mgt-extensions</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.35-SNAPSHOT</version>
<version>5.0.38-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<artifactId>device-mgt-extensions</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.35-SNAPSHOT</version>
<version>5.0.38-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<artifactId>device-mgt-extensions</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.35-SNAPSHOT</version>
<version>5.0.38-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<artifactId>io.entgra.device.mgt.core.parent</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.35-SNAPSHOT</version>
<version>5.0.38-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<artifactId>device-mgt</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.35-SNAPSHOT</version>
<version>5.0.38-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -952,7 +952,7 @@ public interface UserManagementService {
tags = "User Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = Constants.SCOPE, value = "perm:users:send-invitation")
@ExtensionProperty(name = Constants.SCOPE, value = "um:users:invite")
})
}
)

@ -18,6 +18,21 @@
package io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.impl;
import com.google.gson.Gson;
import io.entgra.device.mgt.core.device.mgt.common.group.mgt.DeviceGroup;
import io.entgra.device.mgt.core.device.mgt.common.group.mgt.DeviceGroupConstants;
import io.entgra.device.mgt.core.device.mgt.common.group.mgt.DeviceGroupRoleWrapper;
import io.entgra.device.mgt.core.device.mgt.common.group.mgt.DeviceTypesOfGroups;
import io.entgra.device.mgt.core.device.mgt.common.group.mgt.GroupAlreadyExistException;
import io.entgra.device.mgt.core.device.mgt.common.group.mgt.GroupManagementException;
import io.entgra.device.mgt.core.device.mgt.common.group.mgt.GroupNotExistException;
import io.entgra.device.mgt.core.device.mgt.common.group.mgt.RoleDoesNotExistException;
import io.entgra.device.mgt.core.device.mgt.extensions.logger.spi.EntgraLogger;
import io.entgra.device.mgt.core.notification.logger.GroupMgtLogContext;
import io.entgra.device.mgt.core.notification.logger.impl.EntgraGroupMgtLoggerImpl;
import org.wso2.carbon.CarbonConstants;
import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.DeviceGroupList;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.DeviceList;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.DeviceToGroupsAssignment;
@ -57,7 +72,8 @@ import java.util.List;
public class GroupManagementServiceImpl implements GroupManagementService {
private static final Log log = LogFactory.getLog(GroupManagementServiceImpl.class);
GroupMgtLogContext.Builder groupMgtContextBuilder = new GroupMgtLogContext.Builder();
private static final EntgraLogger log = new EntgraGroupMgtLoggerImpl(GroupManagementServiceImpl.class);
private static final String DEFAULT_ADMIN_ROLE = "admin";
private static final String[] DEFAULT_ADMIN_PERMISSIONS = {"/permission/device-mgt/admin/groups",
@ -161,6 +177,8 @@ public class GroupManagementServiceImpl implements GroupManagementService {
@Override
public Response createGroup(DeviceGroup group) {
String tenantId = String.valueOf(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());
String tenantDomain = String.valueOf(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain());
String owner = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
if (group == null) {
return Response.status(Response.Status.BAD_REQUEST).build();
@ -169,6 +187,22 @@ public class GroupManagementServiceImpl implements GroupManagementService {
group.setStatus(DeviceGroupConstants.GroupStatus.ACTIVE);
try {
DeviceMgtAPIUtils.getGroupManagementProviderService().createGroup(group, DEFAULT_ADMIN_ROLE, DEFAULT_ADMIN_PERMISSIONS);
int deviceCount = DeviceMgtAPIUtils.getGroupManagementProviderService().getDeviceCount(group.getGroupId());
String stringDevices = new Gson().toJson(DeviceMgtAPIUtils.getGroupManagementProviderService().getAllDevicesOfGroup(group.getName(), false));
log.info(
"Group " + group.getName() + " created",
groupMgtContextBuilder
.setActionTag("ADD_GROUP")
.setGroupId(String.valueOf(group.getGroupId()))
.setName(group.getName())
.setOwner(group.getOwner())
.setDeviceCount(String.valueOf(deviceCount))
.setDevices(stringDevices)
.setTenantID(tenantId)
.setTenantDomain(tenantDomain)
.setUserName(owner)
.build()
);
return Response.status(Response.Status.CREATED).build();
} catch (GroupManagementException e) {
String msg = "Error occurred while adding new group.";
@ -218,11 +252,30 @@ public class GroupManagementServiceImpl implements GroupManagementService {
@Override
public Response updateGroup(int groupId, DeviceGroup deviceGroup) {
String tenantId = String.valueOf(CarbonContext.getThreadLocalCarbonContext().getTenantId());
String tenantDomain = String.valueOf(CarbonContext.getThreadLocalCarbonContext().getTenantDomain());
String username = CarbonContext.getThreadLocalCarbonContext().getUsername();
if (deviceGroup == null) {
return Response.status(Response.Status.BAD_REQUEST).build();
}
try {
DeviceMgtAPIUtils.getGroupManagementProviderService().updateGroup(deviceGroup, groupId);
int deviceCount = DeviceMgtAPIUtils.getGroupManagementProviderService().getDeviceCount(groupId);
String stringDevices = new Gson().toJson(DeviceMgtAPIUtils.getGroupManagementProviderService().getAllDevicesOfGroup(deviceGroup.getName(), false));
log.info(
"Group " + deviceGroup.getName() + " updated",
groupMgtContextBuilder
.setActionTag("UPDATE_GROUP")
.setGroupId(String.valueOf(deviceGroup.getGroupId()))
.setName(deviceGroup.getName())
.setOwner(deviceGroup.getOwner())
.setDeviceCount(String.valueOf(deviceCount))
.setDevices(stringDevices)
.setTenantID(tenantId)
.setTenantDomain(tenantDomain)
.setUserName(username)
.build()
);
return Response.status(Response.Status.OK).build();
} catch (GroupManagementException e) {
String msg = "Error occurred while adding new group.";
@ -242,7 +295,20 @@ public class GroupManagementServiceImpl implements GroupManagementService {
@Override
public Response deleteGroup(int groupId, boolean isDeleteChildren) {
try {
String tenantId = String.valueOf(CarbonContext.getThreadLocalCarbonContext().getTenantId());
String tenantDomain = String.valueOf(CarbonContext.getThreadLocalCarbonContext().getTenantDomain());
String username = CarbonContext.getThreadLocalCarbonContext().getUsername();
if (DeviceMgtAPIUtils.getGroupManagementProviderService().deleteGroup(groupId, isDeleteChildren)) {
log.info(
"Group with group id " + groupId + " deleted",
groupMgtContextBuilder
.setActionTag("DELETE_GROUP")
.setGroupId(String.valueOf(groupId))
.setTenantID(tenantId)
.setTenantDomain(tenantDomain)
.setUserName(username)
.build()
);
return Response.status(Response.Status.OK).build();
} else {
return Response.status(Response.Status.NOT_FOUND).entity("Group not found.").build();
@ -328,17 +394,36 @@ public class GroupManagementServiceImpl implements GroupManagementService {
@Override
public Response addDevicesToGroup(int groupId, List<DeviceIdentifier> deviceIdentifiers) {
try {
String tenantId = String.valueOf(CarbonContext.getThreadLocalCarbonContext().getTenantId());
String tenantDomain = String.valueOf(CarbonContext.getThreadLocalCarbonContext().getTenantDomain());
String username = CarbonContext.getThreadLocalCarbonContext().getUsername();
DeviceMgtAPIUtils.getGroupManagementProviderService().addDevices(groupId, deviceIdentifiers);
PolicyAdministratorPoint pap = DeviceMgtAPIUtils.getPolicyManagementService().getPAP();
DeviceManagementProviderService dms = DeviceMgtAPIUtils.getDeviceManagementService();
List<Device> devices = new ArrayList<>();
for(DeviceIdentifier deviceIdentifier : deviceIdentifiers) {
Device device = dms.getDevice(deviceIdentifier, false);
devices.add(device);
if(!device.getEnrolmentInfo().getStatus().equals(EnrolmentInfo.Status.REMOVED)) {
pap.removePolicyUsed(deviceIdentifier);
DeviceMgtAPIUtils.getPolicyManagementService().getEffectivePolicy(deviceIdentifier);
}
}
pap.publishChanges();
int deviceCount = DeviceMgtAPIUtils.getGroupManagementProviderService().getDeviceCount(groupId);
String stringDevices = new Gson().toJson(devices);
log.info(
"Devices added for group id " + groupId,
groupMgtContextBuilder
.setActionTag("ADD_DEVICES")
.setGroupId(String.valueOf(groupId))
.setDeviceCount(String.valueOf(deviceCount))
.setDevices(stringDevices)
.setTenantID(tenantId)
.setTenantDomain(tenantDomain)
.setUserName(username)
.build()
);
return Response.status(Response.Status.OK).build();
} catch (GroupManagementException e) {
String msg = "Error occurred while adding devices to group.";
@ -460,6 +545,9 @@ public class GroupManagementServiceImpl implements GroupManagementService {
@Path("/roles/share")
@Override
public Response createGroupWithRoles(DeviceGroupRoleWrapper groups) {
String tenantId = String.valueOf(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());
String tenantDomain = String.valueOf(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain());
String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
if (groups == null) {
return Response.status(Response.Status.BAD_REQUEST).build();
}
@ -471,6 +559,22 @@ public class GroupManagementServiceImpl implements GroupManagementService {
PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername().isEmpty());
if (group != null) {
DeviceMgtAPIUtils.getGroupManagementProviderService().manageGroupSharing(group.getGroupId(), groups.getUserRoles());
int deviceCount = DeviceMgtAPIUtils.getGroupManagementProviderService().getDeviceCount(group.getGroupId());
String stringDevices = new Gson().toJson(DeviceMgtAPIUtils.getGroupManagementProviderService().getAllDevicesOfGroup(group.getName(), false));
log.info(
"Group " + group.getName() + " created",
groupMgtContextBuilder
.setActionTag("ADD_GROUP")
.setGroupId(String.valueOf(group.getGroupId()))
.setName(group.getName())
.setOwner(group.getOwner())
.setDeviceCount(String.valueOf(deviceCount))
.setDevices(stringDevices)
.setTenantID(tenantId)
.setTenantDomain(tenantDomain)
.setUserName(username)
.build()
);
return Response.status(Response.Status.CREATED).entity(group.getGroupId()).build();
} else {
String msg = "Error occurred while retrieving newly created group.";

@ -17,17 +17,19 @@
*/
package io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.impl;
import com.google.gson.Gson;
import io.entgra.device.mgt.core.apimgt.webapp.publisher.exception.APIManagerPublisherException;
import com.google.common.base.Strings;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.MetadataManagementException;
import io.entgra.device.mgt.core.device.mgt.common.group.mgt.GroupManagementException;
import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.Metadata;
import org.apache.commons.logging.Log;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.CarbonConstants;
import io.entgra.device.mgt.core.device.mgt.extensions.logger.spi.EntgraLogger;
import io.entgra.device.mgt.core.notification.logger.RoleMgtLogContext;
import io.entgra.device.mgt.core.notification.logger.impl.EntgraRoleMgtLoggerImpl;
import org.wso2.carbon.base.MultitenantConstants;
import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.context.PrivilegedCarbonContext;
@ -88,7 +90,8 @@ import static io.entgra.device.mgt.core.device.mgt.api.jaxrs.util.Constants.PRIM
public class RoleManagementServiceImpl implements RoleManagementService {
private static final String API_BASE_PATH = "/roles";
private static final Log log = LogFactory.getLog(RoleManagementServiceImpl.class);
RoleMgtLogContext.Builder roleMgtContextBuilder = new RoleMgtLogContext.Builder();
private static final EntgraLogger log = new EntgraRoleMgtLoggerImpl(RoleManagementServiceImpl.class);
@GET
@Override
@ -425,6 +428,9 @@ public class RoleManagementServiceImpl implements RoleManagementService {
RequestValidationUtil.validateRoleDetails(roleInfo);
RequestValidationUtil.validateRoleName(roleInfo.getRoleName());
try {
String tenantId = String.valueOf(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());
String tenantDomain = String.valueOf(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain());
String userName = String.valueOf(PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername());
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
if (log.isDebugEnabled()) {
log.debug("Persisting the role in the underlying user store");
@ -450,7 +456,19 @@ public class RoleManagementServiceImpl implements RoleManagementService {
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
String stringUsers = new Gson().toJson(roleInfo.getUsers());
log.info(
"Role " + roleInfo.getRoleName().split("/")[1] + " created",
roleMgtContextBuilder
.setActionTag("ADD_ROLE")
.setUserStoreDomain(roleInfo.getRoleName().split("/")[0])
.setRoleName(roleInfo.getRoleName().split("/")[1])
.setUsers(stringUsers)
.setTenantID(tenantId)
.setTenantDomain(tenantDomain)
.setUserName(userName)
.build()
);
//TODO fix what's returned in the entity
return Response.created(new URI(API_BASE_PATH + "/" + URLEncoder.encode(roleInfo.getRoleName(), "UTF-8"))).
entity("Role '" + roleInfo.getRoleName() + "' has " + "successfully been"
@ -556,6 +574,9 @@ public class RoleManagementServiceImpl implements RoleManagementService {
RequestValidationUtil.validateRoleName(roleName);
RequestValidationUtil.validateRoleDetails(roleInfo);
try {
String tenantId = String.valueOf(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());
String tenantDomain = String.valueOf(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain());
String userName = String.valueOf(PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername());
final UserRealm userRealm = DeviceMgtAPIUtils.getUserRealm();
final UserStoreManager userStoreManager = userRealm.getUserStoreManager();
if (!userStoreManager.isExistingRole(roleName)) {
@ -587,6 +608,19 @@ public class RoleManagementServiceImpl implements RoleManagementService {
String[] roleDetails = roleName.split("/");
updatePermissions(roleDetails[roleDetails.length - 1], roleInfo, userRealm);
}
String stringUsers = new Gson().toJson(roleInfo.getUsers());
log.info(
"Role " + roleInfo.getRoleName().split("/")[1] + " updated",
roleMgtContextBuilder
.setActionTag("UPDATE_ROLE")
.setUserStoreDomain(roleInfo.getRoleName().split("/")[0])
.setRoleName(roleInfo.getRoleName().split("/")[1])
.setUsers(stringUsers)
.setTenantID(tenantId)
.setTenantDomain(tenantDomain)
.setUserName(userName)
.build()
);
//TODO: Need to send the updated role information in the entity back to the client
return Response.status(Response.Status.OK).entity("Role '" + roleInfo.getRoleName() + "' has " +
"successfully been updated").build();
@ -622,6 +656,8 @@ public class RoleManagementServiceImpl implements RoleManagementService {
}
RequestValidationUtil.validateRoleName(roleName);
try {
String tenantDomain = String.valueOf(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain());
String userName = String.valueOf(PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername());
final UserRealm userRealm = DeviceMgtAPIUtils.getUserRealm();
final UserStoreManager userStoreManager = userRealm.getUserStoreManager();
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
@ -635,6 +671,17 @@ public class RoleManagementServiceImpl implements RoleManagementService {
log.debug("Deleting the role in user store");
}
DeviceMgtAPIUtils.getGroupManagementProviderService().deleteRoleAndRoleGroupMapping(roleName, roleToDelete, tenantId, userStoreManager, authorizationManager);
log.info(
"Role " + roleName.split("/")[1] + " deleted",
roleMgtContextBuilder
.setActionTag("DELETE_ROLE")
.setUserStoreDomain(userStoreName)
.setRoleName(roleName.split("/")[1])
.setTenantID(String.valueOf(tenantId))
.setTenantDomain(tenantDomain)
.setUserName(userName)
.build()
);
return Response.status(Response.Status.OK).build();
} catch (UserStoreException e) {
String msg = "Error occurred while deleting the role '" + roleName + "'";

@ -17,11 +17,13 @@
*/
package io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.impl;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import io.entgra.device.mgt.core.device.mgt.extensions.logger.spi.EntgraLogger;
import io.entgra.device.mgt.core.notification.logger.UserMgtLogContext;
import io.entgra.device.mgt.core.notification.logger.impl.EntgraUserMgtLoggerImpl;
import org.apache.http.HttpStatus;
import org.eclipse.wst.common.uriresolver.internal.util.URIEncoder;
import org.wso2.carbon.context.CarbonContext;
@ -104,7 +106,8 @@ public class UserManagementServiceImpl implements UserManagementService {
private static final String ROLE_EVERYONE = "Internal/everyone";
private static final String API_BASE_PATH = "/users";
private static final Log log = LogFactory.getLog(UserManagementServiceImpl.class);
UserMgtLogContext.Builder userMgtContextBuilder = new UserMgtLogContext.Builder();
private static final EntgraLogger log = new EntgraUserMgtLoggerImpl(UserManagementServiceImpl.class);
// Permissions that are given for a normal device user.
private static final Permission[] PERMISSIONS_FOR_DEVICE_USER = {
@ -149,7 +152,10 @@ public class UserManagementServiceImpl implements UserManagementService {
if (log.isDebugEnabled()) {
log.debug("User '" + userInfo.getUsername() + "' has successfully been added.");
}
String tenantId = String.valueOf(CarbonContext.getThreadLocalCarbonContext().getTenantId());
String tenantDomain = String.valueOf(CarbonContext.getThreadLocalCarbonContext().getTenantDomain());
String loggeduserName = String.valueOf(CarbonContext.getThreadLocalCarbonContext().getUsername());
String stringRoles = new Gson().toJson(userInfo.getRoles());
BasicUserInfo createdUserInfo = this.getBasicUserInfo(userInfo.getUsername());
// Outputting debug message upon successful retrieval of user
if (log.isDebugEnabled()) {
@ -164,6 +170,20 @@ public class UserManagementServiceImpl implements UserManagementService {
props.setProperty("last-name", userInfo.getLastname());
props.setProperty("username", username);
props.setProperty("password", initialUserPassword);
log.info(
"User " + username + " created",
userMgtContextBuilder
.setActionTag("ADD_USER")
.setUserStoreDomain(userInfo.getUsername().split("/")[0])
.setFirstName(userInfo.getFirstname())
.setLastName(userInfo.getLastname())
.setEmail(userInfo.getEmailAddress())
.setUserRoles(stringRoles)
.setTenantID(tenantId)
.setTenantDomain(tenantDomain)
.setUserName(loggeduserName)
.build()
);
EmailMetaInfo metaInfo = new EmailMetaInfo(recipient, props);
BasicUserInfoWrapper userInfoWrapper = new BasicUserInfoWrapper();
@ -238,6 +258,9 @@ public class UserManagementServiceImpl implements UserManagementService {
username = domain + '/' + username;
}
try {
String tenantId = String.valueOf(CarbonContext.getThreadLocalCarbonContext().getTenantId());
String tenantDomain = String.valueOf(CarbonContext.getThreadLocalCarbonContext().getTenantDomain());
String loggeduserName = String.valueOf(CarbonContext.getThreadLocalCarbonContext().getUsername());
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
if (!userStoreManager.isExistingUser(username)) {
if (log.isDebugEnabled()) {
@ -284,6 +307,21 @@ public class UserManagementServiceImpl implements UserManagementService {
if (log.isDebugEnabled()) {
log.debug("User by username: " + username + " was successfully updated.");
}
String stringRoles = new Gson().toJson(newRoles);
log.info(
"User " + username + " updated",
userMgtContextBuilder
.setActionTag("UPDATE_USER")
.setUserStoreDomain(username.split("/")[0])
.setFirstName(userInfo.getFirstname())
.setLastName(userInfo.getLastname())
.setEmail(userInfo.getEmailAddress())
.setUserRoles(stringRoles)
.setTenantID(tenantId)
.setTenantDomain(tenantDomain)
.setUserName(loggeduserName)
.build()
);
BasicUserInfo updatedUserInfo = this.getBasicUserInfo(username);
return Response.ok().entity(updatedUserInfo).build();
@ -317,6 +355,8 @@ public class UserManagementServiceImpl implements UserManagementService {
username = domain + '/' + username;
nameWithDomain = true;
}
String tenantId = String.valueOf(CarbonContext.getThreadLocalCarbonContext().getTenantId());
String tenantDomain = String.valueOf(CarbonContext.getThreadLocalCarbonContext().getTenantDomain());
try {
int deviceCount;
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
@ -338,6 +378,16 @@ public class UserManagementServiceImpl implements UserManagementService {
if (log.isDebugEnabled()) {
log.debug("User '" + username + "' was successfully removed.");
}
log.info(
"User " + username + " removed",
userMgtContextBuilder
.setActionTag("REMOVE_USER")
.setUserStoreDomain(domain)
.setTenantID(tenantId)
.setTenantDomain(tenantDomain)
.setUserName(username)
.build()
);
return Response.status(Response.Status.OK).build();
} else {
String msg = "Before deleting this user, ensure there are no devices assigned to the user. You can either remove the devices or change their owner through an update enrollment operation.";
@ -410,7 +460,8 @@ public class UserManagementServiceImpl implements UserManagementService {
userList = new ArrayList<>(users.size());
BasicUserInfo user;
for (String username : users) {
if (Constants.APIM_RESERVED_USER.equals(username) || Constants.RESERVED_USER.equals(username)) {
if (Constants.APIM_RESERVED_USER.equals(username) || Constants.RESERVED_USER.equals(username) ||
Constants.SCOPE_PUBLISH_RESERVED_USER.equals(username)) {
continue;
}
user = getBasicUserInfo(username);
@ -476,6 +527,7 @@ public class UserManagementServiceImpl implements UserManagementService {
if (commonUsers != null) {
commonUsers.remove(Constants.APIM_RESERVED_USER);
commonUsers.remove(Constants.RESERVED_USER);
commonUsers.remove(Constants.SCOPE_PUBLISH_RESERVED_USER);
}
if (!skipSearch(commonUsers) && StringUtils.isNotEmpty(firstName)) {
@ -651,7 +703,8 @@ public class UserManagementServiceImpl implements UserManagementService {
userList = new ArrayList<>();
UserInfo user;
for (String username : users) {
if (Constants.APIM_RESERVED_USER.equals(username) || Constants.RESERVED_USER.equals(username)) {
if (Constants.APIM_RESERVED_USER.equals(username) || Constants.RESERVED_USER.equals(username) ||
Constants.SCOPE_PUBLISH_RESERVED_USER.equals(username)) {
continue;
}
user = new UserInfo();
@ -1219,17 +1272,17 @@ public class UserManagementServiceImpl implements UserManagementService {
}
private String getTemplateName(String deviceType, String prefix, String separator) throws NoSuchFileException {
String templateName = deviceType + separator + prefix + ".vm";
String templateName = deviceType + separator + prefix;
List<String> templatePathSegments =
Arrays.asList(CarbonUtils.getCarbonHome(), "repository", "resources", "email-templates", templateName);
Arrays.asList(CarbonUtils.getCarbonHome(), "repository", "resources", "email-templates", templateName + ".vm");
File template = new File(String.join(File.separator, templatePathSegments));
if (template.exists()) {
return templateName;
}
String defaultTemplateName = "default" + separator + prefix + ".vm";
String defaultTemplateName = "default" + separator + prefix;
List<String> defaultTemplatePathSegments =
Arrays.asList(CarbonUtils.getCarbonHome(), "repository", "resources", "email-templates", defaultTemplateName);
Arrays.asList(CarbonUtils.getCarbonHome(), "repository", "resources", "email-templates", defaultTemplateName + ".vm");
File defaultTemplate = new File(String.join(File.separator, defaultTemplatePathSegments));
if (defaultTemplate.exists()) {

@ -31,6 +31,7 @@ public class Constants {
public static final String USER_CLAIM_DEVICES = "http://wso2.org/claims/devices";
public static final String PRIMARY_USER_STORE = "PRIMARY";
public static final String APIM_RESERVED_USER = "apim_reserved_user";
public static final String SCOPE_PUBLISH_RESERVED_USER = "scope_publish_reserved_user";
public static final String RESERVED_USER = "reserved_user";
public static final String DEFAULT_STREAM_VERSION = "1.0.0";
public static final String SCOPE = "scope";

@ -53,7 +53,7 @@ import java.util.List;
*/
@PowerMockIgnore({"javax.ws.rs.*", "org.apache.log4j.*", "javax.xml.parsers", "org.mockito.*"})
@SuppressStaticInitializationFor({"io.entgra.device.mgt.core.device.mgt.api.jaxrs.util.DeviceMgtAPIUtils",
"org.wso2.carbon.context.PrivilegedCarbonContext"})
"org.wso2.carbon.context.CarbonContext", "org.wso2.carbon.context.PrivilegedCarbonContext"})
@PrepareForTest({DeviceMgtAPIUtils.class, CarbonContext.class})
public class GroupManagementServiceImplTest {
private GroupManagementService groupManagementService;
@ -187,6 +187,12 @@ public class GroupManagementServiceImplTest {
public void testUpdateGroup() throws GroupManagementException, GroupNotExistException, GroupAlreadyExistException {
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getGroupManagementProviderService"))
.toReturn(groupManagementProviderService);
CarbonContext carbonContext = Mockito.mock(CarbonContext.class, Mockito.RETURNS_MOCKS);
PowerMockito.stub(PowerMockito.method(CarbonContext.class, "getThreadLocalCarbonContext"))
.toReturn(carbonContext);
Mockito.when(carbonContext.getTenantId()).thenReturn(-1234);
Mockito.when(carbonContext.getUsername()).thenReturn("admin");
Mockito.when(carbonContext.getTenantDomain()).thenReturn("carbon.super");
DeviceGroup deviceGroup = new DeviceGroup();
deviceGroup.setGroupId(1);
Mockito.doNothing().when(groupManagementProviderService).updateGroup(deviceGroup, 1);
@ -211,6 +217,12 @@ public class GroupManagementServiceImplTest {
public void testDeleteGroup() throws GroupManagementException {
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getGroupManagementProviderService"))
.toReturn(groupManagementProviderService);
CarbonContext carbonContext = Mockito.mock(CarbonContext.class, Mockito.RETURNS_MOCKS);
PowerMockito.stub(PowerMockito.method(CarbonContext.class, "getThreadLocalCarbonContext"))
.toReturn(carbonContext);
Mockito.when(carbonContext.getTenantId()).thenReturn(-1234);
Mockito.when(carbonContext.getUsername()).thenReturn("admin");
Mockito.when(carbonContext.getTenantDomain()).thenReturn("carbon.super");
Mockito.doReturn(true).when(groupManagementProviderService).deleteGroup(1, false);
Mockito.doReturn(false).when(groupManagementProviderService).deleteGroup(2, false);
Mockito.doThrow(new GroupManagementException()).when(groupManagementProviderService).deleteGroup(3, false);
@ -304,6 +316,12 @@ public class GroupManagementServiceImplTest {
.toReturn(policyManagerService);
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
.toReturn(deviceManagementProviderService);
CarbonContext carbonContext = Mockito.mock(CarbonContext.class, Mockito.RETURNS_MOCKS);
PowerMockito.stub(PowerMockito.method(CarbonContext.class, "getThreadLocalCarbonContext"))
.toReturn(carbonContext);
Mockito.when(carbonContext.getTenantId()).thenReturn(-1234);
Mockito.when(carbonContext.getUsername()).thenReturn("admin");
Mockito.when(carbonContext.getTenantDomain()).thenReturn("carbon.super");
List<DeviceIdentifier> deviceIdentifiers = new ArrayList<>();
Mockito.doNothing().when(groupManagementProviderService).addDevices(1, deviceIdentifiers);
Mockito.doThrow(new GroupManagementException()).when(groupManagementProviderService).addDevices(2,

@ -115,6 +115,12 @@ public class UserManagementServiceImplTest {
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
.toReturn(this.deviceManagementProviderService);
Mockito.doReturn(true).when(userStoreManager).isExistingUser("admin");
CarbonContext carbonContext = Mockito.mock(CarbonContext.class, Mockito.RETURNS_MOCKS);
PowerMockito.stub(PowerMockito.method(CarbonContext.class, "getThreadLocalCarbonContext"))
.toReturn(carbonContext);
Mockito.when(carbonContext.getTenantId()).thenReturn(-1234);
Mockito.when(carbonContext.getUsername()).thenReturn("admin");
Mockito.when(carbonContext.getTenantDomain()).thenReturn("carbon.super");
Mockito.doAnswer(new Answer() {
private int count = 0;
@ -170,6 +176,12 @@ public class UserManagementServiceImplTest {
public void testUpdateUser() throws UserStoreException {
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getUserStoreManager"))
.toReturn(this.userStoreManager);
CarbonContext carbonContext = Mockito.mock(CarbonContext.class, Mockito.RETURNS_MOCKS);
PowerMockito.stub(PowerMockito.method(CarbonContext.class, "getThreadLocalCarbonContext"))
.toReturn(carbonContext);
Mockito.when(carbonContext.getTenantId()).thenReturn(-1234);
Mockito.when(carbonContext.getUsername()).thenReturn("admin");
Mockito.when(carbonContext.getTenantDomain()).thenReturn("carbon.super");
Response response = userManagementService.updateUser(TEST2_USERNAME, null, null);
Assert.assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode(),
"Non-existing user was successfully updated");
@ -273,6 +285,11 @@ public class UserManagementServiceImplTest {
.toReturn(this.userStoreManager);
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
.toReturn(this.deviceManagementProviderService);
CarbonContext carbonContext = Mockito.mock(CarbonContext.class, Mockito.RETURNS_MOCKS);
PowerMockito.stub(PowerMockito.method(CarbonContext.class, "getThreadLocalCarbonContext"))
.toReturn(carbonContext);
Mockito.when(carbonContext.getTenantId()).thenReturn(-1234);
Mockito.when(carbonContext.getTenantDomain()).thenReturn("carbon.super");
Mockito.doReturn(0).when(deviceManagementProviderService).getDeviceCount(TEST_USERNAME);
Mockito.doNothing().when(userStoreManager).deleteUser(Mockito.anyString());
Response response = userManagementService.removeUser(TEST_USERNAME, null);
@ -325,6 +342,12 @@ public class UserManagementServiceImplTest {
public void testNegativeScenarios2() throws UserStoreException {
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getUserStoreManager"))
.toReturn(this.userStoreManager);
CarbonContext carbonContext = Mockito.mock(CarbonContext.class, Mockito.RETURNS_MOCKS);
PowerMockito.stub(PowerMockito.method(CarbonContext.class, "getThreadLocalCarbonContext"))
.toReturn(carbonContext);
Mockito.when(carbonContext.getTenantId()).thenReturn(-1234);
Mockito.when(carbonContext.getUsername()).thenReturn("admin");
Mockito.when(carbonContext.getTenantDomain()).thenReturn("carbon.super");
Mockito.doThrow(new UserStoreException()).when(userStoreManager).isExistingUser(TEST3_USERNAME);
Response response = userManagementService.getUser(TEST3_USERNAME, null, null);
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),

@ -21,7 +21,7 @@
<parent>
<artifactId>device-mgt</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.35-SNAPSHOT</version>
<version>5.0.38-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<artifactId>device-mgt</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.35-SNAPSHOT</version>
<version>5.0.38-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>device-mgt</artifactId>
<version>5.0.35-SNAPSHOT</version>
<version>5.0.38-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
@ -524,6 +524,10 @@
<artifactId>jaxb-impl</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>io.entgra.device.mgt.core.apimgt.extension.rest.api</artifactId>
</dependency>
</dependencies>
</project>

@ -124,6 +124,7 @@ public final class DeviceManagementConstants {
public static final String DEVICE_ENROLLMENT_MAIL_KEY = "enrollment";
public static final String TEMPLATE_NAME_PART_JOINER = "-";
public static final String ENROLLMENT_TYPE_SPLITTER = "_";
public static final String DOC_URL = "doc-url";
}
public static final class OperationAttributes {

@ -18,6 +18,7 @@
package io.entgra.device.mgt.core.device.mgt.core.config.metadata.mgt;
import io.entgra.device.mgt.core.device.mgt.core.config.metadata.mgt.documentation.DocConfiguration;
import io.entgra.device.mgt.core.device.mgt.core.config.metadata.mgt.whitelabel.WhiteLabelConfiguration;
import javax.xml.bind.annotation.XmlElement;
@ -26,6 +27,7 @@ import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "MetaDataConfiguration")
public class MetaDataConfiguration {
private WhiteLabelConfiguration whiteLabelConfiguration;
private DocConfiguration docConfiguration;
@XmlElement(name = "WhiteLabelConfiguration", required = true)
public WhiteLabelConfiguration getWhiteLabelConfiguration() {
@ -35,4 +37,13 @@ public class MetaDataConfiguration {
public void setWhiteLabelConfiguration(WhiteLabelConfiguration whiteLabelConfiguration) {
this.whiteLabelConfiguration = whiteLabelConfiguration;
}
@XmlElement(name = "DocConfiguration", required = true)
public DocConfiguration getDocConfiguration() {
return docConfiguration;
}
public void setDocConfiguration(DocConfiguration docConfiguration) {
this.docConfiguration = docConfiguration;
}
}

@ -0,0 +1,36 @@
/*
* Copyright (c) 2018 - 2024, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. 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 io.entgra.device.mgt.core.device.mgt.core.config.metadata.mgt.documentation;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "DocConfiguration")
public class DocConfiguration {
private String docUrl;
@XmlElement(name = "DocUrl", required = true)
public String getDocUrl() {
return docUrl;
}
public void setDocUrl(String docUrl) {
this.docUrl = docUrl;
}
}

@ -442,8 +442,8 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager {
if (deviceLocation != null) {
deviceDetailsDAO.deleteDeviceLocation(device.getId(), device.getEnrolmentInfo().getId());
} else {
log.error("Device location not found for device: " + device.getId());
throw new DeviceDetailsMgtException("Device location not found for device: " + device.getId());
log.warn("Unable to find location for device with ID " + device.getId() + ". Location deletion request cannot be processed.");
return;
}
DeviceManagementDAOFactory.commitTransaction();
} catch (TransactionManagementException e) {

@ -18,6 +18,8 @@
package io.entgra.device.mgt.core.device.mgt.core.internal;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.APIApplicationServices;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.PublisherRESTAPIServices;
import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.DeviceStatusManagementService;
import io.entgra.device.mgt.core.server.bootup.heartbeat.beacon.service.HeartBeatManagementService;
import org.wso2.carbon.context.PrivilegedCarbonContext;
@ -93,8 +95,9 @@ public class DeviceManagementDataHolder {
private MetadataManagementService metadataManagementService;
private WhiteLabelManagementService whiteLabelManagementService;
private TraccarManagementService traccarManagementService;
private DeviceStatusManagementService deviceStatusManagementService;
private APIApplicationServices apiApplicationServices;
private PublisherRESTAPIServices publisherRESTAPIServices;
private final Map<DeviceType, DeviceStatusTaskPluginConfig> deviceStatusTaskPluginConfigs = Collections.synchronizedMap(
new HashMap<>());
@ -410,4 +413,38 @@ public class DeviceManagementDataHolder {
public void setTraccarManagementService(TraccarManagementService traccarManagementService) {
this.traccarManagementService = traccarManagementService;
}
/**
* Retrieves the Dynamic Client Registration REST API Service instance from OSGI service context.
* @return {@link APIApplicationServices} Dynamic Client Registration REST API Service
*/
public APIApplicationServices getApiApplicationServices() {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
apiApplicationServices = (APIApplicationServices) ctx.getOSGiService(APIApplicationServices.class, null);
if (apiApplicationServices == null) {
throw new IllegalStateException("Dynamic Client Registration REST API Service was not initialized.");
}
return apiApplicationServices;
}
public void setApiApplicationServices(APIApplicationServices apiApplicationServices) {
this.apiApplicationServices = apiApplicationServices;
}
/**
* Retrieves the API Manager Publisher REST API Service instance from OSGI service context.
* @return {@link PublisherRESTAPIServices} API Manager Publisher REST API Service
*/
public PublisherRESTAPIServices getPublisherRESTAPIServices() {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
publisherRESTAPIServices = (PublisherRESTAPIServices) ctx.getOSGiService(PublisherRESTAPIServices.class, null);
if (publisherRESTAPIServices == null) {
throw new IllegalStateException("API Manager Publisher REST API Service was not initialized.");
}
return publisherRESTAPIServices;
}
public void setPublisherRESTAPIServices(PublisherRESTAPIServices publisherRESTAPIServices) {
this.publisherRESTAPIServices = publisherRESTAPIServices;
}
}

@ -17,21 +17,49 @@
*/
package io.entgra.device.mgt.core.device.mgt.core.internal;
import io.entgra.device.mgt.core.device.mgt.core.DeviceManagementConstants;
import io.entgra.device.mgt.core.device.mgt.core.DeviceManagementConstants.User;
import com.google.gson.Gson;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.APIApplicationServices;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.PublisherRESTAPIServices;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.constants.Constants;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIApplicationKey;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo.Scope;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.AccessTokenInfo;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.APIServicesException;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.BadRequestException;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.UnexpectedResponseException;
import io.entgra.device.mgt.core.apimgt.extension.rest.api.util.APIPublisherUtils;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.MetadataKeyAlreadyExistsException;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.MetadataManagementException;
import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.Metadata;
import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.MetadataManagementService;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.user.api.*;
import io.entgra.device.mgt.core.device.mgt.core.DeviceManagementConstants;
import io.entgra.device.mgt.core.device.mgt.core.DeviceManagementConstants.User;
import org.wso2.carbon.tenant.mgt.exception.TenantManagementException;
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.utils.AbstractAxis2ConfigurationContextObserver;
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
import org.wso2.carbon.utils.multitenancy.MultitenantUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Load configuration files to tenant's registry.
*/
public class TenantCreateObserver extends AbstractAxis2ConfigurationContextObserver {
private static final Log log = LogFactory.getLog(TenantCreateObserver.class);
private String msg = null;
/**
* Create configuration context.
@ -78,6 +106,19 @@ public class TenantCreateObserver extends AbstractAxis2ConfigurationContextObser
userStoreManager.updateRoleListOfUser(tenantAdminName, null,
new String[] {DeviceManagementConstants.User.DEFAULT_DEVICE_ADMIN,
DeviceManagementConstants.User.DEFAULT_DEVICE_USER});
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
try {
publishScopesToTenant(tenantDomain);
} catch (TenantManagementException e) {
log.error("Error occurred while generating API application for the tenant: " + tenantDomain + ".");
}
}
});
thread.start();
if (log.isDebugEnabled()) {
log.debug("Device management roles: " + User.DEFAULT_DEVICE_USER + ", " + User.DEFAULT_DEVICE_ADMIN +
" created for the tenant:" + tenantDomain + "."
@ -90,4 +131,312 @@ public class TenantCreateObserver extends AbstractAxis2ConfigurationContextObser
log.error("Error occurred while creating roles for the tenant: " + tenantDomain + ".");
}
}
/**
* This method will create OAuth application under the given tenant domain and generate an access token against the
* client credentials. Once this access token is generated it will then be used to retrieve all the scopes that are already
* published to that tenant space. The scopes of the super tenant will also be retrieved in order to compare which scopes were added
* or removed. (A temporary admin user will be created in the sub tenant space to publish the scopes and will be deleted once
* the scope publishing task is done)
* @param tenantDomain tenant domain that the scopes will be published to.
* @throws TenantManagementException if there are any errors when publishing scopes to a tenant
*/
private void publishScopesToTenant(String tenantDomain) throws TenantManagementException {
if (!MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) {
MetadataManagementService metadataManagementService = DeviceManagementDataHolder.getInstance().getMetadataManagementService();
Map<String, String> superTenantPermScopeMapping = getPermScopeMapping(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
Map<String, String> subTenantPermScopeMapping = getPermScopeMapping(tenantDomain);
if (superTenantPermScopeMapping == null) {
msg = "Error occurred while retrieving meta key '" + Constants.PERM_SCOPE_MAPPING_META_KEY + "' for tenant '" +
MultitenantConstants.SUPER_TENANT_DOMAIN_NAME + "'. Hence aborting publishing scopes to tenant: '" +
tenantDomain + "'.";
log.error(msg);
throw new TenantManagementException(msg);
}
if (superTenantPermScopeMapping.equals(subTenantPermScopeMapping)) {
if (log.isDebugEnabled()) {
log.debug( "Scopes in '" + tenantDomain + "' are up to date with super tenant scopes.");
}
return;
}
APIApplicationServices apiApplicationServices = DeviceManagementDataHolder.getInstance().getApiApplicationServices();
APIApplicationKey apiApplicationKey;
AccessTokenInfo accessTokenInfo;
try {
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain, true);
APIPublisherUtils.createScopePublishUserIfNotExists(tenantDomain);
apiApplicationKey = apiApplicationServices.createAndRetrieveApplicationCredentials(
"ClientForScopePublish",
"client_credentials password refresh_token");
accessTokenInfo = apiApplicationServices.generateAccessTokenFromRegisteredApplication(
apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret());
} catch (APIServicesException e) {
msg = "Error occurred while generating the API application for tenant: '" + tenantDomain + "'.";
log.error(msg, e);
throw new TenantManagementException(msg, e);
}
try {
PublisherRESTAPIServices publisherRESTAPIServices = DeviceManagementDataHolder.getInstance().getPublisherRESTAPIServices();
Scope[] superTenantScopes = getAllScopesFromSuperTenant(apiApplicationServices, publisherRESTAPIServices);
if (superTenantScopes != null) {
if (log.isDebugEnabled()) {
log.debug("Number of super tenant scopes already published - " + superTenantScopes.length);
}
Scope[] subTenantScopes = publisherRESTAPIServices.getScopes(apiApplicationKey, accessTokenInfo);
if (subTenantScopes.length > 0) {
// If there is already existing scopes on the sub tenant space then do a comparison with the
// super tenant scopes to add those new scopes to sub tenant space or to delete them from
// sub tenant space if it is not existing on the super tenant scope list.
if (log.isDebugEnabled()) {
log.debug("Number of sub tenant scopes already published - " + subTenantScopes.length);
}
List<Scope> missingScopes = new ArrayList<>();
List<Scope> deletedScopes = new ArrayList<>();
for (Scope superTenantScope : superTenantScopes) {
boolean isMatchingScope = false;
for (Scope subTenantScope : subTenantScopes) {
if (superTenantScope.getName().equals(subTenantScope.getName())) {
isMatchingScope = true;
break;
}
}
if (!isMatchingScope) {
if (log.isDebugEnabled()) {
log.debug("Missing scope found in sub tenant space - " +
superTenantScope.getName());
}
missingScopes.add(superTenantScope);
}
}
if (log.isDebugEnabled()) {
log.debug("Total number of missing scopes found in sub tenant space - " +
missingScopes.size());
}
if (missingScopes.size() > 0) {
if (log.isDebugEnabled()) {
log.debug("Starting to add new/updated shared scopes to the tenant: '" + tenantDomain + "'.");
}
publishSharedScopes(missingScopes, publisherRESTAPIServices, apiApplicationKey,
accessTokenInfo);
}
for (Scope subTenantScope : subTenantScopes) {
boolean isMatchingScope = false;
for (Scope superTenantScope : superTenantScopes) {
if (superTenantScope.getName().equals(subTenantScope.getName())) {
isMatchingScope = true;
break;
}
}
if (!isMatchingScope) {
if (log.isDebugEnabled()) {
log.debug("Deleted scope found in sub tenant space - " +
subTenantScope.getName());
}
deletedScopes.add(subTenantScope);
}
}
if (log.isDebugEnabled()) {
log.debug("Total number of deleted scopes found in sub tenant space - " +
deletedScopes.size());
}
if (deletedScopes.size() > 0) {
if (log.isDebugEnabled()) {
log.debug("Starting to delete shared scopes from the tenant: '" + tenantDomain + "'.");
}
for (Scope deletedScope : deletedScopes) {
if (publisherRESTAPIServices.isSharedScopeNameExists(apiApplicationKey, accessTokenInfo,
deletedScope.getName())) {
Scope scope = createScopeObject(deletedScope);
publisherRESTAPIServices.deleteSharedScope(apiApplicationKey, accessTokenInfo, scope);
}
}
}
if (missingScopes.size() > 0 || deletedScopes.size() > 0) {
updatePermScopeMetaData(superTenantPermScopeMapping, metadataManagementService);
}
} else {
if (log.isDebugEnabled()) {
log.debug("Starting to publish shared scopes to newly created tenant: '" + tenantDomain + "'.");
}
publishSharedScopes(Arrays.asList(superTenantScopes), publisherRESTAPIServices,
apiApplicationKey, accessTokenInfo);
updatePermScopeMetaData(superTenantPermScopeMapping, metadataManagementService);
}
} else {
msg = "Unable to publish scopes to sub tenants due to super tenant scopes list being empty.";
log.error(msg);
throw new TenantManagementException(msg);
}
} catch (BadRequestException e) {
msg = "Invalid request sent when publishing scopes to '" + tenantDomain + "' tenant space.";
log.error(msg, e);
throw new TenantManagementException(msg, e);
} catch (UnexpectedResponseException e) {
msg = "Unexpected response received when publishing scopes to '" + tenantDomain + "' tenant space.";
log.error(msg, e);
throw new TenantManagementException(msg, e);
} catch (APIServicesException e) {
msg = "Error occurred while publishing scopes to '" + tenantDomain + "' tenant space.";
log.error(msg, e);
throw new TenantManagementException(msg, e);
} catch (MetadataManagementException e) {
msg = "Error occurred trying to create metadata entry '" + Constants.PERM_SCOPE_MAPPING_META_KEY + "'.";
log.error(msg);
throw new TenantManagementException(msg);
} catch (MetadataKeyAlreadyExistsException e) {
msg = "Error occurred trying to create metadata entry '" + Constants.PERM_SCOPE_MAPPING_META_KEY + "'. The meta key " +
"already exists.";
log.error(msg);
throw new TenantManagementException(msg);
} finally {
APIPublisherUtils.removeScopePublishUserIfExists(tenantDomain);
PrivilegedCarbonContext.endTenantFlow();
}
}
}
/**
* This method will retrieve the value of the permission scope mapping meta key stored in each tenant's metadata
* @param tenantDomain the tenant domain that the permission scope mapping meta value retrieved from
* @return {@link Map} containing the permission key and the scope value
* @throws TenantManagementException if there is an error while retrieving permission scope metadata
*/
private Map<String, String> getPermScopeMapping(String tenantDomain) throws TenantManagementException {
if (log.isDebugEnabled()) {
log.debug("Retrieving permission scope mapping from metadata from the tenant: '" + tenantDomain + "'.");
}
Map<String, String> permScopeMapping = null;
try {
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain, true);
MetadataManagementService metadataManagementService = DeviceManagementDataHolder.getInstance().getMetadataManagementService();
Metadata metadata = metadataManagementService.retrieveMetadata(Constants.PERM_SCOPE_MAPPING_META_KEY);
if (metadata != null) {
permScopeMapping = new Gson().fromJson(metadata.getMetaValue().toString(), HashMap.class);
}
} catch (MetadataManagementException e) {
msg = "Error occurred while retrieving permission scope mapping from metadata for tenant: '" + tenantDomain + "'.";
log.error(msg, e);
throw new TenantManagementException(msg, e);
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
return permScopeMapping;
}
/**
* This method will create a new metadata entry or update the existing metadata entry in the sub tenant metadata repository which is
* taken from the super tenant metadata
* @param superTenantPermScopeMapping {@link Map} containing the permission key and the scope value of the super tenant
* @param metadataManagementService {@link MetadataManagementService} instance
* @throws MetadataManagementException if there is an error while creating or updating the metadata entry
* @throws MetadataKeyAlreadyExistsException if the metadata key already exists while trying to create a new metadata entry
*/
private void updatePermScopeMetaData(Map<String, String> superTenantPermScopeMapping,
MetadataManagementService metadataManagementService) throws MetadataManagementException,
MetadataKeyAlreadyExistsException {
Metadata newMetaData = new Metadata();
newMetaData.setMetaKey(Constants.PERM_SCOPE_MAPPING_META_KEY);
newMetaData.setMetaValue(new Gson().toJson(superTenantPermScopeMapping));
if (metadataManagementService.retrieveMetadata(Constants.PERM_SCOPE_MAPPING_META_KEY) == null) {
metadataManagementService.createMetadata(newMetaData);
} else {
metadataManagementService.updateMetadata(newMetaData);
}
}
/**
* Get all the scopes from the super tenant space
* @param apiApplicationServices {@link APIApplicationServices} is used to create an OAuth application and retrieve client ID and secret
* @param publisherRESTAPIServices {@link PublisherRESTAPIServices} is used to get all scopes under a given tenant using client credentials
* @return array of {@link Scope}
* @throws BadRequestException if an invalid request is sent to the API Manager Publisher REST API Service
* @throws UnexpectedResponseException if an unexpected response is received from the API Manager Publisher REST API Service
* @throws TenantManagementException if an error occurred while processing the request sent to API Manager Publisher REST API Service
*/
private Scope[] getAllScopesFromSuperTenant(APIApplicationServices apiApplicationServices,
PublisherRESTAPIServices publisherRESTAPIServices) throws BadRequestException,
UnexpectedResponseException, TenantManagementException {
try {
// Get all scopes of super tenant to compare later with the sub tenant scopes. This is done
// in order to see if any new scopes were added or deleted
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, true);
APIApplicationKey superTenantApiApplicationKey = apiApplicationServices.createAndRetrieveApplicationCredentials(
"ClientForScopePublish",
"client_credentials password refresh_token");
AccessTokenInfo superTenantAccessToken = apiApplicationServices.generateAccessTokenFromRegisteredApplication(
superTenantApiApplicationKey.getClientId(), superTenantApiApplicationKey.getClientSecret());
return publisherRESTAPIServices.getScopes(superTenantApiApplicationKey, superTenantAccessToken);
} catch (APIServicesException e) {
msg = "Error occurred while retrieving access token from super tenant";
log.error(msg, e);
throw new TenantManagementException(msg, e);
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
}
/**
* Add shared scopes to the tenant space.
* @param scopeList {@link List} of {@link Scope}
* @param publisherRESTAPIServices {@link PublisherRESTAPIServices} is used to add shared scopes to a given tenant using client credentials
* @param apiApplicationKey {@link APIApplicationKey} contains client credentials of the OAuth application
* @param accessTokenInfo {@link AccessTokenInfo} contains token information generated from the client credentials
* @throws BadRequestException if an invalid request is sent to the API Manager Publisher REST API Service
* @throws UnexpectedResponseException if an unexpected response is received from the API Manager Publisher REST API Service
* @throws APIServicesException if an error occurred while processing the request sent to API Manager Publisher REST API Service
*/
private void publishSharedScopes (List<Scope> scopeList, PublisherRESTAPIServices publisherRESTAPIServices,
APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo)
throws BadRequestException, UnexpectedResponseException, APIServicesException {
for (Scope tenantScope : scopeList) {
if (!publisherRESTAPIServices.isSharedScopeNameExists(apiApplicationKey, accessTokenInfo,
tenantScope.getName())) {
Scope scope = createScopeObject(tenantScope);
publisherRESTAPIServices.addNewSharedScope(apiApplicationKey, accessTokenInfo, scope);
}
}
}
/**
* Creates a new scope object from the passed scope which includes the id, display name, description, name and bindings.
* @param tenantScope existing {@link Scope} from a tenant
* @return {@link Scope}
*/
private Scope createScopeObject (Scope tenantScope) {
Scope scope = new Scope();
scope.setId(tenantScope.getId());
scope.setDisplayName(tenantScope.getDisplayName());
scope.setDescription(tenantScope.getDescription());
scope.setName(tenantScope.getName());
List<String> bindings = new ArrayList<>();
bindings.add(Constants.ADMIN_ROLE_KEY);
scope.setBindings(bindings);
return scope;
}
}

@ -1568,6 +1568,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
new TypedValue<>(String.class, DeviceManagerUtil.getServerBaseHttpsUrl()));
params.put(io.entgra.device.mgt.core.device.mgt.core.DeviceManagementConstants.EmailAttributes.SERVER_BASE_URL_HTTP,
new TypedValue<>(String.class, DeviceManagerUtil.getServerBaseHttpUrl()));
params.put(DeviceManagementConstants.EmailAttributes.DOC_URL,
new TypedValue<>(String.class, DeviceManagerUtil.getDocUrl()));
try {
EmailContext ctx =
new EmailContext.EmailContextBuilder(new ContentProviderInfo(templateName, params),

@ -19,8 +19,36 @@ package io.entgra.device.mgt.core.device.mgt.core.util;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.Gson;
import io.entgra.device.mgt.core.device.mgt.common.*;
import io.entgra.device.mgt.core.device.mgt.common.configuration.mgt.*;
import io.entgra.device.mgt.core.device.mgt.core.config.metadata.mgt.MetaDataConfiguration;
import io.entgra.device.mgt.core.device.mgt.core.config.metadata.mgt.documentation.DocConfiguration;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.protocol.HTTP;
import org.w3c.dom.Document;
import org.wso2.carbon.base.MultitenantConstants;
import org.wso2.carbon.caching.impl.CacheImpl;
import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import io.entgra.device.mgt.core.device.mgt.common.AppRegistrationCredentials;
import io.entgra.device.mgt.core.device.mgt.common.ApplicationRegistration;
import io.entgra.device.mgt.core.device.mgt.common.ApplicationRegistrationException;
import io.entgra.device.mgt.core.device.mgt.common.Device;
import io.entgra.device.mgt.core.device.mgt.common.DeviceIdentifier;
import io.entgra.device.mgt.core.device.mgt.common.EnrolmentInfo;
import io.entgra.device.mgt.core.device.mgt.common.GroupPaginationRequest;
import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest;
import io.entgra.device.mgt.core.device.mgt.common.PaginationResult;
import io.entgra.device.mgt.core.device.mgt.common.configuration.mgt.ConfigurationEntry;
import io.entgra.device.mgt.core.device.mgt.common.configuration.mgt.ConfigurationManagementException;
import io.entgra.device.mgt.core.device.mgt.common.configuration.mgt.EnrollmentConfiguration;
import io.entgra.device.mgt.core.device.mgt.common.configuration.mgt.PlatformConfiguration;
import io.entgra.device.mgt.core.device.mgt.common.configuration.mgt.PlatformConfigurationManagementService;
import io.entgra.device.mgt.core.device.mgt.common.event.config.EventConfigurationProviderService;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.DeviceManagementException;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.DeviceNotFoundException;
@ -1254,4 +1282,14 @@ public final class DeviceManagerUtil {
+ deviceGroup.getGroupId();
}
}
/**
* Retrieve the documentation url
* @return documentation url
*/
public static String getDocUrl() {
DeviceManagementConfig deviceManagementConfig = DeviceConfigurationManager.getInstance().getDeviceManagementConfig();
DocConfiguration docConfiguration = deviceManagementConfig.getMetaDataConfiguration().getDocConfiguration();
return docConfiguration.getDocUrl();
}
}

@ -159,5 +159,10 @@
<MaximumMessageBufferSize>640</MaximumMessageBufferSize>
</RemoteSessionConfiguration>
<DefaultGroupsConfiguration>BYOD,COPE</DefaultGroupsConfiguration>
<MetaDataConfiguration>
<DocConfiguration>
<DocUrl>https://docs.entgra.io/uem/6.0.0</DocUrl>
</DocConfiguration>
</MetaDataConfiguration>
</DeviceMgtConfiguration>

@ -22,7 +22,7 @@
<parent>
<artifactId>device-mgt</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.35-SNAPSHOT</version>
<version>5.0.38-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -23,7 +23,7 @@
<parent>
<artifactId>device-mgt</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.35-SNAPSHOT</version>
<version>5.0.38-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>io.entgra.device.mgt.core.parent</artifactId>
<version>5.0.35-SNAPSHOT</version>
<version>5.0.38-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>heartbeat-management</artifactId>
<version>5.0.35-SNAPSHOT</version>
<version>5.0.38-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>io.entgra.device.mgt.core.parent</artifactId>
<version>5.0.35-SNAPSHOT</version>
<version>5.0.38-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>identity-extensions</artifactId>
<version>5.0.35-SNAPSHOT</version>
<version>5.0.38-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>identity-extensions</artifactId>
<version>5.0.35-SNAPSHOT</version>
<version>5.0.38-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>io.entgra.device.mgt.core.parent</artifactId>
<version>5.0.35-SNAPSHOT</version>
<version>5.0.38-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

@ -23,7 +23,7 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>logger</artifactId>
<version>5.0.35-SNAPSHOT</version>
<version>5.0.38-SNAPSHOT</version>
</parent>
<artifactId>io.entgra.device.mgt.core.notification.logger</artifactId>

@ -0,0 +1,181 @@
/*
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. 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 io.entgra.device.mgt.core.notification.logger;
import io.entgra.device.mgt.core.device.mgt.extensions.logger.LogContext;
public class GroupMgtLogContext extends LogContext {
private final String groupId;
private final String name;
private final String owner;
private final String actionTag;
private final String deviceCount;
private final String devices;
private final String userName;
private final String tenantID;
private final String tenantDomain;
private GroupMgtLogContext(Builder builder) {
this.groupId = builder.groupId;
this.name = builder.name;
this.owner = builder.owner;
this.actionTag = builder.actionTag;
this.deviceCount = builder.deviceCount;
this.devices = builder.devices;
this.userName = builder.userName;
this.tenantID = builder.tenantID;
this.tenantDomain = builder.tenantDomain;
}
public String getGroupId() {
return groupId;
}
public String getName() {
return name;
}
public String getOwner() {
return owner;
}
public String getActionTag() {
return actionTag;
}
public String getDeviceCount() {
return deviceCount;
}
public String getDevices() {
return devices;
}
public String getUserName() {
return userName;
}
public String getTenantID() {
return tenantID;
}
public String getTenantDomain() {
return tenantDomain;
}
public static class Builder {
private String groupId;
private String name;
private String owner;
private String actionTag;
private String deviceCount;
private String devices;
private String userName;
private String tenantID;
private String tenantDomain;
public Builder() {
}
public String getGroupId() {
return groupId;
}
public Builder setGroupId(String groupId) {
this.groupId = groupId;
return this;
}
public String getName() {
return name;
}
public Builder setName(String name) {
this.name = name;
return this;
}
public String getOwner() {
return owner;
}
public Builder setOwner(String owner) {
this.owner = owner;
return this;
}
public String getActionTag() {
return actionTag;
}
public Builder setActionTag(String actionTag) {
this.actionTag = actionTag;
return this;
}
public String getDeviceCount() {
return deviceCount;
}
public Builder setDeviceCount(String deviceCount) {
this.deviceCount = deviceCount;
return this;
}
public String getDevices() {
return devices;
}
public Builder setDevices(String devices) {
this.devices = devices;
return this;
}
public String getUserName() {
return userName;
}
public Builder setUserName(String userName) {
this.userName = userName;
return this;
}
public String getTenantID() {
return tenantID;
}
public Builder setTenantID(String tenantID) {
this.tenantID = tenantID;
return this;
}
public String getTenantDomain() {
return tenantDomain;
}
public Builder setTenantDomain(String tenantDomain) {
this.tenantDomain = tenantDomain;
return this;
}
public GroupMgtLogContext build() {
return new GroupMgtLogContext(this);
}
}
}

@ -0,0 +1,149 @@
/*
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. 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 io.entgra.device.mgt.core.notification.logger;
import io.entgra.device.mgt.core.device.mgt.extensions.logger.LogContext;
public class RoleMgtLogContext extends LogContext {
private final String userStoreDomain;
private final String roleName;
private final String users;
private final String actionTag;
private final String userName;
private final String tenantID;
private final String tenantDomain;
private RoleMgtLogContext(Builder builder) {
this.userStoreDomain = builder.userStoreDomain;
this.roleName = builder.roleName;
this.users = builder.users;
this.actionTag = builder.actionTag;
this.userName = builder.userName;
this.tenantID = builder.tenantID;
this.tenantDomain = builder.tenantDomain;
}
public String getRoleName() {
return roleName;
}
public String getUserStoreDomain() {
return userStoreDomain;
}
public String getUsers() {
return users;
}
public String getActionTag() {
return actionTag;
}
public String getUserName() {
return userName;
}
public String getTenantID() {
return tenantID;
}
public String getTenantDomain() {
return tenantDomain;
}
public static class Builder {
private String userStoreDomain;
private String roleName;
private String users;
private String actionTag;
private String userName;
private String tenantID;
private String tenantDomain;
public Builder() {
}
public String getUserStoreDomain() {
return userStoreDomain;
}
public Builder setUserStoreDomain(String userStoreDomain) {
this.userStoreDomain = userStoreDomain;
return this;
}
public String getRoleName() {
return roleName;
}
public Builder setRoleName(String roleName) {
this.roleName = roleName;
return this;
}
public String getUsers() {
return users;
}
public Builder setUsers(String users) {
this.users = users;
return this;
}
public String getActionTag() {
return actionTag;
}
public Builder setActionTag(String actionTag) {
this.actionTag = actionTag;
return this;
}
public String getUserName() {
return userName;
}
public Builder setUserName(String userName) {
this.userName = userName;
return this;
}
public String getTenantID() {
return tenantID;
}
public Builder setTenantID(String tenantID) {
this.tenantID = tenantID;
return this;
}
public String getTenantDomain() {
return tenantDomain;
}
public Builder setTenantDomain(String tenantDomain) {
this.tenantDomain = tenantDomain;
return this;
}
public RoleMgtLogContext build() {
return new RoleMgtLogContext(this);
}
}
}

@ -20,22 +20,22 @@ package io.entgra.device.mgt.core.notification.logger;
import io.entgra.device.mgt.core.device.mgt.extensions.logger.LogContext;
public class UserLogContext extends LogContext {
public class UserLoginLogContext extends LogContext {
private final String userName;
private final String userEmail;
private final String metaInfo;
private final String tenantID;
private final boolean isUserRegistered;
private final boolean isDeviceRegisterged;
private final boolean isDeviceRegistered;
private final String tenantDomain;
private UserLogContext(Builder builder) {
private UserLoginLogContext(Builder builder) {
this.userEmail = builder.userEmail;
this.userName = builder.userName;
this.metaInfo = builder.metaInfo;
this.tenantID = builder.tenantID;
this.isUserRegistered = builder.isUserRegistered;
this.isDeviceRegisterged = builder.isDeviceRegisterged;
this.isDeviceRegistered = builder.isDeviceRegistered;
this.tenantDomain = builder.tenantDomain;
}
@ -59,8 +59,8 @@ public class UserLogContext extends LogContext {
return isUserRegistered;
}
public boolean isDeviceRegisterged() {
return isDeviceRegisterged;
public boolean isDeviceRegistered() {
return isDeviceRegistered;
}
public String getTenantDomain() {
@ -73,7 +73,7 @@ public class UserLogContext extends LogContext {
private String metaInfo;
private String tenantID;
private boolean isUserRegistered;
private boolean isDeviceRegisterged;
private boolean isDeviceRegistered;
private String tenantDomain;
public Builder() {
@ -124,12 +124,12 @@ public class UserLogContext extends LogContext {
return this;
}
public boolean getIsDeviceRegisterged() {
return isDeviceRegisterged;
public boolean getIsDeviceRegistered() {
return isDeviceRegistered;
}
public Builder setDeviceRegisterged(boolean deviceRegisterged) {
isDeviceRegisterged = deviceRegisterged;
public Builder setDeviceRegistered(boolean deviceRegistered) {
isDeviceRegistered = deviceRegistered;
return this;
}
@ -142,8 +142,8 @@ public class UserLogContext extends LogContext {
return this;
}
public UserLogContext build() {
return new UserLogContext(this);
public UserLoginLogContext build() {
return new UserLoginLogContext(this);
}
}

@ -0,0 +1,181 @@
/*
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. 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 io.entgra.device.mgt.core.notification.logger;
import io.entgra.device.mgt.core.device.mgt.extensions.logger.LogContext;
public class UserMgtLogContext extends LogContext {
private final String userStoreDomain;
private final String firstName;
private final String lastName;
private final String email;
private final String userRoles;
private final String actionTag;
private final String userName;
private final String tenantID;
private final String tenantDomain;
private UserMgtLogContext(Builder builder) {
this.userStoreDomain = builder.userStoreDomain;
this.firstName = builder.firstName;
this.lastName = builder.lastName;
this.email = builder.email;
this.userRoles = builder.userRoles;
this.actionTag = builder.actionTag;
this.userName = builder.userName;
this.tenantID = builder.tenantID;
this.tenantDomain = builder.tenantDomain;
}
public String getFirstName() {
return firstName;
}
public String getLastName() {
return lastName;
}
public String getUserStoreDomain() {
return userStoreDomain;
}
public String getEmail() {
return email;
}
public String getUserRoles() {
return userRoles;
}
public String getActionTag() {
return actionTag;
}
public String getUserName() {
return userName;
}
public String getTenantID() {
return tenantID;
}
public String getTenantDomain() {
return tenantDomain;
}
public static class Builder {
private String userStoreDomain;
private String firstName;
private String lastName;
private String email;
private String userRoles;
private String actionTag;
private String userName;
private String tenantID;
private String tenantDomain;
public Builder() {
}
public String getUserStoreDomain() {
return userStoreDomain;
}
public Builder setUserStoreDomain(String userStoreDomain) {
this.userStoreDomain = userStoreDomain;
return this;
}
public String getFirstName() {
return firstName;
}
public Builder setFirstName(String firstName) {
this.firstName = firstName;
return this;
}
public String getLastName() {
return lastName;
}
public Builder setLastName(String lastName) {
this.lastName = lastName;
return this;
}
public String getEmail() {
return email;
}
public Builder setEmail(String email) {
this.email = email;
return this;
}
public String getUserRoles() {
return userRoles;
}
public Builder setUserRoles(String userRoles) {
this.userRoles = userRoles;
return this;
}
public String getActionTag() {
return actionTag;
}
public Builder setActionTag(String actionTag) {
this.actionTag = actionTag;
return this;
}
public String getUserName() {
return userName;
}
public Builder setUserName(String userName) {
this.userName = userName;
return this;
}
public String getTenantID() {
return tenantID;
}
public Builder setTenantID(String tenantID) {
this.tenantID = tenantID;
return this;
}
public String getTenantDomain() {
return tenantDomain;
}
public Builder setTenantDomain(String tenantDomain) {
this.tenantDomain = tenantDomain;
return this;
}
public UserMgtLogContext build() {
return new UserMgtLogContext(this);
}
}
}

@ -0,0 +1,318 @@
/*
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. 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 io.entgra.device.mgt.core.notification.logger.impl;
import io.entgra.device.mgt.core.device.mgt.extensions.logger.LogContext;
import io.entgra.device.mgt.core.device.mgt.extensions.logger.spi.EntgraLogger;
import io.entgra.device.mgt.core.notification.logger.GroupMgtLogContext;
import io.entgra.device.mgt.core.notification.logger.util.MDCContextUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.log4j.MDC;
public class EntgraGroupMgtLoggerImpl implements EntgraLogger {
private static Log log = null;
public EntgraGroupMgtLoggerImpl(Class<?> clazz) {
log = LogFactory.getLog(clazz);
}
public void info(String message) {
log.info(message);
}
public void info(String message, Throwable t) {
log.info(message, t);
}
@Override
public void info(Object o) {
log.info(o);
}
@Override
public void info(Object o, Throwable throwable) {
log.info(o, throwable);
}
@Override
public void info(String message, LogContext logContext) {
GroupMgtLogContext groupMgtLogContext = (GroupMgtLogContext) logContext;
MDCContextUtil.populateGroupMgtMDCContext(groupMgtLogContext);
log.info(message);
}
@Override
public void info(Object object, LogContext logContext) {
GroupMgtLogContext groupMgtLogContext = (GroupMgtLogContext) logContext;
MDCContextUtil.populateGroupMgtMDCContext(groupMgtLogContext);
log.info(object);
}
@Override
public void info(Object object, Throwable t, LogContext logContext) {
GroupMgtLogContext groupMgtLogContext = (GroupMgtLogContext) logContext;
MDCContextUtil.populateGroupMgtMDCContext(groupMgtLogContext);
log.info(object, t);
}
public void debug(String message) {
log.debug(message);
}
public void debug(String message, Throwable t) {
log.debug(message, t);
}
@Override
public void debug(Object o) {
log.debug(o);
}
@Override
public void debug(Object o, Throwable throwable) {
log.debug(o, throwable);
}
@Override
public void debug(String message, LogContext logContext) {
GroupMgtLogContext groupMgtLogContext = (GroupMgtLogContext) logContext;
MDCContextUtil.populateGroupMgtMDCContext(groupMgtLogContext);
log.debug(message);
}
@Override
public void debug(Object object, LogContext logContext) {
GroupMgtLogContext groupMgtLogContext = (GroupMgtLogContext) logContext;
MDCContextUtil.populateGroupMgtMDCContext(groupMgtLogContext);
log.debug(object);
}
@Override
public void debug(Object object, Throwable t, LogContext logContext) {
GroupMgtLogContext groupMgtLogContext = (GroupMgtLogContext) logContext;
MDCContextUtil.populateGroupMgtMDCContext(groupMgtLogContext);
log.debug(object, t);
}
public void error(String message) {
log.error(message);
}
public void error(String message, Throwable t) {
log.error(message, t);
}
@Override
public void error(Object o) {
log.error(o);
}
@Override
public void error(Object o, Throwable throwable) {
log.error(o, throwable);
}
@Override
public void error(String message, LogContext logContext) {
GroupMgtLogContext groupMgtLogContext = (GroupMgtLogContext) logContext;
MDCContextUtil.populateGroupMgtMDCContext(groupMgtLogContext);
log.error(message);
}
@Override
public void error(String message, Throwable t, LogContext logContext) {
GroupMgtLogContext groupMgtLogContext = (GroupMgtLogContext) logContext;
MDCContextUtil.populateGroupMgtMDCContext(groupMgtLogContext);
log.error(message, t);
}
@Override
public void error(Object object, LogContext logContext) {
GroupMgtLogContext groupMgtLogContext = (GroupMgtLogContext) logContext;
MDCContextUtil.populateGroupMgtMDCContext(groupMgtLogContext);
log.error(object);
}
@Override
public void error(Object object, Throwable t, LogContext logContext) {
GroupMgtLogContext groupMgtLogContext = (GroupMgtLogContext) logContext;
MDCContextUtil.populateGroupMgtMDCContext(groupMgtLogContext);
log.error(object, t);
}
public void warn(String message) {
log.warn(message);
}
public void warn(String message, Throwable t) {
log.warn(message, t);
}
@Override
public void warn(Object o) {
log.warn(o);
}
@Override
public void warn(Object o, Throwable throwable) {
log.warn(o, throwable);
}
@Override
public void warn(String message, LogContext logContext) {
GroupMgtLogContext groupMgtLogContext = (GroupMgtLogContext) logContext;
MDCContextUtil.populateGroupMgtMDCContext(groupMgtLogContext);
log.warn(message);
}
@Override
public void warn(String message, Throwable t, LogContext logContext) {
GroupMgtLogContext groupMgtLogContext = (GroupMgtLogContext) logContext;
MDCContextUtil.populateGroupMgtMDCContext(groupMgtLogContext);
log.warn(message, t);
}
@Override
public void warn(Object object, LogContext logContext) {
GroupMgtLogContext groupMgtLogContext = (GroupMgtLogContext) logContext;
MDCContextUtil.populateGroupMgtMDCContext(groupMgtLogContext);
log.warn(object);
}
@Override
public void warn(Object object, Throwable t, LogContext logContext) {
GroupMgtLogContext groupMgtLogContext = (GroupMgtLogContext) logContext;
MDCContextUtil.populateGroupMgtMDCContext(groupMgtLogContext);
log.warn(object, t);
}
public void trace(String message) {
log.trace(message);
}
public void trace(String message, Throwable t) {
log.trace(message, t);
}
@Override
public void trace(Object o) {
log.trace(o);
}
@Override
public void trace(Object o, Throwable throwable) {
log.trace(o, throwable);
}
@Override
public void trace(String message, LogContext logContext) {
GroupMgtLogContext groupMgtLogContext = (GroupMgtLogContext) logContext;
MDCContextUtil.populateGroupMgtMDCContext(groupMgtLogContext);
log.trace(message);
}
@Override
public void trace(Object object, LogContext logContext) {
GroupMgtLogContext groupMgtLogContext = (GroupMgtLogContext) logContext;
MDCContextUtil.populateGroupMgtMDCContext(groupMgtLogContext);
log.trace(object);
}
@Override
public void trace(Object object, Throwable t, LogContext logContext) {
GroupMgtLogContext groupMgtLogContext = (GroupMgtLogContext) logContext;
MDCContextUtil.populateGroupMgtMDCContext(groupMgtLogContext);
log.trace(object, t);
}
public void fatal(String message) {
log.fatal(message);
}
public void fatal(String message, Throwable t) {
log.fatal(message, t);
}
@Override
public void fatal(Object o) {
log.fatal(0);
}
@Override
public void fatal(Object o, Throwable throwable) {
log.fatal(0, throwable);
}
@Override
public void fatal(String message, LogContext logContext) {
GroupMgtLogContext groupMgtLogContext = (GroupMgtLogContext) logContext;
MDCContextUtil.populateGroupMgtMDCContext(groupMgtLogContext);
log.fatal(message);
}
@Override
public void fatal(Object object, LogContext logContext) {
GroupMgtLogContext groupMgtLogContext = (GroupMgtLogContext) logContext;
MDCContextUtil.populateGroupMgtMDCContext(groupMgtLogContext);
log.fatal(object);
}
@Override
public void fatal(Object object, Throwable t, LogContext logContext) {
GroupMgtLogContext groupMgtLogContext = (GroupMgtLogContext) logContext;
MDCContextUtil.populateGroupMgtMDCContext(groupMgtLogContext);
log.fatal(object, t);
}
@Override
public boolean isDebugEnabled() {
return log.isDebugEnabled();
}
@Override
public boolean isErrorEnabled() {
return log.isErrorEnabled();
}
@Override
public boolean isFatalEnabled() {
return log.isFatalEnabled();
}
@Override
public boolean isInfoEnabled() {
return log.isInfoEnabled();
}
@Override
public boolean isTraceEnabled() {
return log.isTraceEnabled();
}
@Override
public boolean isWarnEnabled() {
return log.isWarnEnabled();
}
@Override
public void clearLogContext() {
MDC.clear();
}
}

@ -19,17 +19,17 @@ package io.entgra.device.mgt.core.notification.logger.impl;
import io.entgra.device.mgt.core.device.mgt.extensions.logger.LogContext;
import io.entgra.device.mgt.core.device.mgt.extensions.logger.spi.EntgraLogger;
import io.entgra.device.mgt.core.notification.logger.UserLogContext;
import io.entgra.device.mgt.core.notification.logger.RoleMgtLogContext;
import io.entgra.device.mgt.core.notification.logger.util.MDCContextUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.log4j.MDC;
public class EntgraUserLoggerImpl implements EntgraLogger {
public class EntgraRoleMgtLoggerImpl implements EntgraLogger {
private static Log log = null;
public EntgraUserLoggerImpl(Class<?> clazz) {
public EntgraRoleMgtLoggerImpl(Class<?> clazz) {
log = LogFactory.getLog(clazz);
}
@ -53,26 +53,25 @@ public class EntgraUserLoggerImpl implements EntgraLogger {
@Override
public void info(String message, LogContext logContext) {
UserLogContext userLogContext = (UserLogContext) logContext;
MDCContextUtil.populateUserMDCContext(userLogContext);
RoleMgtLogContext roleMgtLogContext = (RoleMgtLogContext) logContext;
MDCContextUtil.populateRoleMgtMDCContext(roleMgtLogContext);
log.info(message);
}
@Override
public void info(Object object, LogContext logContext) {
UserLogContext userLogContext = (UserLogContext) logContext;
MDCContextUtil.populateUserMDCContext(userLogContext);
RoleMgtLogContext roleMgtLogContext = (RoleMgtLogContext) logContext;
MDCContextUtil.populateRoleMgtMDCContext(roleMgtLogContext);
log.info(object);
}
@Override
public void info(Object object, Throwable t, LogContext logContext) {
UserLogContext userLogContext = (UserLogContext) logContext;
MDCContextUtil.populateUserMDCContext(userLogContext);
RoleMgtLogContext roleMgtLogContext = (RoleMgtLogContext) logContext;
MDCContextUtil.populateRoleMgtMDCContext(roleMgtLogContext);
log.info(object, t);
}
public void debug(String message) {
log.debug(message);
}
@ -93,26 +92,25 @@ public class EntgraUserLoggerImpl implements EntgraLogger {
@Override
public void debug(String message, LogContext logContext) {
UserLogContext userLogContext = (UserLogContext) logContext;
MDCContextUtil.populateUserMDCContext(userLogContext);
RoleMgtLogContext roleMgtLogContext = (RoleMgtLogContext) logContext;
MDCContextUtil.populateRoleMgtMDCContext(roleMgtLogContext);
log.debug(message);
}
@Override
public void debug(Object object, LogContext logContext) {
UserLogContext userLogContext = (UserLogContext) logContext;
MDCContextUtil.populateUserMDCContext(userLogContext);
RoleMgtLogContext roleMgtLogContext = (RoleMgtLogContext) logContext;
MDCContextUtil.populateRoleMgtMDCContext(roleMgtLogContext);
log.debug(object);
}
@Override
public void debug(Object object, Throwable t, LogContext logContext) {
UserLogContext userLogContext = (UserLogContext) logContext;
MDCContextUtil.populateUserMDCContext(userLogContext);
RoleMgtLogContext roleMgtLogContext = (RoleMgtLogContext) logContext;
MDCContextUtil.populateRoleMgtMDCContext(roleMgtLogContext);
log.debug(object, t);
}
public void error(String message) {
log.error(message);
}
@ -133,33 +131,32 @@ public class EntgraUserLoggerImpl implements EntgraLogger {
@Override
public void error(String message, LogContext logContext) {
UserLogContext userLogContext = (UserLogContext) logContext;
MDCContextUtil.populateUserMDCContext(userLogContext);
RoleMgtLogContext roleMgtLogContext = (RoleMgtLogContext) logContext;
MDCContextUtil.populateRoleMgtMDCContext(roleMgtLogContext);
log.error(message);
}
@Override
public void error(String message, Throwable t, LogContext logContext) {
UserLogContext userLogContext = (UserLogContext) logContext;
MDCContextUtil.populateUserMDCContext(userLogContext);
RoleMgtLogContext roleMgtLogContext = (RoleMgtLogContext) logContext;
MDCContextUtil.populateRoleMgtMDCContext(roleMgtLogContext);
log.error(message, t);
}
@Override
public void error(Object object, LogContext logContext) {
UserLogContext userLogContext = (UserLogContext) logContext;
MDCContextUtil.populateUserMDCContext(userLogContext);
RoleMgtLogContext roleMgtLogContext = (RoleMgtLogContext) logContext;
MDCContextUtil.populateRoleMgtMDCContext(roleMgtLogContext);
log.error(object);
}
@Override
public void error(Object object, Throwable t, LogContext logContext) {
UserLogContext userLogContext = (UserLogContext) logContext;
MDCContextUtil.populateUserMDCContext(userLogContext);
RoleMgtLogContext roleMgtLogContext = (RoleMgtLogContext) logContext;
MDCContextUtil.populateRoleMgtMDCContext(roleMgtLogContext);
log.error(object, t);
}
public void warn(String message) {
log.warn(message);
}
@ -180,29 +177,29 @@ public class EntgraUserLoggerImpl implements EntgraLogger {
@Override
public void warn(String message, LogContext logContext) {
UserLogContext userLogContext = (UserLogContext) logContext;
MDCContextUtil.populateUserMDCContext(userLogContext);
RoleMgtLogContext roleMgtLogContext = (RoleMgtLogContext) logContext;
MDCContextUtil.populateRoleMgtMDCContext(roleMgtLogContext);
log.warn(message);
}
@Override
public void warn(String message, Throwable t, LogContext logContext) {
UserLogContext userLogContext = (UserLogContext) logContext;
MDCContextUtil.populateUserMDCContext(userLogContext);
RoleMgtLogContext roleMgtLogContext = (RoleMgtLogContext) logContext;
MDCContextUtil.populateRoleMgtMDCContext(roleMgtLogContext);
log.warn(message, t);
}
@Override
public void warn(Object object, LogContext logContext) {
UserLogContext userLogContext = (UserLogContext) logContext;
MDCContextUtil.populateUserMDCContext(userLogContext);
RoleMgtLogContext roleMgtLogContext = (RoleMgtLogContext) logContext;
MDCContextUtil.populateRoleMgtMDCContext(roleMgtLogContext);
log.warn(object);
}
@Override
public void warn(Object object, Throwable t, LogContext logContext) {
UserLogContext userLogContext = (UserLogContext) logContext;
MDCContextUtil.populateUserMDCContext(userLogContext);
RoleMgtLogContext roleMgtLogContext = (RoleMgtLogContext) logContext;
MDCContextUtil.populateRoleMgtMDCContext(roleMgtLogContext);
log.warn(object, t);
}
@ -226,27 +223,25 @@ public class EntgraUserLoggerImpl implements EntgraLogger {
@Override
public void trace(String message, LogContext logContext) {
UserLogContext userLogContext = (UserLogContext) logContext;
MDCContextUtil.populateUserMDCContext(userLogContext);
RoleMgtLogContext roleMgtLogContext = (RoleMgtLogContext) logContext;
MDCContextUtil.populateRoleMgtMDCContext(roleMgtLogContext);
log.trace(message);
}
@Override
public void trace(Object object, LogContext logContext) {
UserLogContext userLogContext = (UserLogContext) logContext;
MDCContextUtil.populateUserMDCContext(userLogContext);
RoleMgtLogContext roleMgtLogContext = (RoleMgtLogContext) logContext;
MDCContextUtil.populateRoleMgtMDCContext(roleMgtLogContext);
log.trace(object);
}
@Override
public void trace(Object object, Throwable t, LogContext logContext) {
UserLogContext userLogContext = (UserLogContext) logContext;
MDCContextUtil.populateUserMDCContext(userLogContext);
RoleMgtLogContext roleMgtLogContext = (RoleMgtLogContext) logContext;
MDCContextUtil.populateRoleMgtMDCContext(roleMgtLogContext);
log.trace(object, t);
}
public void fatal(String message) {
log.fatal(message);
}
@ -267,22 +262,22 @@ public class EntgraUserLoggerImpl implements EntgraLogger {
@Override
public void fatal(String message, LogContext logContext) {
UserLogContext userLogContext = (UserLogContext) logContext;
MDCContextUtil.populateUserMDCContext(userLogContext);
RoleMgtLogContext roleMgtLogContext = (RoleMgtLogContext) logContext;
MDCContextUtil.populateRoleMgtMDCContext(roleMgtLogContext);
log.fatal(message);
}
@Override
public void fatal(Object object, LogContext logContext) {
UserLogContext userLogContext = (UserLogContext) logContext;
MDCContextUtil.populateUserMDCContext(userLogContext);
RoleMgtLogContext roleMgtLogContext = (RoleMgtLogContext) logContext;
MDCContextUtil.populateRoleMgtMDCContext(roleMgtLogContext);
log.fatal(object);
}
@Override
public void fatal(Object object, Throwable t, LogContext logContext) {
UserLogContext userLogContext = (UserLogContext) logContext;
MDCContextUtil.populateUserMDCContext(userLogContext);
RoleMgtLogContext roleMgtLogContext = (RoleMgtLogContext) logContext;
MDCContextUtil.populateRoleMgtMDCContext(roleMgtLogContext);
log.fatal(object, t);
}

@ -0,0 +1,323 @@
/*
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. 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 io.entgra.device.mgt.core.notification.logger.impl;
import io.entgra.device.mgt.core.device.mgt.extensions.logger.LogContext;
import io.entgra.device.mgt.core.device.mgt.extensions.logger.spi.EntgraLogger;
import io.entgra.device.mgt.core.notification.logger.UserLoginLogContext;
import io.entgra.device.mgt.core.notification.logger.util.MDCContextUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.log4j.MDC;
public class EntgraUserLoginLoggerImpl implements EntgraLogger {
private static Log log = null;
public EntgraUserLoginLoggerImpl(Class<?> clazz) {
log = LogFactory.getLog(clazz);
}
public void info(String message) {
log.info(message);
}
public void info(String message, Throwable t) {
log.info(message, t);
}
@Override
public void info(Object o) {
log.info(o);
}
@Override
public void info(Object o, Throwable throwable) {
log.info(o, throwable);
}
@Override
public void info(String message, LogContext logContext) {
UserLoginLogContext userLoginLogContext = (UserLoginLogContext) logContext;
MDCContextUtil.populateUserMDCContext(userLoginLogContext);
log.info(message);
}
@Override
public void info(Object object, LogContext logContext) {
UserLoginLogContext userLoginLogContext = (UserLoginLogContext) logContext;
MDCContextUtil.populateUserMDCContext(userLoginLogContext);
log.info(object);
}
@Override
public void info(Object object, Throwable t, LogContext logContext) {
UserLoginLogContext userLoginLogContext = (UserLoginLogContext) logContext;
MDCContextUtil.populateUserMDCContext(userLoginLogContext);
log.info(object, t);
}
public void debug(String message) {
log.debug(message);
}
public void debug(String message, Throwable t) {
log.debug(message, t);
}
@Override
public void debug(Object o) {
log.debug(o);
}
@Override
public void debug(Object o, Throwable throwable) {
log.debug(o, throwable);
}
@Override
public void debug(String message, LogContext logContext) {
UserLoginLogContext userLoginLogContext = (UserLoginLogContext) logContext;
MDCContextUtil.populateUserMDCContext(userLoginLogContext);
log.debug(message);
}
@Override
public void debug(Object object, LogContext logContext) {
UserLoginLogContext userLoginLogContext = (UserLoginLogContext) logContext;
MDCContextUtil.populateUserMDCContext(userLoginLogContext);
log.debug(object);
}
@Override
public void debug(Object object, Throwable t, LogContext logContext) {
UserLoginLogContext userLoginLogContext = (UserLoginLogContext) logContext;
MDCContextUtil.populateUserMDCContext(userLoginLogContext);
log.debug(object, t);
}
public void error(String message) {
log.error(message);
}
public void error(String message, Throwable t) {
log.error(message, t);
}
@Override
public void error(Object o) {
log.error(o);
}
@Override
public void error(Object o, Throwable throwable) {
log.error(o, throwable);
}
@Override
public void error(String message, LogContext logContext) {
UserLoginLogContext userLoginLogContext = (UserLoginLogContext) logContext;
MDCContextUtil.populateUserMDCContext(userLoginLogContext);
log.error(message);
}
@Override
public void error(String message, Throwable t, LogContext logContext) {
UserLoginLogContext userLoginLogContext = (UserLoginLogContext) logContext;
MDCContextUtil.populateUserMDCContext(userLoginLogContext);
log.error(message, t);
}
@Override
public void error(Object object, LogContext logContext) {
UserLoginLogContext userLoginLogContext = (UserLoginLogContext) logContext;
MDCContextUtil.populateUserMDCContext(userLoginLogContext);
log.error(object);
}
@Override
public void error(Object object, Throwable t, LogContext logContext) {
UserLoginLogContext userLoginLogContext = (UserLoginLogContext) logContext;
MDCContextUtil.populateUserMDCContext(userLoginLogContext);
log.error(object, t);
}
public void warn(String message) {
log.warn(message);
}
public void warn(String message, Throwable t) {
log.warn(message, t);
}
@Override
public void warn(Object o) {
log.warn(o);
}
@Override
public void warn(Object o, Throwable throwable) {
log.warn(o, throwable);
}
@Override
public void warn(String message, LogContext logContext) {
UserLoginLogContext userLoginLogContext = (UserLoginLogContext) logContext;
MDCContextUtil.populateUserMDCContext(userLoginLogContext);
log.warn(message);
}
@Override
public void warn(String message, Throwable t, LogContext logContext) {
UserLoginLogContext userLoginLogContext = (UserLoginLogContext) logContext;
MDCContextUtil.populateUserMDCContext(userLoginLogContext);
log.warn(message, t);
}
@Override
public void warn(Object object, LogContext logContext) {
UserLoginLogContext userLoginLogContext = (UserLoginLogContext) logContext;
MDCContextUtil.populateUserMDCContext(userLoginLogContext);
log.warn(object);
}
@Override
public void warn(Object object, Throwable t, LogContext logContext) {
UserLoginLogContext userLoginLogContext = (UserLoginLogContext) logContext;
MDCContextUtil.populateUserMDCContext(userLoginLogContext);
log.warn(object, t);
}
public void trace(String message) {
log.trace(message);
}
public void trace(String message, Throwable t) {
log.trace(message, t);
}
@Override
public void trace(Object o) {
log.trace(o);
}
@Override
public void trace(Object o, Throwable throwable) {
log.trace(o, throwable);
}
@Override
public void trace(String message, LogContext logContext) {
UserLoginLogContext userLoginLogContext = (UserLoginLogContext) logContext;
MDCContextUtil.populateUserMDCContext(userLoginLogContext);
log.trace(message);
}
@Override
public void trace(Object object, LogContext logContext) {
UserLoginLogContext userLoginLogContext = (UserLoginLogContext) logContext;
MDCContextUtil.populateUserMDCContext(userLoginLogContext);
log.trace(object);
}
@Override
public void trace(Object object, Throwable t, LogContext logContext) {
UserLoginLogContext userLoginLogContext = (UserLoginLogContext) logContext;
MDCContextUtil.populateUserMDCContext(userLoginLogContext);
log.trace(object, t);
}
public void fatal(String message) {
log.fatal(message);
}
public void fatal(String message, Throwable t) {
log.fatal(message, t);
}
@Override
public void fatal(Object o) {
log.fatal(0);
}
@Override
public void fatal(Object o, Throwable throwable) {
log.fatal(0, throwable);
}
@Override
public void fatal(String message, LogContext logContext) {
UserLoginLogContext userLoginLogContext = (UserLoginLogContext) logContext;
MDCContextUtil.populateUserMDCContext(userLoginLogContext);
log.fatal(message);
}
@Override
public void fatal(Object object, LogContext logContext) {
UserLoginLogContext userLoginLogContext = (UserLoginLogContext) logContext;
MDCContextUtil.populateUserMDCContext(userLoginLogContext);
log.fatal(object);
}
@Override
public void fatal(Object object, Throwable t, LogContext logContext) {
UserLoginLogContext userLoginLogContext = (UserLoginLogContext) logContext;
MDCContextUtil.populateUserMDCContext(userLoginLogContext);
log.fatal(object, t);
}
@Override
public boolean isDebugEnabled() {
return log.isDebugEnabled();
}
@Override
public boolean isErrorEnabled() {
return log.isErrorEnabled();
}
@Override
public boolean isFatalEnabled() {
return log.isFatalEnabled();
}
@Override
public boolean isInfoEnabled() {
return log.isInfoEnabled();
}
@Override
public boolean isTraceEnabled() {
return log.isTraceEnabled();
}
@Override
public boolean isWarnEnabled() {
return log.isWarnEnabled();
}
@Override
public void clearLogContext() {
MDC.clear();
}
}

@ -0,0 +1,318 @@
/*
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. 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 io.entgra.device.mgt.core.notification.logger.impl;
import io.entgra.device.mgt.core.device.mgt.extensions.logger.LogContext;
import io.entgra.device.mgt.core.device.mgt.extensions.logger.spi.EntgraLogger;
import io.entgra.device.mgt.core.notification.logger.UserMgtLogContext;
import io.entgra.device.mgt.core.notification.logger.util.MDCContextUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.log4j.MDC;
public class EntgraUserMgtLoggerImpl implements EntgraLogger {
private static Log log = null;
public EntgraUserMgtLoggerImpl(Class<?> clazz) {
log = LogFactory.getLog(clazz);
}
public void info(String message) {
log.info(message);
}
public void info(String message, Throwable t) {
log.info(message, t);
}
@Override
public void info(Object o) {
log.info(o);
}
@Override
public void info(Object o, Throwable throwable) {
log.info(o, throwable);
}
@Override
public void info(String message, LogContext logContext) {
UserMgtLogContext userMgtLogContext = (UserMgtLogContext) logContext;
MDCContextUtil.populateUserMgtMDCContext(userMgtLogContext);
log.info(message);
}
@Override
public void info(Object object, LogContext logContext) {
UserMgtLogContext userMgtLogContext = (UserMgtLogContext) logContext;
MDCContextUtil.populateUserMgtMDCContext(userMgtLogContext);
log.info(object);
}
@Override
public void info(Object object, Throwable t, LogContext logContext) {
UserMgtLogContext userMgtLogContext = (UserMgtLogContext) logContext;
MDCContextUtil.populateUserMgtMDCContext(userMgtLogContext);
log.info(object, t);
}
public void debug(String message) {
log.debug(message);
}
public void debug(String message, Throwable t) {
log.debug(message, t);
}
@Override
public void debug(Object o) {
log.debug(o);
}
@Override
public void debug(Object o, Throwable throwable) {
log.debug(o, throwable);
}
@Override
public void debug(String message, LogContext logContext) {
UserMgtLogContext userMgtLogContext = (UserMgtLogContext) logContext;
MDCContextUtil.populateUserMgtMDCContext(userMgtLogContext);
log.debug(message);
}
@Override
public void debug(Object object, LogContext logContext) {
UserMgtLogContext userMgtLogContext = (UserMgtLogContext) logContext;
MDCContextUtil.populateUserMgtMDCContext(userMgtLogContext);
log.debug(object);
}
@Override
public void debug(Object object, Throwable t, LogContext logContext) {
UserMgtLogContext userMgtLogContext = (UserMgtLogContext) logContext;
MDCContextUtil.populateUserMgtMDCContext(userMgtLogContext);
log.debug(object, t);
}
public void error(String message) {
log.error(message);
}
public void error(String message, Throwable t) {
log.error(message, t);
}
@Override
public void error(Object o) {
log.error(o);
}
@Override
public void error(Object o, Throwable throwable) {
log.error(o, throwable);
}
@Override
public void error(String message, LogContext logContext) {
UserMgtLogContext userMgtLogContext = (UserMgtLogContext) logContext;
MDCContextUtil.populateUserMgtMDCContext(userMgtLogContext);
log.error(message);
}
@Override
public void error(String message, Throwable t, LogContext logContext) {
UserMgtLogContext userMgtLogContext = (UserMgtLogContext) logContext;
MDCContextUtil.populateUserMgtMDCContext(userMgtLogContext);
log.error(message, t);
}
@Override
public void error(Object object, LogContext logContext) {
UserMgtLogContext userMgtLogContext = (UserMgtLogContext) logContext;
MDCContextUtil.populateUserMgtMDCContext(userMgtLogContext);
log.error(object);
}
@Override
public void error(Object object, Throwable t, LogContext logContext) {
UserMgtLogContext userMgtLogContext = (UserMgtLogContext) logContext;
MDCContextUtil.populateUserMgtMDCContext(userMgtLogContext);
log.error(object, t);
}
public void warn(String message) {
log.warn(message);
}
public void warn(String message, Throwable t) {
log.warn(message, t);
}
@Override
public void warn(Object o) {
log.warn(o);
}
@Override
public void warn(Object o, Throwable throwable) {
log.warn(o, throwable);
}
@Override
public void warn(String message, LogContext logContext) {
UserMgtLogContext userMgtLogContext = (UserMgtLogContext) logContext;
MDCContextUtil.populateUserMgtMDCContext(userMgtLogContext);
log.warn(message);
}
@Override
public void warn(String message, Throwable t, LogContext logContext) {
UserMgtLogContext userMgtLogContext = (UserMgtLogContext) logContext;
MDCContextUtil.populateUserMgtMDCContext(userMgtLogContext);
log.warn(message, t);
}
@Override
public void warn(Object object, LogContext logContext) {
UserMgtLogContext userMgtLogContext = (UserMgtLogContext) logContext;
MDCContextUtil.populateUserMgtMDCContext(userMgtLogContext);
log.warn(object);
}
@Override
public void warn(Object object, Throwable t, LogContext logContext) {
UserMgtLogContext userMgtLogContext = (UserMgtLogContext) logContext;
MDCContextUtil.populateUserMgtMDCContext(userMgtLogContext);
log.warn(object, t);
}
public void trace(String message) {
log.trace(message);
}
public void trace(String message, Throwable t) {
log.trace(message, t);
}
@Override
public void trace(Object o) {
log.trace(o);
}
@Override
public void trace(Object o, Throwable throwable) {
log.trace(o, throwable);
}
@Override
public void trace(String message, LogContext logContext) {
UserMgtLogContext userMgtLogContext = (UserMgtLogContext) logContext;
MDCContextUtil.populateUserMgtMDCContext(userMgtLogContext);
log.trace(message);
}
@Override
public void trace(Object object, LogContext logContext) {
UserMgtLogContext userMgtLogContext = (UserMgtLogContext) logContext;
MDCContextUtil.populateUserMgtMDCContext(userMgtLogContext);
log.trace(object);
}
@Override
public void trace(Object object, Throwable t, LogContext logContext) {
UserMgtLogContext userMgtLogContext = (UserMgtLogContext) logContext;
MDCContextUtil.populateUserMgtMDCContext(userMgtLogContext);
log.trace(object, t);
}
public void fatal(String message) {
log.fatal(message);
}
public void fatal(String message, Throwable t) {
log.fatal(message, t);
}
@Override
public void fatal(Object o) {
log.fatal(0);
}
@Override
public void fatal(Object o, Throwable throwable) {
log.fatal(0, throwable);
}
@Override
public void fatal(String message, LogContext logContext) {
UserMgtLogContext userMgtLogContext = (UserMgtLogContext) logContext;
MDCContextUtil.populateUserMgtMDCContext(userMgtLogContext);
log.fatal(message);
}
@Override
public void fatal(Object object, LogContext logContext) {
UserMgtLogContext userMgtLogContext = (UserMgtLogContext) logContext;
MDCContextUtil.populateUserMgtMDCContext(userMgtLogContext);
log.fatal(object);
}
@Override
public void fatal(Object object, Throwable t, LogContext logContext) {
UserMgtLogContext userMgtLogContext = (UserMgtLogContext) logContext;
MDCContextUtil.populateUserMgtMDCContext(userMgtLogContext);
log.fatal(object, t);
}
@Override
public boolean isDebugEnabled() {
return log.isDebugEnabled();
}
@Override
public boolean isErrorEnabled() {
return log.isErrorEnabled();
}
@Override
public boolean isFatalEnabled() {
return log.isFatalEnabled();
}
@Override
public boolean isInfoEnabled() {
return log.isInfoEnabled();
}
@Override
public boolean isTraceEnabled() {
return log.isTraceEnabled();
}
@Override
public boolean isWarnEnabled() {
return log.isWarnEnabled();
}
@Override
public void clearLogContext() {
MDC.clear();
}
}

@ -37,7 +37,7 @@ public final class MDCContextUtil {
}
}
public static void populateUserMDCContext(final UserLogContext mdcContext) {
public static void populateUserMDCContext(final UserLoginLogContext mdcContext) {
if (mdcContext.getUserName() != null) {
MDC.put("UserName", mdcContext.getUserName());
}
@ -53,8 +53,8 @@ public final class MDCContextUtil {
if (mdcContext.isUserRegistered()) {
MDC.put("IsUserRegistered", "Registered");
}
if (mdcContext.isDeviceRegisterged()) {
MDC.put("IsDeviceRegistered", mdcContext.isDeviceRegisterged());
if (mdcContext.isDeviceRegistered()) {
MDC.put("IsDeviceRegistered", mdcContext.isDeviceRegistered());
}
if (mdcContext.getTenantDomain() != null) {
MDC.put("TenantDomain", mdcContext.getTenantDomain());
@ -160,6 +160,88 @@ public final class MDCContextUtil {
MDC.put("UserName", mdcContext.getUserName());
}
}
}
public static void populateRoleMgtMDCContext(final RoleMgtLogContext mdcContext) {
if (mdcContext.getUserStoreDomain() != null) {
MDC.put("UserStoreDomain", mdcContext.getUserStoreDomain());
}
if (mdcContext.getRoleName() != null) {
MDC.put("RoleName", mdcContext.getRoleName());
}
if (mdcContext.getUsers() != null) {
MDC.put("Users", mdcContext.getUsers());
}
if (mdcContext.getActionTag() != null) {
MDC.put("ActionTag", mdcContext.getActionTag());
}
if (mdcContext.getUserName() != null) {
MDC.put("UserName", mdcContext.getUserName());
}
if (mdcContext.getTenantDomain() != null) {
MDC.put("TenantDomain", mdcContext.getTenantDomain());
}
if (mdcContext.getTenantID() != null) {
MDC.put("TenantId", mdcContext.getTenantID());
}
}
public static void populateUserMgtMDCContext(final UserMgtLogContext mdcContext) {
if (mdcContext.getUserStoreDomain() != null) {
MDC.put("UserStoreDomain", mdcContext.getUserStoreDomain());
}
if (mdcContext.getFirstName() != null) {
MDC.put("FirstName", mdcContext.getFirstName());
}
if (mdcContext.getLastName() != null) {
MDC.put("LastName", mdcContext.getLastName());
}
if (mdcContext.getEmail() != null) {
MDC.put("Email", mdcContext.getEmail());
}
if (mdcContext.getUserRoles() != null) {
MDC.put("UserRoles", mdcContext.getUserRoles());
}
if (mdcContext.getActionTag() != null) {
MDC.put("ActionTag", mdcContext.getActionTag());
}
if (mdcContext.getUserName() != null) {
MDC.put("UserName", mdcContext.getUserName());
}
if (mdcContext.getTenantDomain() != null) {
MDC.put("TenantDomain", mdcContext.getTenantDomain());
}
if (mdcContext.getTenantID() != null) {
MDC.put("TenantId", mdcContext.getTenantID());
}
}
public static void populateGroupMgtMDCContext(final GroupMgtLogContext mdcContext) {
if (mdcContext.getGroupId() != null) {
MDC.put("GroupId", mdcContext.getGroupId());
}
if (mdcContext.getName() != null) {
MDC.put("Name", mdcContext.getName());
}
if (mdcContext.getOwner() != null) {
MDC.put("Owner", mdcContext.getOwner());
}
if (mdcContext.getActionTag() != null) {
MDC.put("ActionTag", mdcContext.getActionTag());
}
if (mdcContext.getDeviceCount() != null) {
MDC.put("DeviceCount", mdcContext.getDeviceCount());
}
if (mdcContext.getDevices() != null) {
MDC.put("Devices", mdcContext.getDevices());
}
if (mdcContext.getUserName() != null) {
MDC.put("UserName", mdcContext.getUserName());
}
if (mdcContext.getTenantDomain() != null) {
MDC.put("TenantDomain", mdcContext.getTenantDomain());
}
if (mdcContext.getTenantID() != null) {
MDC.put("TenantId", mdcContext.getTenantID());
}
}
}

@ -22,7 +22,7 @@
<parent>
<artifactId>io.entgra.device.mgt.core.parent</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.35-SNAPSHOT</version>
<version>5.0.38-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

@ -21,7 +21,7 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>operation-template-mgt</artifactId>
<version>5.0.35-SNAPSHOT</version>
<version>5.0.38-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>io.entgra.device.mgt.core.parent</artifactId>
<version>5.0.35-SNAPSHOT</version>
<version>5.0.38-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

@ -21,7 +21,7 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>policy-mgt</artifactId>
<version>5.0.35-SNAPSHOT</version>
<version>5.0.38-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -21,7 +21,7 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>policy-mgt</artifactId>
<version>5.0.35-SNAPSHOT</version>
<version>5.0.38-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>policy-mgt</artifactId>
<version>5.0.35-SNAPSHOT</version>
<version>5.0.38-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>policy-mgt</artifactId>
<version>5.0.35-SNAPSHOT</version>
<version>5.0.38-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -23,7 +23,7 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>io.entgra.device.mgt.core.parent</artifactId>
<version>5.0.35-SNAPSHOT</version>
<version>5.0.38-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

@ -20,7 +20,7 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>subtype-mgt</artifactId>
<version>5.0.35-SNAPSHOT</version>
<version>5.0.38-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -20,7 +20,7 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>io.entgra.device.mgt.core.parent</artifactId>
<version>5.0.35-SNAPSHOT</version>
<version>5.0.38-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

@ -21,7 +21,7 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>io.entgra.device.mgt.core.parent</artifactId>
<version>5.0.35-SNAPSHOT</version>
<version>5.0.38-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

@ -20,7 +20,7 @@
<parent>
<artifactId>task-manager</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.35-SNAPSHOT</version>
<version>5.0.38-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -21,7 +21,7 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>task-manager</artifactId>
<version>5.0.35-SNAPSHOT</version>
<version>5.0.38-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -21,7 +21,7 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>task-mgt</artifactId>
<version>5.0.35-SNAPSHOT</version>
<version>5.0.38-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -21,7 +21,7 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>task-watcher</artifactId>
<version>5.0.35-SNAPSHOT</version>
<version>5.0.38-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -21,7 +21,7 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>task-mgt</artifactId>
<version>5.0.35-SNAPSHOT</version>
<version>5.0.38-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -20,7 +20,7 @@
<parent>
<artifactId>tenant-mgt</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.35-SNAPSHOT</version>
<version>5.0.38-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -20,7 +20,7 @@
<parent>
<artifactId>tenant-mgt</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.35-SNAPSHOT</version>
<version>5.0.38-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -20,7 +20,7 @@
<parent>
<artifactId>io.entgra.device.mgt.core.parent</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.35-SNAPSHOT</version>
<version>5.0.38-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save