use of org.forgerock.json.resource.Connection in project OpenAM by OpenRock.
the class ElevatedConnectionFactoryWrapperTest method requestGetsElevatedToAdminSession.
@Test
public void requestGetsElevatedToAdminSession() throws Exception {
// Given
SSOToken ssoToken = mock(SSOToken.class);
given(ssoTokenPrivilegedAction.run()).willReturn(ssoToken);
SSOPrincipal principal = new SSOPrincipal("test");
given(ssoToken.getPrincipal()).willReturn(principal);
SSOTokenID tokenID = mock(SSOTokenID.class);
given(ssoToken.getTokenID()).willReturn(tokenID);
given(internalConnectionFactory.getConnection()).willReturn(connection);
// When
RootContext context = new RootContext();
ReadRequest readRequest = Requests.newReadRequest("/test", "abc");
try (Connection connection = connectionFactory.getConnection()) {
connection.read(context, readRequest);
}
// Then
verify(connection).read(contextCaptor.capture(), eq(readRequest));
Context capturedContext = contextCaptor.getValue();
assertThat(capturedContext.containsContext(SecurityContext.class)).isTrue();
SecurityContext securityContext = capturedContext.asContext(SecurityContext.class);
assertThat(securityContext.getAuthenticationId()).isEqualTo("test");
assertThat(securityContext.getAuthorization()).containsOnlyKeys("authLevel", "tokenId");
}
use of org.forgerock.json.resource.Connection in project OpenAM by OpenRock.
the class TrustedDevicesResourceTest method shouldDeleteTrustedDevice.
@Test
public void shouldDeleteTrustedDevice() throws ResourceException {
//Given
DeleteRequest request = Requests.newDeleteRequest("UUID_1");
Connection connection = newInternalConnection(newCollection(resource));
List<JsonValue> devices = new ArrayList<JsonValue>();
devices.add(json(object(field("uuid", "UUID_1"), field("name", "NAME_1"))));
devices.add(json(object(field("uuid", "UUID_2"), field("name", "NAME_2"))));
given(dao.getDeviceProfiles(anyString(), anyString())).willReturn(devices);
//When
connection.delete(ctx(), request);
//Then
ArgumentCaptor<List> devicesCaptor = ArgumentCaptor.forClass(List.class);
verify(dao).saveDeviceProfiles(anyString(), anyString(), devicesCaptor.capture());
assertThat(devicesCaptor.getValue()).hasSize(1);
}
use of org.forgerock.json.resource.Connection in project OpenAM by OpenRock.
the class TrustedDevicesResourceTest method shouldQueryTrustedDevices.
@Test
public void shouldQueryTrustedDevices() throws ResourceException {
//Given
QueryRequest request = Requests.newQueryRequest("");
Connection connection = newInternalConnection(newCollection(resource));
QueryResourceHandler handler = mock(QueryResourceHandler.class);
List<JsonValue> devices = new ArrayList<>();
devices.add(json(object(field("name", "NAME_1"), field("lastSelectedDate", new Date().getTime()))));
devices.add(json(object(field("name", "NAME_2"), field("lastSelectedDate", new Date().getTime() + 1000))));
given(dao.getDeviceProfiles(anyString(), anyString())).willReturn(devices);
//When
connection.query(ctx(), request, handler);
//Then
verify(handler, times(2)).handleResource(Matchers.<ResourceResponse>anyObject());
}
use of org.forgerock.json.resource.Connection in project OpenAM by OpenRock.
the class AuditEventPublisherImpl method publishForRealm.
private void publishForRealm(String realm, String topic, AuditEvent auditEvent) throws ResourceException {
AMAuditService auditService = auditServiceProvider.getAuditService(realm);
Connection connection = newInternalConnection(auditService);
CreateRequest request = newCreateRequest(topic, auditEvent.getValue());
try {
connection.create(new RootContext(), request);
} catch (ServiceUnavailableException e) {
debug.message("Audit Service for realm {} is unavailable. Trying the default Audit Service.", realm, e);
publishToDefault(topic, auditEvent);
}
}
use of org.forgerock.json.resource.Connection in project OpenAM by OpenRock.
the class TrustedDevicesResourceTest method shouldNotDeleteTrustedDeviceWhenNotFound.
@Test(expectedExceptions = NotFoundException.class)
public void shouldNotDeleteTrustedDeviceWhenNotFound() throws ResourceException {
//Given
DeleteRequest request = Requests.newDeleteRequest("UUID_3");
Connection connection = newInternalConnection(newCollection(resource));
List<JsonValue> devices = new ArrayList<JsonValue>();
devices.add(json(object(field("uuid", "UUID_1"), field("name", "NAME_1"))));
devices.add(json(object(field("uuid", "UUID_2"), field("name", "NAME_2"))));
given(dao.getDeviceProfiles(anyString(), anyString())).willReturn(devices);
//When
connection.delete(ctx(), request);
//Then
//Expected NotFoundException
}
Aggregations