Merge pull request #524 from geethkokila/release-2.0.x

Removing two unnecessary classes from the project and adding java doc…
4.x.x
Rasika Perera 8 years ago committed by GitHub
commit 5d5f76ca21

@ -1,26 +0,0 @@
/*
* 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.apimgt.handlers.invoker;
public class RESTConstants {
static String REST_CLIENT_CONFIG_ELEMENT = "restClientConfiguration";
static String REST_CLIENT_MAX_TOTAL_CONNECTIONS = "maxTotalConnections";
static String REST_CLIENT_MAX_CONNECTIONS_PER_ROUTE = "maxConnectionsPerRoute";
static String REST_CLIENT_CONNECTION_TIMEOUT = "connectionTimeout";
static String REST_CLIENT_SOCKET_TIMEOUT = "socketTimeout";
}

@ -1,156 +0,0 @@
/*
* 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.apimgt.handlers.utils;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.util.AXIOMUtil;
import org.apache.commons.io.FileUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.utils.CarbonUtils;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamException;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
public class CoreUtils {
private static final Log log = LogFactory.getLog(CoreUtils.class);
private static String host = "localhost";
private static int httpsPort = 9443;
private static String username = "admin";
private static String password = "admin";
private static String iosVerifyEndpoint = "/api/certificate-mgt/v1.0/admin/certificates/verify/ios";
private static String androidVerifyEndpoint = "/api/certificate-mgt/v1.0/admin/certificates/verify/android";
// /**
// * Reading configurations from api-filter-config.xml file
// *
// * @return ArrayList of api contexts
// */
// public static ArrayList<String> readApiFilterList() {
// ArrayList<String> apiList = new ArrayList<String>();
// String carbonConfigDirPath = CarbonUtils.getCarbonConfigDirPath();
// String apiFilterConfigPath = carbonConfigDirPath + File.separator +
// AuthConstants.AUTH_CONFIGURATION_FILE_NAME;
// File configFile = new File(apiFilterConfigPath);
//
// try {
// String configContent = FileUtils.readFileToString(configFile);
// OMElement configElement = AXIOMUtil.stringToOM(configContent);
// Iterator beans = configElement.getChildrenWithName(
// new QName("http://www.springframework.org/schema/beans", "bean"));
//
// while (beans.hasNext()) {
// OMElement bean = (OMElement) beans.next();
// String beanId = bean.getAttributeValue(new QName(null, "id"));
// if (beanId.equals(AuthConstants.API_FILTER_CONFIG_ELEMENT)) {
// Iterator beanProps = bean.getChildrenWithName(
// new QName("http://www.springframework.org/schema/beans", "property"));
//
// while (beanProps.hasNext()) {
// OMElement beanProp = (OMElement) beanProps.next();
// String beanName = beanProp.getAttributeValue(new QName(null, "name"));
// if (AuthConstants.API_LIST_PROPERTY.equals(beanName)) {
// Iterator apiListSet = ((OMElement) beanProp.getChildrenWithLocalName("set").next())
// .getChildrenWithLocalName("value");
// while (apiListSet.hasNext()) {
// String apiContext = ((OMElement) apiListSet.next()).getText();
// apiList.add(apiContext);
// CoreUtils.debugLog(log, "Adding security to api: ", apiContext);
// }
// } else if (AuthConstants.HOST.equals(beanName)) {
// String value = beanProp.getAttributeValue(new QName(null, "value"));
// host = value;
// } else if (AuthConstants.HTTPS_PORT.equals(beanName)) {
// String value = beanProp.getAttributeValue(new QName(null, "value"));
// if (value != null && !value.trim().equals("")) {
// httpsPort = Integer.parseInt(value);
// }
// } else if (AuthConstants.USERNAME.equals(beanName)) {
// String value = beanProp.getAttributeValue(new QName(null, "value"));
// username = value;
// } else if (AuthConstants.PASSWORD.equals(beanName)) {
// String value = beanProp.getAttributeValue(new QName(null, "value"));
// password = value;
// } else if (AuthConstants.IOS_VERIFY_ENDPOINT.equals(beanName)) {
// String value = beanProp.getAttributeValue(new QName(null, "value"));
// iosVerifyEndpoint = value;
// } else if (AuthConstants.ANDROID_VERIFY_ENDPOINT.equals(beanName)) {
// String value = beanProp.getAttributeValue(new QName(null, "value"));
// androidVerifyEndpoint = value;
// }
// }
// }
// }
// } catch (IOException e) {
// log.error("Error in reading api filter settings", e);
// } catch (XMLStreamException e) {
// log.error("Error in reading api filter settings", e);
// }
// return apiList;
// }
//
// /**
// * Universal debug log function
// *
// * @param logger Log object specific to the class
// * @param message initial debug log message
// * @param vars optional strings to be appended for the log
// */
// public static void debugLog(Log logger, String message, Object ... vars) {
// if(logger.isDebugEnabled()) {
// if (vars.length < 1) {
// logger.debug(message);
// return;
// }
// StringBuilder stringBuilder = new StringBuilder();
// stringBuilder.append(message);
// for (Object var : vars) {
// stringBuilder.append(var.toString());
// }
// logger.debug(stringBuilder.toString());
// }
// }
public static String getHost() {
return host;
}
public static int getHttpsPort() {
return httpsPort;
}
public static String getUsername() {
return username;
}
public static String getPassword() {
return password;
}
public static String getIosVerifyEndpoint() {
return iosVerifyEndpoint;
}
public static String getAndroidVerifyEndpoint() {
return androidVerifyEndpoint;
}
}

@ -19,6 +19,9 @@
package org.wso2.carbon.apimgt.handlers;
/**
* Error handling class for the apimgt handler.
*/
public class APIMCertificateMGTException extends Exception{
private static final long serialVersionUID = -37676242646464497L;

@ -40,7 +40,7 @@ import java.util.HashMap;
import java.util.Map;
/**
* Synapse gateway handler for API authentication
* Synapse gateway handler for API authentication.
*/
public class AuthenticationHandler extends AbstractHandler {
private static final Log log = LogFactory.getLog(AuthenticationHandler.class);
@ -60,6 +60,11 @@ public class AuthenticationHandler extends AbstractHandler {
this.iotServerConfiguration = Utils.initConfig();
}
/**
* Handling the message and checking the security.
* @param messageContext
* @return
*/
@Override
public boolean handleRequest(org.apache.synapse.MessageContext messageContext) {
org.apache.axis2.context.MessageContext axisMC = ((Axis2MessageContext) messageContext).getAxis2MessageContext();

@ -19,10 +19,16 @@
package org.wso2.carbon.apimgt.handlers.beans;
/**
* This class keeps the certificate data.
*/
public class Certificate {
// public key of the certificate
private String pem;
// Tenant id
private int tenantId;
// Serial of the certificate.
private String serial;
public String getPem() {

@ -19,11 +19,18 @@
package org.wso2.carbon.apimgt.handlers.beans;
/**
* This class holds the DCR endpoints data to create an application.
*/
public class DCR {
// Owner of the application
private String owner;
// Client name
private String clientName;
// Oauth Grant type
private String grantType;
// Scope of the token
private String tokenScope;
public String getOwner() {

@ -19,6 +19,9 @@
package org.wso2.carbon.apimgt.handlers.beans;
/**
* This class holds the data returned from the backend after the certificate was authenticated.
*/
public class ValidationResponce {
private String JWTToken; // X-JWT-Assertion

@ -25,6 +25,10 @@ import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlValue;
import java.util.List;
/**
* This class initialize the iot-api-config.xml and hold the values, in order to be read from the relevant classes. This
* get initialized at the start of the server when apis get loaded.
*/
@XmlRootElement(name = "ServerConfiguration")
public class IOTServerConfiguration {

@ -17,10 +17,7 @@
*/
package org.wso2.carbon.apimgt.handlers.invoker;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.util.AXIOMUtil;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@ -32,17 +29,10 @@ import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.util.EntityUtils;
import org.wso2.carbon.apimgt.handlers.utils.AuthConstants;
import org.wso2.carbon.apimgt.handlers.utils.CoreUtils;
import org.wso2.carbon.utils.CarbonUtils;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamException;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.util.Iterator;
import java.util.Map;
public class RESTInvoker {
@ -61,65 +51,8 @@ public class RESTInvoker {
configureHttpClient();
}
// private void parseConfiguration() {
// String carbonConfigDirPath = CarbonUtils.getCarbonConfigDirPath();
// String apiFilterConfigPath = carbonConfigDirPath + File.separator +
// AuthConstants.AUTH_CONFIGURATION_FILE_NAME;
// File configFile = new File(apiFilterConfigPath);
//
// try {
// String configContent = FileUtils.readFileToString(configFile);
// OMElement configElement = AXIOMUtil.stringToOM(configContent);
// Iterator beans = configElement.getChildrenWithName(
// new QName("http://www.springframework.org/schema/beans", "bean"));
//
// while (beans.hasNext()) {
// OMElement bean = (OMElement) beans.next();
// String beanId = bean.getAttributeValue(new QName(null, "id"));
// if (beanId.equals(RESTConstants.REST_CLIENT_CONFIG_ELEMENT)) {
// Iterator beanProps = bean.getChildrenWithName(
// new QName("http://www.springframework.org/schema/beans", "property"));
//
// while (beanProps.hasNext()) {
// OMElement beanProp = (OMElement) beanProps.next();
// String beanName = beanProp.getAttributeValue(new QName(null, "name"));
// if (RESTConstants.REST_CLIENT_MAX_TOTAL_CONNECTIONS.equals(beanName)) {
// String value = beanProp.getAttributeValue(new QName(null, "value"));
// if (value != null && !value.trim().equals("")) {
// maxTotalConnections = Integer.parseInt(value);
// }
// CoreUtils.debugLog(log, "Max total http connections ", maxTotalConnections);
// } else if (RESTConstants.REST_CLIENT_MAX_CONNECTIONS_PER_ROUTE.equals(beanName)) {
// String value = beanProp.getAttributeValue(new QName(null, "value"));
// if (value != null && !value.trim().equals("")) {
// maxTotalConnectionsPerRoute = Integer.parseInt(value);
// }
// CoreUtils.debugLog(log, "Max total client connections per route ", maxTotalConnectionsPerRoute);
// } else if (RESTConstants.REST_CLEINT_CONNECTION_TIMEOUT.equals(beanName)) {
// String value = beanProp.getAttributeValue(new QName(null, "value"));
// if (value != null && !value.trim().equals("")) {
// connectionTimeout = Integer.parseInt(value);
// }
// } else if (RESTConstants.REST_CLEINT_SOCKET_TIMEOUT.equals(beanName)) {
// String value = beanProp.getAttributeValue(new QName(null, "value"));
// if (value != null && !value.trim().equals("")) {
// socketTimeout = Integer.parseInt(value);
// }
// }
// }
// }
// }
// } catch (XMLStreamException e) {
// log.error("Error in processing http connection settings, using default settings", e);
// } catch (IOException e) {
// log.error("Error in processing http connection settings, using default settings", e);
// }
// }
private void configureHttpClient() {
// parseConfiguration();
RequestConfig defaultRequestConfig = RequestConfig.custom()
.setExpectContinueEnabled(true)
.setConnectTimeout(connectionTimeout)
@ -140,11 +73,7 @@ public class RESTInvoker {
"maxConnectionsPerRoute = " + maxTotalConnectionsPerRoute +
"connectionTimeout = " + connectionTimeout);
}
//
// CoreUtils.debugLog(log, "REST client initialized with ",
// "maxTotalConnection = ", maxTotalConnections,
// "maxConnectionsPerRoute = ", maxTotalConnectionsPerRoute,
// "connectionTimeout = ", connectionTimeout);
}
public void closeHttpClient() {

@ -17,19 +17,22 @@
*/
package org.wso2.carbon.apimgt.handlers.utils;
/**
* This initializes the constance.
*/
public class AuthConstants {
public static final String SEC_FAULT = "SECURITY_VALIDATION_FAILURE";
public static final String HTTPS = "https";
public static final String WSSE = "wsse";
public static final String AUTH_CONFIGURATION_FILE_NAME = "api-filter-config.xml";
public static final String API_FILTER_CONFIG_ELEMENT = "apiFilterConfig";
public static final String API_LIST_PROPERTY = "apiList";
public static final String HOST = "host";
public static final String HTTPS_PORT = "httpsPort";
public static final String USERNAME = "username";
public static final String PASSWORD = "password";
public static final String IOS_VERIFY_ENDPOINT = "ios-verify-endpoint";
public static final String ANDROID_VERIFY_ENDPOINT = "android-verify-endpoint";
// public static final String SEC_FAULT = "SECURITY_VALIDATION_FAILURE";
// public static final String HTTPS = "https";
// public static final String WSSE = "wsse";
// public static final String AUTH_CONFIGURATION_FILE_NAME = "api-filter-config.xml";
// public static final String API_FILTER_CONFIG_ELEMENT = "apiFilterConfig";
// public static final String API_LIST_PROPERTY = "apiList";
// public static final String HOST = "host";
// public static final String HTTPS_PORT = "httpsPort";
// public static final String USERNAME = "username";
// public static final String PASSWORD = "password";
// public static final String IOS_VERIFY_ENDPOINT = "ios-verify-endpoint";
// public static final String ANDROID_VERIFY_ENDPOINT = "android-verify-endpoint";
public static final String MDM_SIGNATURE = "mdm-signature";
public static final String PROXY_MUTUAL_AUTH_HEADER = "proxy-mutual-auth-header";
public static final String ENCODED_PEM = "encoded-pem";

@ -56,6 +56,10 @@ public class Utils {
private static String clientId;
private static String clientSecret;
/**
* This method initializes the iot-api-config.xml file.
* @return
*/
public static IOTServerConfiguration initConfig() {
try {
@ -74,6 +78,12 @@ public class Utils {
}
}
/**
* This class build the iot-api-config.xml file.
* @param file
* @return
* @throws APIMCertificateMGTException
*/
public static Document convertToDocument(File file) throws APIMCertificateMGTException {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
@ -87,6 +97,12 @@ public class Utils {
}
}
/**
* This class get the access token from the key manager.
* @param iotServerConfiguration
* @return
* @throws APIMCertificateMGTException
*/
public static String getAccessToken(IOTServerConfiguration iotServerConfiguration)
throws APIMCertificateMGTException {
try {
@ -120,6 +136,11 @@ public class Utils {
}
}
/**
* This method register an application to get the client key and secret.
* @param iotServerConfiguration
* @throws APIMCertificateMGTException
*/
private static void getClientSecretes(IOTServerConfiguration iotServerConfiguration)
throws APIMCertificateMGTException {
try {
Loading…
Cancel
Save