Search in sources :

Example 1 with SecureStoreData

use of io.cdap.cdap.api.security.store.SecureStoreData in project cdap by caskdata.

the class FakeSecureStore method get.

@Override
public SecureStoreData get(String namespace, String name) throws Exception {
    Map<String, SecureStoreData> namespaceData = values.get(namespace);
    if (namespaceData == null) {
        throw new Exception("namespace " + namespace + " does not exist");
    }
    SecureStoreData data = namespaceData.get(name);
    if (data == null) {
        throw new Exception("Data for name " + name + " does not exist");
    }
    return data;
}
Also used : SecureStoreData(io.cdap.cdap.api.security.store.SecureStoreData)

Example 2 with SecureStoreData

use of io.cdap.cdap.api.security.store.SecureStoreData in project cdap by caskdata.

the class FileSecureStoreServiceTest method testGet.

@Test
public void testGet() throws Exception {
    populateStore();
    SecureStoreMetadata metadata = new SecureStoreMetadata(KEY1, DESCRIPTION1, System.currentTimeMillis(), PROPERTIES_1);
    SecureStoreData secureStoreData = new SecureStoreData(metadata, VALUE1.getBytes(Charsets.UTF_8));
    Assert.assertArrayEquals(secureStoreData.get(), secureStore.get(NAMESPACE1, KEY1).get());
    Assert.assertEquals(metadata.getDescription(), secureStore.get(NAMESPACE1, KEY1).getMetadata().getDescription());
    Assert.assertEquals(metadata.getName(), secureStore.get(NAMESPACE1, KEY1).getMetadata().getName());
}
Also used : SecureStoreData(io.cdap.cdap.api.security.store.SecureStoreData) SecureStoreMetadata(io.cdap.cdap.api.security.store.SecureStoreMetadata) Test(org.junit.Test)

Example 3 with SecureStoreData

use of io.cdap.cdap.api.security.store.SecureStoreData in project cdap by caskdata.

the class FileSecureStoreServiceTest method testDelete.

@Test(expected = NotFoundException.class)
public void testDelete() throws Exception {
    populateStore();
    SecureStoreMetadata metadata = new SecureStoreMetadata(KEY1, DESCRIPTION1, System.currentTimeMillis(), PROPERTIES_1);
    SecureStoreData secureStoreData = new SecureStoreData(metadata, VALUE1.getBytes(Charsets.UTF_8));
    Assert.assertArrayEquals(secureStoreData.get(), secureStore.get(NAMESPACE1, KEY1).get());
    secureStoreManager.delete(NAMESPACE1, KEY1);
    try {
        secureStore.get(NAMESPACE1, KEY1);
    } catch (IOException ioe) {
        Assert.assertTrue(ioe.getMessage().contains("not found in the secure store"));
        throw ioe;
    }
}
Also used : SecureStoreData(io.cdap.cdap.api.security.store.SecureStoreData) SecureStoreMetadata(io.cdap.cdap.api.security.store.SecureStoreMetadata) IOException(java.io.IOException) Test(org.junit.Test)

Example 4 with SecureStoreData

use of io.cdap.cdap.api.security.store.SecureStoreData in project cdap by caskdata.

the class SecretManagerSecureStoreService method get.

@Override
public SecureStoreData get(String namespace, String name) throws Exception {
    validate(namespace);
    try {
        Secret secret = secretManager.get(namespace, name);
        SecretMetadata metadata = secret.getMetadata();
        return new SecureStoreData(new SecureStoreMetadata(metadata.getName(), metadata.getDescription(), metadata.getCreationTimeMs(), metadata.getProperties()), secret.getData());
    } catch (SecretNotFoundException e) {
        throw new SecureKeyNotFoundException(new SecureKeyId(namespace, name), e);
    }
}
Also used : Secret(io.cdap.cdap.securestore.spi.secret.Secret) SecureStoreData(io.cdap.cdap.api.security.store.SecureStoreData) SecureKeyId(io.cdap.cdap.proto.id.SecureKeyId) SecureStoreMetadata(io.cdap.cdap.api.security.store.SecureStoreMetadata) SecretMetadata(io.cdap.cdap.securestore.spi.secret.SecretMetadata) SecureKeyNotFoundException(io.cdap.cdap.common.SecureKeyNotFoundException) SecretNotFoundException(io.cdap.cdap.securestore.spi.SecretNotFoundException)

Example 5 with SecureStoreData

use of io.cdap.cdap.api.security.store.SecureStoreData in project cdap by caskdata.

the class RemoteSecureStore method get.

@Override
public SecureStoreData get(String namespace, String name) throws Exception {
    // 1. Get metadata of the secure key
    HttpRequest request = remoteClient.requestBuilder(HttpMethod.GET, createPath(namespace, name) + "/metadata").build();
    HttpResponse response = remoteClient.execute(request);
    handleResponse(response, namespace, name, String.format("Error occurred while getting metadata for key %s:%s", namespace, name));
    SecureStoreMetadata metadata = GSON.fromJson(response.getResponseBodyAsString(), SecureStoreMetadata.class);
    // 2. Get sensitive data for the secure key
    request = remoteClient.requestBuilder(HttpMethod.GET, createPath(namespace, name)).build();
    response = remoteClient.execute(request);
    handleResponse(response, namespace, name, String.format("Error occurred while getting key %s:%s", namespace, name));
    // response is not a json object
    byte[] data = response.getResponseBody();
    return new SecureStoreData(metadata, data);
}
Also used : HttpRequest(io.cdap.common.http.HttpRequest) SecureStoreData(io.cdap.cdap.api.security.store.SecureStoreData) SecureStoreMetadata(io.cdap.cdap.api.security.store.SecureStoreMetadata) HttpResponse(io.cdap.common.http.HttpResponse)

Aggregations

SecureStoreData (io.cdap.cdap.api.security.store.SecureStoreData)12 SecureStoreMetadata (io.cdap.cdap.api.security.store.SecureStoreMetadata)9 Test (org.junit.Test)5 SecureKeyId (io.cdap.cdap.proto.id.SecureKeyId)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 NamespaceNotFoundException (io.cdap.cdap.common.NamespaceNotFoundException)1 NotFoundException (io.cdap.cdap.common.NotFoundException)1 SecureKeyNotFoundException (io.cdap.cdap.common.SecureKeyNotFoundException)1 SecretNotFoundException (io.cdap.cdap.securestore.spi.SecretNotFoundException)1 Secret (io.cdap.cdap.securestore.spi.secret.Secret)1 SecretMetadata (io.cdap.cdap.securestore.spi.secret.SecretMetadata)1 HttpRequest (io.cdap.common.http.HttpRequest)1 HttpResponse (io.cdap.common.http.HttpResponse)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 DataInputStream (java.io.DataInputStream)1 KeyStoreException (java.security.KeyStoreException)1 SecretKeySpec (javax.crypto.spec.SecretKeySpec)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1