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

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

Introduction

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

Prototype

Map<String, Object> getAdditionalInformation();

Source Link

Document

Additional information for this client, not needed by the vanilla OAuth protocol but might be useful, for example, for storing descriptive information.

Usage

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:eu.trentorise.smartcampus.permissionprovider.controller.AccessConfirmationController.java

/**
 * Request the user confirmation for the resources enabled for the requesting client
 * @param model// w ww. j  a v  a 2  s .co m
 * @return
 * @throws Exception
 */
@RequestMapping("/oauth/confirm_access")
public ModelAndView getAccessConfirmation(Map<String, Object> model) throws Exception {
    AuthorizationRequest clientAuth = (AuthorizationRequest) model.remove("authorizationRequest");
    // load client information given the client credentials obtained from the request
    ClientDetails client = clientDetailsService.loadClientByClientId(clientAuth.getClientId());
    ClientAppInfo info = ClientAppInfo.convert(client.getAdditionalInformation());
    List<Resource> resources = new ArrayList<Resource>();

    Set<String> all = client.getScope();
    Set<String> requested = clientAuth.getScope();
    if (requested == null || requested.isEmpty()) {
        requested = all;
    } else {
        requested = new HashSet<String>(requested);
        for (Iterator<String> iterator = requested.iterator(); iterator.hasNext();) {
            String r = iterator.next();
            if (!all.contains(r))
                iterator.remove();
        }
    }

    for (String rUri : requested) {
        try {
            Resource r = resourceRepository.findByResourceUri(rUri);
            // ask the user only for the resources associated to the user role and not managed by this client
            if (r.getAuthority().equals(AUTHORITY.ROLE_USER)
                    && !clientAuth.getClientId().equals(r.getClientId())) {
                resources.add(r);
            }
        } catch (Exception e) {
            logger.error("Error reading resource with uri " + rUri + ": " + e.getMessage());
        }
    }
    model.put("resources", resources);
    model.put("auth_request", clientAuth);
    model.put("clientName", info.getName());
    return new ModelAndView("access_confirmation", model);
}

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

private boolean isAutoApprove(ClientDetails client, Collection<String> scopes) {
    Map<String, Object> info = client.getAdditionalInformation();
    if (info.containsKey("autoapprove")) {
        Object object = info.get("autoapprove");
        if (object instanceof Boolean && (Boolean) object || "true".equals(object)) {
            return true;
        }//  w  ww . j  av  a2 s  .c om
        if (object instanceof Collection) {
            @SuppressWarnings("unchecked")
            Collection<String> autoScopes = (Collection<String>) object;
            if (autoScopes.containsAll(scopes)) {
                return true;
            }
        }
    }
    return false;
}

From source file:st.malike.auth.server.service.security.ClientDetailService.java

private ClientDetail getMongoDBClientDetailsFromClient(ClientDetails cd) {
    ClientDetail clientDetails = new ClientDetail();
    clientDetails.setAccessTokenValiditySeconds(cd.getAccessTokenValiditySeconds());
    clientDetails.setAdditionalInformation(cd.getAdditionalInformation());
    clientDetails.setAuthorizedGrantTypes(cd.getAuthorizedGrantTypes());
    clientDetails.setClientId(cd.getClientId());
    clientDetails.setClientSecret(cd.getClientSecret());
    clientDetails.setRefreshTokenValiditySeconds(cd.getRefreshTokenValiditySeconds());
    clientDetails.setRegisteredRedirectUri(cd.getRegisteredRedirectUri());
    clientDetails.setResourceIds(cd.getResourceIds());
    clientDetails.setScope(cd.getScope());
    clientDetails.setScoped(cd.isScoped());
    clientDetails.setSecretRequired(cd.isSecretRequired());
    clientDetails.setId(cd.getClientId());
    return clientDetails;
}

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

public ClientDetail getMongoDBClientDetailsFromClient(ClientDetails cd) {
    ClientDetail clientDetails = new ClientDetail();
    clientDetails.setAccessTokenValiditySeconds(cd.getAccessTokenValiditySeconds());
    clientDetails.setAdditionalInformation(cd.getAdditionalInformation());
    clientDetails.setAuthorizedGrantTypes(cd.getAuthorizedGrantTypes());
    clientDetails.setClientId(cd.getClientId());
    clientDetails.setClientSecret(cd.getClientSecret());
    clientDetails.setRefreshTokenValiditySeconds(cd.getRefreshTokenValiditySeconds());
    clientDetails.setRegisteredRedirectUri(cd.getRegisteredRedirectUri());
    clientDetails.setResourceIds(cd.getResourceIds());
    clientDetails.setScope(cd.getScope());
    clientDetails.setScoped(cd.isScoped());
    clientDetails.setSecretRequired(cd.isSecretRequired());
    clientDetails.setId(cd.getClientId());
    return clientDetails;
}

From source file:org.springframework.security.oauth2.provider.client.JdbcClientDetailsService.java

private Object[] getFieldsForUpdate(ClientDetails clientDetails) {
    String json = null;/*ww  w .j av a2s. c o  m*/
    try {
        json = mapper.write(clientDetails.getAdditionalInformation());
    } catch (Exception e) {
        logger.warn("Could not serialize additional information: " + clientDetails, e);
    }
    return new Object[] {
            clientDetails.getResourceIds() != null
                    ? StringUtils.collectionToCommaDelimitedString(clientDetails.getResourceIds())
                    : null,
            clientDetails.getScope() != null
                    ? StringUtils.collectionToCommaDelimitedString(clientDetails.getScope())
                    : null,
            clientDetails.getAuthorizedGrantTypes() != null
                    ? StringUtils.collectionToCommaDelimitedString(clientDetails.getAuthorizedGrantTypes())
                    : null,
            clientDetails.getRegisteredRedirectUri() != null
                    ? StringUtils.collectionToCommaDelimitedString(clientDetails.getRegisteredRedirectUri())
                    : null,
            clientDetails.getAuthorities() != null
                    ? StringUtils.collectionToCommaDelimitedString(clientDetails.getAuthorities())
                    : null,
            clientDetails.getAccessTokenValiditySeconds(), clientDetails.getRefreshTokenValiditySeconds(), json,
            getAutoApproveScopes(clientDetails), clientDetails.getClientId() };
}

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

@Test
public void testLoadingClientIdWithAdditionalInformation() {
    collection.insert(new BasicDBObject("clientId", "clientIdWithAddInfo").append("additionalInformation",
            new BasicDBObject("foo", "bar")));

    ClientDetails clientDetails = fixture.loadClientByClientId("clientIdWithAddInfo");

    assertEquals("clientIdWithAddInfo", clientDetails.getClientId());
    assertEquals(Collections.singletonMap("foo", "bar"), clientDetails.getAdditionalInformation());
}

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

private QueryableResourceManager<ClientDetails> mockClientDetailsService(String id, String[] scope,
        Map<String, Object> addlInfo) {
    @SuppressWarnings("unchecked")
    QueryableResourceManager<ClientDetails> service = Mockito.mock(QueryableResourceManager.class);
    ClientDetails details = Mockito.mock(ClientDetails.class);
    Mockito.when(service.retrieve(id)).thenReturn(details);
    Mockito.when(details.getScope()).thenReturn(new HashSet<String>(Arrays.asList(scope)));
    Mockito.when(details.getAdditionalInformation()).thenReturn(addlInfo);
    return service;
}