lasantha 8 years ago
commit 331e0ec8ca

@ -51,7 +51,7 @@ public class GlobalThrowableMapper implements ExceptionMapper {
if (e instanceof JsonParseException) { if (e instanceof JsonParseException) {
String errorMessage = "Malformed request body."; String errorMessage = "Malformed request body.";
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.error(errorMessage, e); log.debug(errorMessage, e);
} }
return AndroidDeviceUtils.buildBadRequestException(errorMessage).getResponse(); return AndroidDeviceUtils.buildBadRequestException(errorMessage).getResponse();
} }
@ -63,13 +63,16 @@ public class GlobalThrowableMapper implements ExceptionMapper {
} }
if (e instanceof UnexpectedServerErrorException) { if (e instanceof UnexpectedServerErrorException) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.error("Unexpected server error", e); log.debug("Unexpected server error", e);
} }
return ((UnexpectedServerErrorException) e).getResponse(); return ((UnexpectedServerErrorException) e).getResponse();
} }
if (e instanceof ConstraintViolationException) { if (e instanceof ConstraintViolationException) {
if (log.isDebugEnabled()) {
log.debug("Constraint violation issue.", e);
return ((ParameterValidationException) e).getResponse(); return ((ParameterValidationException) e).getResponse();
} }
}
if (e instanceof IllegalArgumentException) { if (e instanceof IllegalArgumentException) {
ErrorDTO errorDetail = new ErrorDTO(); ErrorDTO errorDetail = new ErrorDTO();
errorDetail.setCode((long) 400); errorDetail.setCode((long) 400);
@ -83,7 +86,7 @@ public class GlobalThrowableMapper implements ExceptionMapper {
} }
if (e instanceof ClientErrorException) { if (e instanceof ClientErrorException) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.error("Client error", e); log.debug("Client error", e);
} }
return ((ClientErrorException) e).getResponse(); return ((ClientErrorException) e).getResponse();
} }
@ -100,7 +103,7 @@ public class GlobalThrowableMapper implements ExceptionMapper {
} }
if (e instanceof ForbiddenException) { if (e instanceof ForbiddenException) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.error("Resource forbidden", e); log.debug("Resource forbidden", e);
} }
return ((ForbiddenException) e).getResponse(); return ((ForbiddenException) e).getResponse();
} }

@ -706,6 +706,17 @@ var androidOperationModule = function () {
} }
} }
} }
// only for app whitelisting and black listing
if (operationCode == "APP-RESTRICTION" && key == "restrictedApplications") {
var i;
for (i = 0; i < uiPayload.restrictedApplications.length; ++i) {
$("#restrictedapplication-list").append('<tr>' +
'<th>'+ (i+1) +'</th> <th>' + uiPayload.restrictedApplications[i].appName +
'</th> <th>' + uiPayload.restrictedApplications[i].packageName + '</th></tr>');
}
}
} }
); );
}; };

@ -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; package org.wso2.carbon.device.mgt.mobile.windows.api.common.util;
import org.apache.commons.codec.binary.Base64; import org.apache.commons.codec.binary.Base64;
import org.apache.http.auth.AUTH;
import org.apache.ws.security.WSSecurityException; import org.apache.ws.security.WSSecurityException;
import org.apache.ws.security.handler.RequestData; import org.apache.ws.security.handler.RequestData;
import org.apache.ws.security.message.token.BinarySecurity; 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.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.mobile.windows.api.common.PluginConstants; 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.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.AuthenticationException;
import org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions.OAuthTokenValidationException; 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.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 org.wso2.carbon.device.mgt.mobile.windows.impl.dto.MobileCacheEntry;
import java.util.HashMap; import java.util.HashMap;

@ -22,11 +22,9 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.PrivilegedCarbonContext; 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.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.WindowsTokenService;
import org.wso2.carbon.device.mgt.mobile.windows.impl.dao.MobileDeviceManagementDAOException; 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.dto.MobileCacheEntry;
import org.wso2.carbon.device.mgt.mobile.windows.impl.util.WindowsUtils;
import java.util.UUID; import java.util.UUID;
@ -35,20 +33,12 @@ import java.util.UUID;
*/ */
public class DeviceUtil { 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 WindowsTokenService tokenService;
private static final Log log = LogFactory.getLog(DeviceUtil.class); private static final Log log = LogFactory.getLog(DeviceUtil.class);
static { static {
try { tokenService = WindowsAPIUtils.getEnrollmentTokenService();
tokenService = WindowsUtils.getEnrollmentTokenService();
} catch (WindowsDeviceMgtPluginException e) {
log.error("WindowsTokenService cannot be initialized.", e);
}
} }
public static String generateRandomToken() { public static String generateRandomToken() {
@ -59,7 +49,7 @@ public class DeviceUtil {
throws WindowsDeviceEnrolmentException { throws WindowsDeviceEnrolmentException {
try { try {
if(tokenService == null) { if(tokenService == null) {
tokenService = WindowsUtils.getEnrollmentTokenService(); tokenService = WindowsAPIUtils.getEnrollmentTokenService();
} }
MobileCacheEntry existingCacheEntry = tokenService.getCacheToken(token); MobileCacheEntry existingCacheEntry = tokenService.getCacheToken(token);
PrivilegedCarbonContext carbonCtx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); PrivilegedCarbonContext carbonCtx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
@ -77,12 +67,7 @@ public class DeviceUtil {
tokenService.updateCacheToken(existingCacheEntry); tokenService.updateCacheToken(existingCacheEntry);
} }
} catch (MobileDeviceManagementDAOException e) { } catch (MobileDeviceManagementDAOException e) {
String msg = "Error occured when saving cache token for device: " + deviceID; String msg = "Error occurred 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);
throw new WindowsDeviceEnrolmentException(msg, e); throw new WindowsDeviceEnrolmentException(msg, e);
} }
} }
@ -92,16 +77,11 @@ public class DeviceUtil {
MobileCacheEntry tokenEntry; MobileCacheEntry tokenEntry;
try { try {
if (tokenService == null) { if (tokenService == null) {
tokenService = WindowsUtils.getEnrollmentTokenService(); tokenService = WindowsAPIUtils.getEnrollmentTokenService();
} }
tokenEntry = tokenService.getCacheToken(token); 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) { } catch (MobileDeviceManagementDAOException e) {
String msg = "Error occured when retrieving enrollment token."; String msg = "Error occurred when retrieving enrollment token.";
log.error(msg);
throw new WindowsDeviceEnrolmentException(msg, e); throw new WindowsDeviceEnrolmentException(msg, e);
} }
return tokenEntry; return tokenEntry;
@ -112,16 +92,12 @@ public class DeviceUtil {
MobileCacheEntry tokenEntry; MobileCacheEntry tokenEntry;
try { try {
if (tokenService == null) { if (tokenService == null) {
tokenService = WindowsUtils.getEnrollmentTokenService(); tokenService = WindowsAPIUtils.getEnrollmentTokenService();
} }
tokenEntry = tokenService.getCacheTokenFromDeviceId(deviceId); 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) { } catch (MobileDeviceManagementDAOException e) {
String msg = "Error occured when retrieving enrollment token."; String msg = "Error occurred when retrieving enrollment token.";
log.error(msg);
throw new WindowsDeviceEnrolmentException(msg, e); throw new WindowsDeviceEnrolmentException(msg, e);
} }
return tokenEntry; return tokenEntry;
@ -130,14 +106,11 @@ public class DeviceUtil {
public static void removeTokenEntry(String token) { public static void removeTokenEntry(String token) {
try { try {
if (tokenService == null) { if (tokenService == null) {
tokenService = WindowsUtils.getEnrollmentTokenService(); tokenService = WindowsAPIUtils.getEnrollmentTokenService();
} }
tokenService.removeCacheToken(token); tokenService.removeCacheToken(token);
} catch (WindowsDeviceMgtPluginException e) {
String msg = "Error occured when retrieving enrollment token service.";
log.error(msg);
} catch (MobileDeviceManagementDAOException e) { } catch (MobileDeviceManagementDAOException e) {
String msg = "Error occured when removing enrollment token."; String msg = "Error occurred when removing enrollment token.";
log.error(msg); 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.PluginConstants;
import org.wso2.carbon.device.mgt.mobile.windows.api.common.beans.ErrorResponse; 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.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.core.util.IdentityTenantUtil;
import org.wso2.carbon.identity.oauth2.OAuth2TokenValidationService; import org.wso2.carbon.identity.oauth2.OAuth2TokenValidationService;
import org.wso2.carbon.policy.mgt.core.PolicyManagerService; import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
@ -90,6 +92,18 @@ public class WindowsAPIUtils {
return notificationManagementService; 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) { public static MediaType getResponseMediaType(String acceptHeader) {
MediaType responseMediaType; MediaType responseMediaType;
if (MediaType.WILDCARD.equals(acceptHeader)) { 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> </propertyDef>
</properties> </properties>
</adviceFile> </adviceFile>
<!--<bundles>--> <bundles>
<!--<bundleDef>--> <bundleDef>
<!--org.wso2.carbon.devicemgt-plugins:org.wso2.carbon.device.mgt.mobile.windows:${carbon.devicemgt.plugins.version}--> org.wso2.carbon.devicemgt-plugins:org.wso2.carbon.device.mgt.mobile.windows:${carbon.devicemgt.plugins.version}
<!--</bundleDef>--> </bundleDef>
<!--</bundles>--> </bundles>
<importFeatures> <importFeatures>
<importFeatureDef> <importFeatureDef>
org.wso2.carbon.core.server:${carbon.kernel.version} org.wso2.carbon.core.server:${carbon.kernel.version}

Loading…
Cancel
Save