use of ca.corefacility.bioinformatics.irida.model.IridaClientDetails in project irida by phac-nml.
the class ClientsControllerTest method testRead.
@Test
public void testRead() {
Long clientId = 1L;
ExtendedModelMap model = new ExtendedModelMap();
IridaClientDetails iridaClientDetails = new IridaClientDetails();
iridaClientDetails.setId(clientId);
when(clientDetailsService.read(clientId)).thenReturn(iridaClientDetails);
String detailsPage = controller.read(clientId, model);
assertEquals(ClientsController.CLIENT_DETAILS_PAGE, detailsPage);
assertEquals(model.get("client"), iridaClientDetails);
assertTrue(model.containsAttribute("grants"));
verify(clientDetailsService).read(clientId);
}
use of ca.corefacility.bioinformatics.irida.model.IridaClientDetails in project irida by phac-nml.
the class ClientsControllerTest method testGetEditPage.
@Test
public void testGetEditPage() {
IridaClientDetails client = new IridaClientDetails();
client.setAuthorizedGrantTypes(ImmutableSet.of("password"));
client.setScope(ImmutableSet.of("read"));
client.setAutoApprovableScopes(ImmutableSet.of(""));
Long id = 1L;
client.setId(id);
ExtendedModelMap model = new ExtendedModelMap();
when(clientDetailsService.read(id)).thenReturn(client);
String editPage = controller.getEditPage(id, model);
assertEquals(ClientsController.EDIT_CLIENT_PAGE, editPage);
assertTrue(model.containsAttribute("client"));
assertTrue(model.containsAttribute("given_scope_read"));
}
use of ca.corefacility.bioinformatics.irida.model.IridaClientDetails in project irida by phac-nml.
the class UserRevListener method setClientId.
/**
* Add the OAuth2 client ID to the revision listener if the user is
* connecting via OAuth2
*
* @param entity
* The revision entity to modify if necessary
*/
private void setClientId(UserRevEntity entity) {
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
// OAuth2Authentication
if (auth instanceof OAuth2Authentication) {
try {
logger.trace("Found OAuth2Authentication in session. Storing clientId in revision.");
OAuth2Authentication oAuth = (OAuth2Authentication) auth;
String clientId = oAuth.getOAuth2Request().getClientId();
IridaClientDetails clientDetails = clientRepo.loadClientDetailsByClientId(clientId);
entity.setClientId(clientDetails.getId());
} catch (NullPointerException ex) {
throw new IllegalStateException("The OAuth2 client details are not in the session so it cannot be added to the revision.");
}
}
}
use of ca.corefacility.bioinformatics.irida.model.IridaClientDetails in project irida by phac-nml.
the class ClientsControllerTest method testPostCreateClient.
@Test
public void testPostCreateClient() {
IridaClientDetails client = new IridaClientDetails();
client.setId(1L);
ExtendedModelMap model = new ExtendedModelMap();
String scope_read = "read";
String scope_write = "";
when(clientDetailsService.create(client)).thenReturn(client);
String postCreateClient = controller.postCreateClient(client, scope_read, scope_write, "", "", "", model, locale);
assertEquals("redirect:/clients/1", postCreateClient);
verify(clientDetailsService).create(client);
}
use of ca.corefacility.bioinformatics.irida.model.IridaClientDetails in project irida by phac-nml.
the class ClientsControllerTest method testSubmitEditClientError.
@Test
public void testSubmitEditClientError() {
IridaClientDetails client = new IridaClientDetails();
Long id = 1L;
client.setId(id);
client.setAutoApprovableScopes(ImmutableSet.of(""));
ExtendedModelMap model = new ExtendedModelMap();
when(clientDetailsService.read(id)).thenReturn(client);
DataIntegrityViolationException ex = new DataIntegrityViolationException("Error: " + IridaClientDetails.CLIENT_ID_CONSTRAINT_NAME);
when(clientDetailsService.update(any(IridaClientDetails.class))).thenThrow(ex);
String postCreateClient = controller.postEditClient(id, 0, "", "", "", "", "", "", 0, "", model, locale);
assertEquals(ClientsController.EDIT_CLIENT_PAGE, postCreateClient);
}
Aggregations