本文整理匯總了Java中org.springframework.security.oauth2.provider.ClientDetails類的典型用法代碼示例。如果您正苦於以下問題:Java ClientDetails類的具體用法?Java ClientDetails怎麽用?Java ClientDetails使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ClientDetails類屬於org.springframework.security.oauth2.provider包,在下文中一共展示了ClientDetails類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testEnvironmentalOverrides
import org.springframework.security.oauth2.provider.ClientDetails; //導入依賴的package包/類
@Test
public void testEnvironmentalOverrides() {
this.context = new AnnotationConfigServletWebServerApplicationContext();
TestPropertyValues
.of("security.oauth2.client.clientId:myclientid",
"security.oauth2.client.clientSecret:mysecret",
"security.oauth2.client.autoApproveScopes:read,write",
"security.oauth2.client.accessTokenValiditySeconds:40",
"security.oauth2.client.refreshTokenValiditySeconds:80")
.applyTo(this.context);
this.context.register(AuthorizationAndResourceServerConfiguration.class,
MinimalSecureWebApplication.class);
this.context.refresh();
ClientDetails config = this.context.getBean(ClientDetails.class);
assertThat(config.getClientId()).isEqualTo("myclientid");
assertThat(config.getClientSecret()).isEqualTo("mysecret");
assertThat(config.isAutoApprove("read")).isTrue();
assertThat(config.isAutoApprove("write")).isTrue();
assertThat(config.isAutoApprove("foo")).isFalse();
assertThat(config.getAccessTokenValiditySeconds()).isEqualTo(40);
assertThat(config.getRefreshTokenValiditySeconds()).isEqualTo(80);
verifyAuthentication(config);
}
開發者ID:spring-projects,項目名稱:spring-security-oauth2-boot,代碼行數:24,代碼來源:OAuth2AutoConfigurationTests.java
示例2: testDefaultPrePostSecurityAnnotations
import org.springframework.security.oauth2.provider.ClientDetails; //導入依賴的package包/類
@Test
public void testDefaultPrePostSecurityAnnotations() {
this.context = new AnnotationConfigServletWebServerApplicationContext();
this.context.register(AuthorizationAndResourceServerConfiguration.class,
MinimalSecureWebApplication.class);
this.context.refresh();
this.context.getBean(OAuth2MethodSecurityConfiguration.class);
ClientDetails config = this.context.getBean(ClientDetails.class);
DelegatingMethodSecurityMetadataSource source = this.context
.getBean(DelegatingMethodSecurityMetadataSource.class);
List<MethodSecurityMetadataSource> sources = source
.getMethodSecurityMetadataSources();
assertThat(sources.size()).isEqualTo(1);
assertThat(sources.get(0).getClass().getName())
.isEqualTo(PrePostAnnotationSecurityMetadataSource.class.getName());
verifyAuthentication(config);
}
開發者ID:spring-projects,項目名稱:spring-security-oauth2-boot,代碼行數:18,代碼來源:OAuth2AutoConfigurationTests.java
示例3: testClassicSecurityAnnotationOverride
import org.springframework.security.oauth2.provider.ClientDetails; //導入依賴的package包/類
@Test
public void testClassicSecurityAnnotationOverride() {
this.context = new AnnotationConfigServletWebServerApplicationContext();
this.context.register(SecuredEnabledConfiguration.class,
MinimalSecureWebApplication.class);
this.context.refresh();
this.context.getBean(OAuth2MethodSecurityConfiguration.class);
ClientDetails config = this.context.getBean(ClientDetails.class);
DelegatingMethodSecurityMetadataSource source = this.context
.getBean(DelegatingMethodSecurityMetadataSource.class);
List<MethodSecurityMetadataSource> sources = source
.getMethodSecurityMetadataSources();
assertThat(sources.size()).isEqualTo(1);
assertThat(sources.get(0).getClass().getName())
.isEqualTo(SecuredAnnotationSecurityMetadataSource.class.getName());
verifyAuthentication(config, HttpStatus.OK);
}
開發者ID:spring-projects,項目名稱:spring-security-oauth2-boot,代碼行數:18,代碼來源:OAuth2AutoConfigurationTests.java
示例4: testJsr250SecurityAnnotationOverride
import org.springframework.security.oauth2.provider.ClientDetails; //導入依賴的package包/類
@Test
public void testJsr250SecurityAnnotationOverride() {
this.context = new AnnotationConfigServletWebServerApplicationContext();
this.context.register(Jsr250EnabledConfiguration.class,
MinimalSecureWebApplication.class);
this.context.refresh();
this.context.getBean(OAuth2MethodSecurityConfiguration.class);
ClientDetails config = this.context.getBean(ClientDetails.class);
DelegatingMethodSecurityMetadataSource source = this.context
.getBean(DelegatingMethodSecurityMetadataSource.class);
List<MethodSecurityMetadataSource> sources = source
.getMethodSecurityMetadataSources();
assertThat(sources.size()).isEqualTo(1);
assertThat(sources.get(0).getClass().getName())
.isEqualTo(Jsr250MethodSecurityMetadataSource.class.getName());
verifyAuthentication(config, HttpStatus.OK);
}
開發者ID:spring-projects,項目名稱:spring-security-oauth2-boot,代碼行數:18,代碼來源:OAuth2AutoConfigurationTests.java
示例5: getAccessConfirmation
import org.springframework.security.oauth2.provider.ClientDetails; //導入依賴的package包/類
@RequestMapping("/oauth/confirm_access")
public ModelAndView getAccessConfirmation(Map<String, Object> model, Principal principal) throws Exception {
AuthorizationRequest clientAuth = (AuthorizationRequest) model.remove("authorizationRequest");
ClientDetails client = clientDetailsService.loadClientByClientId(clientAuth.getClientId());
model.put("auth_request", clientAuth);
model.put("client", client);
Map<String, String> scopes = new LinkedHashMap<String, String>();
for (String scope : clientAuth.getScope()) {
scopes.put(OAuth2Utils.SCOPE_PREFIX + scope, "false");
}
for (Approval approval : approvalStore.getApprovals(principal.getName(), client.getClientId())) {
if (clientAuth.getScope().contains(approval.getScope())) {
scopes.put(OAuth2Utils.SCOPE_PREFIX + approval.getScope(),
approval.getStatus() == ApprovalStatus.APPROVED ? "true" : "false");
}
}
model.put("scopes", scopes);
return new ModelAndView("authorize", model);
}
示例6: convertAccessToken
import org.springframework.security.oauth2.provider.ClientDetails; //導入依賴的package包/類
/**
* Values placed into the map will be included in the JWT token only, not the OAuth 2 response itself.
*/
@Override
public Map<String, ?> convertAccessToken(OAuth2AccessToken token, OAuth2Authentication authentication) {
Map<String, Object> map = (Map<String, Object>) super.convertAccessToken(token, authentication);
OAuth2Request request = authentication.getOAuth2Request();
Set<String> authorities = request.getAuthorities().stream().map(a -> a.getAuthority()).collect(Collectors.toSet());
ClientDetails client = clientAuthenticationService.loadClientByClientId(request.getClientId());
if (client.getResourceIds() != null && !client.getResourceIds().isEmpty()) {
map.put(AUDIENCE, client.getResourceIds());
}
Authentication userAuthentication = authentication.getUserAuthentication();
if (userAuthentication == null) {
map.remove("authorities");
}
map.put(CLIENT_AUTHORITIES, authorities);
return map;
}
示例7: loadClientByClientId
import org.springframework.security.oauth2.provider.ClientDetails; //導入依賴的package包/類
public ClientDetails loadClientByClientId(String id) throws ClientRegistrationException {
if (CurrentAuthenticatedClientContext.hasAuthenticatedClient()) {
AuthenticatedClient client = CurrentAuthenticatedClientContext.getAuthenticatedClient();
if (client.getClientId().equals(id)) {
return CurrentAuthenticatedClientContext.getAuthenticatedClient();
}
CurrentAuthenticatedClientContext.clear();
}
Result<Client> result = clientService.findByClientId(id);
if (result.rejected()) {
CurrentAuthenticatedClientContext.clear();
throw new UsernameNotFoundException("Could not find client with client id " + id);
}
return CurrentAuthenticatedClientContext.setAuthenticatedClient(new AuthenticatedClient(result.getInstance()));
}
示例8: build
import org.springframework.security.oauth2.provider.ClientDetails; //導入依賴的package包/類
public ClientDetails build() {
BaseClientDetails result = new BaseClientDetails();
result.setClientId(clientId);
result.setAuthorizedGrantTypes(authorizedGrantTypes);
result.setAccessTokenValiditySeconds(accessTokenValiditySeconds);
result.setRefreshTokenValiditySeconds(refreshTokenValiditySeconds);
result.setRegisteredRedirectUri(registeredRedirectUris);
result.setClientSecret(secret);
result.setScope(scopes);
result.setAuthorities(AuthorityUtils.createAuthorityList(authorities.toArray(new String[authorities.size()])));
result.setResourceIds(resourceIds);
result.setAdditionalInformation(additionalInformation);
if (autoApprove) {
result.setAutoApproveScopes(scopes);
}
else {
result.setAutoApproveScopes(autoApproveScopes);
}
return result;
}
示例9: addClient
import org.springframework.security.oauth2.provider.ClientDetails; //導入依賴的package包/類
@Override
protected void addClient(String clientId, ClientDetails value) {
OAuth2Client oAuth2Client = new OAuth2Client();
oAuth2Client.setClientId(clientId);
oAuth2Client.setClientSecret(value.getClientSecret());
oAuth2Client.setRefreshTokenValiditySeconds(value.getRefreshTokenValiditySeconds());
oAuth2Client.setAccessTokenValiditySeconds(value.getAccessTokenValiditySeconds());
oAuth2Client.setAdditionalInformation(value.getAdditionalInformation());
oAuth2Client.setAuthorities(value.getAuthorities());
oAuth2Client.setAuthorizedGrantTypes(value.getAuthorizedGrantTypes());
oAuth2Client.setRegisteredRedirectUris(value.getRegisteredRedirectUri());
oAuth2Client.setScope(value.getScope());
oAuth2Client.setResourceIds(value.getResourceIds());
oAuth2ClientRepository.save(oAuth2Client);
}
示例10: loadClientByClientId_whenClientRepositoryReturnsAClient_returnsExpectedObject
import org.springframework.security.oauth2.provider.ClientDetails; //導入依賴的package包/類
@Test
public void loadClientByClientId_whenClientRepositoryReturnsAClient_returnsExpectedObject() throws Exception {
CustomClient customClient = new CustomClient();
customClient.setId(1L);
customClient.setClientName("someClient");
customClient.setClientSecret("clientSecret");
customClient.setScopes("this, that");
when(customClientRepository.findByClientName("someClient")).thenReturn(customClient);
ClientDetails result = subject.loadClientByClientId("someClient");
assertThat(result.getClientId()).isEqualTo("someClient");
assertThat(result.getResourceIds()).isNull();
assertThat(result.isSecretRequired()).isTrue();
assertThat(result.isScoped()).isFalse();
assertThat(result.getScope()).containsExactlyInAnyOrder("this", "that");
assertThat(result.getAuthorizedGrantTypes()).containsExactlyInAnyOrder("authorization_code", "token", "refresh_token", "password");
assertThat(result.getRegisteredRedirectUri()).isNull();
assertThat(result.getAuthorities()).contains(new SimpleGrantedAuthority("ROLE_USER"));
assertThat(result.getAccessTokenValiditySeconds()).isNull();
assertThat(result.getRefreshTokenValiditySeconds()).isNull();
assertThat(result.isAutoApprove("")).isTrue();
assertThat(result.getAdditionalInformation()).isNull();
}
示例11: toClientDetails
import org.springframework.security.oauth2.provider.ClientDetails; //導入依賴的package包/類
public ClientDetails toClientDetails() {
BaseClientDetails clientDetails =
new BaseClientDetails(
getClientId(),
getResourceIdsAsString(),
getScopeAsString(),
getAuthorizedGrantTypesAsString(),
getAuthoritiesAsString(),
getWebServerRedirectUri());
clientDetails.setClientSecret(clientSecret);
clientDetails.setAdditionalInformation(additionalInformation);
clientDetails.setAccessTokenValiditySeconds(accessTokenValidity);
clientDetails.setRefreshTokenValiditySeconds(refreshTokenValidity);
return clientDetails;
}
示例12: saveAndLoadGatewayClient
import org.springframework.security.oauth2.provider.ClientDetails; //導入依賴的package包/類
@Test
public void saveAndLoadGatewayClient() {
Gateway gateway = new Gateway();
gateway.setId("gateway-id");
gateway.setGuid("gateway-guid");
gateway.setTenant(tenant);
OauthClientDetails clientDetails = new OauthClientDetails();
clientDetails.setGatewayProperties(gateway);
ServiceResponse<OauthClientDetails> serviceResponse = oauthClientDetailsService.saveClient(tenant, null, clientDetails);
assertThat(serviceResponse, isResponseOk());
ClientDetails clientDetailsDB = oauthClientDetailsService.loadClientByClientId(gateway.getRoutUriTemplate());
assertThat(clientDetailsDB, notNullValue());
}
示例13: getAccessConfirmation
import org.springframework.security.oauth2.provider.ClientDetails; //導入依賴的package包/類
@RequestMapping("/oauth/confirm_access")
public ModelAndView getAccessConfirmation(Map<String, Object> model, Principal principal) throws Exception {
AuthorizationRequest clientAuth = (AuthorizationRequest) model.remove("authorizationRequest");
ClientDetails client = clientDetailsService.loadClientByClientId(clientAuth.getClientId());
model.put("auth_request", clientAuth);
model.put("client", client);
Map<String, String> scopes = new LinkedHashMap<String, String>();
for (String scope : clientAuth.getScope()) {
scopes.put(OAuth2Utils.SCOPE_PREFIX + scope, "false");
}
for (Approval approval : approvalStore.getApprovals(principal.getName(), client.getClientId())) {
if (clientAuth.getScope().contains(approval.getScope())) {
scopes.put(OAuth2Utils.SCOPE_PREFIX + approval.getScope(),
approval.getStatus() == Approval.ApprovalStatus.APPROVED ? "true" : "false");
}
}
model.put("scopes", scopes);
return new ModelAndView("access_confirmation", model); // 訂閱 appproval 頁麵
}
示例14: testEnvironmentalOverrides
import org.springframework.security.oauth2.provider.ClientDetails; //導入依賴的package包/類
@Test
public void testEnvironmentalOverrides() {
this.context = new AnnotationConfigEmbeddedWebApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context,
"security.oauth2.client.clientId:myclientid",
"security.oauth2.client.clientSecret:mysecret",
"security.oauth2.client.autoApproveScopes:read,write",
"security.oauth2.client.accessTokenValiditySeconds:40",
"security.oauth2.client.refreshTokenValiditySeconds:80");
this.context.register(AuthorizationAndResourceServerConfiguration.class,
MinimalSecureWebApplication.class);
this.context.refresh();
ClientDetails config = this.context.getBean(ClientDetails.class);
assertThat(config.getClientId()).isEqualTo("myclientid");
assertThat(config.getClientSecret()).isEqualTo("mysecret");
assertThat(config.isAutoApprove("read")).isTrue();
assertThat(config.isAutoApprove("write")).isTrue();
assertThat(config.isAutoApprove("foo")).isFalse();
assertThat(config.getAccessTokenValiditySeconds()).isEqualTo(40);
assertThat(config.getRefreshTokenValiditySeconds()).isEqualTo(80);
verifyAuthentication(config);
}
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:23,代碼來源:OAuth2AutoConfigurationTests.java
示例15: loadClientByClientId
import org.springframework.security.oauth2.provider.ClientDetails; //導入依賴的package包/類
@Override
public ClientDetails loadClientByClientId(String clientId) throws ClientRegistrationException {
Client client = this.clientRepository.findByClientId(clientId);
if (client == null) {
throw new NoSuchClientException(String.format("No client with requested id: %s", clientId));
}
BaseClientDetails baseClientDetails = new BaseClientDetails();
baseClientDetails.setClientId(client.getClientId());
baseClientDetails.setClientSecret(client.getClientSecret());
baseClientDetails.setResourceIds(StringUtils.commaDelimitedListToSet(client.getResourceIds()));
baseClientDetails.setScope(StringUtils.commaDelimitedListToSet(client.getScopes()));
baseClientDetails.setAuthorizedGrantTypes(StringUtils.commaDelimitedListToSet(client.getGrantTypes()));
baseClientDetails.setRegisteredRedirectUri(StringUtils.commaDelimitedListToSet(client.getRedirectUris()));
baseClientDetails.setAutoApproveScopes(StringUtils.commaDelimitedListToSet(client.getAutoApproveScopes()));
return baseClientDetails;
}