Search in sources :

Example 26 with AccessTokenResponse

use of com.tremolosecurity.proxy.auth.oauth2.AccessTokenResponse in project openhab-core by openhab.

the class OAuthStoreHandlerImpl method decryptToken.

private AccessTokenResponse decryptToken(AccessTokenResponse accessTokenResponse) throws GeneralSecurityException {
    AccessTokenResponse decryptedToken = (AccessTokenResponse) accessTokenResponse.clone();
    if (!storageCipher.isPresent()) {
        // do nothing if no cipher
        return decryptedToken;
    }
    logger.debug("Decrypting token: {}", accessTokenResponse);
    decryptedToken.setAccessToken(storageCipher.get().decrypt(accessTokenResponse.getAccessToken()));
    decryptedToken.setRefreshToken(storageCipher.get().decrypt(accessTokenResponse.getRefreshToken()));
    return decryptedToken;
}
Also used : AccessTokenResponse(org.openhab.core.auth.client.oauth2.AccessTokenResponse)

Example 27 with AccessTokenResponse

use of com.tremolosecurity.proxy.auth.oauth2.AccessTokenResponse in project openhab-core by openhab.

the class OAuthStoreHandlerImpl method saveAccessTokenResponse.

@Override
public void saveAccessTokenResponse(String handle, @Nullable AccessTokenResponse pAccessTokenResponse) {
    AccessTokenResponse accessTokenResponse = pAccessTokenResponse;
    if (accessTokenResponse == null) {
        // put empty
        accessTokenResponse = new AccessTokenResponse();
    }
    AccessTokenResponse encryptedToken;
    try {
        encryptedToken = encryptToken(accessTokenResponse);
    } catch (GeneralSecurityException e) {
        logger.warn("Unable to encrypt token, storing as-is", e);
        encryptedToken = accessTokenResponse;
    }
    storageFacade.put(handle, encryptedToken);
}
Also used : GeneralSecurityException(java.security.GeneralSecurityException) AccessTokenResponse(org.openhab.core.auth.client.oauth2.AccessTokenResponse)

Example 28 with AccessTokenResponse

use of com.tremolosecurity.proxy.auth.oauth2.AccessTokenResponse in project openhab-core by openhab.

the class AbstractTestAgent method testGetAccessTokenByResourceOwnerPasswordCredentials.

@Override
public AccessTokenResponse testGetAccessTokenByResourceOwnerPasswordCredentials() throws OAuthException, IOException, OAuthResponseException {
    logger.debug("test getOAuthTokenByResourceOwnerPasswordCredentials");
    if (handle == null) {
        logger.debug("Creating new oauth service");
        oauthClientService = testCreateClient();
    } else {
        logger.debug("getting oauth client by handle: {}", handle);
        oauthClientService = oauthFactory.getOAuthClientService(handle);
    }
    AccessTokenResponse accessTokenResponse = oauthClientService.getAccessTokenByResourceOwnerPasswordCredentials(username, password, scope);
    logger.debug("Token: {}", accessTokenResponse);
    return accessTokenResponse;
}
Also used : AccessTokenResponse(org.openhab.core.auth.client.oauth2.AccessTokenResponse)

Example 29 with AccessTokenResponse

use of com.tremolosecurity.proxy.auth.oauth2.AccessTokenResponse in project openhab-core by openhab.

the class AbstractTestAgent method testGetCachedAccessToken.

@Override
public AccessTokenResponse testGetCachedAccessToken() throws OAuthException, IOException, OAuthResponseException {
    logger.debug("test getCachedAccessToken");
    AccessTokenResponse oldRefreshedToken = oauthClientService.getAccessTokenResponse();
    return oldRefreshedToken;
}
Also used : AccessTokenResponse(org.openhab.core.auth.client.oauth2.AccessTokenResponse)

Example 30 with AccessTokenResponse

use of com.tremolosecurity.proxy.auth.oauth2.AccessTokenResponse in project smarthome by eclipse.

the class OAuthStoreHandlerImpl method loadAccessTokenResponse.

@Override
@Nullable
public AccessTokenResponse loadAccessTokenResponse(String handle) throws GeneralSecurityException {
    AccessTokenResponse accessTokenResponseFromStore = (AccessTokenResponse) storageFacade.get(handle, ACCESS_TOKEN_RESPONSE);
    if (accessTokenResponseFromStore == null) {
        // token does not exist
        return null;
    }
    AccessTokenResponse decryptedAccessToken = decryptToken(accessTokenResponseFromStore);
    return decryptedAccessToken;
}
Also used : AccessTokenResponse(org.eclipse.smarthome.core.auth.client.oauth2.AccessTokenResponse) Nullable(org.eclipse.jdt.annotation.Nullable)

Aggregations

AccessTokenResponse (org.openhab.core.auth.client.oauth2.AccessTokenResponse)36 OAuthException (org.openhab.core.auth.client.oauth2.OAuthException)17 IOException (java.io.IOException)15 AccessTokenResponse (org.eclipse.smarthome.core.auth.client.oauth2.AccessTokenResponse)12 OAuthResponseException (org.openhab.core.auth.client.oauth2.OAuthResponseException)12 ContentResponse (org.eclipse.jetty.client.api.ContentResponse)8 OAuthClientService (org.openhab.core.auth.client.oauth2.OAuthClientService)8 Nullable (org.eclipse.jdt.annotation.Nullable)7 ExecutionException (java.util.concurrent.ExecutionException)6 OAuthException (org.eclipse.smarthome.core.auth.client.oauth2.OAuthException)6 TimeoutException (java.util.concurrent.TimeoutException)5 Request (org.eclipse.jetty.client.api.Request)5 OAuthFactory (org.openhab.core.auth.client.oauth2.OAuthFactory)5 JsonSyntaxException (com.google.gson.JsonSyntaxException)4 GeneralSecurityException (java.security.GeneralSecurityException)4 NonNullByDefault (org.eclipse.jdt.annotation.NonNullByDefault)3 StringContentProvider (org.eclipse.jetty.client.util.StringContentProvider)3 Test (org.junit.jupiter.api.Test)3 PrivilegedActionException (java.security.PrivilegedActionException)2 Collections (java.util.Collections)2