You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by ud...@apache.org on 2014/12/05 17:23:22 UTC
[3/6] stratos git commit: creating token at application deployment
creating token at application deployment
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/96146274
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/96146274
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/96146274
Branch: refs/heads/master
Commit: 96146274841a2b6f2a63dbc0a0b6ac5225ff95ba
Parents: 61b1d31
Author: Udara Liyanage <ud...@wso2.com>
Authored: Thu Dec 4 21:07:08 2014 +0530
Committer: Udara Liyanage <ud...@wso2.com>
Committed: Fri Dec 5 19:31:33 2014 +0530
----------------------------------------------------------------------
.../org.apache.stratos.autoscaler/pom.xml | 16 +-
.../apache/stratos/autoscaler/Constants.java | 4 +
.../parser/DefaultApplicationParser.java | 49 ++++-
...ntityApplicationManagementServiceClient.java | 196 ++++++++++++++++++
.../stratos/autoscaler/client/Utility.java | 86 ++++++++
.../client/oAuthAdminServiceClient.java | 97 +++++++++
components/org.apache.stratos.manager/pom.xml | 15 --
...ntityApplicationManagementServiceClient.java | 202 -------------------
.../apache/stratos/manager/client/Utility.java | 86 --------
.../manager/client/oAuthAdminServiceClient.java | 96 ---------
.../org.apache.stratos.metadataservice/pom.xml | 7 +-
.../rest/endpoint/api/StratosApiV41Utils.java | 29 +--
.../config/all/repository/conf/autoscaler.xml | 5 +
13 files changed, 451 insertions(+), 437 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/stratos/blob/96146274/components/org.apache.stratos.autoscaler/pom.xml
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/pom.xml b/components/org.apache.stratos.autoscaler/pom.xml
index 394784e..7ae4dd2 100644
--- a/components/org.apache.stratos.autoscaler/pom.xml
+++ b/components/org.apache.stratos.autoscaler/pom.xml
@@ -188,7 +188,21 @@
<artifactId>org.apache.stratos.metadata.client</artifactId>
<version>${project.version}</version>
</dependency>
-
+ <dependency>
+ <groupId>org.wso2.carbon</groupId>
+ <artifactId>org.wso2.carbon.identity.oauth</artifactId>
+ <version>4.2.3</version>
+ </dependency>
+ <dependency>
+ <groupId>org.wso2.carbon</groupId>
+ <artifactId>org.wso2.carbon.identity.oauth.stub</artifactId>
+ <version>4.2.3</version>
+ </dependency>
+ <dependency>
+ <groupId>org.wso2.carbon</groupId>
+ <artifactId>org.wso2.carbon.identity.application.mgt.stub</artifactId>
+ <version>4.2.0</version>
+ </dependency>
</dependencies>
http://git-wip-us.apache.org/repos/asf/stratos/blob/96146274/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/Constants.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/Constants.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/Constants.java
index 7ca6282..837e504 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/Constants.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/Constants.java
@@ -84,4 +84,8 @@ public class Constants {
public static final String CARTRIDGE = "cartridge";
+ public static final int IS_DEFAULT_PORT = 9443;
+ public static final String OAUTH_SERVICE_SFX = "services/OAuthAdminService";
+ public static final String IDENTITY_APPLICATION_SERVICE_SFX = "services/IdentityApplicationManagementService";
+ public static final String TOKEN_ENDPOINT_SFX = "oauth2/token";
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/96146274/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/parser/DefaultApplicationParser.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/parser/DefaultApplicationParser.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/parser/DefaultApplicationParser.java
index 8078ebd..5472163 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/parser/DefaultApplicationParser.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/parser/DefaultApplicationParser.java
@@ -19,6 +19,9 @@
package org.apache.stratos.autoscaler.applications.parser;
+import org.apache.amber.oauth2.common.exception.OAuthProblemException;
+import org.apache.amber.oauth2.common.exception.OAuthSystemException;
+import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -26,27 +29,30 @@ import org.apache.stratos.autoscaler.applications.ApplicationUtils;
import org.apache.stratos.autoscaler.applications.ClusterInformation;
import org.apache.stratos.autoscaler.applications.MTClusterInformation;
import org.apache.stratos.autoscaler.applications.STClusterInformation;
+import org.apache.stratos.autoscaler.applications.payload.PayloadData;
import org.apache.stratos.autoscaler.applications.pojo.*;
import org.apache.stratos.autoscaler.client.CloudControllerClient;
+import org.apache.stratos.autoscaler.client.IdentityApplicationManagementServiceClient;
+import org.apache.stratos.autoscaler.client.oAuthAdminServiceClient;
+import org.apache.stratos.autoscaler.exception.AutoScalerException;
import org.apache.stratos.autoscaler.exception.application.ApplicationDefinitionException;
import org.apache.stratos.autoscaler.exception.cartridge.CartridgeInformationException;
import org.apache.stratos.autoscaler.pojo.ServiceGroup;
import org.apache.stratos.autoscaler.registry.RegistryManager;
import org.apache.stratos.cloud.controller.stub.domain.CartridgeInfo;
+import org.apache.stratos.common.Properties;
import org.apache.stratos.common.Property;
import org.apache.stratos.messaging.domain.applications.Application;
import org.apache.stratos.messaging.domain.applications.ClusterDataHolder;
import org.apache.stratos.messaging.domain.applications.DependencyOrder;
import org.apache.stratos.messaging.domain.applications.Group;
-import org.apache.stratos.common.Properties;
-
-import java.util.*;
+import org.wso2.carbon.identity.oauth.stub.OAuthAdminServiceException;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
-
-import org.apache.commons.codec.binary.Base64;
+import java.rmi.RemoteException;
+import java.util.*;
/**
* Default implementation of the Application Parser. One Application should be processed by one
@@ -750,7 +756,6 @@ public class DefaultApplicationParser implements ApplicationParser {
ApplicationClusterContext appClusterCtxt = createApplicationClusterContext(appId, groupName, cartridgeInfo,
key, tenantId, subscribableInfoCtxt.getRepoUrl(), subscribableCtxt.getAlias(),
clusterId, hostname, subscribableInfoCtxt.getDeploymentPolicy(), false, subscribableInfoCtxt.getDependencyAliases(), subscribableInfoCtxt.getProperties());
-
appClusterCtxt.setAutoscalePolicyName(subscribableInfoCtxt.getAutoscalingPolicy());
appClusterCtxt.setProperties(subscribableInfoCtxt.getProperties());
this.applicationClusterContexts.add(appClusterCtxt);
@@ -787,12 +792,40 @@ public class DefaultApplicationParser implements ApplicationParser {
throws ApplicationDefinitionException {
// Create text payload
- String textPayload = ApplicationUtils.createPayload(appId, groupName, cartridgeInfo, subscriptionKey, tenantId, clusterId,
- hostname, repoUrl, alias, null, dependencyAliases, properties).toString();
+ PayloadData payloadData = ApplicationUtils.createPayload(appId, groupName, cartridgeInfo, subscriptionKey, tenantId, clusterId,
+ hostname, repoUrl, alias, null, dependencyAliases, properties);
+ payloadData.add("TOKEN", createToken(appId));
+ String textPayload = payloadData.toString();
return new ApplicationClusterContext(cartridgeInfo.getType(), clusterId, hostname, textPayload, deploymentPolicy, isLB);
}
+ public String createToken(String appid) throws AutoScalerException {
+ String token = null;
+ String ouathAppName = appid + Math.random();
+ String serviceProviderName = ouathAppName;
+
+ try {
+ oAuthAdminServiceClient.getServiceClient().registerOauthApplication(ouathAppName);
+ } catch (RemoteException e) {
+ throw new AutoScalerException(e);
+ } catch (OAuthAdminServiceException e) {
+ throw new AutoScalerException(e);
+ }
+ try {
+ token = IdentityApplicationManagementServiceClient.getServiceClient().createServiceProvider(ouathAppName, serviceProviderName, appid);
+ } catch (RemoteException e) {
+ throw new AutoScalerException(e);
+ } catch (OAuthAdminServiceException e) {
+ e.printStackTrace();
+ } catch (OAuthProblemException e) {
+ throw new AutoScalerException(e);
+ } catch (OAuthSystemException e) {
+ throw new AutoScalerException(e);
+ }
+
+ return token;
+ }
private CartridgeInfo getCartridge (String cartridgeType) throws ApplicationDefinitionException {
try {
http://git-wip-us.apache.org/repos/asf/stratos/blob/96146274/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/client/IdentityApplicationManagementServiceClient.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/client/IdentityApplicationManagementServiceClient.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/client/IdentityApplicationManagementServiceClient.java
new file mode 100644
index 0000000..deccaf3
--- /dev/null
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/client/IdentityApplicationManagementServiceClient.java
@@ -0,0 +1,196 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF 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.apache.stratos.autoscaler.client;
+
+import org.apache.amber.oauth2.client.OAuthClient;
+import org.apache.amber.oauth2.client.URLConnectionClient;
+import org.apache.amber.oauth2.client.request.OAuthClientRequest;
+import org.apache.amber.oauth2.client.response.OAuthClientResponse;
+import org.apache.amber.oauth2.common.exception.OAuthProblemException;
+import org.apache.amber.oauth2.common.exception.OAuthSystemException;
+import org.apache.amber.oauth2.common.message.types.GrantType;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.transport.http.HTTPConstants;
+import org.apache.commons.configuration.XMLConfiguration;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.autoscaler.Constants;
+import org.apache.stratos.autoscaler.util.ConfUtil;
+import org.wso2.carbon.base.ServerConfiguration;
+import org.wso2.carbon.identity.application.common.model.xsd.InboundAuthenticationRequestConfig;
+import org.wso2.carbon.identity.application.common.model.xsd.OutboundProvisioningConfig;
+import org.wso2.carbon.identity.application.common.model.xsd.Property;
+import org.wso2.carbon.identity.application.common.model.xsd.ServiceProvider;
+import org.wso2.carbon.identity.application.mgt.stub.IdentityApplicationManagementServiceIdentityApplicationManagementException;
+import org.wso2.carbon.identity.application.mgt.stub.IdentityApplicationManagementServiceStub;
+import org.wso2.carbon.identity.oauth.stub.OAuthAdminServiceException;
+import org.wso2.carbon.identity.oauth.stub.dto.OAuthConsumerAppDTO;
+import org.wso2.carbon.utils.CarbonUtils;
+
+import java.rmi.RemoteException;
+import java.util.ArrayList;
+import java.util.List;
+
+public class IdentityApplicationManagementServiceClient {
+
+ private static final Log log = LogFactory.getLog(IdentityApplicationManagementServiceClient.class);
+ private static final String ID_TOKEN = "id_token";
+
+ private static IdentityApplicationManagementServiceClient serviceClient;
+ private final IdentityApplicationManagementServiceStub stub;
+
+ public IdentityApplicationManagementServiceClient(String epr) throws AxisFault {
+
+ XMLConfiguration conf = ConfUtil.getInstance(null).getConfiguration();
+ int autosclaerSocketTimeout = conf.getInt("autoscaler.identity.clientTimeout", 180000);
+ try {
+ ServerConfiguration serverConfig = CarbonUtils.getServerConfiguration();
+ String trustStorePath = serverConfig.getFirstProperty("Security.TrustStore.Location");
+ String trustStorePassword = serverConfig.getFirstProperty("Security.TrustStore.Password");
+ String type = serverConfig.getFirstProperty("Security.TrustStore.Type");
+
+ System.setProperty("javax.net.ssl.trustStore", trustStorePath);
+ System.setProperty("javax.net.ssl.trustStorePassword", trustStorePassword);
+ System.setProperty("javax.net.ssl.trustStoreType", type);
+
+ stub = new IdentityApplicationManagementServiceStub(epr);
+ stub._getServiceClient().getOptions().setProperty(HTTPConstants.SO_TIMEOUT, autosclaerSocketTimeout);
+ stub._getServiceClient().getOptions().setProperty(HTTPConstants.CONNECTION_TIMEOUT, autosclaerSocketTimeout);
+ Utility.setAuthHeaders(stub._getServiceClient(), "admin");
+
+ } catch (AxisFault axisFault) {
+ String msg = "Failed to initiate identity service client. " + axisFault.getMessage();
+ log.error(msg, axisFault);
+ throw new AxisFault(msg, axisFault);
+ }
+ }
+
+ public static IdentityApplicationManagementServiceClient getServiceClient() throws AxisFault {
+ if (serviceClient == null) {
+ synchronized (IdentityApplicationManagementServiceClient.class) {
+ if (serviceClient == null) {
+ XMLConfiguration conf = ConfUtil.getInstance(null).getConfiguration();
+ String hostname = conf.getString("autoscaler.identity.hostname", "localhost");
+ int port = conf.getInt("autoscaler.cloudController.port", Constants.IS_DEFAULT_PORT);
+ String epr = "https://" + hostname + ":" + port + "/" + Constants.IDENTITY_APPLICATION_SERVICE_SFX;
+ serviceClient = new IdentityApplicationManagementServiceClient(epr);
+ }
+ }
+ }
+ return serviceClient;
+ }
+
+ public String createServiceProvider(String appName, String spName, String compositeAppId) throws RemoteException, OAuthAdminServiceException, OAuthProblemException, OAuthSystemException {
+ OAuthConsumerAppDTO oAuthApplication = null;
+ String accessToken;
+
+ oAuthApplication = oAuthAdminServiceClient.getServiceClient().getOAuthApplication(appName);
+
+ if(oAuthApplication == null){
+ return null;
+ }
+
+ String consumerKey = oAuthApplication.getOauthConsumerKey();
+ String consumerSecret = oAuthApplication.getOauthConsumerSecret();
+
+ ServiceProvider serviceProvider = new ServiceProvider();
+ serviceProvider.setApplicationName(spName);
+
+ try {
+ stub.createApplication(serviceProvider);
+ } catch (IdentityApplicationManagementServiceIdentityApplicationManagementException e) {
+ throw new RuntimeException(e);
+ }
+ try {
+ serviceProvider = stub.getApplication(spName);
+ } catch (IdentityApplicationManagementServiceIdentityApplicationManagementException e) {
+ throw new RuntimeException(e);
+ }
+
+ serviceProvider.setOutboundProvisioningConfig(new OutboundProvisioningConfig());
+
+ List<InboundAuthenticationRequestConfig> authRequestList = new ArrayList<InboundAuthenticationRequestConfig>();
+
+
+ if (consumerKey != null) {
+ InboundAuthenticationRequestConfig opicAuthenticationRequest =
+ new InboundAuthenticationRequestConfig();
+ opicAuthenticationRequest.setInboundAuthKey(consumerKey);
+ opicAuthenticationRequest.setInboundAuthType("oauth2");
+ if (consumerSecret != null && !consumerSecret.isEmpty()) {
+ Property property = new Property();
+ property.setName("oauthConsumerSecret");
+ property.setValue(consumerSecret);
+ Property[] properties = {property};
+ opicAuthenticationRequest.setProperties(properties);
+ }
+ authRequestList.add(opicAuthenticationRequest);
+ }
+
+ String passiveSTSRealm = spName;
+ if (passiveSTSRealm != null) {
+ InboundAuthenticationRequestConfig opicAuthenticationRequest =
+ new InboundAuthenticationRequestConfig();
+ opicAuthenticationRequest.setInboundAuthKey(passiveSTSRealm);
+ opicAuthenticationRequest.setInboundAuthType("passivests");
+ authRequestList.add(opicAuthenticationRequest);
+ }
+
+ String openidRealm = spName;
+ if (openidRealm != null) {
+ InboundAuthenticationRequestConfig opicAuthenticationRequest =
+ new InboundAuthenticationRequestConfig();
+ opicAuthenticationRequest.setInboundAuthKey(openidRealm);
+ opicAuthenticationRequest.setInboundAuthType("openid");
+ authRequestList.add(opicAuthenticationRequest);
+ }
+
+ if (authRequestList.size() > 0) {
+ serviceProvider.getInboundAuthenticationConfig()
+ .setInboundAuthenticationRequestConfigs(authRequestList.toArray(new InboundAuthenticationRequestConfig[authRequestList.size()]));
+ }
+
+ try {
+ stub.updateApplication(serviceProvider);
+ } catch (IdentityApplicationManagementServiceIdentityApplicationManagementException e) {
+ throw new RuntimeException(e);
+ }
+
+ accessToken = getIdToken(compositeAppId, consumerKey, consumerSecret);
+ return accessToken;
+ }
+
+
+ private String getIdToken(String compositeAppId, String consumerKey, String consumerSecret) throws OAuthSystemException, OAuthProblemException {
+ XMLConfiguration conf = ConfUtil.getInstance(null).getConfiguration();
+ String hostname = conf.getString("autoscaler.identity.hostname", "localhost");
+ int port = conf.getInt("autoscaler.cloudController.port", Constants.IS_DEFAULT_PORT);
+ String tokenEndpoint = "https://" + hostname + ":" + port + "/" + Constants.TOKEN_ENDPOINT_SFX;
+ OAuthClientRequest accessRequest = OAuthClientRequest.tokenLocation(tokenEndpoint)
+ .setGrantType(GrantType.CLIENT_CREDENTIALS)
+ .setClientId(consumerKey)
+ .setClientSecret(consumerSecret)
+ .setScope(compositeAppId)
+ .buildBodyMessage();
+ OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());
+
+ OAuthClientResponse oAuthResponse = oAuthClient.accessToken(accessRequest);
+ return oAuthResponse.getParam(ID_TOKEN);
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/96146274/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/client/Utility.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/client/Utility.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/client/Utility.java
new file mode 100644
index 0000000..5e13139
--- /dev/null
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/client/Utility.java
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF 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.apache.stratos.autoscaler.client;
+
+import com.nimbusds.jose.JWSAlgorithm;
+import com.nimbusds.jose.JWSHeader;
+import com.nimbusds.jose.JWSSigner;
+import com.nimbusds.jose.crypto.RSASSASigner;
+import com.nimbusds.jwt.JWTClaimsSet;
+import com.nimbusds.jwt.SignedJWT;
+import org.apache.axiom.util.base64.Base64Utils;
+import org.apache.axis2.client.ServiceClient;
+import org.apache.axis2.transport.http.HTTPConstants;
+import org.apache.commons.httpclient.Header;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.base.MultitenantConstants;
+import org.wso2.carbon.core.util.KeyStoreManager;
+
+import java.security.SignatureException;
+import java.security.interfaces.RSAPrivateKey;
+import java.util.ArrayList;
+import java.util.List;
+
+public class Utility {
+ public static final String SIGNED_JWT_AUTH_USERNAME = "Username";
+ public static final String BEARER = "Bearer";
+ private static final Log log = LogFactory.getLog(Utility.class);
+
+ /**
+ * Set Auth headers to service client. Singed JWT authentication handler expect username
+ * as a claim in order to validate the user. This is an alternative to mutual auth.
+ *
+ * @param serviceClient Service client.
+ * @param username username which is set in header.
+ */
+
+ public static void setAuthHeaders(ServiceClient serviceClient, String username) {
+ List headerList = new ArrayList();
+ Header header = new Header();
+ header.setName(HTTPConstants.HEADER_AUTHORIZATION);
+ header.setValue(getAuthHeader(username));
+ headerList.add(header);
+ serviceClient.getOptions().setProperty(HTTPConstants.HTTP_HEADERS, headerList);
+ }
+
+ public static String getAuthHeader(String username) throws RuntimeException {
+
+ KeyStoreManager keyStoreManager;
+ keyStoreManager = KeyStoreManager.getInstance(MultitenantConstants.SUPER_TENANT_ID);
+ try {
+ keyStoreManager.getDefaultPrimaryCertificate();
+ JWSSigner signer = new RSASSASigner((RSAPrivateKey) keyStoreManager.getDefaultPrivateKey());
+ JWTClaimsSet claimsSet = new JWTClaimsSet();
+ claimsSet.setClaim(SIGNED_JWT_AUTH_USERNAME, username);
+ SignedJWT signedJWT = new SignedJWT(new JWSHeader(JWSAlgorithm.RS512), claimsSet);
+ signedJWT.sign(signer);
+
+ return BEARER + " " + Base64Utils.encode(signedJWT.serialize().getBytes());
+ } catch (SignatureException e) {
+ String msg = "Failed to sign with signature instance";
+ log.error(msg, e);
+ throw new RuntimeException(msg, e);
+ } catch (Exception e) {
+ String msg = "Failed to get primary default certificate";
+ log.error(msg, e);
+ throw new RuntimeException(msg, e);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/96146274/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/client/oAuthAdminServiceClient.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/client/oAuthAdminServiceClient.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/client/oAuthAdminServiceClient.java
new file mode 100644
index 0000000..3cddaed
--- /dev/null
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/client/oAuthAdminServiceClient.java
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF 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.apache.stratos.autoscaler.client;
+
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.transport.http.HTTPConstants;
+import org.apache.commons.configuration.XMLConfiguration;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.autoscaler.Constants;
+import org.apache.stratos.autoscaler.util.ConfUtil;
+import org.wso2.carbon.base.ServerConfiguration;
+import org.wso2.carbon.identity.oauth.stub.OAuthAdminServiceException;
+import org.wso2.carbon.identity.oauth.stub.OAuthAdminServiceStub;
+import org.wso2.carbon.identity.oauth.stub.dto.OAuthConsumerAppDTO;
+import org.wso2.carbon.utils.CarbonUtils;
+
+import java.rmi.RemoteException;
+
+public class oAuthAdminServiceClient {
+
+ public static final String GRANT_TYPE = "client-credentials";
+ private static final Log log = LogFactory.getLog(oAuthAdminServiceClient.class);
+ private static final String OAUTH_2_0 = "oauth-2.0";
+ private static oAuthAdminServiceClient serviceClient;
+ private final OAuthAdminServiceStub stub;
+
+ public oAuthAdminServiceClient(String epr) throws AxisFault {
+
+ XMLConfiguration conf = ConfUtil.getInstance(null).getConfiguration();
+ int autosclaerSocketTimeout = conf.getInt("autoscaler.identity.clientTimeout", 180000);
+
+ try {
+ ServerConfiguration serverConfig = CarbonUtils.getServerConfiguration();
+ String trustStorePath = serverConfig.getFirstProperty("Security.TrustStore.Location");
+ String trustStorePassword = serverConfig.getFirstProperty("Security.TrustStore.Password");
+ String type = serverConfig.getFirstProperty("Security.TrustStore.Type");
+ System.setProperty("javax.net.ssl.trustStore", trustStorePath);
+ System.setProperty("javax.net.ssl.trustStorePassword", trustStorePassword);
+ System.setProperty("javax.net.ssl.trustStoreType", type);
+
+ stub = new OAuthAdminServiceStub(epr);
+ stub._getServiceClient().getOptions().setProperty(HTTPConstants.SO_TIMEOUT, autosclaerSocketTimeout);
+ stub._getServiceClient().getOptions().setProperty(HTTPConstants.CONNECTION_TIMEOUT, autosclaerSocketTimeout);
+ Utility.setAuthHeaders(stub._getServiceClient(), "admin");
+
+ } catch (AxisFault axisFault) {
+ String msg = "Failed to initiate identity service client. " + axisFault.getMessage();
+ log.error(msg, axisFault);
+ throw new AxisFault(msg, axisFault);
+ }
+ }
+
+ public static oAuthAdminServiceClient getServiceClient() throws AxisFault {
+ if (serviceClient == null) {
+ synchronized (oAuthAdminServiceClient.class) {
+ if (serviceClient == null) {
+ XMLConfiguration conf = ConfUtil.getInstance(null).getConfiguration();
+ String hostname = conf.getString("autoscaler.identity.hostname", "localhost");
+ int port = conf.getInt("autoscaler.cloudController.port", Constants.IS_DEFAULT_PORT);
+ String epr = "https://" + hostname + ":" + port + "/" + Constants.OAUTH_SERVICE_SFX;
+ serviceClient = new oAuthAdminServiceClient(epr);
+ }
+ }
+ }
+ return serviceClient;
+ }
+
+ public void registerOauthApplication(String appName) throws RemoteException, OAuthAdminServiceException {
+ OAuthConsumerAppDTO oAuthConsumerDTO = new OAuthConsumerAppDTO();
+ oAuthConsumerDTO.setApplicationName(appName);
+ oAuthConsumerDTO.setOAuthVersion(OAUTH_2_0);
+ oAuthConsumerDTO.setGrantTypes(GRANT_TYPE);
+ stub.registerOAuthApplicationData(oAuthConsumerDTO);
+ }
+
+ public OAuthConsumerAppDTO getOAuthApplication(String name) throws RemoteException, OAuthAdminServiceException {
+ return stub.getOAuthApplicationDataByAppName(name);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/96146274/components/org.apache.stratos.manager/pom.xml
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager/pom.xml b/components/org.apache.stratos.manager/pom.xml
index 1f3d82a..9e1386f 100644
--- a/components/org.apache.stratos.manager/pom.xml
+++ b/components/org.apache.stratos.manager/pom.xml
@@ -126,21 +126,6 @@
<artifactId>mqtt-client</artifactId>
<version>0.4.0</version>
</dependency>
- <dependency>
- <groupId>org.wso2.carbon</groupId>
- <artifactId>org.wso2.carbon.identity.oauth</artifactId>
- <version>4.2.3</version>
- </dependency>
- <dependency>
- <groupId>org.wso2.carbon</groupId>
- <artifactId>org.wso2.carbon.identity.oauth.stub</artifactId>
- <version>4.2.3</version>
- </dependency>
- <dependency>
- <groupId>org.wso2.carbon</groupId>
- <artifactId>org.wso2.carbon.identity.application.mgt.stub</artifactId>
- <version>4.2.0</version>
- </dependency>
</dependencies>
<build>
http://git-wip-us.apache.org/repos/asf/stratos/blob/96146274/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/client/IdentityApplicationManagementServiceClient.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/client/IdentityApplicationManagementServiceClient.java b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/client/IdentityApplicationManagementServiceClient.java
deleted file mode 100644
index 7dccc7c..0000000
--- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/client/IdentityApplicationManagementServiceClient.java
+++ /dev/null
@@ -1,202 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF 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.apache.stratos.manager.client;
-
-import org.apache.amber.oauth2.client.OAuthClient;
-import org.apache.amber.oauth2.client.URLConnectionClient;
-import org.apache.amber.oauth2.client.request.OAuthClientRequest;
-import org.apache.amber.oauth2.client.response.OAuthClientResponse;
-import org.apache.amber.oauth2.common.exception.OAuthProblemException;
-import org.apache.amber.oauth2.common.exception.OAuthSystemException;
-import org.apache.amber.oauth2.common.message.types.GrantType;
-import org.apache.axis2.AxisFault;
-import org.apache.axis2.context.ConfigurationContext;
-import org.apache.axis2.transport.http.HTTPConstants;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.manager.internal.DataHolder;
-import org.apache.stratos.manager.utils.CartridgeConstants;
-import org.wso2.carbon.base.ServerConfiguration;
-import org.wso2.carbon.identity.application.common.model.xsd.InboundAuthenticationRequestConfig;
-import org.wso2.carbon.identity.application.common.model.xsd.OutboundProvisioningConfig;
-import org.wso2.carbon.identity.application.common.model.xsd.Property;
-import org.wso2.carbon.identity.application.common.model.xsd.ServiceProvider;
-import org.wso2.carbon.identity.application.mgt.stub.IdentityApplicationManagementServiceIdentityApplicationManagementException;
-import org.wso2.carbon.identity.application.mgt.stub.IdentityApplicationManagementServiceStub;
-import org.wso2.carbon.identity.oauth.stub.OAuthAdminServiceException;
-import org.wso2.carbon.identity.oauth.stub.dto.OAuthConsumerAppDTO;
-import org.wso2.carbon.utils.CarbonUtils;
-
-import java.rmi.RemoteException;
-import java.util.ArrayList;
-import java.util.List;
-
-public class IdentityApplicationManagementServiceClient {
-
- private static final Log log = LogFactory.getLog(IdentityApplicationManagementServiceClient.class);
- private static final String ID_TOKEN = "id_token";
-
- private static IdentityApplicationManagementServiceClient serviceClient;
- private final IdentityApplicationManagementServiceStub stub;
-
- public IdentityApplicationManagementServiceClient(String epr) throws AxisFault {
-
-
- String autosclaerSocketTimeout =
- System.getProperty(CartridgeConstants.AUTOSCALER_SOCKET_TIMEOUT) == null ? "300000" : System.getProperty(CartridgeConstants.AUTOSCALER_SOCKET_TIMEOUT);
- String autosclaerConnectionTimeout =
- System.getProperty(CartridgeConstants.AUTOSCALER_CONNECTION_TIMEOUT) == null ? "300000" : System.getProperty(CartridgeConstants.AUTOSCALER_CONNECTION_TIMEOUT);
-
- ConfigurationContext clientConfigContext = DataHolder.getClientConfigContext();
- try {
- ServerConfiguration serverConfig = CarbonUtils.getServerConfiguration();
- String trustStorePath = serverConfig.getFirstProperty("Security.TrustStore.Location");
- String trustStorePassword = serverConfig.getFirstProperty("Security.TrustStore.Password");
- String type = serverConfig.getFirstProperty("Security.TrustStore.Type");
-
- System.setProperty("javax.net.ssl.trustStore", trustStorePath);
- System.setProperty("javax.net.ssl.trustStorePassword", trustStorePassword);
- System.setProperty("javax.net.ssl.trustStoreType", type);
-
- stub = new IdentityApplicationManagementServiceStub(clientConfigContext, epr);
- stub._getServiceClient().getOptions().setProperty(HTTPConstants.SO_TIMEOUT, new Integer(autosclaerSocketTimeout));
- stub._getServiceClient().getOptions().setProperty(HTTPConstants.CONNECTION_TIMEOUT, new Integer(autosclaerConnectionTimeout));
- Utility.setAuthHeaders(stub._getServiceClient(), "admin");
-
- } catch (AxisFault axisFault) {
- String msg = "Failed to initiate identity service client. " + axisFault.getMessage();
- log.error(msg, axisFault);
- throw new AxisFault(msg, axisFault);
- }
- }
-
- public static IdentityApplicationManagementServiceClient getServiceClient() throws AxisFault {
- if (serviceClient == null) {
- synchronized (IdentityApplicationManagementServiceClient.class) {
- if (serviceClient == null) {
- serviceClient = new IdentityApplicationManagementServiceClient(System.getProperty(CartridgeConstants.IDENTITY_SERVICE_URL) + "/services/IdentityApplicationManagementService");
- }
- }
- }
- return serviceClient;
- }
-
- public String createServiceProvider(String appName, String spName, String compositeAppId) throws RemoteException, OAuthAdminServiceException {
- OAuthConsumerAppDTO oAuthApplication = null;
- String accessToken = null;
-
- oAuthApplication = oAuthAdminServiceClient.getServiceClient().getOAuthApplication(appName);
-
- if(oAuthApplication == null){
- return null;
- }
-
- String consumerKey = oAuthApplication.getOauthConsumerKey();
- String consumerSecret = oAuthApplication.getOauthConsumerSecret();
-
- ServiceProvider serviceProvider = new ServiceProvider();
- serviceProvider.setApplicationName(spName);
-
- try {
- stub.createApplication(serviceProvider);
- } catch (IdentityApplicationManagementServiceIdentityApplicationManagementException e) {
- e.printStackTrace();
- }
- try {
- serviceProvider = stub.getApplication(spName);
- } catch (IdentityApplicationManagementServiceIdentityApplicationManagementException e) {
- e.printStackTrace();
- }
-
- serviceProvider.setOutboundProvisioningConfig(new OutboundProvisioningConfig());
-
- List<InboundAuthenticationRequestConfig> authRequestList = new ArrayList<InboundAuthenticationRequestConfig>();
-
-
- if (consumerKey != null) {
- InboundAuthenticationRequestConfig opicAuthenticationRequest =
- new InboundAuthenticationRequestConfig();
- opicAuthenticationRequest.setInboundAuthKey(consumerKey);
- opicAuthenticationRequest.setInboundAuthType("oauth2");
- if (consumerSecret != null && !consumerSecret.isEmpty()) {
- Property property = new Property();
- property.setName("oauthConsumerSecret");
- property.setValue(consumerSecret);
- Property[] properties = {property};
- opicAuthenticationRequest.setProperties(properties);
- }
- authRequestList.add(opicAuthenticationRequest);
- }
-
- String passiveSTSRealm = spName;
- if (passiveSTSRealm != null) {
- InboundAuthenticationRequestConfig opicAuthenticationRequest =
- new InboundAuthenticationRequestConfig();
- opicAuthenticationRequest.setInboundAuthKey(passiveSTSRealm);
- opicAuthenticationRequest.setInboundAuthType("passivests");
- authRequestList.add(opicAuthenticationRequest);
- }
-
- String openidRealm = spName;
- if (openidRealm != null) {
- InboundAuthenticationRequestConfig opicAuthenticationRequest =
- new InboundAuthenticationRequestConfig();
- opicAuthenticationRequest.setInboundAuthKey(openidRealm);
- opicAuthenticationRequest.setInboundAuthType("openid");
- authRequestList.add(opicAuthenticationRequest);
- }
-
- if (authRequestList.size() > 0) {
- serviceProvider.getInboundAuthenticationConfig()
- .setInboundAuthenticationRequestConfigs(authRequestList.toArray(new InboundAuthenticationRequestConfig[authRequestList.size()]));
- }
-
- try {
- stub.updateApplication(serviceProvider);
- } catch (IdentityApplicationManagementServiceIdentityApplicationManagementException e) {
- e.printStackTrace();
- }
-
- accessToken = getIdToken(compositeAppId, accessToken, consumerKey, consumerSecret);
- return accessToken;
- }
-
- private String getIdToken(String compositeAppId, String accessToken, String consumerKey, String consumerSecret) {
- String tokenEndpoint = System.getProperty(CartridgeConstants.IDENTITY_SERVICE_URL) + "oauth2/token";
- try {
- OAuthClientRequest accessRequest = OAuthClientRequest.tokenLocation(tokenEndpoint)
- .setGrantType(GrantType.CLIENT_CREDENTIALS)
- .setClientId(consumerKey)
- .setClientSecret(consumerSecret)
- .setScope(compositeAppId)
- .buildBodyMessage();
- OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());
-
- OAuthClientResponse oAuthResponse = oAuthClient.accessToken(accessRequest);
- accessToken = oAuthResponse.getParam(ID_TOKEN);
-
- } catch (OAuthSystemException e) {
- e.printStackTrace();
- } catch (OAuthProblemException e) {
- e.printStackTrace();
- }
- return accessToken;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/stratos/blob/96146274/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/client/Utility.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/client/Utility.java b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/client/Utility.java
deleted file mode 100644
index 59f4230..0000000
--- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/client/Utility.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF 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.apache.stratos.manager.client;
-
-import com.nimbusds.jose.JWSAlgorithm;
-import com.nimbusds.jose.JWSHeader;
-import com.nimbusds.jose.JWSSigner;
-import com.nimbusds.jose.crypto.RSASSASigner;
-import com.nimbusds.jwt.JWTClaimsSet;
-import com.nimbusds.jwt.SignedJWT;
-import org.apache.axiom.util.base64.Base64Utils;
-import org.apache.axis2.client.ServiceClient;
-import org.apache.axis2.transport.http.HTTPConstants;
-import org.apache.commons.httpclient.Header;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.wso2.carbon.base.MultitenantConstants;
-import org.wso2.carbon.core.util.KeyStoreManager;
-
-import java.security.SignatureException;
-import java.security.interfaces.RSAPrivateKey;
-import java.util.ArrayList;
-import java.util.List;
-
-public class Utility {
- public static final String SIGNED_JWT_AUTH_USERNAME = "Username";
- public static final String BEARER = "Bearer";
- private static final Log log = LogFactory.getLog(Utility.class);
-
- /**
- * Set Auth headers to service client. Singed JWT authentication handler expect username
- * as a claim in order to validate the user. This is an alternative to mutual auth.
- *
- * @param serviceClient Service client.
- * @param username username which is set in header.
- */
-
- public static void setAuthHeaders(ServiceClient serviceClient, String username) {
- List headerList = new ArrayList();
- Header header = new Header();
- header.setName(HTTPConstants.HEADER_AUTHORIZATION);
- header.setValue(getAuthHeader(username));
- headerList.add(header);
- serviceClient.getOptions().setProperty(HTTPConstants.HTTP_HEADERS, headerList);
- }
-
- public static String getAuthHeader(String username) throws RuntimeException {
-
- KeyStoreManager keyStoreManager;
- keyStoreManager = KeyStoreManager.getInstance(MultitenantConstants.SUPER_TENANT_ID);
- try {
- keyStoreManager.getDefaultPrimaryCertificate();
- JWSSigner signer = new RSASSASigner((RSAPrivateKey) keyStoreManager.getDefaultPrivateKey());
- JWTClaimsSet claimsSet = new JWTClaimsSet();
- claimsSet.setClaim(SIGNED_JWT_AUTH_USERNAME, username);
- SignedJWT signedJWT = new SignedJWT(new JWSHeader(JWSAlgorithm.RS512), claimsSet);
- signedJWT.sign(signer);
-
- return BEARER + " " + Base64Utils.encode(signedJWT.serialize().getBytes());
- } catch (SignatureException e) {
- String msg = "Failed to sign with signature instance";
- log.error(msg, e);
- throw new RuntimeException(msg, e);
- } catch (Exception e) {
- String msg = "Failed to get primary default certificate";
- log.error(msg, e);
- throw new RuntimeException(msg, e);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/stratos/blob/96146274/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/client/oAuthAdminServiceClient.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/client/oAuthAdminServiceClient.java b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/client/oAuthAdminServiceClient.java
deleted file mode 100644
index febf8c7..0000000
--- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/client/oAuthAdminServiceClient.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF 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.apache.stratos.manager.client;
-
-import org.apache.axis2.AxisFault;
-import org.apache.axis2.context.ConfigurationContext;
-import org.apache.axis2.transport.http.HTTPConstants;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.manager.internal.DataHolder;
-import org.apache.stratos.manager.utils.CartridgeConstants;
-import org.wso2.carbon.base.ServerConfiguration;
-import org.wso2.carbon.identity.oauth.stub.OAuthAdminServiceException;
-import org.wso2.carbon.identity.oauth.stub.OAuthAdminServiceStub;
-import org.wso2.carbon.identity.oauth.stub.dto.OAuthConsumerAppDTO;
-import org.wso2.carbon.utils.CarbonUtils;
-
-import java.rmi.RemoteException;
-
-public class oAuthAdminServiceClient {
-
- public static final String GRANT_TYPE = "client-credentials";
- private static final Log log = LogFactory.getLog(oAuthAdminServiceClient.class);
- private static final String OAUTH_2_0 = "oauth-2.0";
- private static oAuthAdminServiceClient serviceClient;
- private final OAuthAdminServiceStub stub;
-
- public oAuthAdminServiceClient(String epr) throws AxisFault {
-
- String autosclaerSocketTimeout =
- System.getProperty(CartridgeConstants.AUTOSCALER_SOCKET_TIMEOUT) == null ? "300000" : System.getProperty(CartridgeConstants.AUTOSCALER_SOCKET_TIMEOUT);
- String autosclaerConnectionTimeout =
- System.getProperty(CartridgeConstants.AUTOSCALER_CONNECTION_TIMEOUT) == null ? "300000" : System.getProperty(CartridgeConstants.AUTOSCALER_CONNECTION_TIMEOUT);
-
- ConfigurationContext clientConfigContext = DataHolder.getClientConfigContext();
- try {
- ServerConfiguration serverConfig = CarbonUtils.getServerConfiguration();
- String trustStorePath = serverConfig.getFirstProperty("Security.TrustStore.Location");
- String trustStorePassword = serverConfig.getFirstProperty("Security.TrustStore.Password");
- String type = serverConfig.getFirstProperty("Security.TrustStore.Type");
- System.setProperty("javax.net.ssl.trustStore", trustStorePath);
- System.setProperty("javax.net.ssl.trustStorePassword", trustStorePassword);
- System.setProperty("javax.net.ssl.trustStoreType", type);
-
- stub = new OAuthAdminServiceStub(clientConfigContext, epr);
- stub._getServiceClient().getOptions().setProperty(HTTPConstants.SO_TIMEOUT, new Integer(autosclaerSocketTimeout));
- stub._getServiceClient().getOptions().setProperty(HTTPConstants.CONNECTION_TIMEOUT, new Integer(autosclaerConnectionTimeout));
- Utility.setAuthHeaders(stub._getServiceClient(), "admin");
-
- } catch (AxisFault axisFault) {
- String msg = "Failed to initiate identity service client. " + axisFault.getMessage();
- log.error(msg, axisFault);
- throw new AxisFault(msg, axisFault);
- }
- }
-
- public static oAuthAdminServiceClient getServiceClient() throws AxisFault {
- if (serviceClient == null) {
- synchronized (oAuthAdminServiceClient.class) {
- if (serviceClient == null) {
- serviceClient = new oAuthAdminServiceClient(System.getProperty(CartridgeConstants.IDENTITY_SERVICE_URL) + "/services/OAuthAdminService");
- }
- }
- }
- return serviceClient;
- }
-
- public void registerOauthApplication(String appName) throws RemoteException, OAuthAdminServiceException {
- OAuthConsumerAppDTO oAuthConsumerDTO = new OAuthConsumerAppDTO();
- oAuthConsumerDTO.setApplicationName(appName);
- oAuthConsumerDTO.setOAuthVersion(OAUTH_2_0);
- oAuthConsumerDTO.setGrantTypes(GRANT_TYPE);
- stub.registerOAuthApplicationData(oAuthConsumerDTO);
- }
-
- public OAuthConsumerAppDTO getOAuthApplication(String name) throws RemoteException, OAuthAdminServiceException {
- return stub.getOAuthApplicationDataByAppName(name);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/stratos/blob/96146274/components/org.apache.stratos.metadataservice/pom.xml
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.metadataservice/pom.xml b/components/org.apache.stratos.metadataservice/pom.xml
index 9e0b6d2..93b12e9 100644
--- a/components/org.apache.stratos.metadataservice/pom.xml
+++ b/components/org.apache.stratos.metadataservice/pom.xml
@@ -73,7 +73,7 @@
<directory>src/main/webapp/${appName}</directory>
</resource>
</webResources>
- <warName>stratosmetadataservice</warName>
+ <warName>metadataapi</warName>
@@ -158,6 +158,11 @@
<version>4.2.0</version>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>com.nimbusds.wso2</groupId>
+ <artifactId>nimbus-jose-jwt</artifactId>
+ <version>2.26.1.wso2v2</version>
+ </dependency>
</dependencies>
http://git-wip-us.apache.org/repos/asf/stratos/blob/96146274/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java
index 6290500..6282901 100644
--- a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java
+++ b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java
@@ -23,19 +23,14 @@ import org.apache.axis2.context.ConfigurationContext;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.autoscaler.stub.Properties;
-import org.apache.stratos.autoscaler.stub.pojo.ApplicationContext;
import org.apache.stratos.autoscaler.stub.*;
import org.apache.stratos.autoscaler.stub.deployment.policy.DeploymentPolicy;
-import org.apache.stratos.autoscaler.stub.exception.InvalidKubernetesGroupException;
+import org.apache.stratos.autoscaler.stub.pojo.ApplicationContext;
import org.apache.stratos.cloud.controller.stub.*;
import org.apache.stratos.cloud.controller.stub.domain.CartridgeConfig;
import org.apache.stratos.cloud.controller.stub.domain.CartridgeInfo;
-import org.apache.stratos.common.Property;
import org.apache.stratos.manager.client.AutoscalerServiceClient;
import org.apache.stratos.manager.client.CloudControllerServiceClient;
-import org.apache.stratos.manager.client.IdentityApplicationManagementServiceClient;
-import org.apache.stratos.manager.client.oAuthAdminServiceClient;
import org.apache.stratos.manager.composite.application.beans.ApplicationDefinition;
import org.apache.stratos.manager.deploy.cartridge.CartridgeDeploymentManager;
import org.apache.stratos.manager.deploy.service.Service;
@@ -81,11 +76,9 @@ import org.apache.stratos.rest.endpoint.bean.repositoryNotificationInfoBean.Payl
import org.apache.stratos.rest.endpoint.bean.subscription.domain.SubscriptionDomainBean;
import org.apache.stratos.rest.endpoint.bean.util.converter.PojoConverter;
import org.apache.stratos.rest.endpoint.exception.RestAPIException;
-import org.wso2.carbon.identity.oauth.stub.OAuthAdminServiceException;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
-
import java.rmi.RemoteException;
import java.util.*;
import java.util.regex.Pattern;
@@ -1965,25 +1958,5 @@ public class StratosApiV41Utils {
throw new RestAPIException(e.getMessage(), e);
}
}
-
- }
-
- public static void createToken() throws RestAPIException {
- String appName = "testudara" + Math.random();
- String compositeAppId = "app1";
- try {
- oAuthAdminServiceClient.getServiceClient().registerOauthApplication(appName);
- } catch (RemoteException e) {
- throw new RestAPIException(e);
- } catch (OAuthAdminServiceException e) {
- throw new RestAPIException(e);
- }
- try {
- IdentityApplicationManagementServiceClient.getServiceClient().createServiceProvider(appName, appName, compositeAppId);
- } catch (RemoteException e) {
- throw new RestAPIException(e);
- } catch (OAuthAdminServiceException e) {
- e.printStackTrace();
- }
}
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/96146274/tools/stratos-installer/config/all/repository/conf/autoscaler.xml
----------------------------------------------------------------------
diff --git a/tools/stratos-installer/config/all/repository/conf/autoscaler.xml b/tools/stratos-installer/config/all/repository/conf/autoscaler.xml
index c2579ef..7a73300 100755
--- a/tools/stratos-installer/config/all/repository/conf/autoscaler.xml
+++ b/tools/stratos-installer/config/all/repository/conf/autoscaler.xml
@@ -37,6 +37,11 @@
<!--SM client timeout in ms-->
<clientTimeout>300000</clientTimeout>
</stratosManager>
+ <identity>
+ <hostname>localhost</hostname>
+ <port>9443</port>
+ <clientTimeout>300000</clientTimeout>
+ </identity>
<member>
<vm>
<!-- this is the maximum time(ms) a vm member can be in pending member state -->