forked from community/device-mgt-core
Merge branch 'master' of https://github.com/wso2/carbon-device-mgt
commit
d22570dadb
@ -0,0 +1,87 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
@XmlRootElement(name = "Resource")
|
||||
public class APIResource{
|
||||
|
||||
private String AuthType;
|
||||
private String HttpVerb;
|
||||
private String Uri;
|
||||
private String UriTemplate;
|
||||
private String consumes;
|
||||
private String produces;
|
||||
|
||||
public String getAuthType() {
|
||||
return AuthType;
|
||||
}
|
||||
|
||||
@XmlElement(name = "AuthType", required = true)
|
||||
public void setAuthType(String authType) {
|
||||
AuthType = authType;
|
||||
}
|
||||
|
||||
public String getHttpVerb() {
|
||||
return HttpVerb;
|
||||
}
|
||||
|
||||
@XmlElement(name = "HttpVerb", required = true)
|
||||
public void setHttpVerb(String httpVerb) {
|
||||
HttpVerb = httpVerb;
|
||||
}
|
||||
|
||||
public String getUri() {
|
||||
return Uri;
|
||||
}
|
||||
|
||||
@XmlElement(name = "Uri", required = true)
|
||||
public void setUri(String uri) {
|
||||
Uri = uri;
|
||||
}
|
||||
|
||||
public String getUriTemplate() {
|
||||
return UriTemplate;
|
||||
}
|
||||
|
||||
@XmlElement(name = "UriTemplate", required = true)
|
||||
public void setUriTemplate(String uriTemplate) {
|
||||
UriTemplate = uriTemplate;
|
||||
}
|
||||
|
||||
public String getConsumes() {
|
||||
return consumes;
|
||||
}
|
||||
|
||||
@XmlElement(name = "Consumes", required = true)
|
||||
public void setConsumes(String consumes) {
|
||||
this.consumes = consumes;
|
||||
}
|
||||
|
||||
public String getProduces() {
|
||||
return produces;
|
||||
}
|
||||
|
||||
@XmlElement(name = "Produces", required = true)
|
||||
public void setProduces(String produces) {
|
||||
this.produces = produces;
|
||||
}
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import java.util.List;
|
||||
|
||||
@XmlRootElement(name = "ResourceConfiguration")
|
||||
public class APIResourceConfiguration {
|
||||
|
||||
private String name;
|
||||
private String context;
|
||||
private String version;
|
||||
private List<APIResource> resources;
|
||||
private String[] tags;
|
||||
|
||||
public List<APIResource> getResources() {
|
||||
return resources;
|
||||
}
|
||||
|
||||
@XmlElement(name = "Resources", required = true)
|
||||
public void setResources(List<APIResource> resources) {
|
||||
this.resources = resources;
|
||||
}
|
||||
|
||||
public String getContext() {
|
||||
return context;
|
||||
}
|
||||
|
||||
@XmlElement(name = "Context", required = true)
|
||||
public void setContext(String context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@XmlElement(name = "Name")
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
@XmlElement(name = "Version")
|
||||
public void setVersion(String version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public String[] getTags() {
|
||||
return tags;
|
||||
}
|
||||
|
||||
@XmlElement(name = "Tags")
|
||||
public void setTags(String[] tags) {
|
||||
this.tags = tags;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package org.wso2.carbon.apimgt.webapp.publisher.config;
|
||||
|
||||
public class APIResourceManagementException extends Exception{
|
||||
private static final long serialVersionUID = -3151279311929070297L;
|
||||
|
||||
private String errorMessage;
|
||||
|
||||
public String getErrorMessage() {
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
public void setErrorMessage(String errorMessage) {
|
||||
this.errorMessage = errorMessage;
|
||||
}
|
||||
|
||||
public APIResourceManagementException(String msg, Exception nestedEx) {
|
||||
super(msg, nestedEx);
|
||||
setErrorMessage(msg);
|
||||
}
|
||||
|
||||
public APIResourceManagementException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
setErrorMessage(message);
|
||||
}
|
||||
|
||||
public APIResourceManagementException(String msg) {
|
||||
super(msg);
|
||||
setErrorMessage(msg);
|
||||
}
|
||||
|
||||
public APIResourceManagementException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public APIResourceManagementException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* This class will add, update custom permissions defined in resources.xml in webapps.
|
||||
*/
|
||||
public class APIResourceManager {
|
||||
|
||||
private static APIResourceManager resourceManager;
|
||||
private List<APIResource> resourceList;
|
||||
|
||||
private APIResourceManager(){};
|
||||
|
||||
public static APIResourceManager getInstance() {
|
||||
if (resourceManager == null) {
|
||||
synchronized (APIResourceManager.class) {
|
||||
if (resourceManager == null) {
|
||||
resourceManager = new APIResourceManager();
|
||||
}
|
||||
}
|
||||
}
|
||||
return resourceManager;
|
||||
}
|
||||
|
||||
public void initializeResources(InputStream resourceStream) throws APIResourceManagementException {
|
||||
try {
|
||||
if(resourceStream != null){
|
||||
/* Un-marshaling Device Management configuration */
|
||||
JAXBContext cdmContext = JAXBContext.newInstance(APIResourceConfiguration.class);
|
||||
Unmarshaller unmarshaller = cdmContext.createUnmarshaller();
|
||||
APIResourceConfiguration resourcesConfiguration = (APIResourceConfiguration)
|
||||
unmarshaller.unmarshal(resourceStream);
|
||||
if((resourcesConfiguration != null) && (resourcesConfiguration.getResources() != null)){
|
||||
this.resourceList = resourcesConfiguration.getResources();
|
||||
}
|
||||
}
|
||||
} catch (JAXBException e) {
|
||||
throw new APIResourceManagementException("Error occurred while initializing Data Source config", e);
|
||||
}
|
||||
}
|
||||
|
||||
public List<APIResource> getAPIResources(){
|
||||
return resourceList;
|
||||
}
|
||||
}
|
@ -0,0 +1,265 @@
|
||||
/*
|
||||
* 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.apache.catalina.core.StandardContext;
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.scannotation.AnnotationDB;
|
||||
import org.scannotation.WarUrlFinder;
|
||||
import org.wso2.carbon.apimgt.webapp.publisher.config.APIResource;
|
||||
import org.wso2.carbon.apimgt.webapp.publisher.config.APIResourceConfiguration;
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.ws.rs.*;
|
||||
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.URL;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.util.*;
|
||||
|
||||
public class AnnotationUtil {
|
||||
|
||||
private static final Log log = LogFactory.getLog(AnnotationUtil.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 AUTH_TYPE = "Any";
|
||||
private static final String PROTOCOL_HTTP = "http";
|
||||
private static final String SERVER_HOST = "carbon.local.ip";
|
||||
private static final String HTTP_PORT = "httpPort";
|
||||
public static final String DIR_WEB_INF_LIB = "/WEB-INF/lib";
|
||||
public static final String STRING_ARR = "string_arr";
|
||||
public static final String STRING = "string";
|
||||
|
||||
private StandardContext context;
|
||||
private Method[] pathClazzMethods;
|
||||
private Class<Path> pathClazz;
|
||||
private ClassLoader classLoader;
|
||||
private ServletContext servletContext;
|
||||
|
||||
|
||||
public AnnotationUtil(final StandardContext context) {
|
||||
this.context = 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 {
|
||||
AnnotationDB db = new AnnotationDB();
|
||||
db.addIgnoredPackages(PACKAGE_ORG_APACHE);
|
||||
db.addIgnoredPackages(PACKAGE_ORG_CODEHAUS);
|
||||
db.addIgnoredPackages(PACKAGE_ORG_SPRINGFRAMEWORK);
|
||||
|
||||
URL[] libPath = WarUrlFinder.findWebInfLibClasspaths(servletContext);
|
||||
URL classPath = WarUrlFinder.findWebInfClassesPath(servletContext);
|
||||
URL[] urls = (URL[]) ArrayUtils.add(libPath, libPath.length, classPath);
|
||||
|
||||
db.scanArchives(urls);
|
||||
|
||||
//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<APIResourceConfiguration> extractAPIInfo(Set<String> entityClasses)
|
||||
throws ClassNotFoundException {
|
||||
|
||||
List<APIResourceConfiguration> apiResourceConfigs = new ArrayList<APIResourceConfiguration>();
|
||||
|
||||
if (entityClasses != null && !entityClasses.isEmpty()) {
|
||||
for (final String className : entityClasses) {
|
||||
|
||||
APIResourceConfiguration resource =
|
||||
AccessController.doPrivileged(new PrivilegedAction<APIResourceConfiguration>() {
|
||||
public APIResourceConfiguration run() {
|
||||
Class<?> clazz = null;
|
||||
APIResourceConfiguration apiResourceConfig = null;
|
||||
try {
|
||||
clazz = classLoader.loadClass(className);
|
||||
Class<Path> apiClazz = (Class<Path>)
|
||||
classLoader.loadClass(org.wso2.carbon.apimgt.annotations.api.API.class.getName());
|
||||
Annotation apiAnno = clazz.getAnnotation(apiClazz);
|
||||
|
||||
List<APIResource> resourceList = null;
|
||||
apiResourceConfig = new APIResourceConfiguration();
|
||||
|
||||
if (apiAnno != null) {
|
||||
|
||||
Method[] apiClazzMethods = apiClazz.getMethods();
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Application Context root = " + servletContext.getContextPath());
|
||||
}
|
||||
|
||||
try {
|
||||
for(int k=0;k<apiClazzMethods.length;k++){
|
||||
switch (apiClazzMethods[k].getName()){
|
||||
case "name" :
|
||||
apiResourceConfig.setName(invokeMethod(apiClazzMethods[k], apiAnno, STRING));
|
||||
break;
|
||||
case "version" :
|
||||
apiResourceConfig.setVersion(invokeMethod(apiClazzMethods[k], apiAnno, STRING));
|
||||
break;
|
||||
case "context" :
|
||||
apiResourceConfig.setContext(invokeMethod(apiClazzMethods[k], apiAnno, STRING));
|
||||
break;
|
||||
case "tags" :
|
||||
apiResourceConfig.setTags(invokeMethod(apiClazzMethods[k], apiAnno));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
String rootContext = "";
|
||||
pathClazz = (Class<Path>) classLoader.loadClass(Path.class.getName());
|
||||
pathClazzMethods = pathClazz.getMethods();
|
||||
|
||||
Annotation rootContectAnno = clazz.getAnnotation(pathClazz);
|
||||
if (rootContectAnno != null) {
|
||||
rootContext = invokeMethod(pathClazzMethods[0], rootContectAnno, STRING);
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("API Root Context = " + rootContext);
|
||||
}
|
||||
}
|
||||
|
||||
Method[] annotatedMethods = clazz.getDeclaredMethods();
|
||||
resourceList = getApiResources(rootContext, annotatedMethods);
|
||||
apiResourceConfig.setResources(resourceList);
|
||||
} 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 apiResourceConfig;
|
||||
}
|
||||
});
|
||||
apiResourceConfigs.add(resource);
|
||||
}
|
||||
}
|
||||
return apiResourceConfigs;
|
||||
}
|
||||
|
||||
private List<APIResource> getApiResources(String rootContext, Method[] annotatedMethods) throws Throwable {
|
||||
List<APIResource> resourceList;
|
||||
resourceList = new ArrayList<APIResource>();
|
||||
for (Method method : annotatedMethods) {
|
||||
Annotation methodContextAnno = method.getAnnotation(pathClazz);
|
||||
if (methodContextAnno != null) {
|
||||
String subCtx = invokeMethod(pathClazzMethods[0], methodContextAnno, STRING);
|
||||
APIResource resource = new APIResource();
|
||||
resource.setUriTemplate(makeContextURLReady(subCtx));
|
||||
|
||||
String serverIP = System.getProperty(SERVER_HOST);
|
||||
String httpServerPort = System.getProperty(HTTP_PORT);
|
||||
|
||||
resource.setUri(PROTOCOL_HTTP + "://" + serverIP + ":" + httpServerPort + makeContextURLReady(rootContext) + makeContextURLReady(subCtx));
|
||||
resource.setAuthType(AUTH_TYPE);
|
||||
|
||||
Annotation[] annotations = method.getDeclaredAnnotations();
|
||||
for(int i=0; i<annotations.length; i++){
|
||||
|
||||
if(annotations[i].annotationType().getName().equals(GET.class.getName())){
|
||||
resource.setHttpVerb(HttpMethod.GET);
|
||||
}
|
||||
if(annotations[i].annotationType().getName().equals(POST.class.getName())){
|
||||
resource.setHttpVerb(HttpMethod.POST);
|
||||
}
|
||||
if(annotations[i].annotationType().getName().equals(OPTIONS.class.getName())){
|
||||
resource.setHttpVerb(HttpMethod.OPTIONS);
|
||||
}
|
||||
if(annotations[i].annotationType().getName().equals(DELETE.class.getName())){
|
||||
resource.setHttpVerb(HttpMethod.DELETE);
|
||||
}
|
||||
if(annotations[i].annotationType().getName().equals(PUT.class.getName())){
|
||||
resource.setHttpVerb(HttpMethod.PUT);
|
||||
}
|
||||
if(annotations[i].annotationType().getName().equals(Consumes.class.getName())){
|
||||
Class<Consumes> consumesClass = (Class<Consumes>) classLoader.loadClass(Consumes.class.getName());
|
||||
Method[] consumesClassMethods = consumesClass.getMethods();
|
||||
Annotation consumesAnno = method.getAnnotation(consumesClass);
|
||||
resource.setConsumes(invokeMethod(consumesClassMethods[0], consumesAnno, STRING_ARR));
|
||||
}
|
||||
if(annotations[i].annotationType().getName().equals(Produces.class.getName())){
|
||||
Class<Produces> producesClass = (Class<Produces>) classLoader.loadClass(Produces.class.getName());
|
||||
Method[] producesClassMethods = producesClass.getMethods();
|
||||
Annotation producesAnno = method.getAnnotation(producesClass);
|
||||
resource.setProduces(invokeMethod(producesClassMethods[0], producesAnno, STRING_ARR));
|
||||
}
|
||||
}
|
||||
resourceList.add(resource);
|
||||
}
|
||||
}
|
||||
return resourceList;
|
||||
}
|
||||
|
||||
private String makeContextURLReady(String context){
|
||||
if(context != null && !context.equalsIgnoreCase("")){
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* When an annotation and method is passed, this method invokes that executes said method against the annotation
|
||||
*/
|
||||
private String[] invokeMethod(Method method, Annotation annotation) throws Throwable {
|
||||
InvocationHandler methodHandler = Proxy.getInvocationHandler(annotation);
|
||||
return ((String[])methodHandler.invoke(annotation, method, null));
|
||||
}
|
||||
}
|
@ -1,144 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
|
||||
<parent>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<artifactId>device-mgt</artifactId>
|
||||
<version>1.1.0-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>org.wso2.carbon.device.mgt.analytics</artifactId>
|
||||
<version>1.1.0-SNAPSHOT</version>
|
||||
<packaging>bundle</packaging>
|
||||
<name>WSO2 Carbon - Device Analytics</name>
|
||||
<description>WSO2 Carbon - Device Analytics</description>
|
||||
<url>http://wso2.org</url>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.osgi</groupId>
|
||||
<artifactId>org.eclipse.osgi</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.osgi</groupId>
|
||||
<artifactId>org.eclipse.osgi.services</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.testng</groupId>
|
||||
<artifactId>testng</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.tomcat</groupId>
|
||||
<artifactId>tomcat</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.tomcat</groupId>
|
||||
<artifactId>tomcat-servlet-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.logging</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.utils</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<artifactId>org.wso2.carbon.device.mgt.core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.analytics-common</groupId>
|
||||
<artifactId>org.wso2.carbon.databridge.agent</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.analytics-common</groupId>
|
||||
<artifactId>org.wso2.carbon.databridge.commons</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.analytics</groupId>
|
||||
<artifactId>org.wso2.carbon.analytics.api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.registry</groupId>
|
||||
<artifactId>org.wso2.carbon.registry.indexing</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.json.wso2</groupId>
|
||||
<artifactId>json</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.felix</groupId>
|
||||
<artifactId>maven-scr-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.felix</groupId>
|
||||
<artifactId>maven-bundle-plugin</artifactId>
|
||||
<version>1.4.0</version>
|
||||
<extensions>true</extensions>
|
||||
<configuration>
|
||||
<instructions>
|
||||
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
|
||||
<Bundle-Name>${project.artifactId}</Bundle-Name>
|
||||
<Bundle-Version>${carbon.device.mgt.version}</Bundle-Version>
|
||||
<Bundle-Description>Data Publisher</Bundle-Description>
|
||||
<Private-Package>org.wso2.carbon.device.mgt.analytics.internal</Private-Package>
|
||||
<Export-Package>
|
||||
!org.wso2.carbon.device.mgt.analytics.internal,
|
||||
org.wso2.carbon.device.mgt.analytics.*;version="${carbon.device.mgt.version}"
|
||||
</Export-Package>
|
||||
<Import-Package>
|
||||
org.osgi.framework,
|
||||
org.osgi.service.component,
|
||||
org.apache.commons.logging.*,
|
||||
org.wso2.carbon.context;version="${carbon.kernel.version.range}",
|
||||
org.wso2.carbon.utils;version="${carbon.kernel.version.range}",
|
||||
org.wso2.carbon.databridge.*;version="${carbon.analytics.common.version.range}",
|
||||
org.wso2.carbon.analytics.*;version="${carbon.analytics.version.range}",
|
||||
org.wso2.carbon.registry.core.*;resolution:=optional,
|
||||
org.wso2.carbon.registry.common.*;version="${carbon.registry.imp.pkg.version.range}",
|
||||
org.wso2.carbon.registry.indexing.*; version="${carbon.registry.imp.pkg.version.range}",
|
||||
org.json;version="${commons-json.version}",
|
||||
javax.xml.bind,
|
||||
javax.xml.bind.annotation,
|
||||
javax.xml.parsers,
|
||||
org.w3c.dom,
|
||||
org.wso2.carbon.base
|
||||
</Import-Package>
|
||||
</instructions>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* This class holds the information of the device type and its provider tenant.
|
||||
*/
|
||||
public class DeviceTypeIdentifier implements Serializable {
|
||||
|
||||
private String deviceType;
|
||||
private int tenantId;
|
||||
private static final int DEFAULT_SHARE_WITH_ALL_TENANTS_ID = -1;
|
||||
|
||||
public DeviceTypeIdentifier(String deviceType, int tenantId) {
|
||||
this.deviceType = deviceType;
|
||||
this.tenantId = tenantId;
|
||||
}
|
||||
|
||||
public DeviceTypeIdentifier(String deviceType) {
|
||||
this.deviceType = deviceType;
|
||||
this.tenantId = DEFAULT_SHARE_WITH_ALL_TENANTS_ID;
|
||||
}
|
||||
|
||||
public void setTenantId(int tenantId) {
|
||||
this.tenantId = tenantId;
|
||||
}
|
||||
|
||||
public String getDeviceType() {
|
||||
return this.deviceType;
|
||||
}
|
||||
|
||||
public int getTenantId() {
|
||||
return this.tenantId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = this.deviceType.hashCode();
|
||||
result = 31 * result + ("@" + this.tenantId).hashCode();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return (obj instanceof DeviceTypeIdentifier) && deviceType.equals(
|
||||
((DeviceTypeIdentifier) obj).deviceType) && tenantId == ((DeviceTypeIdentifier) obj).tenantId;
|
||||
}
|
||||
|
||||
public boolean isSharedWithAllTenant() {
|
||||
return tenantId == DEFAULT_SHARE_WITH_ALL_TENANTS_ID;
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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.webapp.authenticator.framework.authorizer;
|
||||
|
||||
import org.apache.catalina.connector.Request;
|
||||
import org.wso2.carbon.webapp.authenticator.framework.AuthenticationInfo;
|
||||
import org.wso2.carbon.webapp.authenticator.framework.authenticator.WebappAuthenticator;
|
||||
|
||||
/**
|
||||
* This class represents the methods that are used to authorize requests based on the tenant subscription.
|
||||
*/
|
||||
public class WebappTenantAuthorizer {
|
||||
private static final String SHARED_WITH_ALL_TENANTS_PARAM_NAME = "isSharedWithAllTenants";
|
||||
private static final String PROVIDER_TENANT_DOMAIN_PARAM_NAME = "providerTenantDomain";
|
||||
|
||||
public static WebappAuthenticator.Status authorize(Request request, AuthenticationInfo authenticationInfo) {
|
||||
String tenantDomain = authenticationInfo.getTenantDomain();
|
||||
if (tenantDomain != null && isSharedWithAllTenants(request) || isProviderTenant(request, tenantDomain)) {
|
||||
return WebappAuthenticator.Status.CONTINUE;
|
||||
}
|
||||
return WebappAuthenticator.Status.FAILURE;
|
||||
}
|
||||
|
||||
private static boolean isSharedWithAllTenants(Request request) {
|
||||
String param = request.getContext().findParameter(SHARED_WITH_ALL_TENANTS_PARAM_NAME);
|
||||
return (param == null || Boolean.parseBoolean(param));
|
||||
}
|
||||
|
||||
private static boolean isProviderTenant(Request request, String requestTenantDomain) {
|
||||
String param = request.getContext().findParameter(PROVIDER_TENANT_DOMAIN_PARAM_NAME);
|
||||
return (param == null || requestTenantDomain.equals(param));
|
||||
}
|
||||
}
|
@ -0,0 +1,134 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<artifactId>apimgt-extensions-feature</artifactId>
|
||||
<version>1.1.0-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>org.wso2.carbon.apimgt.application.extension.feature</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<version>1.1.0-SNAPSHOT</version>
|
||||
<name>WSO2 Carbon - API Management Application Extension Feature</name>
|
||||
<url>http://wso2.org</url>
|
||||
<description>This feature contains an implementation of a api application registration, which takes care of subscription
|
||||
and generating keys.
|
||||
</description>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<artifactId>org.wso2.carbon.apimgt.application.extension</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<version>2.6</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>copy-resources</id>
|
||||
<phase>generate-resources</phase>
|
||||
<goals>
|
||||
<goal>copy-resources</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputDirectory>src/main/resources</outputDirectory>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>resources</directory>
|
||||
<includes>
|
||||
<include>build.properties</include>
|
||||
<include>p2.inf</include>
|
||||
</includes>
|
||||
</resource>
|
||||
</resources>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>copy-jaxrs-war</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>copy</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<artifactItems>
|
||||
<artifactItem>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<artifactId>org.wso2.carbon.apimgt.application.extension.api</artifactId>
|
||||
<type>war</type>
|
||||
<overWrite>true</overWrite>
|
||||
<outputDirectory>${project.build.directory}/maven-shared-archive-resources/webapps/</outputDirectory>
|
||||
<destFileName>api-application-registration.war</destFileName>
|
||||
</artifactItem>
|
||||
</artifactItems>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.wso2.maven</groupId>
|
||||
<artifactId>carbon-p2-plugin</artifactId>
|
||||
<version>${carbon.p2.plugin.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>p2-feature-generation</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>p2-feature-gen</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<id>org.wso2.carbon.apimgt.application.extension</id>
|
||||
<propertiesFile>../../../features/etc/feature.properties</propertiesFile>
|
||||
<adviceFile>
|
||||
<properties>
|
||||
<propertyDef>org.wso2.carbon.p2.category.type:server</propertyDef>
|
||||
<propertyDef>org.eclipse.equinox.p2.type.group:false</propertyDef>
|
||||
</properties>
|
||||
</adviceFile>
|
||||
<bundles>
|
||||
<bundleDef>
|
||||
org.wso2.carbon.devicemgt:org.wso2.carbon.apimgt.application.extension:${carbon.device.mgt.version}
|
||||
</bundleDef>
|
||||
</bundles>
|
||||
<importFeatures>
|
||||
<importFeatureDef>org.wso2.carbon.core.server:${carbon.kernel.version}</importFeatureDef>
|
||||
</importFeatures>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
@ -0,0 +1 @@
|
||||
custom = true
|
@ -0,0 +1,3 @@
|
||||
instructions.configure = \
|
||||
org.eclipse.equinox.p2.touchpoint.natives.mkdir(path:${installFolder}/../../deployment/server/webapps/);\
|
||||
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.apimgt.application.extension_${feature.version}/webapps/,target:${installFolder}/../../deployment/server/webapps/,overwrite:true);\
|
@ -1,2 +1,2 @@
|
||||
instructions.configure = \
|
||||
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.server_${feature.version}/conf/device-analytics-config.xml,target:${installFolder}/../../conf/etc/device-analytics-config.xml,overwrite:true);\
|
||||
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.analytics.data.publisher_${feature.version}/conf/device-analytics-config.xml,target:${installFolder}/../../conf/etc/device-analytics-config.xml,overwrite:true);\
|
Loading…
Reference in new issue