Search in sources :

Example 6 with IridaClientDetails

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);
}
Also used : ExtendedModelMap(org.springframework.ui.ExtendedModelMap) IridaClientDetails(ca.corefacility.bioinformatics.irida.model.IridaClientDetails) Test(org.junit.Test)

Example 7 with IridaClientDetails

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"));
}
Also used : ExtendedModelMap(org.springframework.ui.ExtendedModelMap) IridaClientDetails(ca.corefacility.bioinformatics.irida.model.IridaClientDetails) Test(org.junit.Test)

Example 8 with IridaClientDetails

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.");
        }
    }
}
Also used : OAuth2Authentication(org.springframework.security.oauth2.provider.OAuth2Authentication) Authentication(org.springframework.security.core.Authentication) OAuth2Authentication(org.springframework.security.oauth2.provider.OAuth2Authentication) IridaClientDetails(ca.corefacility.bioinformatics.irida.model.IridaClientDetails)

Example 9 with IridaClientDetails

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);
}
Also used : ExtendedModelMap(org.springframework.ui.ExtendedModelMap) IridaClientDetails(ca.corefacility.bioinformatics.irida.model.IridaClientDetails) Test(org.junit.Test)

Example 10 with IridaClientDetails

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);
}
Also used : ExtendedModelMap(org.springframework.ui.ExtendedModelMap) IridaClientDetails(ca.corefacility.bioinformatics.irida.model.IridaClientDetails) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) Test(org.junit.Test)

Aggregations

IridaClientDetails (ca.corefacility.bioinformatics.irida.model.IridaClientDetails)15 Test (org.junit.Test)8 ExtendedModelMap (org.springframework.ui.ExtendedModelMap)7 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 DataTablesResponse (ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesResponse)2 DataTablesResponseModel (ca.corefacility.bioinformatics.irida.ria.web.components.datatables.models.DataTablesResponseModel)2 DataIntegrityViolationException (org.springframework.dao.DataIntegrityViolationException)2 PageRequest (org.springframework.data.domain.PageRequest)2 DataTablesParams (ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesParams)1 DTClient (ca.corefacility.bioinformatics.irida.ria.web.models.datatables.DTClient)1 PageImpl (org.springframework.data.domain.PageImpl)1 Sort (org.springframework.data.domain.Sort)1 Specification (org.springframework.data.jpa.domain.Specification)1 Authentication (org.springframework.security.core.Authentication)1 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1