use of net.minidev.json.JSONObject in project cas by apereo.
the class TokenWebApplicationServiceResponseBuilder method generateToken.
/**
* Generate token string.
*
* @param service the service
* @param parameters the parameters
* @return the jwt
*/
protected String generateToken(final Service service, final Map<String, String> parameters) {
try {
final String ticketId = parameters.get(CasProtocolConstants.PARAMETER_TICKET);
final Cas30ServiceTicketValidator validator = new Cas30ServiceTicketValidator(casProperties.getServer().getPrefix());
final Assertion assertion = validator.validate(ticketId, service.getId());
final JWTClaimsSet.Builder claims = new JWTClaimsSet.Builder().audience(service.getId()).issuer(casProperties.getServer().getPrefix()).jwtID(ticketId).issueTime(assertion.getAuthenticationDate()).subject(assertion.getPrincipal().getName());
assertion.getAttributes().forEach(claims::claim);
assertion.getPrincipal().getAttributes().forEach(claims::claim);
if (assertion.getValidUntilDate() != null) {
claims.expirationTime(assertion.getValidUntilDate());
} else {
final ZonedDateTime dt = ZonedDateTime.now().plusSeconds(ticketGrantingTicketExpirationPolicy.getTimeToLive());
claims.expirationTime(DateTimeUtils.dateOf(dt));
}
final JWTClaimsSet claimsSet = claims.build();
final JSONObject object = claimsSet.toJSONObject();
return tokenCipherExecutor.encode(object.toJSONString());
} catch (final Exception e) {
throw Throwables.propagate(e);
}
}
use of net.minidev.json.JSONObject in project nifi by apache.
the class TestPutRethinkDB method testValidSingleMessage.
@Test
public void testValidSingleMessage() {
runner.setProperty(PutRethinkDB.MAX_DOCUMENTS_SIZE, "1 MB");
runner.assertValid();
result.remove(PutRethinkDB.RESULT_FIRST_ERROR_KEY);
result.remove(PutRethinkDB.RESULT_WARNINGS_KEY);
JSONObject message = new JSONObject();
message.put("hello", "rethinkdb");
byte[] bytes = message.toJSONString().getBytes();
runner.enqueue(bytes);
runner.run(1, true, true);
runner.assertAllFlowFilesTransferred(PutRethinkDB.REL_SUCCESS, 1);
List<MockFlowFile> flowFiles = runner.getFlowFilesForRelationship(PutRethinkDB.REL_SUCCESS);
assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_DELETED_KEY), "0");
assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_ERROR_KEY), "0");
assertNotNull(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_GENERATED_KEYS_KEY));
assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_INSERTED_KEY), "1");
assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_REPLACED_KEY), "0");
assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_SKIPPED_KEY), "0");
assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_UNCHANGED_KEY), "0");
assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_FIRST_ERROR_KEY), "null");
assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_FIRST_ERROR_KEY), "null");
}
use of net.minidev.json.JSONObject in project nifi by apache.
the class ITDeleteRethinkDBTest method testDeleteDocumentByIdNoChanges.
@Test
public void testDeleteDocumentByIdNoChanges() {
JSONObject message = new JSONObject();
message.put("id", "11");
message.put("value", "one");
RethinkDB.r.db(dbName).table(table).insert(message).run(connection);
long count = RethinkDB.r.db(dbName).table(table).count().run(connection);
assertEquals("Count should be same", 1L, count);
runner.setProperty(AbstractRethinkDBProcessor.RETHINKDB_DOCUMENT_ID, "${rethinkdb.id}");
runner.setProperty(DeleteRethinkDB.RETURN_CHANGES, "false");
Map<String, String> props = new HashMap<>();
props.put("rethinkdb.id", "11");
runner.enqueue(new byte[] {}, props);
runner.run(1, true, true);
runner.assertAllFlowFilesTransferred(AbstractRethinkDBProcessor.REL_SUCCESS, 1);
List<MockFlowFile> flowFiles = runner.getFlowFilesForRelationship(AbstractRethinkDBProcessor.REL_SUCCESS);
assertEquals("Flow file count should be same", 1, flowFiles.size());
assertEquals("Error should be null", null, flowFiles.get(0).getAttribute(AbstractRethinkDBProcessor.RETHINKDB_ERROR_MESSAGE));
assertEquals(flowFiles.get(0).getAttribute(DeleteRethinkDB.RETHINKDB_DELETE_RESULT_DELETED_KEY), "1");
assertEquals(flowFiles.get(0).getAttribute(DeleteRethinkDB.RETHINKDB_DELETE_RESULT_ERROR_KEY), "0");
assertEquals(flowFiles.get(0).getAttribute(DeleteRethinkDB.RETHINKDB_DELETE_RESULT_INSERTED_KEY), "0");
assertEquals(flowFiles.get(0).getAttribute(DeleteRethinkDB.RETHINKDB_DELETE_RESULT_REPLACED_KEY), "0");
assertEquals(flowFiles.get(0).getAttribute(DeleteRethinkDB.RETHINKDB_DELETE_RESULT_SKIPPED_KEY), "0");
assertEquals(flowFiles.get(0).getAttribute(DeleteRethinkDB.RETHINKDB_DELETE_RESULT_UNCHANGED_KEY), "0");
assertEquals(flowFiles.get(0).getSize(), 0);
Map<String, Object> document = RethinkDB.r.db(dbName).table(table).get("1").run(connection);
assertEquals("Document should be null", document, null);
}
use of net.minidev.json.JSONObject in project nifi by apache.
the class ITGetRethinkDBTest method testGetDocumentByHardCodedId.
@Test
public void testGetDocumentByHardCodedId() {
JSONObject message = new JSONObject();
message.put("id", "2");
message.put("value", "two");
RethinkDB.r.db(dbName).table(table).insert(message).run(connection);
long count = RethinkDB.r.db(dbName).table(table).count().run(connection);
assertEquals("Count should be same", 1, count);
runner.setProperty(GetRethinkDB.RETHINKDB_DOCUMENT_ID, "2");
runner.assertValid();
Map<String, String> props = new HashMap<>();
runner.enqueue(new byte[] {}, props);
runner.run(1, true, true);
runner.assertAllFlowFilesTransferred(AbstractRethinkDBProcessor.REL_SUCCESS, 1);
List<MockFlowFile> flowFiles = runner.getFlowFilesForRelationship(AbstractRethinkDBProcessor.REL_SUCCESS);
assertEquals("Flow file count should be same", 1, flowFiles.size());
assertEquals("Error should be null", null, flowFiles.get(0).getAttribute(AbstractRethinkDBProcessor.RETHINKDB_ERROR_MESSAGE));
assertEquals("Content should be same size", message.toString().length(), flowFiles.get(0).getSize());
flowFiles.get(0).assertContentEquals(message.toString());
}
use of net.minidev.json.JSONObject in project nifi by apache.
the class ITPutRethinkDBTest method testValidArrayMessage.
@Test
public void testValidArrayMessage() {
runner.assertValid();
RethinkDB.r.db(dbName).table(table).delete().run(connection);
long count = RethinkDB.r.db(dbName).table(table).count().run(connection);
assertEquals("Count should be same", 0L, count);
JSONObject message1 = new JSONObject();
message1.put("hello", "rethinkdb");
JSONObject message2 = new JSONObject();
message2.put("hello2", "rethinkdb2");
JSONArray array = new JSONArray();
array.add(message1);
array.add(message2);
byte[] bytes = array.toJSONString().getBytes();
runner.enqueue(bytes);
runner.run(1, true, true);
runner.assertAllFlowFilesTransferred(PutRethinkDB.REL_SUCCESS, 1);
List<MockFlowFile> flowFiles = runner.getFlowFilesForRelationship(PutRethinkDB.REL_SUCCESS);
assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_DELETED_KEY), "0");
assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_ERROR_KEY), "0");
assertNotNull(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_GENERATED_KEYS_KEY));
assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_INSERTED_KEY), "2");
assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_REPLACED_KEY), "0");
assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_SKIPPED_KEY), "0");
assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_UNCHANGED_KEY), "0");
assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_FIRST_ERROR_KEY), "null");
count = RethinkDB.r.db(dbName).table(table).count().run(connection);
assertEquals("Count should be same", 2L, count);
}
Aggregations