Example usage for org.springframework.security.oauth2.provider ClientAlreadyExistsException ClientAlreadyExistsException

List of usage examples for org.springframework.security.oauth2.provider ClientAlreadyExistsException ClientAlreadyExistsException

Introduction

In this page you can find the example usage for org.springframework.security.oauth2.provider ClientAlreadyExistsException ClientAlreadyExistsException.

Prototype

public ClientAlreadyExistsException(String msg) 

Source Link

Usage

From source file:org.openmhealth.dsu.service.SpringDataClientRegistrationServiceImpl.java

@Override
@Transactional/* w w w . j  a v a2 s.  com*/
public void addClientDetails(ClientDetails clientDetails) throws ClientAlreadyExistsException {

    if (repository.findOne(clientDetails.getClientId()).isPresent()) {
        throw new ClientAlreadyExistsException(
                format("A client with id '%s' already exists.", clientDetails.getClientId()));
    }

    repository.save(new SimpleClientDetails(clientDetails));
}

From source file:org.cloudfoundry.identity.uaa.oauth.ClientAdminBootstrapTests.java

@Test
public void testOverrideClient() throws Exception {
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("secret", "bar");
    map.put("override", true);
    bootstrap.setClients(Collections.singletonMap("foo", map));
    doThrow(new ClientAlreadyExistsException("Planned")).when(clientRegistrationService)
            .addClientDetails(any(ClientDetails.class));
    bootstrap.afterPropertiesSet();/*from www . ja  va 2  s  .  c o  m*/
    verify(clientRegistrationService, times(1)).addClientDetails(any(ClientDetails.class));
    verify(clientRegistrationService, times(1)).updateClientDetails(any(ClientDetails.class));
    verify(clientRegistrationService, times(1)).updateClientSecret("foo", "bar");
}

From source file:org.cloudfoundry.identity.uaa.oauth.ClientAdminBootstrapTests.java

@Test
public void testOverrideClientByDefault() throws Exception {
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("secret", "bar");
    bootstrap.setClients(Collections.singletonMap("foo", map));
    doThrow(new ClientAlreadyExistsException("Planned")).when(clientRegistrationService)
            .addClientDetails(any(ClientDetails.class));
    bootstrap.afterPropertiesSet();//from   ww w. j  a  va  2 s  . co m
    verify(clientRegistrationService, times(1)).addClientDetails(any(ClientDetails.class));
    verify(clientRegistrationService, times(1)).updateClientDetails(any(ClientDetails.class));
    verify(clientRegistrationService, times(1)).updateClientSecret("foo", "bar");
}

From source file:org.cloudfoundry.identity.uaa.oauth.ClientAdminBootstrapTests.java

@Test
@SuppressWarnings("unchecked")
public void testOverrideClientWithYaml() throws Exception {
    @SuppressWarnings("rawtypes")
    Map fooClient = new Yaml().loadAs("id: foo\noverride: true\nsecret: bar\n" + "access-token-validity: 100",
            Map.class);
    @SuppressWarnings("rawtypes")
    Map barClient = new Yaml().loadAs("id: bar\noverride: true\nsecret: bar\n" + "access-token-validity: 100",
            Map.class);
    @SuppressWarnings("rawtypes")
    Map clients = new HashMap();
    clients.put("foo", fooClient);
    clients.put("bar", barClient);
    bootstrap.setClients(clients);//w  ww.ja v  a 2s. c om
    doThrow(new ClientAlreadyExistsException("Planned")).when(clientRegistrationService)
            .addClientDetails(any(ClientDetails.class));
    bootstrap.afterPropertiesSet();
    verify(clientRegistrationService, times(2)).addClientDetails(any(ClientDetails.class));
    verify(clientRegistrationService, times(2)).updateClientDetails(any(ClientDetails.class));
    verify(clientRegistrationService, times(1)).updateClientSecret("foo", "bar");
    verify(clientRegistrationService, times(1)).updateClientSecret("bar", "bar");
}

From source file:com.cedac.security.oauth2.provider.client.MongoClientDetailsService.java

public void addClientDetails(ClientDetails clientDetails) throws ClientAlreadyExistsException {
    DBObject query = new BasicDBObject(clientIdFieldName, clientDetails.getClientId());
    if (getClientDetailsCollection().count(query) == 0) {
        DBObject entry = toDBObject(clientDetails);
        getClientDetailsCollection().insert(entry, writeConcern);
    } else {//w  ww .  j a  va2s.c o m
        throw new ClientAlreadyExistsException("Client already exists: " + clientDetails.getClientId());
    }
}

From source file:org.cloudfoundry.identity.uaa.oauth.ClientAdminEndpointsTests.java

@Test
public void testHandleClientAlreadyExists() throws Exception {
    ResponseEntity<InvalidClientDetailsException> result = endpoints
            .handleClientAlreadyExists(new ClientAlreadyExistsException("No such client: foo"));
    assertEquals(HttpStatus.CONFLICT, result.getStatusCode());
}