use of com.ibm.cloud.cloudant.v1.model.Security in project cloudant-java-sdk by IBM.
the class Cloudant method getSecurity.
/**
* Retrieve database permissions information.
*
* See who has permission to read, write, and manage the database. The credentials you use to log in to the dashboard
* automatically include `_admin` permissions to all databases you create. Everyone and everything else, including
* users you share databases with and API keys you create, must be given a permission level explicitly.
*
* @param getSecurityOptions the {@link GetSecurityOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link Security}
*/
public ServiceCall<Security> getSecurity(GetSecurityOptions getSecurityOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(getSecurityOptions, "getSecurityOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("db", getSecurityOptions.db());
RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}/_security", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "getSecurity");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
ResponseConverter<Security> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Security>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
use of com.ibm.cloud.cloudant.v1.model.Security in project cloudant-java-sdk by IBM.
the class SecurityTest method testSecurity.
@Test
public void testSecurity() throws Throwable {
SecurityObject securityObjectModel = new SecurityObject.Builder().names(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).roles(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).build();
assertEquals(securityObjectModel.names(), new java.util.ArrayList<String>(java.util.Arrays.asList("testString")));
assertEquals(securityObjectModel.roles(), new java.util.ArrayList<String>(java.util.Arrays.asList("testString")));
Security securityModel = new Security.Builder().admins(securityObjectModel).members(securityObjectModel).cloudant(new java.util.HashMap<String, List<String>>() {
{
put("foo", new java.util.ArrayList<String>(java.util.Arrays.asList("_reader")));
}
}).couchdbAuthOnly(true).build();
assertEquals(securityModel.admins(), securityObjectModel);
assertEquals(securityModel.members(), securityObjectModel);
assertEquals(securityModel.cloudant(), new java.util.HashMap<String, List<String>>() {
{
put("foo", new java.util.ArrayList<String>(java.util.Arrays.asList("_reader")));
}
});
assertEquals(securityModel.couchdbAuthOnly(), Boolean.valueOf(true));
String json = TestUtilities.serialize(securityModel);
Security securityModelNew = TestUtilities.deserialize(json, Security.class);
assertTrue(securityModelNew instanceof Security);
assertEquals(securityModelNew.admins().toString(), securityObjectModel.toString());
assertEquals(securityModelNew.members().toString(), securityObjectModel.toString());
assertEquals(securityModelNew.couchdbAuthOnly(), Boolean.valueOf(true));
}
use of com.ibm.cloud.cloudant.v1.model.Security in project cloudant-java-sdk by IBM.
the class CloudantTest method testGetSecurityWOptions.
@Test
public void testGetSecurityWOptions() throws Throwable {
// Schedule some responses.
String mockResponseBody = "{\"admins\": {\"names\": [\"names\"], \"roles\": [\"roles\"]}, \"members\": {\"names\": [\"names\"], \"roles\": [\"roles\"]}, \"cloudant\": {\"mapKey\": [\"_reader\"]}, \"couchdb_auth_only\": false}";
String getSecurityPath = "/testString/_security";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
constructClientService();
// Construct an instance of the GetSecurityOptions model
GetSecurityOptions getSecurityOptionsModel = new GetSecurityOptions.Builder().db("testString").build();
// Invoke operation with valid options model (positive test)
Response<Security> response = cloudantService.getSecurity(getSecurityOptionsModel).execute();
assertNotNull(response);
Security responseObj = response.getResult();
assertNotNull(responseObj);
// Verify the contents of the request
RecordedRequest request = server.takeRequest();
assertNotNull(request);
assertEquals(request.getMethod(), "GET");
// Check query
Map<String, String> query = TestUtilities.parseQueryString(request);
assertNull(query);
// Check request path
String parsedPath = TestUtilities.parseReqPath(request);
assertEquals(parsedPath, getSecurityPath);
}
Aggregations