List of usage examples for org.springframework.security.oauth2.provider.client BaseClientDetails setAccessTokenValiditySeconds
public void setAccessTokenValiditySeconds(Integer accessTokenValiditySeconds)
From source file:st.malike.auth.server.service.security.ClientDetailService.java
private BaseClientDetails getClientFromMongoDBClientDetails(ClientDetail clientDetails) { BaseClientDetails bc = new BaseClientDetails(); bc.setAccessTokenValiditySeconds(clientDetails.getAccessTokenValiditySeconds()); bc.setAuthorizedGrantTypes(clientDetails.getAuthorizedGrantTypes()); bc.setClientId(clientDetails.getClientId()); bc.setClientSecret(clientDetails.getClientSecret()); bc.setRefreshTokenValiditySeconds(clientDetails.getRefreshTokenValiditySeconds()); bc.setRegisteredRedirectUri(clientDetails.getRegisteredRedirectUri()); bc.setResourceIds(clientDetails.getResourceIds()); bc.setScope(clientDetails.getScope()); return bc;/* w w w. j a v a 2 s . c o m*/ }
From source file:com.tlantic.integration.authentication.service.security.ClientDetailService.java
private BaseClientDetails getClientFromMongoDBClientDetails(ClientDetail clientDetails) { BaseClientDetails bc = new BaseClientDetails(); bc.setAccessTokenValiditySeconds(clientDetails.getAccessTokenValiditySeconds()); bc.setAuthorizedGrantTypes(clientDetails.getAuthorizedGrantTypes()); bc.setClientId(clientDetails.getClientId()); bc.setClientSecret(clientDetails.getClientSecret()); bc.setRefreshTokenValiditySeconds(clientDetails.getRefreshTokenValiditySeconds()); bc.setRegisteredRedirectUri(clientDetails.getRegisteredRedirectUri()); bc.setResourceIds(clientDetails.getResourceIds()); bc.setScope(clientDetails.getScope()); List<SimpleGrantedAuthority> authorities = new LinkedList<>(); authorities.add(new SimpleGrantedAuthority("trust")); authorities.add(new SimpleGrantedAuthority("read")); authorities.add(new SimpleGrantedAuthority("write")); bc.setAuthorities(authorities);/*w w w . j ava 2s .co m*/ return bc; }
From source file:org.cloudfoundry.identity.uaa.api.client.test.UaaClientOperationTest.java
private BaseClientDetails createClient() { BaseClientDetails client = new BaseClientDetails(); client.setClientId("test"); client.setClientSecret("testsecret"); client.setAccessTokenValiditySeconds(3600); client.setAuthorizedGrantTypes(Arrays.asList(UaaTokenGrantType.authorization_code.toString(), UaaTokenGrantType.client_credentials.toString())); client.setRefreshTokenValiditySeconds(86400); client.setAuthorities(AuthorityUtils.createAuthorityList("uaa.resource")); return operations.create(client); }
From source file:it.smartcommunitylab.aac.model.ClientDetailsRowMapper.java
public ClientDetails mapRow(ResultSet rs, int rowNum) throws SQLException { BaseClientDetails details = new BaseClientDetails(rs.getString("client_id"), rs.getString("resource_ids"), rs.getString("scope"), rs.getString("authorized_grant_types"), rs.getString("authorities"), rs.getString("web_server_redirect_uri")); details.setClientSecret(rs.getString("client_secret")); if (rs.getObject("access_token_validity") != null) { details.setAccessTokenValiditySeconds(rs.getInt("access_token_validity")); }/*from w ww . j a va 2s.c om*/ if (rs.getObject("refresh_token_validity") != null) { details.setRefreshTokenValiditySeconds(rs.getInt("refresh_token_validity")); } String json = rs.getString("additional_information"); if (json != null) { try { @SuppressWarnings("unchecked") Map<String, Object> additionalInformation = mapper.readValue(json, Map.class); details.setAdditionalInformation(additionalInformation); } catch (Exception e) { logger.warn("Could not decode JSON for additional information: " + details, e); } } else { details.setAdditionalInformation(new HashMap<String, Object>()); } // merge developer roles into authorities it.smartcommunitylab.aac.model.User developer = userRepository.findOne(rs.getLong("developerId")); if (developer != null) { List<GrantedAuthority> list = new LinkedList<GrantedAuthority>(); if (details.getAuthorities() != null) list.addAll(details.getAuthorities()); list.addAll(developer.getRoles().stream().filter(r -> !StringUtils.isEmpty(r.getContext())) .collect(Collectors.toList())); details.setAuthorities(list); } return details; }
From source file:com.cedac.security.oauth2.provider.client.MongoClientDetailsService.java
@SuppressWarnings("unchecked") private ClientDetails toClientDetails(DBObject dbo) { final String clientId = (String) dbo.get(clientIdFieldName); final String resourceIds = collectionToCommaDelimitedString((Collection) dbo.get(resourceIdsFieldName)); final String scopes = collectionToCommaDelimitedString((Collection) dbo.get(scopeFieldName)); final String grantTypes = collectionToCommaDelimitedString( (Collection) dbo.get(authorizedGrantTypesFieldName)); final String authorities = collectionToCommaDelimitedString((Collection) dbo.get(authoritiesFieldName)); final String redirectUris = collectionToCommaDelimitedString( (Collection) dbo.get(registeredRedirectUrisFieldName)); BaseClientDetails clientDetails = new BaseClientDetails(clientId, resourceIds, scopes, grantTypes, authorities, redirectUris);/* w w w . jav a 2 s .c o m*/ clientDetails.setClientSecret((String) dbo.get(clientSecretFieldName)); clientDetails.setAccessTokenValiditySeconds((Integer) dbo.get(accessTokenValidityFieldName)); clientDetails.setRefreshTokenValiditySeconds((Integer) dbo.get(refreshTokenValidityFieldName)); Object autoApprove = dbo.get(autoApproveFieldName); if (autoApprove != null) { if (autoApprove instanceof String) { clientDetails.setAutoApproveScopes(Collections.singleton((String) autoApprove)); } else { clientDetails.setAutoApproveScopes((Collection<String>) dbo.get(autoApproveFieldName)); } } DBObject additionalInfo = (DBObject) dbo.get(additionalInformationFieldName); if (additionalInfo != null) { for (String key : additionalInfo.keySet()) { clientDetails.addAdditionalInformation(key, additionalInfo.get(key)); } } return clientDetails; }
From source file:org.meruvian.yama.web.security.oauth.DefaultClientDetailsService.java
@Override public ClientDetails loadClientByClientId(String clientId) throws ClientRegistrationException { Application application = null;//from w ww . j av a2 s. co m if (defaultOauthApplications.containsKey(clientId)) { application = defaultOauthApplications.get(clientId); } else { application = applicationRepository.findById(clientId); } if (application == null) return null; BaseClientDetails details = new BaseClientDetails(); details.setClientId(application.getId()); details.setClientSecret(application.getSecret()); details.setAuthorizedGrantTypes(authorizedGrantTypes); details.setScope(scopes); details.setResourceIds(resourceIds); details.setRegisteredRedirectUri(application.getRegisteredRedirectUris()); if (application.isAutoApprove()) details.setAutoApproveScopes(Arrays.asList("true")); details.setAccessTokenValiditySeconds(application.getAccessTokenValiditySeconds()); details.setRefreshTokenValiditySeconds(application.getRefreshTokenValiditySeconds()); return details; }
From source file:oauth2.authentication.clients.ClientDetailsBuilder.java
public ClientDetails build() { BaseClientDetails client = new BaseClientDetails(); client.setClientId(clientId);/* w w w . j ava 2 s.c o m*/ client.setClientSecret(clientSecret); client.setRegisteredRedirectUri(redirectUris.build()); client.setAuthorizedGrantTypes(authorizedGrantTypes.build()); client.setScope(scopes.build()); client.setAutoApproveScopes(autoApprovedScopes.build()); client.setResourceIds(resourceIds.build()); client.setAuthorities(authorities.build()); client.setAccessTokenValiditySeconds(accessTokenValiditySeconds); client.setRefreshTokenValiditySeconds(refreshTokenValiditySeconds); return client; }
From source file:org.cloudfoundry.identity.uaa.client.ClientAdminBootstrap.java
private void addNewClients() throws Exception { for (Map.Entry<String, Map<String, Object>> entry : clients.entrySet()) { String clientId = entry.getKey(); Map<String, Object> map = entry.getValue(); BaseClientDetails client = new BaseClientDetails(clientId, (String) map.get("resource-ids"), (String) map.get("scope"), (String) map.get("authorized-grant-types"), (String) map.get("authorities"), getRedirectUris(map)); client.setClientSecret((String) map.get("secret")); Integer validity = (Integer) map.get("access-token-validity"); Boolean override = (Boolean) map.get("override"); if (override == null) { override = defaultOverride;//from w w w. ja v a 2 s. c o m } Map<String, Object> info = new HashMap<String, Object>(map); if (validity != null) { client.setAccessTokenValiditySeconds(validity); } validity = (Integer) map.get("refresh-token-validity"); if (validity != null) { client.setRefreshTokenValiditySeconds(validity); } // UAA does not use the resource ids in client registrations client.setResourceIds(Collections.singleton("none")); if (client.getScope().isEmpty()) { client.setScope(Collections.singleton("uaa.none")); } if (client.getAuthorities().isEmpty()) { client.setAuthorities(Collections.singleton(UaaAuthority.UAA_NONE)); } if (client.getAuthorizedGrantTypes().contains("authorization_code")) { client.getAuthorizedGrantTypes().add("refresh_token"); } for (String key : Arrays.asList("resource-ids", "scope", "authorized-grant-types", "authorities", "redirect-uri", "secret", "id", "override", "access-token-validity", "refresh-token-validity", "show-on-homepage", "app-launch-url", "app-icon")) { info.remove(key); } client.setAdditionalInformation(info); try { clientRegistrationService.addClientDetails(client); } catch (ClientAlreadyExistsException e) { if (override == null || override) { logger.debug("Overriding client details for " + clientId); clientRegistrationService.updateClientDetails(client); if (StringUtils.hasText(client.getClientSecret()) && didPasswordChange(clientId, client.getClientSecret())) { clientRegistrationService.updateClientSecret(clientId, client.getClientSecret()); } } else { // ignore it logger.debug(e.getMessage()); } } ClientMetadata clientMetadata = buildClientMetadata(map, clientId); clientMetadataProvisioning.update(clientMetadata); } }
From source file:org.cloudfoundry.identity.uaa.client.ClientAdminEndpoints.java
private ClientDetails syncWithExisting(ClientDetails existing, ClientDetails input) { BaseClientDetails details = new BaseClientDetails(input); if (input instanceof BaseClientDetails) { BaseClientDetails baseInput = (BaseClientDetails) input; if (baseInput.getAutoApproveScopes() != null) { details.setAutoApproveScopes(baseInput.getAutoApproveScopes()); } else {/* w ww . ja va 2s . c o m*/ details.setAutoApproveScopes(new HashSet<String>()); if (existing instanceof BaseClientDetails) { BaseClientDetails existingDetails = (BaseClientDetails) existing; if (existingDetails.getAutoApproveScopes() != null) { for (String scope : existingDetails.getAutoApproveScopes()) { details.getAutoApproveScopes().add(scope); } } } } } if (details.getAccessTokenValiditySeconds() == null) { details.setAccessTokenValiditySeconds(existing.getAccessTokenValiditySeconds()); } if (details.getRefreshTokenValiditySeconds() == null) { details.setRefreshTokenValiditySeconds(existing.getRefreshTokenValiditySeconds()); } if (details.getAuthorities() == null || details.getAuthorities().isEmpty()) { details.setAuthorities(existing.getAuthorities()); } if (details.getAuthorizedGrantTypes() == null || details.getAuthorizedGrantTypes().isEmpty()) { details.setAuthorizedGrantTypes(existing.getAuthorizedGrantTypes()); } if (details.getRegisteredRedirectUri() == null || details.getRegisteredRedirectUri().isEmpty()) { details.setRegisteredRedirectUri(existing.getRegisteredRedirectUri()); } if (details.getResourceIds() == null || details.getResourceIds().isEmpty()) { details.setResourceIds(existing.getResourceIds()); } if (details.getScope() == null || details.getScope().isEmpty()) { details.setScope(existing.getScope()); } Map<String, Object> additionalInformation = new HashMap<String, Object>( existing.getAdditionalInformation()); additionalInformation.putAll(input.getAdditionalInformation()); for (String key : Collections.unmodifiableSet(additionalInformation.keySet())) { if (additionalInformation.get(key) == null) { additionalInformation.remove(key); } } details.setAdditionalInformation(additionalInformation); return details; }
From source file:org.cloudfoundry.identity.uaa.oauth.ClientAdminBootstrap.java
private void addNewClients() throws Exception { for (String clientId : clients.keySet()) { Map<String, Object> map = clients.get(clientId); BaseClientDetails client = new BaseClientDetails(clientId, (String) map.get("resource-ids"), (String) map.get("scope"), (String) map.get("authorized-grant-types"), (String) map.get("authorities"), (String) map.get("redirect-uri")); client.setClientSecret((String) map.get("secret")); Integer validity = (Integer) map.get("access-token-validity"); Boolean override = (Boolean) map.get("override"); if (override == null) { override = defaultOverride;// w w w . java 2 s . com } Map<String, Object> info = new HashMap<String, Object>(map); if (validity != null) { client.setAccessTokenValiditySeconds(validity); } validity = (Integer) map.get("refresh-token-validity"); if (validity != null) { client.setRefreshTokenValiditySeconds(validity); } // UAA does not use the resource ids in client registrations client.setResourceIds(Collections.singleton("none")); if (client.getScope().isEmpty()) { client.setScope(Collections.singleton("uaa.none")); } if (client.getAuthorities().isEmpty()) { client.setAuthorities(Collections.singleton(UaaAuthority.UAA_NONE)); } if (client.getAuthorizedGrantTypes().contains("authorization_code")) { client.getAuthorizedGrantTypes().add("refresh_token"); } for (String key : Arrays.asList("resource-ids", "scope", "authorized-grant-types", "authorities", "redirect-uri", "secret", "id", "override", "access-token-validity", "refresh-token-validity")) { info.remove(key); } client.setAdditionalInformation(info); try { clientRegistrationService.addClientDetails(client); } catch (ClientAlreadyExistsException e) { if (override == null || override) { logger.debug("Overriding client details for " + clientId); clientRegistrationService.updateClientDetails(client); if (StringUtils.hasText(client.getClientSecret())) { clientRegistrationService.updateClientSecret(clientId, client.getClientSecret()); } } else { // ignore it logger.debug(e.getMessage()); } } } }