Skip to content

Commit

Permalink
Sync with SVN
Browse files Browse the repository at this point in the history
  • Loading branch information
yurem committed Jul 16, 2014
1 parent 49d07e6 commit de99fba
Show file tree
Hide file tree
Showing 23 changed files with 140 additions and 67 deletions.
2 changes: 1 addition & 1 deletion Client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<parent>
<groupId>org.xdi</groupId>
<artifactId>oxauth</artifactId>
<version>1.2.0.Final</version>
<version>1.3.0.Final</version>
</parent>

<prerequisites>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
package org.xdi.oxauth.client.uma.wrapper;

import org.xdi.oxauth.client.*;
import java.util.ArrayList;
import java.util.List;

import org.xdi.oxauth.client.AuthorizationRequest;
import org.xdi.oxauth.client.AuthorizationResponse;
import org.xdi.oxauth.client.AuthorizeClient;
import org.xdi.oxauth.client.TokenClient;
import org.xdi.oxauth.client.TokenRequest;
import org.xdi.oxauth.client.TokenResponse;
import org.xdi.oxauth.model.common.AuthenticationMethod;
import org.xdi.oxauth.model.common.GrantType;
import org.xdi.oxauth.model.common.Prompt;
Expand All @@ -9,31 +17,38 @@
import org.xdi.oxauth.model.uma.wrapper.Token;
import org.xdi.oxauth.model.util.Util;

import java.util.ArrayList;
import java.util.List;

/**
* @author Yuriy Zabrovarnyy
* @version 0.9, 15/03/2013
*/

public class UmaClient {

@Deprecated
public static Token requestAat(final String authorizeUrl, final String tokenUrl,
final String umaUserId, final String umaUserSecret,
final String umaClientId, final String umaClientSecret,
final String umaRedirectUri) throws Exception {
return request(authorizeUrl, tokenUrl, umaUserId, umaUserSecret, umaClientId, umaClientSecret, umaRedirectUri, UmaScopeType.AUTHORIZATION);
}

public static Token requestAat(final String tokenUrl, final String umaClientId, final String umaClientSecret) throws Exception {
return request(tokenUrl, umaClientId, umaClientSecret, UmaScopeType.AUTHORIZATION);
}

@Deprecated
public static Token requestPat(final String authorizeUrl, final String tokenUrl,
final String umaUserId, final String umaUserSecret,
final String umaClientId, final String umaClientSecret,
final String umaRedirectUri) throws Exception {
return request(authorizeUrl, tokenUrl, umaUserId, umaUserSecret, umaClientId, umaClientSecret, umaRedirectUri, UmaScopeType.PROTECTION);
}

public static Token requestPat(final String tokenUrl, final String umaClientId, final String umaClientSecret) throws Exception {
return request(tokenUrl, umaClientId, umaClientSecret, UmaScopeType.PROTECTION);
}

@Deprecated
public static Token request(final String authorizeUrl, final String tokenUrl,
final String umaUserId, final String umaUserSecret,
final String umaClientId, final String umaClientSecret,
Expand Down Expand Up @@ -88,4 +103,21 @@ public static Token request(final String authorizeUrl, final String tokenUrl,
return null;
}

public static Token request(final String tokenUrl, final String umaClientId, final String umaClientSecret, UmaScopeType scopeType) throws Exception {
String umaScope = scopeType.getValue();

TokenClient tokenClient = new TokenClient(tokenUrl);
TokenResponse response = tokenClient.execClientCredentialsGrant(umaScope, umaClientId, umaClientSecret);

if (response.getStatus() == 200) {
final String patToken = response.getAccessToken();
final Integer expiresIn = response.getExpiresIn();
if (Util.allNotBlank(patToken)) {
return new Token(null, null, patToken, umaScope, expiresIn);
}
}

return null;
}

}
Original file line number Diff line number Diff line change
@@ -1,14 +1,34 @@
package org.xdi.oxauth.load.benchmark;

import org.apache.http.client.HttpClient;
import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.conn.scheme.PlainSocketFactory;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.conn.ssl.AllowAllHostnameVerifier;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.conn.ssl.TrustStrategy;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.conn.PoolingClientConnectionManager;
import org.jboss.resteasy.client.core.executors.ApacheHttpClient4Executor;
import org.testng.Assert;
import org.testng.annotations.Listeners;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
import org.xdi.oxauth.client.AuthorizationRequest;
import org.xdi.oxauth.client.AuthorizationResponse;
import org.xdi.oxauth.client.AuthorizeClient;
import org.xdi.oxauth.client.OpenIdConfigurationClient;
import org.xdi.oxauth.client.OpenIdConfigurationResponse;
import org.xdi.oxauth.model.common.Prompt;
import org.xdi.oxauth.model.common.ResponseType;

import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.UnrecoverableKeyException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand All @@ -21,19 +41,30 @@
* @version 0.9, 03/07/2014
*/

@Listeners({ BenchmarkTestListener.class })
@Listeners({BenchmarkTestListener.class})
public class BenchmarkAuthorizatoinRequests {


@Test
public void testDiscovery() throws Exception {
OpenIdConfigurationClient client = new OpenIdConfigurationClient("https://pcy28751:8443/oxauth/.well-known/openid-configuration");
// OpenIdConfigurationClient client = new OpenIdConfigurationClient("https://seed.gluu.org/.well-known/openid-configuration");
client.setExecutor(new ApacheHttpClient4Executor(createHttpClientTrustAll()));
OpenIdConfigurationResponse r = client.execOpenIdConfiguration();
Assert.assertNotNull(r);
}

// Think twice before invoking this test ;). Leads to OpenDJ (Berkley DB) failure
// Caused by: LDAPSearchException(resultCode=80 (other), numEntries=0, numReferences=0, errorMessage='Database exception: (JE 4.1.10) JAVA_ERROR: Java Error occurred, recovery may not be possible.')
// http://ox.gluu.org/doku.php?id=oxauth:profiling#obtain_access_token_-_2000_invocations_within_200_concurrent_threads
@Parameters({"userId", "userSecret", "redirectUri", "clientId"})
@Test(invocationCount = 10000, threadPoolSize = 300)
@Test(invocationCount = 2000, threadPoolSize = 10)
// @Test
public void test(final String userId, final String userSecret, String redirectUri, String clientId) {
public void testAuthentication(final String userId, final String userSecret, String redirectUri, String clientId) throws Exception {

// hardcode -> we don't want to loose time on discover call
String authorizationEndpoint = "https://localhost:8443/seam/resource/restv1/oxauth/authorize";
String authorizationEndpoint = "https://pcy28751:8443/oxauth/seam/resource/restv1/oxauth/authorize";
// String authorizationEndpoint = "https://localhost:8443/seam/resource/restv1/oxauth/authorize";

final List<ResponseType> responseTypes = new ArrayList<ResponseType>();
responseTypes.add(ResponseType.TOKEN);
Expand All @@ -51,6 +82,7 @@ public void test(final String userId, final String userSecret, String redirectUr
request.getPrompts().add(Prompt.NONE);

AuthorizeClient authorizeClient = new AuthorizeClient(authorizationEndpoint);
authorizeClient.setExecutor(new ApacheHttpClient4Executor(createHttpClientTrustAll()));
authorizeClient.setRequest(request);
AuthorizationResponse response = authorizeClient.exec();

Expand All @@ -61,4 +93,19 @@ public void test(final String userId, final String userSecret, String redirectUr
assertNotNull(response.getExpiresIn(), "The expires in value is null");
assertNotNull(response.getScope(), "The scope must be null");
}

public static HttpClient createHttpClientTrustAll() throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException {
SSLSocketFactory sf = new SSLSocketFactory(new TrustStrategy() {
@Override
public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
return true;
}
}, new AllowAllHostnameVerifier());

SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme("http", 8080, PlainSocketFactory.getSocketFactory()));
registry.register(new Scheme("https", 8443, sf));
ClientConnectionManager ccm = new PoolingClientConnectionManager(registry);
return new DefaultHttpClient(ccm);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,15 @@ public class IdGenWsHttpTest extends BaseTest {
protected String m_umaAmHost;

@BeforeClass
@Parameters({"umaMetaDataUrl", "umaUserId", "umaUserSecret", "umaAatClientId", "umaAatClientSecret", "umaRedirectUri", "umaAmHost"})
public void init(final String umaMetaDataUrl, final String umaUserId, final String umaUserSecret,
final String umaAatClientId, final String umaAatClientSecret,
final String umaRedirectUri, String umaAmHost) throws Exception {
@Parameters({"umaMetaDataUrl", "umaAatClientId", "umaAatClientSecret", "umaAmHost"})
public void init(final String umaMetaDataUrl,
final String umaAatClientId, final String umaAatClientSecret, String umaAmHost) throws Exception {
m_metadataConfiguration = UmaClientFactory.instance().createMetaDataConfigurationService(umaMetaDataUrl).getMetadataConfiguration();
UmaTestUtil.assert_(m_metadataConfiguration);

m_umaAmHost = umaAmHost;

m_aat = UmaClient.requestAat(authorizationEndpoint, tokenEndpoint, umaUserId, umaUserSecret, umaAatClientId, umaAatClientSecret, umaRedirectUri);
m_aat = UmaClient.requestAat(tokenEndpoint, umaAatClientId, umaAatClientSecret);
UmaTestUtil.assert_(m_aat);

final RequesterPermissionTokenService rptService = UmaClientFactory.instance().createRequesterPermissionTokenService(m_metadataConfiguration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@
public class IntrospectionWsHttpTest extends BaseTest {

@Test
@Parameters({"umaUserId", "umaUserSecret", "umaAatClientId", "umaAatClientSecret", "umaRedirectUri"})
public void test(final String umaUserId, final String umaUserSecret,
final String umaAatClientId, final String umaAatClientSecret,
final String umaRedirectUri) throws Exception {
@Parameters({"umaAatClientId", "umaAatClientSecret"})
public void test(final String umaAatClientId, final String umaAatClientSecret) throws Exception {

final Token authorization = UmaClient.requestAat(authorizationEndpoint, tokenEndpoint, umaUserId, umaUserSecret, umaAatClientId, umaAatClientSecret, umaRedirectUri);
final Token tokenToIntrospect = UmaClient.requestPat(authorizationEndpoint, tokenEndpoint, umaUserId, umaUserSecret, umaAatClientId, umaAatClientSecret, umaRedirectUri);
final Token authorization = UmaClient.requestAat(tokenEndpoint, umaAatClientId, umaAatClientSecret);
final Token tokenToIntrospect = UmaClient.requestPat(tokenEndpoint, umaAatClientId, umaAatClientSecret);

final IntrospectionService introspectionService = ClientFactory.instance().createIntrospectionService(introspectionEndpoint);
final IntrospectionResponse introspectionResponse = introspectionService.introspectToken("Bearer " + authorization.getAccessToken(), tokenToIntrospect.getAccessToken());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,10 @@ public void init(final String umaMetaDataUrl) throws Exception {
* Host obtains PAT
*/
@Test
@Parameters({"umaUserId", "umaUserSecret", "umaPatClientId", "umaPatClientSecret", "umaRedirectUri"})
public void testHostObtainPat(final String umaUserId, final String umaUserSecret, final String umaPatClientId,
final String umaPatClientSecret, final String umaRedirectUri) throws Exception {
@Parameters({"umaPatClientId", "umaPatClientSecret"})
public void testHostObtainPat(final String umaPatClientId, final String umaPatClientSecret) throws Exception {
showTitle("testHostObtainPat");
m_pat = UmaClient.requestPat(authorizationEndpoint, tokenEndpoint, umaUserId, umaUserSecret, umaPatClientId, umaPatClientSecret, umaRedirectUri);
m_pat = UmaClient.requestPat(tokenEndpoint, umaPatClientId, umaPatClientSecret);
UmaTestUtil.assert_(m_pat);

// Init UmaPatTokenAwareHttpTest test
Expand All @@ -85,12 +84,10 @@ public void testHostRegisterResourceSet() throws Exception {
* Requester obtains AAT token
*/
@Test(dependsOnMethods = {"testHostRegisterResourceSet"})
@Parameters({"umaUserId", "umaUserSecret", "umaAatClientId", "umaAatClientSecret", "umaRedirectUri"})
public void testRequesterObtainAat(final String umaUserId, final String umaUserSecret,
final String umaAatClientId, final String umaAatClientSecret,
final String umaRedirectUri) throws Exception {
@Parameters({"umaAatClientId", "umaAatClientSecret"})
public void testRequesterObtainAat(final String umaAatClientId, final String umaAatClientSecret) throws Exception {
showTitle("testRequesterObtainAat");
m_aat = UmaClient.requestAat(authorizationEndpoint, tokenEndpoint, umaUserId, umaUserSecret, umaAatClientId, umaAatClientSecret, umaRedirectUri);
m_aat = UmaClient.requestAat(tokenEndpoint, umaAatClientId, umaAatClientSecret);
UmaTestUtil.assert_(m_aat);

// Init UmaPatTokenAwareHttpTest test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,20 @@ public class ObtainAatTokenFlowHttpTest extends BaseTest {
* Test for the obtaining UMA AAT token
*/
@Test
@Parameters({"umaUserId", "umaUserSecret", "umaAatClientId", "umaAatClientSecret", "umaRedirectUri"})
public void testObtainAatTokenFlow(final String umaUserId, final String umaUserSecret, final String umaAatClientId,
final String umaAatClientSecret, final String umaRedirectUri) throws Exception {
@Parameters({"umaUserId", "umaAatClientSecret"})
public void testObtainAatTokenFlow(final String umaAatClientId, final String umaAatClientSecret) throws Exception {
showTitle("testObtainAatTokenFlow");

m_aat = UmaClient.requestAat(authorizationEndpoint, tokenEndpoint, umaUserId, umaUserSecret, umaAatClientId, umaAatClientSecret, umaRedirectUri);
m_aat = UmaClient.requestAat(tokenEndpoint, umaAatClientId, umaAatClientSecret);
UmaTestUtil.assert_(m_aat);
}

/**
* Test for the obtaining UMA AAT token using refresh token
*/
@Test(dependsOnMethods = {"testObtainAatTokenFlow"})
@Parameters({"umaUserId", "umaUserSecret", "umaAatClientId", "umaAatClientSecret", "umaRedirectUri"})
public void testObtainAatTokenUsingRefreshTokenFlow(final String umaUserId, final String umaUserSecret, final String umaAatClientId,
final String umaAatClientSecret, final String umaRedirectUri) throws Exception {
//@Test(dependsOnMethods = {"testObtainAatTokenFlow"})
@Parameters({"umaAatClientId", "umaAatClientSecret"})
public void testObtainAatTokenUsingRefreshTokenFlow(final String umaAatClientId, final String umaAatClientSecret) throws Exception {
showTitle("testObtainAatTokenUsingRefreshTokenFlow");

// Request new access token using the refresh token.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,20 @@ public class ObtainPatTokenFlowHttpTest extends BaseTest {
* Test for the obtaining UMA PAT token
*/
@Test
@Parameters({"umaUserId", "umaUserSecret", "umaPatClientId", "umaPatClientSecret", "umaRedirectUri"})
public void testObtainPatTokenFlow(final String umaUserId, final String umaUserSecret, final String umaPatClientId,
final String umaPatClientSecret, final String umaRedirectUri) throws Exception {
@Parameters({"umaPatClientId", "umaPatClientSecret"})
public void testObtainPatTokenFlow(final String umaPatClientId, final String umaPatClientSecret) throws Exception {
showTitle("testObtainPatTokenFlow");

m_pat = UmaClient.requestPat(authorizationEndpoint, tokenEndpoint, umaUserId, umaUserSecret, umaPatClientId, umaPatClientSecret, umaRedirectUri);
m_pat = UmaClient.requestPat(tokenEndpoint, umaPatClientId, umaPatClientSecret);
UmaTestUtil.assert_(m_pat);
}

/**
* Test for the obtaining UMA PAT token using refresh token
*/
@Test(dependsOnMethods = {"testObtainPatTokenFlow"})
@Parameters({"umaUserId", "umaUserSecret", "umaPatClientId", "umaPatClientSecret", "umaRedirectUri"})
public void testObtainPatTokenUsingRefreshTokenFlow(final String umaUserId, final String umaUserSecret, final String umaPatClientId, final String umaPatClientSecret,
final String umaRedirectUri) throws Exception {
//@Test(dependsOnMethods = {"testObtainPatTokenFlow"})
@Parameters({"umaPatClientId", "umaPatClientSecret"})
public void testObtainPatTokenUsingRefreshTokenFlow(final String umaPatClientId, final String umaPatClientSecret) throws Exception {
showTitle("testObtainPatTokenUsingRefreshTokenFlow");

// Request new access token using the refresh token.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,14 @@ public ObtainRptTokenFlowHttpTest(MetadataConfiguration metadataConfiguration) {
}

@BeforeClass
@Parameters({"umaMetaDataUrl", "umaUserId", "umaUserSecret", "umaAatClientId", "umaAatClientSecret", "umaRedirectUri"})
public void init(final String umaMetaDataUrl, final String umaUserId, final String umaUserSecret, final String umaAatClientId, final String umaAatClientSecret,
final String umaRedirectUri) throws Exception {
@Parameters({"umaMetaDataUrl", "umaAatClientId", "umaAatClientSecret"})
public void init(final String umaMetaDataUrl, final String umaAatClientId, final String umaAatClientSecret) throws Exception {
if (this.metadataConfiguration == null) {
this.metadataConfiguration = UmaClientFactory.instance().createMetaDataConfigurationService(umaMetaDataUrl).getMetadataConfiguration();
UmaTestUtil.assert_(this.metadataConfiguration);
}

m_aat = UmaClient.requestAat(authorizationEndpoint, tokenEndpoint, umaUserId, umaUserSecret, umaAatClientId, umaAatClientSecret, umaRedirectUri);
m_aat = UmaClient.requestAat(tokenEndpoint, umaAatClientId, umaAatClientSecret);
UmaTestUtil.assert_(m_aat);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,14 @@ public RegisterResourceSetFlowHttpTest(MetadataConfiguration metadataConfigurati
}

@BeforeClass
@Parameters({"umaMetaDataUrl", "umaUserId", "umaUserSecret", "umaPatClientId", "umaPatClientSecret", "umaRedirectUri"})
public void init(final String umaMetaDataUrl, final String umaUserId, final String umaUserSecret,
final String umaPatClientId, final String umaPatClientSecret, final String umaRedirectUri) throws Exception {
@Parameters({"umaMetaDataUrl", "umaPatClientId", "umaPatClientSecret"})
public void init(final String umaMetaDataUrl, final String umaPatClientId, final String umaPatClientSecret) throws Exception {
if (this.metadataConfiguration == null) {
this.metadataConfiguration = UmaClientFactory.instance().createMetaDataConfigurationService(umaMetaDataUrl).getMetadataConfiguration();
UmaTestUtil.assert_(this.metadataConfiguration);
}

m_pat = UmaClient.requestPat(authorizationEndpoint, tokenEndpoint, umaUserId, umaUserSecret, umaPatClientId, umaPatClientSecret, umaRedirectUri);
m_pat = UmaClient.requestPat(tokenEndpoint, umaPatClientId, umaPatClientSecret);
UmaTestUtil.assert_(m_pat);
}

Expand Down
Loading

0 comments on commit de99fba

Please sign in to comment.