List of usage examples for org.springframework.security.oauth2.provider.client BaseClientDetails setClientSecret
public void setClientSecret(String clientSecret)
From source file:com.create.application.configuration.security.ClientConfiguration.java
@Bean @ConfigurationProperties("security.oauth2.client") public BaseClientDetails oauth2ClientDetails(OAuth2ClientProperties client) { BaseClientDetails details = new BaseClientDetails(); details.setClientId(client.getClientId()); details.setClientSecret(client.getClientSecret()); details.setAuthorities(getAuthorities()); details.setRegisteredRedirectUri(Collections.emptySet()); return details; }
From source file:com.cosw.productsmaster.authsec.GuestServiceImpl.java
@Override public ClientDetails loadClientByClientId(String clientId) throws ClientRegistrationException { if (clientId.equals(id)) { List<String> authorizedGrantTypes = new ArrayList<String>(); authorizedGrantTypes.add("password"); authorizedGrantTypes.add("refresh_token"); authorizedGrantTypes.add("client_credentials"); BaseClientDetails clientDetails = new BaseClientDetails(); clientDetails.setClientId(id);/*from w ww . j ava 2s. c o m*/ clientDetails.setClientSecret(secretKey); clientDetails.setAuthorizedGrantTypes(authorizedGrantTypes); return clientDetails; } else { throw new NoSuchClientException("No client recognized with id: " + clientId); } }
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. ja v a 2 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: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:oauth2.authentication.clients.ClientDetailsBuilder.java
public ClientDetails build() { BaseClientDetails client = new BaseClientDetails(); client.setClientId(clientId);/*from www. ja va2 s. co 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.servicebroker.service.UaaServiceInstanceService.java
@Override public ServiceInstance createServiceInstance(ServiceDefinition service, String serviceInstanceId, String planId, String organizationGuid, String spaceGuid) throws ServiceInstanceExistsException, ServiceBrokerException { // TODO: Return new ServiceInstanceExistsException if service instance exists BaseClientDetails clientDetails = new BaseClientDetails(serviceInstanceId, "", "", "authorization_code,refresh_token", "", ""); clientDetails.setClientSecret(serviceInstanceId + "secret"); clientDetails = uaaRestTemplate.postForObject("http://localhost:8081/uaa/oauth/clients", clientDetails, BaseClientDetails.class); // TODO: Store ServiceInstance in repository return new ServiceInstance(serviceInstanceId, service.getId(), planId, organizationGuid, spaceGuid, ""); }
From source file:com.vivastream.security.oauth2.provider.DynamoDBClientDetailsService.java
protected ClientDetails createClientDetails(String clientId, String resourceIds, String scopes, String grantTypes, String authorities, String redirectUris, String clientSecret, Map<String, AttributeValue> attributeValues) { BaseClientDetails cd = new BaseClientDetails(clientId, resourceIds, scopes, grantTypes, authorities, redirectUris);// w ww . j a v a 2s . c o m cd.setClientSecret(clientSecret); return cd; }
From source file:com.katropine.oauth.ClientDetailsServiceImpl.java
@Override public ClientDetails loadClientByClientId(String clientId) throws OAuth2Exception { /**//ww w.java 2 s. c o m * Request access * curl -v -X GET -H "Content-Type: application/json" 'http://localhost:8080/springmvcrest/oauth/token?username=user1&password=user1&client_id=client1&client_secret=client1&grant_type=password'\ * * Request To access protected resource getMyInfo: * curl -H "Authorization:Bearer 6fd0f4b7-ca03-49ff-ae46-eea5e6929325" "http://localhost:8080/springmvcrest/api/getMyInfo" * * Request To logout * curl -H "Authorization:Bearer 6fd0f4b7-ca03-49ff-ae46-eea5e6929325" "http://localhost:8080/springmvcrest/api/logou" * */ System.out.println("client: " + clientId); if (clientId.equals("client1")) { System.out.println("In client: " + clientId); List<String> authorizedGrantTypes = new ArrayList<>(); authorizedGrantTypes.add("password"); authorizedGrantTypes.add("refresh_token"); authorizedGrantTypes.add("client_credentials"); Collection<String> col = new ArrayList<>(); col.add("client1"); BaseClientDetails clientDetails = new BaseClientDetails(); clientDetails.setClientId("client1"); clientDetails.setClientSecret("client1"); clientDetails.setScope(col); clientDetails.setAuthorizedGrantTypes(authorizedGrantTypes); return clientDetails; } else if (clientId.equals("client2")) { System.out.println("In client: " + clientId); List<String> authorizedGrantTypes = new ArrayList<>(); authorizedGrantTypes.add("password"); authorizedGrantTypes.add("refresh_token"); authorizedGrantTypes.add("client_credentials"); BaseClientDetails clientDetails = new BaseClientDetails(); clientDetails.setClientId("client2"); clientDetails.setClientSecret("client2"); clientDetails.setAuthorizedGrantTypes(authorizedGrantTypes); return clientDetails; } else { throw new NoSuchClientException("No client with requested id: " + clientId); } }
From source file:com.example.ClientDetailsController.java
@PostMapping("/clients") public String add(Principal user) { BaseClientDetails client = new BaseClientDetails(strings.generate(), null, "openid,cloud_controller.read,cloud_controller.write", "password,authorization_code,refresh_token", "ROLE_CLIENT"); client.setClientSecret(strings.generate()); client.setAutoApproveScopes(Arrays.asList("true")); clients.addClientDetails(client);//from w ww . ja v a 2 s. co m template.update("INSERT into user_client_details (username, client_id) values (?,?)", user.getName(), client.getClientId()); return "redirect:/clients"; }
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 w w . j ava 2 s. com 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; }