Windows enrollment issue was resolved from wso2/product-iots#1029

revert-dabc3590
Hasunie 8 years ago
parent 2dc23d0574
commit fbd31b77ef

@ -0,0 +1,38 @@
package org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions;
public class WindowsEnrollmentTokenException extends Exception {
private static final long serialVersionUID = -2297311387874900305L;
private String errorMessage;
public String getErrorMessage() {
return errorMessage;
}
public void setErrorMessage(String errorMessage) {
this.errorMessage = errorMessage;
}
public WindowsEnrollmentTokenException(String msg, Exception nestedEx) {
super(msg, nestedEx);
setErrorMessage(msg);
}
public WindowsEnrollmentTokenException(String message, Throwable cause) {
super(message, cause);
setErrorMessage(message);
}
public WindowsEnrollmentTokenException(String msg) {
super(msg);
setErrorMessage(msg);
}
public WindowsEnrollmentTokenException() {
super();
}
public WindowsEnrollmentTokenException(Throwable cause) {
super(cause);
}
}

@ -19,7 +19,6 @@
package org.wso2.carbon.device.mgt.mobile.windows.api.common.util;
import org.apache.commons.codec.binary.Base64;
import org.apache.http.auth.AUTH;
import org.apache.ws.security.WSSecurityException;
import org.apache.ws.security.handler.RequestData;
import org.apache.ws.security.message.token.BinarySecurity;
@ -29,12 +28,9 @@ import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.mobile.windows.api.common.PluginConstants;
import org.wso2.carbon.device.mgt.mobile.windows.api.common.authenticator.OAuthValidatorFactory;
import org.wso2.carbon.device.mgt.mobile.windows.api.common.beans.CacheEntry;
import org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions.AuthenticationException;
import org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions.OAuthTokenValidationException;
import org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions.WindowsDeviceEnrolmentException;
import org.wso2.carbon.device.mgt.mobile.windows.exception.WindowsDeviceMgtPluginException;
import org.wso2.carbon.device.mgt.mobile.windows.impl.dao.MobileDeviceManagementDAOException;
import org.wso2.carbon.device.mgt.mobile.windows.impl.dto.MobileCacheEntry;
import java.util.HashMap;

@ -22,11 +22,9 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions.WindowsDeviceEnrolmentException;
import org.wso2.carbon.device.mgt.mobile.windows.exception.WindowsDeviceMgtPluginException;
import org.wso2.carbon.device.mgt.mobile.windows.impl.WindowsTokenService;
import org.wso2.carbon.device.mgt.mobile.windows.impl.dao.MobileDeviceManagementDAOException;
import org.wso2.carbon.device.mgt.mobile.windows.impl.dto.MobileCacheEntry;
import org.wso2.carbon.device.mgt.mobile.windows.impl.util.WindowsUtils;
import java.util.UUID;
@ -35,20 +33,12 @@ import java.util.UUID;
*/
public class DeviceUtil {
private static final String TOKEN_CACHE_MANAGER = "TOKEN_CACHE_MANAGER";
private static final String TOKEN_CACHE = "TOKEN_CACHE";
private static final long CACHE_DURATION = 15l;
private static boolean isContextCacheInitialized = false;
private static WindowsTokenService tokenService;
private static final Log log = LogFactory.getLog(DeviceUtil.class);
static {
try {
tokenService = WindowsUtils.getEnrollmentTokenService();
} catch (WindowsDeviceMgtPluginException e) {
log.error("WindowsTokenService cannot be initialized.", e);
}
tokenService = WindowsAPIUtils.getEnrollmentTokenService();
}
public static String generateRandomToken() {
@ -59,7 +49,7 @@ public class DeviceUtil {
throws WindowsDeviceEnrolmentException {
try {
if(tokenService == null) {
tokenService = WindowsUtils.getEnrollmentTokenService();
tokenService = WindowsAPIUtils.getEnrollmentTokenService();
}
MobileCacheEntry existingCacheEntry = tokenService.getCacheToken(token);
PrivilegedCarbonContext carbonCtx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
@ -77,12 +67,7 @@ public class DeviceUtil {
tokenService.updateCacheToken(existingCacheEntry);
}
} catch (MobileDeviceManagementDAOException e) {
String msg = "Error occured when saving cache token for device: " + deviceID;
log.error(msg);
throw new WindowsDeviceEnrolmentException(msg, e);
} catch (WindowsDeviceMgtPluginException e) {
String msg = "Error occured when retrieving enrollment token service";
log.error(msg);
String msg = "Error occurred when saving cache token for device: " + deviceID;
throw new WindowsDeviceEnrolmentException(msg, e);
}
}
@ -92,16 +77,11 @@ public class DeviceUtil {
MobileCacheEntry tokenEntry;
try {
if (tokenService == null) {
tokenService = WindowsUtils.getEnrollmentTokenService();
tokenService = WindowsAPIUtils.getEnrollmentTokenService();
}
tokenEntry = tokenService.getCacheToken(token);
} catch (WindowsDeviceMgtPluginException e) {
String msg = "Error occured when retrieving enrollment token service.";
log.error(msg);
throw new WindowsDeviceEnrolmentException(msg, e);
} catch (MobileDeviceManagementDAOException e) {
String msg = "Error occured when retrieving enrollment token.";
log.error(msg);
String msg = "Error occurred when retrieving enrollment token.";
throw new WindowsDeviceEnrolmentException(msg, e);
}
return tokenEntry;
@ -112,16 +92,12 @@ public class DeviceUtil {
MobileCacheEntry tokenEntry;
try {
if (tokenService == null) {
tokenService = WindowsUtils.getEnrollmentTokenService();
tokenService = WindowsAPIUtils.getEnrollmentTokenService();
}
tokenEntry = tokenService.getCacheTokenFromDeviceId(deviceId);
} catch (WindowsDeviceMgtPluginException e) {
String msg = "Error occured when retrieving enrollment token service.";
log.error(msg);
throw new WindowsDeviceEnrolmentException(msg, e);
} catch (MobileDeviceManagementDAOException e) {
String msg = "Error occured when retrieving enrollment token.";
log.error(msg);
String msg = "Error occurred when retrieving enrollment token.";
throw new WindowsDeviceEnrolmentException(msg, e);
}
return tokenEntry;
@ -130,14 +106,11 @@ public class DeviceUtil {
public static void removeTokenEntry(String token) {
try {
if (tokenService == null) {
tokenService = WindowsUtils.getEnrollmentTokenService();
tokenService = WindowsAPIUtils.getEnrollmentTokenService();
}
tokenService.removeCacheToken(token);
} catch (WindowsDeviceMgtPluginException e) {
String msg = "Error occured when retrieving enrollment token service.";
log.error(msg);
} catch (MobileDeviceManagementDAOException e) {
String msg = "Error occured when removing enrollment token.";
String msg = "Error occurred when removing enrollment token.";
log.error(msg);
}
}

@ -40,6 +40,8 @@ import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.device.mgt.mobile.windows.api.common.PluginConstants;
import org.wso2.carbon.device.mgt.mobile.windows.api.common.beans.ErrorResponse;
import org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions.BadRequestException;
import org.wso2.carbon.device.mgt.mobile.windows.exception.WindowsDeviceMgtPluginException;
import org.wso2.carbon.device.mgt.mobile.windows.impl.WindowsTokenService;
import org.wso2.carbon.identity.core.util.IdentityTenantUtil;
import org.wso2.carbon.identity.oauth2.OAuth2TokenValidationService;
import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
@ -90,6 +92,18 @@ public class WindowsAPIUtils {
return notificationManagementService;
}
public static WindowsTokenService getEnrollmentTokenService() {
WindowsTokenService tokenService;
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
tokenService = (WindowsTokenService)
ctx.getOSGiService(WindowsTokenService.class, null);
if(tokenService == null) {
throw new IllegalStateException("WindowsTokenService is not initialized");
}
return tokenService;
}
public static MediaType getResponseMediaType(String acceptHeader) {
MediaType responseMediaType;
if (MediaType.WILDCARD.equals(acceptHeader)) {

@ -1,52 +0,0 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.device.mgt.mobile.windows.impl.util;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.mgt.mobile.windows.exception.WindowsDeviceMgtPluginException;
import org.wso2.carbon.device.mgt.mobile.windows.impl.WindowsTokenService;
import java.util.Map;
/**
* Contains utility methods used by Windows plugin.
*/
public class WindowsUtils {
public static String getDeviceProperty(Map<String, String> deviceProperties, String property) {
String deviceProperty = deviceProperties.get(property);
if (deviceProperty == null) {
return null;
}
return deviceProperty;
}
public static WindowsTokenService getEnrollmentTokenService() throws WindowsDeviceMgtPluginException {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
WindowsTokenService tokenService = (WindowsTokenService)
ctx.getOSGiService(WindowsTokenService.class, null);
if(tokenService == null) {
String msg = "WindowsTokenService is not initialized";
throw new WindowsDeviceMgtPluginException(msg);
}
return tokenService;
}
}

@ -202,11 +202,11 @@
</propertyDef>
</properties>
</adviceFile>
<!--<bundles>-->
<!--<bundleDef>-->
<!--org.wso2.carbon.devicemgt-plugins:org.wso2.carbon.device.mgt.mobile.windows:${carbon.devicemgt.plugins.version}-->
<!--</bundleDef>-->
<!--</bundles>-->
<bundles>
<bundleDef>
org.wso2.carbon.devicemgt-plugins:org.wso2.carbon.device.mgt.mobile.windows:${carbon.devicemgt.plugins.version}
</bundleDef>
</bundles>
<importFeatures>
<importFeatureDef>
org.wso2.carbon.core.server:${carbon.kernel.version}

Loading…
Cancel
Save