Example usage for org.springframework.security.oauth2.provider ClientDetails getClientId

List of usage examples for org.springframework.security.oauth2.provider ClientDetails getClientId

Introduction

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

Prototype

String getClientId();

Source Link

Document

The client id.

Usage

From source file:org.joyrest.oauth2.configurer.client.InMemoryClientDetailsServiceConfigurer.java

@Override
protected void addClient(ClientDetails details) {
    clientDetails.put(details.getClientId(), details);
}

From source file:org.mitre.oauth2.service.impl.TestDefaultIntrospectionAuthorizer.java

private ClientDetails clientWithId(String clientId) {
    ClientDetails client = mock(ClientDetails.class);
    given(client.getClientId()).willReturn(clientId);
    return client;
}

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

@Test
public void testClientinfo() {
    Mockito.when(clientDetailsService.loadClientByClientId("foo")).thenReturn(foo);
    ClientDetails client = endpoint.clientinfo(new UsernamePasswordAuthenticationToken("foo", "<NONE>"));
    assertEquals("foo", client.getClientId());
    assertNull(client.getClientSecret());
    assertTrue(client.getAdditionalInformation().isEmpty());
}

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

@Override
@Transactional//from   w  w  w .j  a v a2  s.co  m
public void updateClientDetails(ClientDetails clientDetails) throws NoSuchClientException {

    if (!repository.findOne(clientDetails.getClientId()).isPresent()) {
        throw new NoSuchClientException(
                format("A client with id '%s' wasn't found.", clientDetails.getClientId()));
    }

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

From source file:com.example.ClientDetailsController.java

@GetMapping("/clients")
public String clients(Map<String, Object> model, Principal user) {
    model.put("user", user.getName());
    List<ClientDetails> details = new ArrayList<>();
    List<Map<String, Object>> list = template.queryForList("SELECT * from user_client_details where username=?",
            user.getName());//w  ww.j a va2  s  . co m
    for (ClientDetails clientDetails : clients.listClientDetails()) {
        if (isOwner(user.getName(), clientDetails.getClientId(), list)) {
            details.add(clientDetails);
        }
    }
    model.put("clients", details);
    return "clients";
}

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

@Override
@Transactional/*ww  w  .j av a2s.c o  m*/
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.login.ClientInfoAuthenticationFilter.java

protected void validateClient(ClientDetails client) {
    String clientId = client.getClientId();
    for (String pattern : allowedClients) {
        if (!clientId.matches(pattern)) {
            throw new BadCredentialsException("Client not permitted: " + clientId);
        }/*w  w  w.  j  a va  2 s  .c o  m*/
    }
    Set<String> grantTypes = client.getAuthorizedGrantTypes();
    boolean matched = false;
    for (String pattern : allowedGrantTypes) {
        for (String grantType : grantTypes) {
            if (grantType.matches(pattern)) {
                matched = true;
            }
        }
    }
    if (!matched) {
        throw new BadCredentialsException("Client not permitted (wrong grant type): " + clientId);
    }
}

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

@Override
public String extractKey(OAuth2Authentication authentication) {
    Map<String, Object> values = new LinkedHashMap<String, Object>();
    AuthorizationRequest authorizationRequest = authentication.getAuthorizationRequest();
    if (!authentication.isClientOnly()) {
        values.putAll(userTokenConverter.convertUserAuthentication(authentication.getUserAuthentication()));
    }/* w  w  w.j a  v  a2 s  . c o  m*/
    ClientDetails client = clientDetailsService.loadClientByClientId(authorizationRequest.getClientId());
    values.put(CLIENT_ID, client.getClientId());
    if (authorizationRequest.getScope() != null) {
        values.put(SCOPE, OAuth2Utils.formatParameterList(authorizationRequest.getScope()));
    }
    Integer validity = client.getAccessTokenValiditySeconds();
    if (validity != null) {
        values.put(ACCESS_TOKEN_VALIDITY, validity);
    }
    validity = client.getRefreshTokenValiditySeconds();
    if (validity != null && client.getAuthorizedGrantTypes().contains("refresh_token")) {
        values.put(REFRESH_TOKEN_VALIDITY, validity);
    }
    MessageDigest digest;
    try {
        digest = MessageDigest.getInstance("MD5");
    } catch (NoSuchAlgorithmException e) {
        throw new IllegalStateException("MD5 algorithm not available.  Fatal (should be in the JDK).");
    }

    try {
        byte[] bytes = digest.digest(values.toString().getBytes("UTF-8"));
        return String.format("%032x", new BigInteger(1, bytes));
    } catch (UnsupportedEncodingException e) {
        throw new IllegalStateException("UTF-8 encoding not available.  Fatal (should be in the JDK).");
    }
}

From source file:org.meruvian.yama.webapi.service.RestOauthClientService.java

@Override
public Application findClientDetailsById(String id) {
    ClientDetails clientDetails = clientDetailsService.loadClientByClientId(id);

    if (clientDetails == null) {
        return null;
    }//from w w  w .j ava 2 s  . c o  m

    Application application = applicationRepository.findById(clientDetails.getClientId());
    application.setScopes(clientDetails.getScope());
    application.setAuthorizedGrantTypes(clientDetails.getAuthorizedGrantTypes());

    return application;
}

From source file:com.tlantic.integration.authentication.service.security.ClientDetailService.java

@Override
public void updateClientDetails(ClientDetails cd) throws NoSuchClientException {
    ClientDetail clientDetails = clientDetailsRepository.findByClientId(cd.getClientId());
    if (null == clientDetails) {
        throw new NoSuchClientException("Client not found with ID '" + cd.getClientId() + "'");
    }/*  w ww  .  j  a v a2s.  c o m*/
    clientDetails = getMongoDBClientDetailsFromClient(cd);
    clientDetailsRepository.save(clientDetails);
}