forked from community/device-mgt-core
commit
b28ed6803e
@ -1,60 +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.apimgt.webapp.publisher.config;
|
||||
|
||||
/**
|
||||
* Custom exception class of Permission related operations.
|
||||
*/
|
||||
public class PermissionManagementException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = -3151279311929070298L;
|
||||
|
||||
private String errorMessage;
|
||||
|
||||
public String getErrorMessage() {
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
public void setErrorMessage(String errorMessage) {
|
||||
this.errorMessage = errorMessage;
|
||||
}
|
||||
|
||||
public PermissionManagementException(String msg, Exception nestedEx) {
|
||||
super(msg, nestedEx);
|
||||
setErrorMessage(msg);
|
||||
}
|
||||
|
||||
public PermissionManagementException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
setErrorMessage(message);
|
||||
}
|
||||
|
||||
public PermissionManagementException(String msg) {
|
||||
super(msg);
|
||||
setErrorMessage(msg);
|
||||
}
|
||||
|
||||
public PermissionManagementException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public PermissionManagementException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
}
|
@ -1,91 +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.apimgt.webapp.publisher.lifecycle.util;
|
||||
|
||||
import org.wso2.carbon.apimgt.webapp.publisher.config.PermissionManagementException;
|
||||
import org.wso2.carbon.apimgt.webapp.publisher.internal.APIPublisherDataHolder;
|
||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||
import org.wso2.carbon.registry.api.RegistryException;
|
||||
import org.wso2.carbon.registry.api.Resource;
|
||||
import org.wso2.carbon.registry.core.Registry;
|
||||
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
/**
|
||||
* Utility class which holds necessary utility methods required for persisting permissions in
|
||||
* registry.
|
||||
*/
|
||||
public class PermissionUtils {
|
||||
|
||||
public static final String ADMIN_PERMISSION_REGISTRY_PATH = "/permission/admin";
|
||||
public static final String PERMISSION_PROPERTY_NAME = "name";
|
||||
|
||||
public static Registry getGovernanceRegistry() throws PermissionManagementException {
|
||||
try {
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
return APIPublisherDataHolder.getInstance().getRegistryService()
|
||||
.getGovernanceSystemRegistry(
|
||||
tenantId);
|
||||
} catch (RegistryException e) {
|
||||
throw new PermissionManagementException(
|
||||
"Error in retrieving governance registry instance: " +
|
||||
e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void addPermission(String permission) throws PermissionManagementException {
|
||||
String resourcePermission = getAbsolutePermissionPath(permission);
|
||||
try {
|
||||
StringTokenizer tokenizer = new StringTokenizer(resourcePermission, "/");
|
||||
String lastToken = "", currentToken, tempPath;
|
||||
while (tokenizer.hasMoreTokens()) {
|
||||
currentToken = tokenizer.nextToken();
|
||||
tempPath = lastToken + "/" + currentToken;
|
||||
if (!checkResourceExists(tempPath)) {
|
||||
createRegistryCollection(tempPath, currentToken);
|
||||
}
|
||||
lastToken = tempPath;
|
||||
}
|
||||
} catch (RegistryException e) {
|
||||
throw new PermissionManagementException("Error occurred while persisting permission : " +
|
||||
resourcePermission, e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void createRegistryCollection(String path, String resourceName)
|
||||
throws PermissionManagementException,
|
||||
RegistryException {
|
||||
Resource resource = PermissionUtils.getGovernanceRegistry().newCollection();
|
||||
resource.addProperty(PERMISSION_PROPERTY_NAME, resourceName);
|
||||
PermissionUtils.getGovernanceRegistry().beginTransaction();
|
||||
PermissionUtils.getGovernanceRegistry().put(path, resource);
|
||||
PermissionUtils.getGovernanceRegistry().commitTransaction();
|
||||
}
|
||||
|
||||
public static boolean checkResourceExists(String path)
|
||||
throws PermissionManagementException,
|
||||
org.wso2.carbon.registry.core.exceptions.RegistryException {
|
||||
return PermissionUtils.getGovernanceRegistry().resourceExists(path);
|
||||
}
|
||||
|
||||
private static String getAbsolutePermissionPath(String permissionPath) {
|
||||
return PermissionUtils.ADMIN_PERMISSION_REGISTRY_PATH + permissionPath;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.jaxrs.beans;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
@ApiModel(value = "Scope", description = "Template of the authorization scope")
|
||||
public class Scope {
|
||||
|
||||
@ApiModelProperty(name = "scope key", value = "An unique string as a key.", required = true)
|
||||
private String key;
|
||||
|
||||
@ApiModelProperty(name = "scope name", value = "Scope name.", required = true)
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty(name = "roles", value = "List of roles to be associated with the scope", required = true)
|
||||
private String roles;
|
||||
|
||||
@ApiModelProperty(name = "scope description", value = "A description of the scope", required = true)
|
||||
private String description;
|
||||
|
||||
public Scope() {
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return this.key;
|
||||
}
|
||||
|
||||
public void setKey(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getRoles() {
|
||||
return this.roles;
|
||||
}
|
||||
|
||||
public void setRoles(String roles) {
|
||||
this.roles = roles;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return this.description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.jaxrs.exception;
|
||||
|
||||
import org.wso2.carbon.device.mgt.jaxrs.util.Constants;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtUtil;
|
||||
|
||||
import javax.validation.ConstraintViolation;
|
||||
import javax.ws.rs.WebApplicationException;
|
||||
import javax.ws.rs.core.Response;
|
||||
import java.util.Set;
|
||||
|
||||
public class ConstraintViolationException extends WebApplicationException {
|
||||
private String message;
|
||||
|
||||
public <T> ConstraintViolationException(Set<ConstraintViolation<T>> violations) {
|
||||
super(Response.status(Response.Status.BAD_REQUEST)
|
||||
.entity(DeviceMgtUtil.getConstraintViolationErrorDTO(violations))
|
||||
.header(Constants.DeviceConstants.HEADER_CONTENT_TYPE, Constants.DeviceConstants.APPLICATION_JSON)
|
||||
.build());
|
||||
|
||||
//Set the error message
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
for (ConstraintViolation violation : violations) {
|
||||
stringBuilder.append(violation.getRootBeanClass().getSimpleName());
|
||||
stringBuilder.append(".");
|
||||
stringBuilder.append(violation.getPropertyPath());
|
||||
stringBuilder.append(": ");
|
||||
stringBuilder.append(violation.getMessage());
|
||||
stringBuilder.append(", ");
|
||||
}
|
||||
message = stringBuilder.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
}
|
@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.jaxrs.exception;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ErrorDTO {
|
||||
|
||||
private Long code = null;
|
||||
private String message = null;
|
||||
private String description = null;
|
||||
|
||||
public void setMoreInfo(String moreInfo) {
|
||||
this.moreInfo = moreInfo;
|
||||
}
|
||||
|
||||
public void setCode(Long code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public void setError(List<ErrorDTO> error) {
|
||||
this.error = error;
|
||||
}
|
||||
|
||||
private String moreInfo = null;
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public Long getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public String getMoreInfo() {
|
||||
return moreInfo;
|
||||
}
|
||||
|
||||
public List<ErrorDTO> getError() {
|
||||
return error;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
stringBuilder.append("class ErrorDTO {\n");
|
||||
stringBuilder.append(" code: ").append(code).append("\n");
|
||||
stringBuilder.append(" message: ").append(message).append("\n");
|
||||
stringBuilder.append(" description: ").append(description).append("\n");
|
||||
stringBuilder.append(" moreInfo: ").append(moreInfo).append("\n");
|
||||
stringBuilder.append(" error: ").append(error).append("\n");
|
||||
stringBuilder.append("}\n");
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
|
||||
private List<ErrorDTO> error = new ArrayList<>();
|
||||
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.jaxrs.exception;
|
||||
|
||||
import org.wso2.carbon.device.mgt.jaxrs.util.Constants;
|
||||
|
||||
import javax.ws.rs.WebApplicationException;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
/**
|
||||
* Exception class that is corresponding to 401 Forbidden response
|
||||
*/
|
||||
|
||||
public class ForbiddenException extends WebApplicationException {
|
||||
|
||||
private String message;
|
||||
|
||||
public ForbiddenException() {
|
||||
super(Response.status(Response.Status.FORBIDDEN)
|
||||
.build());
|
||||
}
|
||||
|
||||
public ForbiddenException(ErrorDTO errorDTO) {
|
||||
super(Response.status(Response.Status.FORBIDDEN)
|
||||
.entity(errorDTO)
|
||||
.header(Constants.DeviceConstants.HEADER_CONTENT_TYPE, Constants.DeviceConstants.APPLICATION_JSON)
|
||||
.build());
|
||||
message = errorDTO.getDescription();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
}
|
@ -0,0 +1,113 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.jaxrs.exception;
|
||||
|
||||
import com.google.gson.JsonParseException;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtUtil;
|
||||
|
||||
import javax.naming.AuthenticationException;
|
||||
import javax.ws.rs.ClientErrorException;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.ext.ExceptionMapper;
|
||||
|
||||
/**
|
||||
* Handle the cxf level exceptions.
|
||||
*/
|
||||
public class GlobalThrowableMapper implements ExceptionMapper {
|
||||
private static final Log log = LogFactory.getLog(GlobalThrowableMapper.class);
|
||||
|
||||
private ErrorDTO e500 = new ErrorDTO();
|
||||
|
||||
GlobalThrowableMapper() {
|
||||
e500.setCode((long) 500);
|
||||
e500.setMessage("Internal server error.");
|
||||
e500.setMoreInfo("");
|
||||
e500.setDescription("The server encountered an internal error. Please contact administrator.");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response toResponse(Throwable e) {
|
||||
|
||||
if (e instanceof JsonParseException) {
|
||||
String errorMessage = "Malformed request body.";
|
||||
if (log.isDebugEnabled()) {
|
||||
log.error(errorMessage, e);
|
||||
}
|
||||
return DeviceMgtUtil.buildBadRequestException(errorMessage).getResponse();
|
||||
}
|
||||
if (e instanceof NotFoundException) {
|
||||
return ((NotFoundException) e).getResponse();
|
||||
}
|
||||
if (e instanceof UnexpectedServerErrorException) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.error("Unexpected server error.", e);
|
||||
}
|
||||
return ((UnexpectedServerErrorException) e).getResponse();
|
||||
}
|
||||
if (e instanceof ConstraintViolationException) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.error("Constraint violation.", e);
|
||||
}
|
||||
return ((ConstraintViolationException) e).getResponse();
|
||||
}
|
||||
if (e instanceof IllegalArgumentException) {
|
||||
ErrorDTO errorDetail = new ErrorDTO();
|
||||
errorDetail.setCode((long) 400);
|
||||
errorDetail.setMoreInfo("");
|
||||
errorDetail.setMessage("");
|
||||
errorDetail.setDescription(e.getMessage());
|
||||
return Response
|
||||
.status(Response.Status.BAD_REQUEST)
|
||||
.entity(errorDetail)
|
||||
.build();
|
||||
}
|
||||
if (e instanceof ClientErrorException) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.error("Client error.", e);
|
||||
}
|
||||
return ((ClientErrorException) e).getResponse();
|
||||
}
|
||||
if (e instanceof AuthenticationException) {
|
||||
ErrorDTO errorDetail = new ErrorDTO();
|
||||
errorDetail.setCode((long) 401);
|
||||
errorDetail.setMoreInfo("");
|
||||
errorDetail.setMessage("");
|
||||
errorDetail.setDescription(e.getMessage());
|
||||
return Response
|
||||
.status(Response.Status.UNAUTHORIZED)
|
||||
.entity(errorDetail)
|
||||
.build();
|
||||
}
|
||||
if (e instanceof ForbiddenException) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.error("Resource forbidden.", e);
|
||||
}
|
||||
return ((ForbiddenException) e).getResponse();
|
||||
}
|
||||
//unknown exception log and return
|
||||
if (log.isDebugEnabled()) {
|
||||
log.error("An Unknown exception has been captured by global exception mapper.", e);
|
||||
}
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).header("Content-Type", "application/json")
|
||||
.entity(e500).build();
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.jaxrs.exception;
|
||||
|
||||
|
||||
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.util.Constants;
|
||||
|
||||
import javax.ws.rs.WebApplicationException;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
public class NotFoundException extends WebApplicationException {
|
||||
private String message;
|
||||
private static final long serialVersionUID = 147943572342342340L;
|
||||
|
||||
public NotFoundException(ErrorResponse error) {
|
||||
super(Response.status(Response.Status.NOT_FOUND).entity(error).build());
|
||||
}
|
||||
public NotFoundException(ErrorDTO errorDTO) {
|
||||
super(Response.status(Response.Status.NOT_FOUND)
|
||||
.entity(errorDTO)
|
||||
.header(Constants.DeviceConstants.HEADER_CONTENT_TYPE, Constants.DeviceConstants.APPLICATION_JSON)
|
||||
.build());
|
||||
message = errorDTO.getDescription();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.jaxrs.exception;
|
||||
|
||||
|
||||
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.util.Constants;
|
||||
|
||||
import javax.ws.rs.WebApplicationException;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
public class UnexpectedServerErrorException extends WebApplicationException {
|
||||
private String message;
|
||||
private static final long serialVersionUID = 147943579458906890L;
|
||||
|
||||
public UnexpectedServerErrorException(ErrorResponse error) {
|
||||
super(Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(error).build());
|
||||
}
|
||||
public UnexpectedServerErrorException(ErrorDTO errorDTO) {
|
||||
super(Response.status(Response.Status.INTERNAL_SERVER_ERROR)
|
||||
.entity(errorDTO)
|
||||
.header(Constants.DeviceConstants.HEADER_CONTENT_TYPE, Constants.DeviceConstants.APPLICATION_JSON)
|
||||
.build());
|
||||
message = errorDTO.getDescription();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,122 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.jaxrs.exception;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.cxf.interceptor.Fault;
|
||||
import org.apache.cxf.jaxrs.lifecycle.ResourceProvider;
|
||||
import org.apache.cxf.jaxrs.model.ClassResourceInfo;
|
||||
import org.apache.cxf.jaxrs.model.OperationResourceInfo;
|
||||
import org.apache.cxf.message.Message;
|
||||
import org.apache.cxf.message.MessageContentsList;
|
||||
import org.apache.cxf.phase.AbstractPhaseInterceptor;
|
||||
import org.apache.cxf.phase.Phase;
|
||||
|
||||
import javax.validation.ConstraintViolation;
|
||||
import javax.validation.Validation;
|
||||
import javax.validation.Validator;
|
||||
import javax.validation.ValidatorFactory;
|
||||
import javax.validation.executable.ExecutableValidator;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class ValidationInterceptor extends AbstractPhaseInterceptor<Message> {
|
||||
private Log log = LogFactory.getLog(getClass());
|
||||
private Validator validator = null; //validator interface is thread-safe
|
||||
|
||||
public ValidationInterceptor() {
|
||||
super(Phase.PRE_INVOKE);
|
||||
ValidatorFactory defaultFactory = Validation.buildDefaultValidatorFactory();
|
||||
validator = defaultFactory.getValidator();
|
||||
if (validator == null) {
|
||||
log.warn("Bean Validation provider could not be found, no validation will be performed");
|
||||
} else {
|
||||
log.debug("Validation In-Interceptor initialized successfully");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMessage(Message message) throws Fault {
|
||||
final OperationResourceInfo operationResource = message.getExchange().get(OperationResourceInfo.class);
|
||||
if (operationResource == null) {
|
||||
log.info("OperationResourceInfo is not available, skipping validation");
|
||||
return;
|
||||
}
|
||||
|
||||
final ClassResourceInfo classResource = operationResource.getClassResourceInfo();
|
||||
if (classResource == null) {
|
||||
log.info("ClassResourceInfo is not available, skipping validation");
|
||||
return;
|
||||
}
|
||||
|
||||
final ResourceProvider resourceProvider = classResource.getResourceProvider();
|
||||
if (resourceProvider == null) {
|
||||
log.info("ResourceProvider is not available, skipping validation");
|
||||
return;
|
||||
}
|
||||
|
||||
final List<Object> arguments = MessageContentsList.getContentsList(message);
|
||||
final Method method = operationResource.getAnnotatedMethod();
|
||||
final Object instance = resourceProvider.getInstance(message);
|
||||
if (method != null && arguments != null) {
|
||||
//validate the parameters(arguments) over the invoked method
|
||||
validate(method, arguments.toArray(), instance);
|
||||
|
||||
//validate the fields of each argument
|
||||
for (Object arg : arguments) {
|
||||
if (arg != null)
|
||||
validate(arg);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public <T> void validate(final Method method, final Object[] arguments, final T instance) {
|
||||
if (validator == null) {
|
||||
log.warn("Bean Validation provider could not be found, no validation will be performed");
|
||||
return;
|
||||
}
|
||||
|
||||
ExecutableValidator methodValidator = validator.forExecutables();
|
||||
Set<ConstraintViolation<T>> violations = methodValidator.validateParameters(instance,
|
||||
method, arguments);
|
||||
|
||||
if (!violations.isEmpty()) {
|
||||
throw new ConstraintViolationException(violations);
|
||||
}
|
||||
}
|
||||
|
||||
public <T> void validate(final T object) {
|
||||
if (validator == null) {
|
||||
log.warn("Bean Validation provider could be found, no validation will be performed");
|
||||
return;
|
||||
}
|
||||
|
||||
Set<ConstraintViolation<T>> violations = validator.validate(object);
|
||||
|
||||
if (!violations.isEmpty()) {
|
||||
throw new ConstraintViolationException(violations);
|
||||
}
|
||||
}
|
||||
|
||||
public void handleFault(org.apache.cxf.message.Message messageParam) {
|
||||
}
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.common.scope.mgt;
|
||||
|
||||
/**
|
||||
* This exception is used to throw when there is an issue in scope management service.
|
||||
*/
|
||||
public class ScopeManagementException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = -315127931137779899L;
|
||||
|
||||
private String errorMessage;
|
||||
|
||||
public String getErrorMessage() {
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
public void setErrorMessage(String errorMessage) {
|
||||
this.errorMessage = errorMessage;
|
||||
}
|
||||
|
||||
public ScopeManagementException(String msg, Exception nestedEx) {
|
||||
super(msg, nestedEx);
|
||||
setErrorMessage(msg);
|
||||
}
|
||||
|
||||
public ScopeManagementException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
setErrorMessage(message);
|
||||
}
|
||||
|
||||
public ScopeManagementException(String msg) {
|
||||
super(msg);
|
||||
setErrorMessage(msg);
|
||||
}
|
||||
|
||||
public ScopeManagementException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public ScopeManagementException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 2016 WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.common.scope.mgt;
|
||||
|
||||
import java.util.List;
|
||||
import org.wso2.carbon.apimgt.api.model.Scope;
|
||||
|
||||
/**
|
||||
* This interface contains the basic operations related to scope management.
|
||||
*/
|
||||
public interface ScopeManagementService {
|
||||
|
||||
/**
|
||||
* This method is used to update the given list of scopes.
|
||||
*
|
||||
* @param scopes List of scopes to be updated.
|
||||
* @throws ScopeManagementException
|
||||
*/
|
||||
void updateScopes(List<Scope> scopes) throws ScopeManagementException;
|
||||
|
||||
/**
|
||||
* This method is used to retrieve all the scopes.
|
||||
*
|
||||
* @return List of scopes.
|
||||
* @throws ScopeManagementException
|
||||
*/
|
||||
List<Scope> getAllScopes() throws ScopeManagementException;
|
||||
|
||||
/**
|
||||
* This method is to retrieve the roles of the given scope
|
||||
* @param scopeKey key of the scope
|
||||
* @return List of roles
|
||||
* @throws ScopeManagementException
|
||||
*/
|
||||
String getRolesOfScope(String scopeKey) throws ScopeManagementException;
|
||||
|
||||
}
|
@ -0,0 +1,332 @@
|
||||
/*
|
||||
* 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.core.config.permission;
|
||||
|
||||
import org.apache.catalina.core.StandardContext;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.scannotation.AnnotationDB;
|
||||
import org.wso2.carbon.apimgt.annotations.api.API;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.ws.rs.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
public class AnnotationProcessor {
|
||||
|
||||
private static final Log log = LogFactory.getLog(AnnotationProcessor.class);
|
||||
|
||||
private static final String PACKAGE_ORG_APACHE = "org.apache";
|
||||
private static final String PACKAGE_ORG_CODEHAUS = "org.codehaus";
|
||||
private static final String PACKAGE_ORG_SPRINGFRAMEWORK = "org.springframework";
|
||||
private static final String WILD_CARD = "/*";
|
||||
private static final String URL_SEPARATOR = "/";
|
||||
|
||||
private static final String STRING_ARR = "string_arr";
|
||||
private static final String STRING = "string";
|
||||
|
||||
private Method[] pathClazzMethods;
|
||||
private Class<Path> pathClazz;
|
||||
Class<API> apiClazz;
|
||||
private ClassLoader classLoader;
|
||||
private ServletContext servletContext;
|
||||
|
||||
|
||||
public AnnotationProcessor(final StandardContext context) {
|
||||
servletContext = context.getServletContext();
|
||||
classLoader = servletContext.getClassLoader();
|
||||
}
|
||||
|
||||
/**
|
||||
* Scan the context for classes with annotations
|
||||
*
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
public Set<String> scanStandardContext(String className) throws IOException {
|
||||
ExtendedAnnotationDB db = new ExtendedAnnotationDB();
|
||||
db.addIgnoredPackages(PACKAGE_ORG_APACHE);
|
||||
db.addIgnoredPackages(PACKAGE_ORG_CODEHAUS);
|
||||
db.addIgnoredPackages(PACKAGE_ORG_SPRINGFRAMEWORK);
|
||||
URL classPath = findWebInfClassesPath(servletContext);
|
||||
db.scanArchives(classPath);
|
||||
|
||||
//Returns a list of classes with given Annotation
|
||||
return db.getAnnotationIndex().get(className);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method identifies the URL templates and context by reading the annotations of a class
|
||||
*
|
||||
* @param entityClasses
|
||||
* @return
|
||||
*/
|
||||
public List<org.wso2.carbon.device.mgt.common.permission.mgt.Permission>
|
||||
extractPermissions(Set<String> entityClasses) {
|
||||
|
||||
List<org.wso2.carbon.device.mgt.common.permission.mgt.Permission> permissions = new ArrayList<>();
|
||||
|
||||
if (entityClasses != null && !entityClasses.isEmpty()) {
|
||||
|
||||
for (final String className : entityClasses) {
|
||||
|
||||
List<org.wso2.carbon.device.mgt.common.permission.mgt.Permission> resourcePermissions =
|
||||
AccessController.doPrivileged(new PrivilegedAction<List<org.wso2.carbon.device.mgt.common.permission.mgt.Permission>>() {
|
||||
public List<org.wso2.carbon.device.mgt.common.permission.mgt.Permission> run() {
|
||||
Class<?> clazz;
|
||||
List<org.wso2.carbon.device.mgt.common.permission.mgt.Permission> apiPermissions =
|
||||
new ArrayList<>();
|
||||
try {
|
||||
clazz = classLoader.loadClass(className);
|
||||
|
||||
apiClazz = (Class<API>)
|
||||
classLoader.loadClass(org.wso2.carbon.apimgt.annotations.api.API
|
||||
.class.getName());
|
||||
|
||||
Annotation apiAnno = clazz.getAnnotation(apiClazz);
|
||||
List<org.wso2.carbon.device.mgt.common.permission.mgt.Permission> resourceList;
|
||||
|
||||
if (apiAnno != null) {
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Application Context root = " + servletContext.getContextPath());
|
||||
}
|
||||
|
||||
try {
|
||||
String rootContext = servletContext.getContextPath();
|
||||
pathClazz = (Class<Path>) classLoader.loadClass(Path.class.getName());
|
||||
pathClazzMethods = pathClazz.getMethods();
|
||||
|
||||
Annotation rootContectAnno = clazz.getAnnotation(pathClazz);
|
||||
String subContext = "";
|
||||
if (rootContectAnno != null) {
|
||||
subContext = invokeMethod(pathClazzMethods[0], rootContectAnno, STRING);
|
||||
if (subContext != null && !subContext.isEmpty()) {
|
||||
if (subContext.trim().startsWith("/")) {
|
||||
rootContext = rootContext + subContext;
|
||||
} else {
|
||||
rootContext = rootContext + "/" + subContext;
|
||||
}
|
||||
}
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("API Root Context = " + rootContext);
|
||||
}
|
||||
}
|
||||
|
||||
Method[] annotatedMethods = clazz.getDeclaredMethods();
|
||||
apiPermissions = getApiResources(rootContext, annotatedMethods);
|
||||
} catch (Throwable throwable) {
|
||||
log.error("Error encountered while scanning for annotations", throwable);
|
||||
}
|
||||
}
|
||||
} catch (ClassNotFoundException e) {
|
||||
log.error("Error when passing the api annotation for device type apis.");
|
||||
}
|
||||
return apiPermissions;
|
||||
}
|
||||
});
|
||||
permissions.addAll(resourcePermissions);
|
||||
}
|
||||
}
|
||||
return permissions;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Resources for each API
|
||||
*
|
||||
* @param resourceRootContext
|
||||
* @param annotatedMethods
|
||||
* @return
|
||||
* @throws Throwable
|
||||
*/
|
||||
private List<org.wso2.carbon.device.mgt.common.permission.mgt.Permission>
|
||||
getApiResources(String resourceRootContext, Method[] annotatedMethods) throws Throwable {
|
||||
|
||||
List<org.wso2.carbon.device.mgt.common.permission.mgt.Permission> permissions = new ArrayList<>();
|
||||
String subCtx;
|
||||
for (Method method : annotatedMethods) {
|
||||
Annotation[] annotations = method.getDeclaredAnnotations();
|
||||
org.wso2.carbon.device.mgt.common.permission.mgt.Permission permission =
|
||||
new org.wso2.carbon.device.mgt.common.permission.mgt.Permission();
|
||||
|
||||
if (isHttpMethodAvailable(annotations)) {
|
||||
Annotation methodContextAnno = method.getAnnotation(pathClazz);
|
||||
if (methodContextAnno != null) {
|
||||
subCtx = invokeMethod(pathClazzMethods[0], methodContextAnno, STRING);
|
||||
} else {
|
||||
subCtx = WILD_CARD;
|
||||
}
|
||||
permission.setContext(makeContextURLReady(resourceRootContext));
|
||||
permission.setUrlTemplate(makeContextURLReady(subCtx));
|
||||
|
||||
// this check is added to avoid url resolving conflict which happens due
|
||||
// to adding of '*' notation for dynamic path variables.
|
||||
if (WILD_CARD.equals(subCtx)) {
|
||||
subCtx = makeContextURLReady(resourceRootContext);
|
||||
} else {
|
||||
subCtx = makeContextURLReady(resourceRootContext) + makeContextURLReady(subCtx);
|
||||
}
|
||||
permission.setUrl(replaceDynamicPathVariables(subCtx));
|
||||
String httpMethod;
|
||||
for (int i = 0; i < annotations.length; i++) {
|
||||
httpMethod = getHTTPMethodAnnotation(annotations[i]);
|
||||
if (httpMethod != null) {
|
||||
permission.setMethod(httpMethod);
|
||||
break;
|
||||
}
|
||||
}
|
||||
permissions.add(permission);
|
||||
}
|
||||
}
|
||||
return permissions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read Method annotations indicating HTTP Methods
|
||||
* @param annotation
|
||||
*/
|
||||
private String getHTTPMethodAnnotation(Annotation annotation) {
|
||||
if (annotation.annotationType().getName().equals(GET.class.getName())) {
|
||||
return HttpMethod.GET;
|
||||
} else if (annotation.annotationType().getName().equals(POST.class.getName())) {
|
||||
return HttpMethod.POST;
|
||||
} else if (annotation.annotationType().getName().equals(OPTIONS.class.getName())) {
|
||||
return HttpMethod.OPTIONS;
|
||||
} else if (annotation.annotationType().getName().equals(DELETE.class.getName())) {
|
||||
return HttpMethod.DELETE;
|
||||
} else if (annotation.annotationType().getName().equals(PUT.class.getName())) {
|
||||
return HttpMethod.PUT;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean isHttpMethodAvailable(Annotation[] annotations) {
|
||||
for (Annotation annotation : annotations) {
|
||||
if (annotation.annotationType().getName().equals(GET.class.getName())) {
|
||||
return true;
|
||||
} else if (annotation.annotationType().getName().equals(POST.class.getName())) {
|
||||
return true;
|
||||
} else if (annotation.annotationType().getName().equals(OPTIONS.class.getName())) {
|
||||
return true;
|
||||
} else if (annotation.annotationType().getName().equals(DELETE.class.getName())) {
|
||||
return true;
|
||||
} else if (annotation.annotationType().getName().equals(PUT.class.getName())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Append '/' to the context and make it URL ready
|
||||
*
|
||||
* @param context
|
||||
* @return
|
||||
*/
|
||||
private String makeContextURLReady(String context) {
|
||||
if (context != null && ! context.isEmpty()) {
|
||||
if (context.startsWith("/")) {
|
||||
return context;
|
||||
} else {
|
||||
return "/" + context;
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* When an annotation and method is passed, this method invokes that executes said method against the annotation
|
||||
*
|
||||
* @param method
|
||||
* @param annotation
|
||||
* @param returnType
|
||||
* @return
|
||||
* @throws Throwable
|
||||
*/
|
||||
private String invokeMethod(Method method, Annotation annotation, String returnType) throws Throwable {
|
||||
InvocationHandler methodHandler = Proxy.getInvocationHandler(annotation);
|
||||
switch (returnType) {
|
||||
case STRING:
|
||||
return (String) methodHandler.invoke(annotation, method, null);
|
||||
case STRING_ARR:
|
||||
return ((String[]) methodHandler.invoke(annotation, method, null))[0];
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Find the URL pointing to "/WEB-INF/classes" This method may not work in conjunction with IteratorFactory
|
||||
* if your servlet container does not extract the /WEB-INF/classes into a real file-based directory
|
||||
*
|
||||
* @param servletContext
|
||||
* @return null if cannot determin /WEB-INF/classes
|
||||
*/
|
||||
public static URL findWebInfClassesPath(ServletContext servletContext)
|
||||
{
|
||||
String path = servletContext.getRealPath("/WEB-INF/classes");
|
||||
if (path == null) return null;
|
||||
File fp = new File(path);
|
||||
if (fp.exists() == false) return null;
|
||||
try
|
||||
{
|
||||
URI uri = fp.toURI();
|
||||
return uri.toURL();
|
||||
}
|
||||
catch (MalformedURLException e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private String replaceDynamicPathVariables(String path) {
|
||||
StringBuilder replacedPath = new StringBuilder();
|
||||
StringTokenizer st = new StringTokenizer(path, URL_SEPARATOR);
|
||||
String currentToken;
|
||||
while (st.hasMoreTokens()) {
|
||||
currentToken = st.nextToken();
|
||||
if (currentToken.charAt(0) == '{') {
|
||||
if (currentToken.charAt(currentToken.length() - 1) == '}') {
|
||||
replacedPath.append(WILD_CARD);
|
||||
}
|
||||
} else {
|
||||
replacedPath.append(URL_SEPARATOR);
|
||||
replacedPath.append(currentToken);
|
||||
}
|
||||
}
|
||||
return replacedPath.toString();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.core.config.permission;
|
||||
|
||||
import org.scannotation.AnnotationDB;
|
||||
import org.scannotation.archiveiterator.Filter;
|
||||
import org.scannotation.archiveiterator.StreamIterator;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
|
||||
public class ExtendedAnnotationDB extends AnnotationDB {
|
||||
|
||||
public ExtendedAnnotationDB() {
|
||||
super();
|
||||
}
|
||||
|
||||
public void scanArchives(URL... urls) throws IOException {
|
||||
URL[] arr$ = urls;
|
||||
int len$ = urls.length;
|
||||
|
||||
for(int i$ = 0; i$ < len$; ++i$) {
|
||||
URL url = arr$[i$];
|
||||
Filter filter = new Filter() {
|
||||
public boolean accepts(String filename) {
|
||||
if(filename.endsWith(".class")) {
|
||||
if(filename.startsWith("/") || filename.startsWith("\\")) {
|
||||
filename = filename.substring(1);
|
||||
}
|
||||
|
||||
if(!ExtendedAnnotationDB.this.ignoreScan(filename.replace('/', '.'))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
StreamIterator it = ExtendedIteratorFactory.create(url, filter);
|
||||
|
||||
InputStream stream;
|
||||
while((stream = it.next()) != null) {
|
||||
this.scanClass(stream);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private boolean ignoreScan(String intf) {
|
||||
String[] arr$;
|
||||
int len$;
|
||||
int i$;
|
||||
String ignored;
|
||||
if(this.scanPackages != null) {
|
||||
arr$ = this.scanPackages;
|
||||
len$ = arr$.length;
|
||||
|
||||
for(i$ = 0; i$ < len$; ++i$) {
|
||||
ignored = arr$[i$];
|
||||
if(intf.startsWith(ignored + ".")) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
} else {
|
||||
arr$ = this.ignoredPackages;
|
||||
len$ = arr$.length;
|
||||
|
||||
for(i$ = 0; i$ < len$; ++i$) {
|
||||
ignored = arr$[i$];
|
||||
if(intf.startsWith(ignored + ".")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.core.config.permission;
|
||||
|
||||
import org.scannotation.archiveiterator.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
|
||||
public class ExtendedFileProtocolIteratorFactory implements DirectoryIteratorFactory {
|
||||
|
||||
@Override
|
||||
public StreamIterator create(URL url, Filter filter) throws IOException {
|
||||
File f = new File(java.net.URLDecoder.decode(url.getPath(), "UTF-8"));
|
||||
return f.isDirectory()?new FileIterator(f, filter):new JarIterator(url.openStream(), filter);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.core.config.permission;
|
||||
|
||||
import org.scannotation.archiveiterator.DirectoryIteratorFactory;
|
||||
import org.scannotation.archiveiterator.Filter;
|
||||
import org.scannotation.archiveiterator.JarIterator;
|
||||
import org.scannotation.archiveiterator.StreamIterator;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class ExtendedIteratorFactory {
|
||||
|
||||
private static final ConcurrentHashMap<String, DirectoryIteratorFactory> registry = new ConcurrentHashMap();
|
||||
|
||||
public static StreamIterator create(URL url, Filter filter) throws IOException {
|
||||
String urlString = url.toString();
|
||||
if(urlString.endsWith("!/")) {
|
||||
urlString = urlString.substring(4);
|
||||
urlString = urlString.substring(0, urlString.length() - 2);
|
||||
url = new URL(urlString);
|
||||
}
|
||||
|
||||
if(!urlString.endsWith("/")) {
|
||||
return new JarIterator(url.openStream(), filter);
|
||||
} else {
|
||||
DirectoryIteratorFactory factory = registry.get(url.getProtocol());
|
||||
if(factory == null) {
|
||||
throw new IOException("Unable to scan directory of protocol: " + url.getProtocol());
|
||||
} else {
|
||||
return factory.create(url, filter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static {
|
||||
registry.put("file", new ExtendedFileProtocolIteratorFactory());
|
||||
}
|
||||
}
|
102
components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/dao/impl/NotificationDAOImpl.java → components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/dao/impl/AbstractNotificationDAOImpl.java
102
components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/dao/impl/NotificationDAOImpl.java → components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/dao/impl/AbstractNotificationDAOImpl.java
@ -0,0 +1,122 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* you may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.core.notification.mgt.dao.impl;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
||||
import org.wso2.carbon.device.mgt.common.notification.mgt.Notification;
|
||||
import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementException;
|
||||
import org.wso2.carbon.device.mgt.core.notification.mgt.dao.NotificationManagementDAOFactory;
|
||||
import org.wso2.carbon.device.mgt.core.notification.mgt.dao.util.NotificationDAOUtil;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This class holds the generic implementation of NotificationDAO which can be used to support ANSI db syntax.
|
||||
*/
|
||||
public class GenericNotificationDAOImpl extends AbstractNotificationDAOImpl {
|
||||
|
||||
@Override
|
||||
public List<Notification> getAllNotifications(PaginationRequest request, int tenantId) throws
|
||||
NotificationManagementException {
|
||||
Connection conn;
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
List<Notification> notifications = null;
|
||||
try {
|
||||
conn = NotificationManagementDAOFactory.getConnection();
|
||||
String sql =
|
||||
"SELECT n1.NOTIFICATION_ID, n1.DEVICE_ID, n1.OPERATION_ID, n1.STATUS, n1.DESCRIPTION," +
|
||||
" d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM DM_DEVICE d, DM_DEVICE_TYPE t, (SELECT " +
|
||||
"NOTIFICATION_ID, DEVICE_ID, OPERATION_ID, STATUS, DESCRIPTION FROM DM_NOTIFICATION WHERE " +
|
||||
"TENANT_ID = ?) n1 WHERE n1.DEVICE_ID = d.ID AND d.DEVICE_TYPE_ID=t.ID AND TENANT_ID = ?";
|
||||
|
||||
sql = sql + " LIMIT ?,?";
|
||||
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setInt(1, tenantId);
|
||||
stmt.setInt(2, tenantId);
|
||||
int paramIdx = 3;
|
||||
|
||||
stmt.setInt(paramIdx++, request.getStartIndex());
|
||||
stmt.setInt(paramIdx, request.getRowCount());
|
||||
|
||||
rs = stmt.executeQuery();
|
||||
notifications = new ArrayList<>();
|
||||
while (rs.next()) {
|
||||
notifications.add(NotificationDAOUtil.getNotification(rs));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new NotificationManagementException(
|
||||
"Error occurred while retrieving information of all notifications", e);
|
||||
} finally {
|
||||
NotificationDAOUtil.cleanupResources(stmt, rs);
|
||||
}
|
||||
return notifications;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<Notification> getNotificationsByStatus(PaginationRequest request, Notification.Status status, int tenantId) throws
|
||||
NotificationManagementException{
|
||||
Connection conn;
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
List<Notification> notifications = null;
|
||||
try {
|
||||
conn = NotificationManagementDAOFactory.getConnection();
|
||||
String sql = "SELECT n1.NOTIFICATION_ID, n1.DEVICE_ID, n1.OPERATION_ID, n1.STATUS," +
|
||||
" n1.DESCRIPTION, d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM " +
|
||||
"DM_DEVICE d, DM_DEVICE_TYPE t, (SELECT NOTIFICATION_ID, DEVICE_ID, " +
|
||||
"OPERATION_ID, STATUS, DESCRIPTION FROM DM_NOTIFICATION WHERE " +
|
||||
"TENANT_ID = ? AND STATUS = ?) n1 WHERE n1.DEVICE_ID = d.ID AND d.DEVICE_TYPE_ID=t.ID " +
|
||||
"AND TENANT_ID = ?";
|
||||
|
||||
sql = sql + " LIMIT ?,?";
|
||||
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setInt(1, tenantId);
|
||||
stmt.setString(2, status.toString());
|
||||
stmt.setInt(3, tenantId);
|
||||
|
||||
int paramIdx = 4;
|
||||
|
||||
stmt.setInt(paramIdx++, request.getStartIndex());
|
||||
stmt.setInt(paramIdx, request.getRowCount());
|
||||
|
||||
|
||||
rs = stmt.executeQuery();
|
||||
notifications = new ArrayList<>();
|
||||
while (rs.next()) {
|
||||
notifications.add(NotificationDAOUtil.getNotification(rs));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new NotificationManagementException(
|
||||
"Error occurred while retrieving information of all " +
|
||||
"notifications by status : " + status, e);
|
||||
} finally {
|
||||
NotificationDAOUtil.cleanupResources(stmt, rs);
|
||||
}
|
||||
return notifications;
|
||||
}
|
||||
}
|
@ -0,0 +1,122 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* you may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.core.notification.mgt.dao.impl;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
||||
import org.wso2.carbon.device.mgt.common.notification.mgt.Notification;
|
||||
import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementException;
|
||||
import org.wso2.carbon.device.mgt.core.notification.mgt.dao.NotificationManagementDAOFactory;
|
||||
import org.wso2.carbon.device.mgt.core.notification.mgt.dao.util.NotificationDAOUtil;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This class holds the Oracle implementation of NotificationDAO which can be used to support Oracle db syntax.
|
||||
*/
|
||||
public class OracleNotificationDAOImpl extends AbstractNotificationDAOImpl {
|
||||
|
||||
@Override
|
||||
public List<Notification> getAllNotifications(PaginationRequest request, int tenantId) throws
|
||||
NotificationManagementException {
|
||||
Connection conn;
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
List<Notification> notifications = null;
|
||||
try {
|
||||
conn = NotificationManagementDAOFactory.getConnection();
|
||||
String sql =
|
||||
"SELECT n1.NOTIFICATION_ID, n1.DEVICE_ID, n1.OPERATION_ID, n1.STATUS, n1.DESCRIPTION," +
|
||||
" d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM DM_DEVICE d, DM_DEVICE_TYPE t, (SELECT " +
|
||||
"NOTIFICATION_ID, DEVICE_ID, OPERATION_ID, STATUS, DESCRIPTION FROM DM_NOTIFICATION WHERE " +
|
||||
"TENANT_ID = ?) n1 WHERE n1.DEVICE_ID = d.ID AND d.DEVICE_TYPE_ID=t.ID AND TENANT_ID = ?";
|
||||
|
||||
sql = sql + " WHERE OFFSET >= ? AND ROWNUM <= ?";
|
||||
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setInt(1, tenantId);
|
||||
stmt.setInt(2, tenantId);
|
||||
int paramIdx = 3;
|
||||
|
||||
stmt.setInt(paramIdx++, request.getStartIndex());
|
||||
stmt.setInt(paramIdx, request.getRowCount());
|
||||
|
||||
rs = stmt.executeQuery();
|
||||
notifications = new ArrayList<>();
|
||||
while (rs.next()) {
|
||||
notifications.add(NotificationDAOUtil.getNotification(rs));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new NotificationManagementException(
|
||||
"Error occurred while retrieving information of all notifications", e);
|
||||
} finally {
|
||||
NotificationDAOUtil.cleanupResources(stmt, rs);
|
||||
}
|
||||
return notifications;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<Notification> getNotificationsByStatus(PaginationRequest request, Notification.Status status, int tenantId) throws
|
||||
NotificationManagementException{
|
||||
Connection conn;
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
List<Notification> notifications = null;
|
||||
try {
|
||||
conn = NotificationManagementDAOFactory.getConnection();
|
||||
String sql = "SELECT n1.NOTIFICATION_ID, n1.DEVICE_ID, n1.OPERATION_ID, n1.STATUS," +
|
||||
" n1.DESCRIPTION, d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM " +
|
||||
"DM_DEVICE d, DM_DEVICE_TYPE t, (SELECT NOTIFICATION_ID, DEVICE_ID, " +
|
||||
"OPERATION_ID, STATUS, DESCRIPTION FROM DM_NOTIFICATION WHERE " +
|
||||
"TENANT_ID = ? AND STATUS = ?) n1 WHERE n1.DEVICE_ID = d.ID AND d.DEVICE_TYPE_ID=t.ID " +
|
||||
"AND TENANT_ID = ?";
|
||||
|
||||
sql = sql + " OFFSET >= ? AND ROWNUM <= ?";
|
||||
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setInt(1, tenantId);
|
||||
stmt.setString(2, status.toString());
|
||||
stmt.setInt(3, tenantId);
|
||||
|
||||
int paramIdx = 4;
|
||||
|
||||
stmt.setInt(paramIdx++, request.getStartIndex());
|
||||
stmt.setInt(paramIdx, request.getRowCount());
|
||||
|
||||
|
||||
rs = stmt.executeQuery();
|
||||
notifications = new ArrayList<>();
|
||||
while (rs.next()) {
|
||||
notifications.add(NotificationDAOUtil.getNotification(rs));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new NotificationManagementException(
|
||||
"Error occurred while retrieving information of all " +
|
||||
"notifications by status : " + status, e);
|
||||
} finally {
|
||||
NotificationDAOUtil.cleanupResources(stmt, rs);
|
||||
}
|
||||
return notifications;
|
||||
}
|
||||
}
|
@ -0,0 +1,122 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* you may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.core.notification.mgt.dao.impl;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
||||
import org.wso2.carbon.device.mgt.common.notification.mgt.Notification;
|
||||
import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementException;
|
||||
import org.wso2.carbon.device.mgt.core.notification.mgt.dao.NotificationManagementDAOFactory;
|
||||
import org.wso2.carbon.device.mgt.core.notification.mgt.dao.util.NotificationDAOUtil;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This class holds the implementation of NotificationDAO which can be used to support PostgreSQL db syntax.
|
||||
*/
|
||||
public class PostgreSQLNotificationDAOImpl extends AbstractNotificationDAOImpl {
|
||||
|
||||
@Override
|
||||
public List<Notification> getAllNotifications(PaginationRequest request, int tenantId) throws
|
||||
NotificationManagementException {
|
||||
Connection conn;
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
List<Notification> notifications = null;
|
||||
try {
|
||||
conn = NotificationManagementDAOFactory.getConnection();
|
||||
String sql =
|
||||
"SELECT n1.NOTIFICATION_ID, n1.DEVICE_ID, n1.OPERATION_ID, n1.STATUS, n1.DESCRIPTION," +
|
||||
" d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM DM_DEVICE d, DM_DEVICE_TYPE t, (SELECT " +
|
||||
"NOTIFICATION_ID, DEVICE_ID, OPERATION_ID, STATUS, DESCRIPTION FROM DM_NOTIFICATION WHERE " +
|
||||
"TENANT_ID = ?) n1 WHERE n1.DEVICE_ID = d.ID AND d.DEVICE_TYPE_ID=t.ID AND TENANT_ID = ?";
|
||||
|
||||
sql = sql + " LIMIT ? OFFSET ?";
|
||||
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setInt(1, tenantId);
|
||||
stmt.setInt(2, tenantId);
|
||||
int paramIdx = 3;
|
||||
|
||||
stmt.setInt(paramIdx++, request.getRowCount());
|
||||
stmt.setInt(paramIdx, request.getStartIndex());
|
||||
|
||||
rs = stmt.executeQuery();
|
||||
notifications = new ArrayList<>();
|
||||
while (rs.next()) {
|
||||
notifications.add(NotificationDAOUtil.getNotification(rs));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new NotificationManagementException(
|
||||
"Error occurred while retrieving information of all notifications", e);
|
||||
} finally {
|
||||
NotificationDAOUtil.cleanupResources(stmt, rs);
|
||||
}
|
||||
return notifications;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<Notification> getNotificationsByStatus(PaginationRequest request, Notification.Status status, int tenantId) throws
|
||||
NotificationManagementException{
|
||||
Connection conn;
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
List<Notification> notifications = null;
|
||||
try {
|
||||
conn = NotificationManagementDAOFactory.getConnection();
|
||||
String sql = "SELECT n1.NOTIFICATION_ID, n1.DEVICE_ID, n1.OPERATION_ID, n1.STATUS," +
|
||||
" n1.DESCRIPTION, d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM " +
|
||||
"DM_DEVICE d, DM_DEVICE_TYPE t, (SELECT NOTIFICATION_ID, DEVICE_ID, " +
|
||||
"OPERATION_ID, STATUS, DESCRIPTION FROM DM_NOTIFICATION WHERE " +
|
||||
"TENANT_ID = ? AND STATUS = ?) n1 WHERE n1.DEVICE_ID = d.ID AND d.DEVICE_TYPE_ID=t.ID " +
|
||||
"AND TENANT_ID = ?";
|
||||
|
||||
sql = sql + " LIMIT ? OFFSET ?";
|
||||
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setInt(1, tenantId);
|
||||
stmt.setString(2, status.toString());
|
||||
stmt.setInt(3, tenantId);
|
||||
|
||||
int paramIdx = 4;
|
||||
|
||||
stmt.setInt(paramIdx++, request.getRowCount());
|
||||
stmt.setInt(paramIdx, request.getStartIndex());
|
||||
|
||||
|
||||
rs = stmt.executeQuery();
|
||||
notifications = new ArrayList<>();
|
||||
while (rs.next()) {
|
||||
notifications.add(NotificationDAOUtil.getNotification(rs));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new NotificationManagementException(
|
||||
"Error occurred while retrieving information of all " +
|
||||
"notifications by status : " + status, e);
|
||||
} finally {
|
||||
NotificationDAOUtil.cleanupResources(stmt, rs);
|
||||
}
|
||||
return notifications;
|
||||
}
|
||||
}
|
@ -0,0 +1,122 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* you may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.core.notification.mgt.dao.impl;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
||||
import org.wso2.carbon.device.mgt.common.notification.mgt.Notification;
|
||||
import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementException;
|
||||
import org.wso2.carbon.device.mgt.core.notification.mgt.dao.NotificationManagementDAOFactory;
|
||||
import org.wso2.carbon.device.mgt.core.notification.mgt.dao.util.NotificationDAOUtil;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This class holds the implementation of NotificationDAO which can be used to support SQLServer db syntax.
|
||||
*/
|
||||
public class SQLServerNotificationDAOImpl extends AbstractNotificationDAOImpl {
|
||||
|
||||
@Override
|
||||
public List<Notification> getAllNotifications(PaginationRequest request, int tenantId) throws
|
||||
NotificationManagementException {
|
||||
Connection conn;
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
List<Notification> notifications = null;
|
||||
try {
|
||||
conn = NotificationManagementDAOFactory.getConnection();
|
||||
String sql =
|
||||
"SELECT n1.NOTIFICATION_ID, n1.DEVICE_ID, n1.OPERATION_ID, n1.STATUS, n1.DESCRIPTION," +
|
||||
" d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM DM_DEVICE d, DM_DEVICE_TYPE t, (SELECT " +
|
||||
"NOTIFICATION_ID, DEVICE_ID, OPERATION_ID, STATUS, DESCRIPTION FROM DM_NOTIFICATION WHERE " +
|
||||
"TENANT_ID = ?) n1 WHERE n1.DEVICE_ID = d.ID AND d.DEVICE_TYPE_ID=t.ID AND TENANT_ID = ?";
|
||||
|
||||
sql = sql + " OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
|
||||
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setInt(1, tenantId);
|
||||
stmt.setInt(2, tenantId);
|
||||
int paramIdx = 3;
|
||||
|
||||
stmt.setInt(paramIdx++, request.getStartIndex());
|
||||
stmt.setInt(paramIdx, request.getRowCount());
|
||||
|
||||
rs = stmt.executeQuery();
|
||||
notifications = new ArrayList<>();
|
||||
while (rs.next()) {
|
||||
notifications.add(NotificationDAOUtil.getNotification(rs));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new NotificationManagementException(
|
||||
"Error occurred while retrieving information of all notifications", e);
|
||||
} finally {
|
||||
NotificationDAOUtil.cleanupResources(stmt, rs);
|
||||
}
|
||||
return notifications;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<Notification> getNotificationsByStatus(PaginationRequest request, Notification.Status status, int tenantId) throws
|
||||
NotificationManagementException{
|
||||
Connection conn;
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
List<Notification> notifications = null;
|
||||
try {
|
||||
conn = NotificationManagementDAOFactory.getConnection();
|
||||
String sql = "SELECT n1.NOTIFICATION_ID, n1.DEVICE_ID, n1.OPERATION_ID, n1.STATUS," +
|
||||
" n1.DESCRIPTION, d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM " +
|
||||
"DM_DEVICE d, DM_DEVICE_TYPE t, (SELECT NOTIFICATION_ID, DEVICE_ID, " +
|
||||
"OPERATION_ID, STATUS, DESCRIPTION FROM DM_NOTIFICATION WHERE " +
|
||||
"TENANT_ID = ? AND STATUS = ?) n1 WHERE n1.DEVICE_ID = d.ID AND d.DEVICE_TYPE_ID=t.ID " +
|
||||
"AND TENANT_ID = ?";
|
||||
|
||||
sql = sql + " OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
|
||||
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setInt(1, tenantId);
|
||||
stmt.setString(2, status.toString());
|
||||
stmt.setInt(3, tenantId);
|
||||
|
||||
int paramIdx = 4;
|
||||
|
||||
stmt.setInt(paramIdx++, request.getStartIndex());
|
||||
stmt.setInt(paramIdx, request.getRowCount());
|
||||
|
||||
|
||||
rs = stmt.executeQuery();
|
||||
notifications = new ArrayList<>();
|
||||
while (rs.next()) {
|
||||
notifications.add(NotificationDAOUtil.getNotification(rs));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new NotificationManagementException(
|
||||
"Error occurred while retrieving information of all " +
|
||||
"notifications by status : " + status, e);
|
||||
} finally {
|
||||
NotificationDAOUtil.cleanupResources(stmt, rs);
|
||||
}
|
||||
return notifications;
|
||||
}
|
||||
}
|
@ -1,25 +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.core.policy.mgt;
|
||||
|
||||
public class EvaluationContext {
|
||||
|
||||
|
||||
|
||||
}
|
@ -1,25 +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.core.policy.mgt;
|
||||
|
||||
public class PolicyEvaluationException extends Exception {
|
||||
|
||||
|
||||
|
||||
}
|
@ -1,25 +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.core.policy.mgt;
|
||||
|
||||
public interface PolicyEvaluationStrategy {
|
||||
|
||||
Profile execute(EvaluationContext ctx) throws PolicyEvaluationException;
|
||||
|
||||
}
|
@ -1,25 +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.core.policy.mgt;
|
||||
|
||||
public class PolicyManagementException extends Exception {
|
||||
|
||||
|
||||
|
||||
}
|
@ -1,60 +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.core.policy.mgt;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||
import org.wso2.carbon.device.mgt.core.policy.mgt.policy.Policy;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface PolicyManager {
|
||||
|
||||
public enum Type {
|
||||
USER_BASED, ROLE_BASED, PLATFORM_BASED
|
||||
}
|
||||
|
||||
boolean addPolicy(Policy policy) throws PolicyManagementException;
|
||||
|
||||
boolean removePolicy(String policyId) throws PolicyManagementException;
|
||||
|
||||
boolean updatePolicy(Policy policy) throws PolicyManagementException;
|
||||
|
||||
Policy getPolicy(String policyId) throws PolicyManagementException;
|
||||
|
||||
List<Policy> getPolicies() throws PolicyManagementException;
|
||||
|
||||
List<Policy> getUserBasedPolicies(String user) throws PolicyManagementException;
|
||||
|
||||
List<Policy> getRoleBasedPolicies(String role) throws PolicyManagementException;
|
||||
|
||||
List<Policy> getPlatformBasedPolicies(String platform) throws PolicyManagementException;
|
||||
|
||||
boolean assignRoleBasedPolicy(String policyId, String role) throws PolicyManagementException;
|
||||
|
||||
boolean assignRoleBasedPolicy(String policyId, List<String> roles) throws PolicyManagementException;
|
||||
|
||||
boolean assignUserBasedPolicy(String policyId, String user) throws PolicyManagementException;
|
||||
|
||||
boolean assignUserBasedPolicy(String policyId, List<String> users) throws PolicyManagementException;
|
||||
|
||||
boolean assignPlatformBasedPolicy(String policyId, String platform) throws PolicyManagementException;
|
||||
|
||||
Profile getEffectiveProfile(DeviceIdentifier deviceId) throws PolicyManagementException;
|
||||
|
||||
}
|
@ -1,35 +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.core.policy.mgt;
|
||||
|
||||
import org.wso2.carbon.device.mgt.core.policy.mgt.policy.Policy;
|
||||
|
||||
public interface PolicyRepository {
|
||||
|
||||
public enum Type {
|
||||
USER_BASED, ROLE_BASED, PLATFORM_BASED
|
||||
}
|
||||
|
||||
void addPolicy(Policy policy) throws PolicyManagementException;
|
||||
|
||||
void remotePolicy(Policy policy) throws PolicyManagementException;
|
||||
|
||||
void getPolicy(String id) throws PolicyManagementException;
|
||||
|
||||
}
|
@ -1,22 +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.core.policy.mgt;
|
||||
|
||||
public class Profile {
|
||||
}
|
@ -1,25 +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.core.policy.mgt;
|
||||
|
||||
public class Rule {
|
||||
|
||||
|
||||
|
||||
}
|
@ -1,25 +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.core.policy.mgt;
|
||||
|
||||
public interface RuleCombiningStrategy {
|
||||
|
||||
|
||||
|
||||
}
|
@ -1,25 +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.core.policy.mgt.dao;
|
||||
|
||||
public interface PolicyDAO {
|
||||
|
||||
|
||||
|
||||
}
|
@ -1,27 +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.core.policy.mgt.dao;
|
||||
|
||||
public class PolicyDAOFactory {
|
||||
|
||||
public static PolicyDAO getPolicyDAO() {
|
||||
return new PolicyDAOImpl();
|
||||
}
|
||||
|
||||
}
|
@ -1,25 +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.core.policy.mgt.dao;
|
||||
|
||||
public class PolicyDAOImpl implements PolicyDAO {
|
||||
|
||||
|
||||
|
||||
}
|
@ -1,33 +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.core.policy.mgt.policy;
|
||||
|
||||
public class PlatformBasedPolicy extends Policy {
|
||||
|
||||
private String platform;
|
||||
|
||||
public String getPlatform() {
|
||||
return platform;
|
||||
}
|
||||
|
||||
public void setPlatform(String platform) {
|
||||
this.platform = platform;
|
||||
}
|
||||
|
||||
}
|
@ -1,33 +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.core.policy.mgt.policy;
|
||||
|
||||
public class Policy {
|
||||
|
||||
private String id;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
}
|
@ -1,33 +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.core.policy.mgt.policy;
|
||||
|
||||
public class RoleBasedPolicy extends Policy {
|
||||
|
||||
private String role;
|
||||
|
||||
public String getRole() {
|
||||
return role;
|
||||
}
|
||||
|
||||
public void setRole(String role) {
|
||||
this.role = role;
|
||||
}
|
||||
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue