DoorsOauthSample & Lyo 2.4 & DOORS 9.7 & Java 11

Changes:

  1. Used Java 11,

  2. Replaced wink with jersey
    RuntimeDelegate.setInstance(new org.glassfish.jersey.server.internal.RuntimeDelegateImpl());

  3. get a org.eclipse.lyo.client.oslc.OAuthRedirectException on step 3:

     		//STEP 3: Try to access the context URL to trigger the OAuth dance and login
     		try {
     			client.getResource(webContextUrl,OSLCConstants.CT_RDF);
     		} catch (OAuthRedirectException oauthE) {
     			validateTokens(client,	oauthE.getRedirectURL() + "?oauth_token=" + oauthE.getAccessor().requestToken, user, passwd, webContextUrl + "/j_acegi_security_check" );
     			// Try to access again
     			***ClientResponse response = client.getResource(webContextUrl,OSLCConstants.CT_RDF);***
     			response.getEntity(InputStream.class).close();
     		}
    
  4. Console output:
    DEBUG [main] (DefaultRequestDirector.java:683) - Attempt 1 to execute request
    DEBUG [main] (DefaultClientConnection.java:268) - Sending request: GET /dwa/oauth-request-token?oauth_consumer_key=mykey&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1580955369&oauth_nonce=194445792445900&oauth_version=1.0&oauth_signature=3NwKSQ4u%2BRYapf4pARTu%2BsBZnf8%3D HTTP/1.1
    DEBUG [main] (DefaultClientConnection.java:272) - >> GET /dwa/oauth-request-token?oauth_consumer_key=mykey&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1580955369&oauth_nonce=194445792445900&oauth_version=1.0&oauth_signature=3NwKSQ4u%2BRYapf4pARTu%2BsBZnf8%3D HTTP/1.1
    DEBUG [main] (DefaultClientConnection.java:275) - >> Host: myhostname:8080
    DEBUG [main] (DefaultClientConnection.java:275) - >> Connection: Keep-Alive
    DEBUG [main] (DefaultClientConnection.java:275) - >> User-Agent: Apache-HttpClient/4.5 (Java/11.0.5)
    DEBUG [main] (DefaultClientConnection.java:275) - >> Cookie: JSESSIONID=146242D83C718BFD0D14E5B46B6F8DBE
    DEBUG [main] (DefaultClientConnection.java:253) - Receiving response: HTTP/1.1 200
    DEBUG [main] (DefaultClientConnection.java:256) - << HTTP/1.1 200
    DEBUG [main] (DefaultClientConnection.java:259) - << Content-Type: application/x-www-form-urlencoded;charset=ISO-8859-1
    DEBUG [main] (DefaultClientConnection.java:259) - << Transfer-Encoding: chunked
    DEBUG [main] (DefaultClientConnection.java:259) - << Date: Thu, 06 Feb 2020 02:16:09 GMT
    DEBUG [main] (DefaultRequestDirector.java:510) - Connection can be kept alive indefinitely
    DEBUG [main] (ThreadSafeClientConnManager.java:280) - Released connection is reusable.
    DEBUG [main] (ConnPoolByRoute.java:429) - Releasing connection [{}->WebURL//myhostname:8080][null]
    DEBUG [main] (ConnPoolByRoute.java:455) - Pooling connection [{}->WebURL//myhostname:8080][null]; keep alive indefinitely
    DEBUG [main] (ConnPoolByRoute.java:676) - Notifying no-one, there are no waiting threads
    Enter this URL in a browser and run again: WebURL//myhostname:8080/dwa/oauth-authorize-token?oauth_token=6d934153-d152-4942-a378-32c9f1549305
    Feb 05, 2020 7:16:09 PM org.eclipse.lyo.client.oslc.samples.DoorsOauthSample main
    SEVERE: null
    org.eclipse.lyo.client.oslc.OAuthRedirectException
    at org.eclipse.lyo.client.oslc.OslcOAuthClient.getResourceInternal(OslcOAuthClient.java:191)
    at org.eclipse.lyo.client.oslc.OslcOAuthClient.getResourceInternal(OslcOAuthClient.java:208)
    at org.eclipse.lyo.client.oslc.OslcOAuthClient.getAuthorizationHeader(OslcOAuthClient.java:155)
    at org.eclipse.lyo.client.oslc.OslcOAuthClient.getResource(OslcOAuthClient.java:115)
    at org.eclipse.lyo.client.oslc.OslcClient.getResource(OslcClient.java:204)
    at org.eclipse.lyo.client.oslc.samples.DoorsOauthSample.main(DoorsOauthSample.java:151)

Hello and welcome to the OSLC forum!

@jamsden has experience with that sample. Before we start debugging, did you read https://www.eclipse.org/forums/index.php/t/1065558/? In other words, do you go to the URL in the myhostname:8080/dwa/oauth-authorize-token?oauth_token=6d934153-d152-4942-a378-32c9f1549305 and still get the exception after re-running?

If you wish to have an app that does not require restart during the OAuth “dance”, please see https://github.com/OSLC/lyo-samples/tree/master/client-oauth-discovery-dui from @jad.

still get the exception after re-running? Yes.

Looked at “https://github.com/OSLC/lyo-samples/tree/master/client-oauth-discovery-dui” and its a Web Application. So, I would replace how we create a OslcOAuthClient (using helper) with using the factory?

OslcOAuthClientBuilder oAuthClientBuilder = OslcClientFactory.oslcOAuthClientBuilder();
oAuthClientBuilder.setFromRootService(rootService);
oAuthClientBuilder.setOAuthConsumer("", consumerKey, consumerSecret);
oAuthClientBuilder.setClientBuilder(clientBuilder);
oAuthClientBuilder.setUnderlyingHttpClient(new UnderlyingHttpClient() {
@Override
public HttpClient get(Client client) {
return ApacheConnectorProvider.getHttpClient(client);
}
});
client = (OslcOAuthClient) oAuthClientBuilder.build();
bindClientToSession(httpServletRequest, client, consumerKey);

Additionally, DOORS classic 9.7 with DOORS Web Access DWA only supports Oauth 1.0 & 1.0a. Does your client code support these versions?

PS thanks for the help :smiley:

Hi

So, I would replace how we create a OslcOAuthClient (using helper ) with using the factory?

Yes! But please note that the OslcClientFactory is the new OSLC client (Lyo 4.0) for Jersey. I believe the DoorsOauthSample code you were looking at is based on Lyo 2.4 (and hence Wink)

Additionally, DOORS classic 9.7 with DOORS Web Access DWA only supports Oauth 1.0 & 1.0a. Does your client code support these versions?

The sample code does support Oauth 1.0 (But I am not exactly sure if it support both 1.0 and 1.0a, but at least one of them for sure.)

I tried to build/run https://github.com/OSLC/lyo-samples/tree/master/client-oauth-discovery-dui and got:

Blockquote Could not find artifact org.eclipse.lyo.clients:oslc4j-client:jar:2.4.0

The pom sets:

Blockquote <version.lyo>4.0.0-SNAPSHOT</version.lyo>

So, not sure why the project is looking for 2.4.0?