forked from community/device-mgt-plugins
commit
fea3486084
@ -0,0 +1,98 @@
|
||||
/**
|
||||
* 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.mobile.impl.config;
|
||||
|
||||
import org.wso2.carbon.apimgt.api.APIProvider;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import javax.xml.bind.annotation.XmlTransient;
|
||||
|
||||
@XmlRootElement(name = "API")
|
||||
public class APIConfig {
|
||||
|
||||
private String name;
|
||||
private String owner;
|
||||
private String context;
|
||||
private String endpoint;
|
||||
private String version;
|
||||
private String transports;
|
||||
private APIProvider provider;
|
||||
|
||||
public void init(APIProvider provider) {
|
||||
this.provider = provider;
|
||||
}
|
||||
|
||||
@XmlTransient
|
||||
public APIProvider getProvider() {
|
||||
return provider;
|
||||
}
|
||||
|
||||
@XmlElement(name = "Name", nillable = false)
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@XmlElement(name = "Owner", nillable = false)
|
||||
public String getOwner() {
|
||||
return owner;
|
||||
}
|
||||
|
||||
public void setOwner(String owner) {
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
@XmlElement(name = "Context", nillable = false)
|
||||
public String getContext() {
|
||||
return context;
|
||||
}
|
||||
|
||||
public void setContext(String context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@XmlElement(name = "Endpoint", nillable = false)
|
||||
public String getEndpoint() {
|
||||
return endpoint;
|
||||
}
|
||||
|
||||
public void setEndpoint(String endpoint) {
|
||||
this.endpoint = endpoint;
|
||||
}
|
||||
|
||||
@XmlElement(name = "Version", nillable = false)
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(String version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
@XmlElement(name = "Transports", nillable = false)
|
||||
public String getTransports() {
|
||||
return transports;
|
||||
}
|
||||
|
||||
public void setTransports(String transports) {
|
||||
this.transports = transports;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
/**
|
||||
* 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.mobile.impl.config;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import java.util.List;
|
||||
|
||||
@XmlRootElement(name = "APIPublisher")
|
||||
public class APIPublisherConfig {
|
||||
|
||||
private List<APIConfig> apis;
|
||||
|
||||
@XmlElement(name = "APIs")
|
||||
public List<APIConfig> getApis() {
|
||||
return apis;
|
||||
}
|
||||
|
||||
public void setApis(List<APIConfig> apis) {
|
||||
this.apis = apis;
|
||||
}
|
||||
|
||||
}
|
@ -1,57 +0,0 @@
|
||||
/**
|
||||
* 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.mobile.impl.dao;
|
||||
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.DataSourceListener;
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.dao.impl.MobileDeviceDAOImpl;
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.dao.impl.MobileDeviceModelDAOImpl;
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.dao.impl.MobileDeviceVendorDAOImpl;
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.dao.impl.MobileOSVersionDAOImpl;
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.dao.util.MobileDeviceManagementDAOUtil;
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.internal.MobileDeviceManagementBundleActivator;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
public class MobileDeviceDAOFactory implements DataSourceListener {
|
||||
|
||||
private static DataSource dataSource;
|
||||
|
||||
public MobileDeviceDAOFactory() {
|
||||
MobileDeviceManagementBundleActivator.registerDataSourceListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notifyObserver() {
|
||||
dataSource = MobileDeviceManagementDAOUtil.resolveDataSource();
|
||||
}
|
||||
|
||||
public static MobileDeviceDAO getMobileDeviceDAO() {
|
||||
return new MobileDeviceDAOImpl(dataSource);
|
||||
}
|
||||
|
||||
public static MobileDeviceModelDAO getMobileDeviceModelDAO() {
|
||||
return new MobileDeviceModelDAOImpl(dataSource);
|
||||
}
|
||||
|
||||
public static MobileDeviceVendorDAO getMobileDeviceVendorDAO() {
|
||||
return new MobileDeviceVendorDAOImpl(dataSource);
|
||||
}
|
||||
|
||||
public static MobileOSVersionDAO getMobileOSVersionDAO() {
|
||||
return new MobileOSVersionDAOImpl(dataSource);
|
||||
}
|
||||
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
/*
|
||||
* 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.mobile.impl.dao;
|
||||
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.dto.MobileDeviceModel;
|
||||
|
||||
/**
|
||||
* This class represents the key operations associated with persisting mobile-device model related
|
||||
* information.
|
||||
*/
|
||||
public interface MobileDeviceModelDAO {
|
||||
|
||||
MobileDeviceModel getDeviceModel(String modelId) throws MobileDeviceManagementDAOException;
|
||||
|
||||
void addDeviceModel(MobileDeviceModel deviceModel) throws MobileDeviceManagementDAOException;
|
||||
|
||||
void updateDeviceModel(MobileDeviceModel deviceModel) throws MobileDeviceManagementDAOException;
|
||||
|
||||
void deleteDeviceModel(String modelId) throws MobileDeviceManagementDAOException;
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
/*
|
||||
* 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.mobile.impl.dao;
|
||||
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.dto.MobileDeviceVendor;
|
||||
|
||||
/**
|
||||
* This class represents the key operations associated with persisting mobile-device vendor
|
||||
* related information.
|
||||
*/
|
||||
public interface MobileDeviceVendorDAO {
|
||||
|
||||
MobileDeviceVendor getDeviceModel(String vendorId) throws MobileDeviceManagementDAOException;
|
||||
|
||||
void addDeviceVendor(MobileDeviceVendor deviceVendor) throws MobileDeviceManagementDAOException;
|
||||
|
||||
void updateDeviceVendor(MobileDeviceVendor deviceVendor)
|
||||
throws MobileDeviceManagementDAOException;
|
||||
|
||||
void deleteDeviceVendor(String vendorId) throws MobileDeviceManagementDAOException;
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
/*
|
||||
* 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.mobile.impl.dao;
|
||||
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.dto.MobileOSVersion;
|
||||
|
||||
/**
|
||||
* This class represents the key operations associated with persisting mobile-device OS version
|
||||
* related information.
|
||||
*/
|
||||
public interface MobileOSVersionDAO {
|
||||
|
||||
MobileOSVersion getMobileOSVersion(String versionId) throws MobileDeviceManagementDAOException;
|
||||
|
||||
void addMobileOSVersion(MobileOSVersion osVersion) throws MobileDeviceManagementDAOException;
|
||||
|
||||
void updateMobileOSVersion(MobileOSVersion osVersion) throws MobileDeviceManagementDAOException;
|
||||
|
||||
void deleteMobileOSVersion(String versionId) throws MobileDeviceManagementDAOException;
|
||||
}
|
@ -1,62 +0,0 @@
|
||||
/*
|
||||
* 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.mobile.impl.dao.impl;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.dao.MobileDeviceManagementDAOException;
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.dao.MobileDeviceModelDAO;
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.dto.MobileDeviceModel;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
/**
|
||||
* Implementation of MobileDeviceModel.
|
||||
*/
|
||||
public class MobileDeviceModelDAOImpl implements MobileDeviceModelDAO {
|
||||
|
||||
private DataSource dataSource;
|
||||
private static final Log log = LogFactory.getLog(MobileDeviceModelDAOImpl.class);
|
||||
|
||||
public MobileDeviceModelDAOImpl(DataSource dataSource) {
|
||||
this.dataSource = dataSource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MobileDeviceModel getDeviceModel(String modelId)
|
||||
throws MobileDeviceManagementDAOException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDeviceModel(MobileDeviceModel deviceModel)
|
||||
throws MobileDeviceManagementDAOException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDeviceModel(MobileDeviceModel deviceModel)
|
||||
throws MobileDeviceManagementDAOException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteDeviceModel(String modelId)
|
||||
throws MobileDeviceManagementDAOException {
|
||||
|
||||
}
|
||||
}
|
@ -1,62 +0,0 @@
|
||||
/*
|
||||
* 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.mobile.impl.dao.impl;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.dao.MobileDeviceManagementDAOException;
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.dao.MobileDeviceVendorDAO;
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.dto.MobileDeviceVendor;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
/**
|
||||
* Implementation of MobileDeviceVendorDAO.
|
||||
*/
|
||||
public class MobileDeviceVendorDAOImpl implements MobileDeviceVendorDAO {
|
||||
|
||||
private DataSource dataSource;
|
||||
private static final Log log = LogFactory.getLog(MobileDeviceVendorDAOImpl.class);
|
||||
|
||||
public MobileDeviceVendorDAOImpl(DataSource dataSource) {
|
||||
this.dataSource = dataSource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MobileDeviceVendor getDeviceModel(String vendorId)
|
||||
throws MobileDeviceManagementDAOException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDeviceVendor(MobileDeviceVendor deviceVendor)
|
||||
throws MobileDeviceManagementDAOException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDeviceVendor(MobileDeviceVendor deviceVendor)
|
||||
throws MobileDeviceManagementDAOException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteDeviceVendor(String vendorId)
|
||||
throws MobileDeviceManagementDAOException {
|
||||
|
||||
}
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
/*
|
||||
* 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.mobile.impl.dao.impl;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.dao.MobileDeviceManagementDAOException;
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.dao.MobileOSVersionDAO;
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.dto.MobileOSVersion;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
/**
|
||||
* Implementation of MobileOSVersionDAO.
|
||||
*/
|
||||
public class MobileOSVersionDAOImpl implements MobileOSVersionDAO {
|
||||
|
||||
private DataSource dataSource;
|
||||
private static final Log log = LogFactory.getLog(MobileOSVersionDAOImpl.class);
|
||||
|
||||
public MobileOSVersionDAOImpl(DataSource dataSource) {
|
||||
this.dataSource = dataSource;
|
||||
}
|
||||
|
||||
@Override public MobileOSVersion getMobileOSVersion(String versionId)
|
||||
throws MobileDeviceManagementDAOException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override public void addMobileOSVersion(MobileOSVersion osVersion)
|
||||
throws MobileDeviceManagementDAOException {
|
||||
|
||||
}
|
||||
|
||||
@Override public void updateMobileOSVersion(MobileOSVersion osVersion)
|
||||
throws MobileDeviceManagementDAOException {
|
||||
|
||||
}
|
||||
|
||||
@Override public void deleteMobileOSVersion(String versionId)
|
||||
throws MobileDeviceManagementDAOException {
|
||||
|
||||
}
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
/*
|
||||
* 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.mobile.impl.dto;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* DTO of MobileDeviceModel.
|
||||
*/
|
||||
public class MobileDeviceModel implements Serializable {
|
||||
|
||||
private int modelId;
|
||||
private String model;
|
||||
|
||||
public int getModelId() {
|
||||
return modelId;
|
||||
}
|
||||
|
||||
public void setModelId(int modelId) {
|
||||
this.modelId = modelId;
|
||||
}
|
||||
|
||||
public String getModel() {
|
||||
return model;
|
||||
}
|
||||
|
||||
public void setModel(String model) {
|
||||
this.model = model;
|
||||
}
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
/*
|
||||
* 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.mobile.impl.dto;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* DTO of MobileVendor.
|
||||
*/
|
||||
public class MobileDeviceVendor implements Serializable {
|
||||
|
||||
private int vendorId;
|
||||
private String vendor;
|
||||
|
||||
public int getVendorId() {
|
||||
return vendorId;
|
||||
}
|
||||
|
||||
public void setVendorId(int vendorId) {
|
||||
this.vendorId = vendorId;
|
||||
}
|
||||
|
||||
public String getVendor() {
|
||||
return vendor;
|
||||
}
|
||||
|
||||
public void setVendor(String vendor) {
|
||||
this.vendor = vendor;
|
||||
}
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
/*
|
||||
* 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.mobile.impl.dto;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* DTO of MobileOSVersion.
|
||||
*/
|
||||
public class MobileOSVersion implements Serializable {
|
||||
|
||||
private int osVersionId;
|
||||
private String osVersion;
|
||||
|
||||
public int getOsVersionId() {
|
||||
return osVersionId;
|
||||
}
|
||||
|
||||
public void setOsVersionId(int osVersionId) {
|
||||
this.osVersionId = osVersionId;
|
||||
}
|
||||
|
||||
public String getOsVersion() {
|
||||
return osVersion;
|
||||
}
|
||||
|
||||
public void setOsVersion(String osVersion) {
|
||||
this.osVersion = osVersion;
|
||||
}
|
||||
}
|
@ -0,0 +1,111 @@
|
||||
/**
|
||||
* 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.mobile.impl.util;
|
||||
|
||||
import org.wso2.carbon.apimgt.api.APIManagementException;
|
||||
import org.wso2.carbon.apimgt.api.APIProvider;
|
||||
import org.wso2.carbon.apimgt.api.model.API;
|
||||
import org.wso2.carbon.apimgt.api.model.APIIdentifier;
|
||||
import org.wso2.carbon.apimgt.api.model.APIStatus;
|
||||
import org.wso2.carbon.apimgt.api.model.URITemplate;
|
||||
import org.wso2.carbon.apimgt.impl.APIConstants;
|
||||
import org.wso2.carbon.apimgt.usage.publisher.service.APIMGTConfigReaderService;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.config.APIConfig;
|
||||
import org.wso2.carbon.utils.CarbonUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class DeviceManagementAPIPublisherUtil {
|
||||
|
||||
enum HTTPMethod {
|
||||
GET, POST, DELETE, PUT, OPTIONS
|
||||
}
|
||||
|
||||
private static List<HTTPMethod> httpMethods;
|
||||
|
||||
static {
|
||||
httpMethods = new ArrayList<HTTPMethod>();
|
||||
httpMethods.add(HTTPMethod.GET);
|
||||
httpMethods.add(HTTPMethod.POST);
|
||||
httpMethods.add(HTTPMethod.DELETE);
|
||||
httpMethods.add(HTTPMethod.PUT);
|
||||
httpMethods.add(HTTPMethod.OPTIONS);
|
||||
}
|
||||
|
||||
public static void publishAPI(APIConfig config) throws DeviceManagementException {
|
||||
APIProvider provider = config.getProvider();
|
||||
APIIdentifier id = new APIIdentifier(config.getOwner(), config.getName(), config.getVersion());
|
||||
API api = new API(id);
|
||||
try {
|
||||
api.setContext(config.getContext());
|
||||
api.setUrl(config.getVersion());
|
||||
api.setUriTemplates(getURITemplates(config.getEndpoint(),
|
||||
APIConstants.AUTH_APPLICATION_OR_USER_LEVEL_TOKEN));
|
||||
api.setVisibility(APIConstants.API_GLOBAL_VISIBILITY);
|
||||
api.addAvailableTiers(provider.getTiers());
|
||||
api.setEndpointSecured(false);
|
||||
api.setStatus(APIStatus.PUBLISHED);
|
||||
api.setTransports(config.getTransports());
|
||||
|
||||
provider.addAPI(api);
|
||||
} catch (APIManagementException e) {
|
||||
throw new DeviceManagementException("Error occurred while registering the API", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void removeAPI(APIConfig config) throws DeviceManagementException {
|
||||
try {
|
||||
APIProvider provider = config.getProvider();
|
||||
APIIdentifier id = new APIIdentifier(config.getOwner(), config.getName(), config.getVersion());
|
||||
provider.deleteAPI(id);
|
||||
} catch (APIManagementException e) {
|
||||
throw new DeviceManagementException("Error occurred while removing API", e);
|
||||
}
|
||||
}
|
||||
|
||||
private static Set<URITemplate> getURITemplates(String endpoint, String authType) {
|
||||
Set<URITemplate> uriTemplates = new LinkedHashSet<URITemplate>();
|
||||
if (APIConstants.AUTH_NO_AUTHENTICATION.equals(authType)) {
|
||||
for (HTTPMethod method : httpMethods) {
|
||||
URITemplate template = new URITemplate();
|
||||
template.setAuthType(APIConstants.AUTH_NO_AUTHENTICATION);
|
||||
template.setHTTPVerb(method.toString());
|
||||
template.setResourceURI(endpoint);
|
||||
template.setUriTemplate("/*");
|
||||
uriTemplates.add(template);
|
||||
}
|
||||
} else {
|
||||
for (HTTPMethod method : httpMethods) {
|
||||
URITemplate template = new URITemplate();
|
||||
if (HTTPMethod.OPTIONS.equals(method)) {
|
||||
template.setAuthType(APIConstants.AUTH_NO_AUTHENTICATION);
|
||||
} else {
|
||||
template.setAuthType(APIConstants.AUTH_APPLICATION_OR_USER_LEVEL_TOKEN);
|
||||
}
|
||||
template.setHTTPVerb(method.toString());
|
||||
template.setResourceURI(endpoint);
|
||||
template.setUriTemplate("/*");
|
||||
uriTemplates.add(template);
|
||||
}
|
||||
}
|
||||
return uriTemplates;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,109 @@
|
||||
/*
|
||||
* 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.mobile.impl.util;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.w3c.dom.Document;
|
||||
import org.wso2.carbon.device.mgt.common.Device;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.dto.MobileDevice;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Provides utility methods required by the mobile device management bundle.
|
||||
*/
|
||||
public class MobileDeviceManagementUtil {
|
||||
|
||||
private static final Log log = LogFactory.getLog(MobileDeviceManagementUtil.class);
|
||||
private static final String MOBILE_DEVICE_IMEI = "imei";
|
||||
private static final String MOBILE_DEVICE_IMSI = "imsi";
|
||||
private static final String MOBILE_DEVICE_REG_ID = "regId";
|
||||
private static final String MOBILE_DEVICE_VENDOR = "vendor";
|
||||
private static final String MOBILE_DEVICE_OS_VERSION = "osVersion";
|
||||
private static final String MOBILE_DEVICE_MODEL = "model";
|
||||
|
||||
public static Document convertToDocument(File file) throws DeviceManagementException {
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
factory.setNamespaceAware(true);
|
||||
try {
|
||||
DocumentBuilder docBuilder = factory.newDocumentBuilder();
|
||||
return docBuilder.parse(file);
|
||||
} catch (Exception e) {
|
||||
throw new DeviceManagementException(
|
||||
"Error occurred while parsing file, while converting " +
|
||||
"to a org.w3c.dom.Document : " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
private static String getPropertyValue(Device device, String property) {
|
||||
for (Device.Property prop : device.getProperties()) {
|
||||
if (property.equals(prop.getName())) {
|
||||
return prop.getValue();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static Device.Property getProperty(String property, String value) {
|
||||
Device.Property prop = null;
|
||||
if(property != null){
|
||||
prop = new Device.Property();
|
||||
prop.setName(property);
|
||||
prop.setValue(value);
|
||||
return prop;
|
||||
}
|
||||
return prop;
|
||||
}
|
||||
|
||||
public static MobileDevice convertToMobileDevice(Device device) {
|
||||
MobileDevice mobileDevice = null;
|
||||
if (device != null) {
|
||||
mobileDevice = new MobileDevice();
|
||||
mobileDevice.setMobileDeviceId(device.getDeviceIdentifier());
|
||||
mobileDevice.setImei(getPropertyValue(device, MOBILE_DEVICE_IMEI));
|
||||
mobileDevice.setImsi(getPropertyValue(device, MOBILE_DEVICE_IMSI));
|
||||
mobileDevice.setRegId(getPropertyValue(device, MOBILE_DEVICE_REG_ID));
|
||||
mobileDevice.setModel(getPropertyValue(device, MOBILE_DEVICE_MODEL));
|
||||
mobileDevice.setOsVersion(getPropertyValue(device, MOBILE_DEVICE_OS_VERSION));
|
||||
mobileDevice.setVendor(getPropertyValue(device, MOBILE_DEVICE_VENDOR));
|
||||
}
|
||||
return mobileDevice;
|
||||
}
|
||||
|
||||
public static Device convertToDevice(MobileDevice mobileDevice) {
|
||||
Device device = null;
|
||||
if(mobileDevice!=null){
|
||||
device = new Device();
|
||||
List<Device.Property> propertyList = new ArrayList<Device.Property>();
|
||||
propertyList.add(getProperty(MOBILE_DEVICE_IMEI,mobileDevice.getImei()));
|
||||
propertyList.add(getProperty(MOBILE_DEVICE_IMSI,mobileDevice.getImsi()));
|
||||
propertyList.add(getProperty(MOBILE_DEVICE_REG_ID,mobileDevice.getRegId()));
|
||||
propertyList.add(getProperty(MOBILE_DEVICE_MODEL,mobileDevice.getModel()));
|
||||
propertyList.add(getProperty(MOBILE_DEVICE_OS_VERSION,mobileDevice.getOsVersion()));
|
||||
propertyList.add(getProperty(MOBILE_DEVICE_VENDOR,mobileDevice.getVendor()));
|
||||
device.setProperties(propertyList);
|
||||
device.setDeviceIdentifier(mobileDevice.getMobileDeviceId());
|
||||
}
|
||||
return device;
|
||||
}
|
||||
}
|
@ -0,0 +1,83 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Copyright (c) 2014, 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</groupId>
|
||||
<artifactId>key-mgt</artifactId>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.key.mgt.handler.valve</artifactId>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
<packaging>bundle</packaging>
|
||||
<name>WSO2 Carbon - Key Management Handler Valve</name>
|
||||
<description>WSO2 Carbon - Key Management Handler Valve</description>
|
||||
<url>http://wso2.org</url>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.felix</groupId>
|
||||
<artifactId>maven-bundle-plugin</artifactId>
|
||||
<extensions>true</extensions>
|
||||
<configuration>
|
||||
<instructions>
|
||||
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
|
||||
<Bundle-Name>${project.artifactId}</Bundle-Name>
|
||||
<Require-Bundle>org.wso2.carbon.tomcat.patch</Require-Bundle>
|
||||
<Private-Package>
|
||||
org.wso2.carbon.key.mgt.handler.valve.*
|
||||
</Private-Package>
|
||||
<Fragment-Host>tomcat</Fragment-Host>
|
||||
</instructions>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.tomcat.wso2</groupId>
|
||||
<artifactId>tomcat</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.apimgt.core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.apimgt.impl</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.tomcat.ext</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
@ -0,0 +1,37 @@
|
||||
/**
|
||||
* 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.key.mgt.handler.valve;
|
||||
|
||||
public class APIFaultException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private int errorCode;
|
||||
|
||||
public APIFaultException(int errorCode, String message) {
|
||||
super(message);
|
||||
this.errorCode = errorCode;
|
||||
}
|
||||
|
||||
public APIFaultException(int errorCode, String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
this.errorCode = errorCode;
|
||||
}
|
||||
|
||||
public int getErrorCode() {
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
/**
|
||||
* 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.key.mgt.handler.valve;
|
||||
|
||||
public class HandlerConstants {
|
||||
|
||||
public static final String HEADER_AUTHORIZATION = "Authorization";
|
||||
public static final String TOKEN_NAME_BEARER = "Bearer";
|
||||
|
||||
public static final String NO_MATCHING_AUTH_SCHEME = "noMatchedAuthScheme";
|
||||
|
||||
}
|
@ -0,0 +1,138 @@
|
||||
/**
|
||||
* 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.key.mgt.handler.valve;
|
||||
|
||||
import org.apache.axiom.om.OMAbstractFactory;
|
||||
import org.apache.axiom.om.OMElement;
|
||||
import org.apache.axiom.om.OMFactory;
|
||||
import org.apache.axiom.om.OMNamespace;
|
||||
import org.apache.catalina.connector.Response;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.apimgt.api.APIManagementException;
|
||||
import org.wso2.carbon.apimgt.core.APIManagerErrorConstants;
|
||||
import org.wso2.carbon.apimgt.core.authenticate.APITokenValidator;
|
||||
import org.wso2.carbon.apimgt.impl.APIConstants;
|
||||
import org.wso2.carbon.apimgt.impl.dto.APIKeyValidationInfoDTO;
|
||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||
import org.wso2.carbon.identity.base.IdentityException;
|
||||
import org.wso2.carbon.identity.core.util.IdentityUtil;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.IOException;
|
||||
|
||||
public class HandlerUtil {
|
||||
|
||||
private static APIKeyValidationInfoDTO apiKeyValidationDTO;
|
||||
private static final Log log = LogFactory.getLog(HandlerUtil.class);
|
||||
|
||||
/**
|
||||
* Retrieve bearer token form the HTTP header
|
||||
* @param bearerToken Bearer Token extracted out of the corresponding HTTP header
|
||||
*/
|
||||
public static String getAccessToken(String bearerToken) {
|
||||
String accessToken = null;
|
||||
String[] token = bearerToken.split(HandlerConstants.TOKEN_NAME_BEARER);
|
||||
if (token.length > 1 && token[1] != null) {
|
||||
accessToken = token[1].trim();
|
||||
}
|
||||
return accessToken;
|
||||
}
|
||||
|
||||
public static String getAPIVersion(HttpServletRequest request) {
|
||||
int contextStartsIndex = (request.getRequestURI()).indexOf(request.getContextPath()) + 1;
|
||||
int length = request.getContextPath().length();
|
||||
String afterContext = (request.getRequestURI()).substring(contextStartsIndex + length);
|
||||
int SlashIndex = afterContext.indexOf(("/"));
|
||||
|
||||
if (SlashIndex != -1) {
|
||||
return afterContext.substring(0, SlashIndex);
|
||||
} else {
|
||||
return afterContext;
|
||||
}
|
||||
}
|
||||
|
||||
public static void handleNoMatchAuthSchemeCallForRestService(Response response,String httpVerb, String reqUri,
|
||||
String version, String context ) {
|
||||
String errMsg = "Resource is not matched for HTTP Verb " + httpVerb + ". API context " + context +
|
||||
",version " + version + ", request " + reqUri;
|
||||
APIFaultException e = new APIFaultException( APIManagerErrorConstants.API_AUTH_INCORRECT_API_RESOURCE, errMsg);
|
||||
String faultPayload = getFaultPayload(e, APIManagerErrorConstants.API_SECURITY_NS,
|
||||
APIManagerErrorConstants.API_SECURITY_NS_PREFIX).toString();
|
||||
handleRestFailure(response, faultPayload);
|
||||
}
|
||||
|
||||
public static boolean doAuthenticate(String context, String version, String accessToken,
|
||||
String requiredAuthenticationLevel, String clientDomain)
|
||||
throws APIManagementException,
|
||||
APIFaultException {
|
||||
|
||||
if (APIConstants.AUTH_NO_AUTHENTICATION.equals(requiredAuthenticationLevel)) {
|
||||
return true;
|
||||
}
|
||||
APITokenValidator tokenValidator = new APITokenValidator();
|
||||
apiKeyValidationDTO = tokenValidator.validateKey(context, version, accessToken,
|
||||
requiredAuthenticationLevel, clientDomain);
|
||||
if (apiKeyValidationDTO.isAuthorized()) {
|
||||
String userName = apiKeyValidationDTO.getEndUserName();
|
||||
PrivilegedCarbonContext.getThreadLocalCarbonContext()
|
||||
.setUsername(apiKeyValidationDTO.getEndUserName());
|
||||
try {
|
||||
PrivilegedCarbonContext.getThreadLocalCarbonContext()
|
||||
.setTenantId(IdentityUtil.getTenantIdOFUser(userName));
|
||||
} catch (IdentityException e) {
|
||||
log.error("Error while retrieving Tenant Id", e);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
throw new APIFaultException(apiKeyValidationDTO.getValidationStatus(),
|
||||
"Access failure for API: " + context + ", version: " +
|
||||
version + " with key: " + accessToken);
|
||||
}
|
||||
}
|
||||
|
||||
public static void handleRestFailure(Response response, String payload) {
|
||||
response.setStatus(403);
|
||||
response.setContentType("application/xml");
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
try {
|
||||
response.getWriter().write(payload);
|
||||
} catch (IOException e) {
|
||||
log.error("Error in sending fault response", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static OMElement getFaultPayload(APIFaultException exception, String FaultNS,
|
||||
String FaultNSPrefix) {
|
||||
OMFactory fac = OMAbstractFactory.getOMFactory();
|
||||
OMNamespace ns = fac.createOMNamespace(FaultNS, FaultNSPrefix);
|
||||
OMElement payload = fac.createOMElement("fault", ns);
|
||||
|
||||
OMElement errorCode = fac.createOMElement("code", ns);
|
||||
errorCode.setText(String.valueOf(exception.getErrorCode()));
|
||||
OMElement errorMessage = fac.createOMElement("message", ns);
|
||||
errorMessage.setText(APIManagerErrorConstants.getFailureMessage(exception.getErrorCode()));
|
||||
OMElement errorDetail = fac.createOMElement("description", ns);
|
||||
errorDetail.setText(exception.getMessage());
|
||||
|
||||
payload.addChild(errorCode);
|
||||
payload.addChild(errorMessage);
|
||||
payload.addChild(errorDetail);
|
||||
return payload;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,141 @@
|
||||
/**
|
||||
* 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.key.mgt.handler.valve;
|
||||
|
||||
import org.apache.catalina.connector.Request;
|
||||
import org.apache.catalina.connector.Response;
|
||||
import org.apache.catalina.valves.ValveBase;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.apimgt.api.APIManagementException;
|
||||
import org.wso2.carbon.apimgt.core.authenticate.APITokenValidator;
|
||||
import org.wso2.carbon.apimgt.core.gateway.APITokenAuthenticator;
|
||||
import org.wso2.carbon.apimgt.impl.APIConstants;
|
||||
import org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO;
|
||||
import org.wso2.carbon.apimgt.impl.utils.APIUtil;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import java.io.IOException;
|
||||
import java.util.Enumeration;
|
||||
|
||||
public class OAuthTokenValidatorValve extends ValveBase {
|
||||
|
||||
private static final Log log = LogFactory.getLog(OAuthTokenValidatorValve.class);
|
||||
|
||||
APITokenAuthenticator authenticator;
|
||||
|
||||
public OAuthTokenValidatorValve() {
|
||||
authenticator = new APITokenAuthenticator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(Request request, Response response) throws java.io.IOException, javax.servlet.ServletException {
|
||||
String context = request.getContextPath();
|
||||
if (context == null || context.equals("")) {
|
||||
//Invoke the next valve in handler chain.
|
||||
getNext().invoke(request, response);
|
||||
return;
|
||||
}
|
||||
|
||||
boolean contextExist;
|
||||
Boolean contextValueInCache = null;
|
||||
if (APIUtil.getAPIContextCache().get(context) != null) {
|
||||
contextValueInCache = Boolean.parseBoolean(APIUtil.getAPIContextCache().get(context).toString());
|
||||
}
|
||||
|
||||
if (contextValueInCache != null) {
|
||||
contextExist = contextValueInCache;
|
||||
} else {
|
||||
contextExist = ApiMgtDAO.isContextExist(context);
|
||||
APIUtil.getAPIContextCache().put(context, contextExist);
|
||||
}
|
||||
|
||||
if (!contextExist) {
|
||||
getNext().invoke(request, response);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
handleWSDLGetRequest(request, response, context);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ServletException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
String authHeader = request.getHeader(APIConstants.OperationParameter.AUTH_PARAM_NAME);
|
||||
String accessToken = null;
|
||||
|
||||
/* Authenticate*/
|
||||
try {
|
||||
if (authHeader != null) {
|
||||
accessToken = HandlerUtil.getAccessToken(authHeader);
|
||||
} else {
|
||||
// There can be some API published with None Auth Type
|
||||
/*
|
||||
* throw new
|
||||
* APIFaultException(APIConstants.KeyValidationStatus
|
||||
* .API_AUTH_INVALID_CREDENTIALS,
|
||||
* "Invalid format for Authorization header. Expected 'Bearer <token>'"
|
||||
* );
|
||||
*/
|
||||
}
|
||||
|
||||
String apiVersion = HandlerUtil.getAPIVersion(request);
|
||||
String domain = request.getHeader(APITokenValidator.getAPIManagerClientDomainHeader());
|
||||
String authLevel = authenticator.getResourceAuthenticationScheme(context,
|
||||
apiVersion,
|
||||
request.getRequestURI(),
|
||||
request.getMethod());
|
||||
if (HandlerConstants.NO_MATCHING_AUTH_SCHEME.equals(authLevel)) {
|
||||
HandlerUtil.handleNoMatchAuthSchemeCallForRestService(response,
|
||||
request.getMethod(), request.getRequestURI(),
|
||||
apiVersion, context);
|
||||
return;
|
||||
} else {
|
||||
HandlerUtil.doAuthenticate(context, apiVersion, accessToken, authLevel, domain);
|
||||
}
|
||||
} catch (APIManagementException e) {
|
||||
//ignore
|
||||
} catch (APIFaultException e) {
|
||||
log.error("Error occurred while key validation", e);
|
||||
return;
|
||||
}
|
||||
|
||||
getNext().invoke(request, response);
|
||||
}
|
||||
|
||||
private void handleWSDLGetRequest(Request request, Response response,
|
||||
String context) throws IOException, ServletException {
|
||||
if (request.getMethod().equals("GET")) {
|
||||
// TODO:Need to get these paths from a config file.
|
||||
if (request.getRequestURI().matches(context + "/[^/]*/services")) {
|
||||
getNext().invoke(request, response);
|
||||
return;
|
||||
}
|
||||
Enumeration<String> params = request.getParameterNames();
|
||||
String paramName;
|
||||
while (params.hasMoreElements()) {
|
||||
paramName = params.nextElement();
|
||||
if (paramName.endsWith("wsdl") || paramName.endsWith("wadl")) {
|
||||
getNext().invoke(request, response);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,117 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Copyright (c) 2014, 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</groupId>
|
||||
<artifactId>wso2cdm-parent</artifactId>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>key-mgt</artifactId>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
<packaging>pom</packaging>
|
||||
<name>WSO2 Carbon - Device Management Component</name>
|
||||
<url>http://wso2.org</url>
|
||||
|
||||
<modules>
|
||||
<module>org.wso2.carbon.key.mgt.handler.valve</module>
|
||||
</modules>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.osgi</groupId>
|
||||
<artifactId>org.eclipse.osgi</artifactId>
|
||||
<version>3.8.1.v20120830-144521</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.equinox</groupId>
|
||||
<artifactId>org.eclipse.equinox.common</artifactId>
|
||||
<version>3.6.100.v20120522-1841</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.logging</artifactId>
|
||||
<version>4.3.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.device.mgt.common</artifactId>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.osgi</groupId>
|
||||
<artifactId>org.eclipse.osgi.services</artifactId>
|
||||
<version>3.3.100.v20120522-1822</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.apimgt.core</artifactId>
|
||||
<version>${apim.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.apimgt.impl</artifactId>
|
||||
<version>${apim.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.tomcat.wso2</groupId>
|
||||
<artifactId>tomcat</artifactId>
|
||||
<version>${orbit.version.tomcat}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.tomcat.ext</artifactId>
|
||||
<version>4.3.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<build>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.felix</groupId>
|
||||
<artifactId>maven-scr-plugin</artifactId>
|
||||
<version>1.7.2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>generate-scr-scrdescriptor</id>
|
||||
<goals>
|
||||
<goal>scr</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
</build>
|
||||
<properties>
|
||||
<orbit.version.h2.engine>1.2.140.wso2v3</orbit.version.h2.engine>
|
||||
<apim.version>1.2.1</apim.version>
|
||||
<orbit.version.tomcat>7.0.52.wso2v5</orbit.version.tomcat>
|
||||
</properties>
|
||||
</project>
|
@ -1,34 +0,0 @@
|
||||
package cdm.api.android;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.*;
|
||||
import org.wso2.carbon.device.mgt.common.Device;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.Response;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@Produces({"application/json", "application/xml"})
|
||||
@Consumes({"application/json", "application/xml"})
|
||||
public class Test {
|
||||
|
||||
@GET
|
||||
public List<org.wso2.carbon.device.mgt.common.Device> getAllDevices() {
|
||||
|
||||
Device dev = new Device();
|
||||
dev.setName("test1");
|
||||
dev.setDateOfEnrolment(11111111L);
|
||||
dev.setDateOfLastUpdate(992093209L);
|
||||
dev.setDescription("sassasaas");
|
||||
|
||||
ArrayList<Device> listdevices = new ArrayList<Device>();
|
||||
listdevices.add(dev);
|
||||
|
||||
return listdevices;
|
||||
}
|
||||
|
||||
}
|
@ -1,38 +1,11 @@
|
||||
CREATE TABLE IF NOT EXISTS MBL_OS_VERSION
|
||||
(
|
||||
VERSION_ID INT NOT NULL AUTO_INCREMENT,
|
||||
NAME VARCHAR(45) NULL DEFAULT NULL,
|
||||
PRIMARY KEY (VERSION_ID)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS MBL_DEVICE_MODEL
|
||||
(
|
||||
MODEL_ID INT NOT NULL AUTO_INCREMENT,
|
||||
MODEL VARCHAR(45) NULL DEFAULT NULL,
|
||||
PRIMARY KEY (MODEL_ID)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS MBL_VENDOR
|
||||
(
|
||||
VENDOR_ID INT NOT NULL AUTO_INCREMENT,
|
||||
VENDOR VARCHAR(45) NULL DEFAULT NULL,
|
||||
PRIMARY KEY (VENDOR_ID)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS MBL_DEVICE
|
||||
(
|
||||
MOBILE_DEVICE_ID VARCHAR(45) NOT NULL,
|
||||
REG_ID VARCHAR(45) NOT NULL,
|
||||
IMEI VARCHAR(45) NOT NULL,
|
||||
IMSI VARCHAR(45) NOT NULL,
|
||||
OS_VERSION_ID INT NOT NULL,
|
||||
DEVICE_MODEL_ID INT NOT NULL,
|
||||
VENDOR_ID INT NOT NULL,
|
||||
PRIMARY KEY (MOBILE_DEVICE_ID),
|
||||
CONSTRAINT fk_DEVICE_OS_VERSION1 FOREIGN KEY (OS_VERSION_ID )
|
||||
REFERENCES MBL_OS_VERSION (VERSION_ID ) ON DELETE NO ACTION ON UPDATE NO ACTION,
|
||||
CONSTRAINT fk_DEVICE_DEVICE_MODEL2 FOREIGN KEY (DEVICE_MODEL_ID )
|
||||
REFERENCES MBL_DEVICE_MODEL (MODEL_ID ) ON DELETE NO ACTION ON UPDATE NO ACTION,
|
||||
CONSTRAINT fk_DEVICE_VENDOR1 FOREIGN KEY (VENDOR_ID )
|
||||
REFERENCES MBL_VENDOR (VENDOR_ID ) ON DELETE NO ACTION ON UPDATE NO ACTION
|
||||
IMSI VARCHAR(45),
|
||||
OS_VERSION VARCHAR(45) NOT NULL,
|
||||
DEVICE_MODEL VARCHAR(45) NOT NULL,
|
||||
VENDOR VARCHAR(45) NOT NULL,
|
||||
PRIMARY KEY (MOBILE_DEVICE_ID)
|
||||
);
|
Loading…
Reference in new issue