Automatically Update Access Token #916

Closed
ahmetkarakaya opened this Issue Jan 10, 2017 · 6 comments

Projects

None yet

2 participants

@ahmetkarakaya
ahmetkarakaya commented Jan 10, 2017 edited

After authenticated I use access until it expires, but when it is expired it does not updated automcatically,
Do I need to check Access() is expired or not manually inside an other thread?

		os = OSFactory.builder().endpoint("http://" + ip + ":5000/v2.0")
			.credentials("testtimsoperator", "123456")
			.tenantName(bipTenantName)
			.perspective(Facing.ADMIN)	//Container oluşturmak için
			//.scopeToProject(projectIdentifier, domainIdentifier)  V3 ile gelen bir özellik.			
			.authenticate();

OSFactory.clientFromAccess(os.getAccess(););

long delay = os.getAccess().getToken().getExpires().getTime() - System.currentTimeMillis();

sleep(delay+5000);

User user = findUserByName("user1");
   
User user2 = findUserByName("user2");


	<dependency>
		<groupId>org.pacesys</groupId>
		<artifactId>openstack4j</artifactId>
		<version>2.20</version>
	</dependency>

	<dependency>
		<groupId>org.pacesys.openstack4j.connectors</groupId>
		<artifactId>openstack4j-jersey2</artifactId>
		<version>2.20</version>
  </dependency>
@auhlig
Member
auhlig commented Jan 12, 2017

Hi @ahmetkarakaya
Reauthentication should be triggered in case the code of the response is 401.
Could you check that's the case?

@ahmetkarakaya
ahmetkarakaya commented Jan 13, 2017 edited

@auhlig yes reauthentication is triggered but newly taken token is only used by one request. For other request to be invoked, same steps are repeated.
I mean first token is used then having 401 error then taken new token to retry the request, I have updated my question by adding sample code portion. As you can see than I have added a delay to expire the token , after then invoking findUserByName() method , I am getting 401 so getting a new token then retring the request.
The problem is when I was invoking findUserByName("user2") I was expecting previous token would be used but I got 401 error then getting a new token . I have analyzed debug logs,

@auhlig
Member
auhlig commented Jan 14, 2017 edited

Understood. Renewed token only used for request. Original token still assigned to session.

Here https://github.com/ContainX/openstack4j/blob/master/connectors/http-connector/src/main/java/org/openstack4j/connectors/http/HttpExecutorServiceImpl.java#L61 we check if the response code is 401, in which case the we trigger re-authentication in ll. 64 and assign the new access to the current request https://github.com/ContainX/openstack4j/blob/master/connectors/http-connector/src/main/java/org/openstack4j/connectors/http/HttpExecutorServiceImpl.java#L65 .

The authentication-method should also assign the new access to the current session https://github.com/ContainX/openstack4j/blob/master/core/src/main/java/org/openstack4j/openstack/internal/OSAuthenticator.java#L116 .
Maybe it fails here somewhere.

Would you like to contribute and look into that? I would support.

@ahmetkarakaya
ahmetkarakaya commented Jan 15, 2017 edited

I have found my faulth that I am always invoking "OSFactory.clientFromAccess(access);" before calling a request and using the same access token.
When I have used OSClient directly instead of OSFactory.clientFromAccess(os.getAccess(), Facing.ADMIN),
I see reauthentication is invoked successfully and newly token is used next request until it expires.

But I am trying to find a solution to a case that
How can I use a single os client with different facing, I need such a case that there many rest requests in a method AllinOneMethod(), some of which must be invoked by ADMIN facing some of which are invokde by null FACING.

@auhlig
Member
auhlig commented Jan 15, 2017

No bug then 😅
Threading maybe. Can we close the issue, since there seems to be no bug? Maybe the google group or stackoverflow community can be of help.

@ahmetkarakaya

thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment