• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java InvalidClientException类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.springframework.security.oauth2.common.exceptions.InvalidClientException的典型用法代码示例。如果您正苦于以下问题:Java InvalidClientException类的具体用法?Java InvalidClientException怎么用?Java InvalidClientException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



InvalidClientException类属于org.springframework.security.oauth2.common.exceptions包,在下文中一共展示了InvalidClientException类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: getOAuth2Authentication

import org.springframework.security.oauth2.common.exceptions.InvalidClientException; //导入依赖的package包/类
@Override
protected OAuth2Authentication getOAuth2Authentication(ClientDetails client, TokenRequest tokenRequest) {

    Map<String, String> parameters = tokenRequest.getRequestParameters();
    String authorizationCode = parameters.get("code");
    String redirectUri = parameters.get(OAuth2Utils.REDIRECT_URI);
    String codeVerifier = parameters.get("code_verifier");

    if (authorizationCode == null) {
        throw new InvalidRequestException("An authorization code must be supplied.");
    }

    OAuth2Authentication storedAuth = authorizationCodeServices.consumeAuthorizationCode(authorizationCode);
    if (storedAuth == null) {
        throw new InvalidGrantException("Invalid authorization code: " + authorizationCode);
    }

    OAuth2Request pendingOAuth2Request = storedAuth.getOAuth2Request();




    // Validates code verifier
    Map<String, String> pendingOauth2RequestParams = pendingOAuth2Request.getRequestParameters();
    String codeChallenge = pendingOauth2RequestParams.get("code_challenge");
    String codeChallengeMethod = pendingOauth2RequestParams.get("code_challenge_method");

    if (codeVerifier == null && codeChallenge != null) {
        // client is using PKCE but did not send the codeVerifier
        throw new InvalidRequestException(
                "Invalid authorization code for current token request.");
    }

    if (codeVerifier != null && codeChallenge != null) {
        String hashed = codeVerifier;
        if ("S256".equals(codeChallengeMethod)) {
            hashed = DigestUtils.sha256Hex(codeVerifier);
        }

        if (!hashed.equalsIgnoreCase(codeChallenge)) {
            throw new InvalidRequestException(
                    "Invalid authorization code for current token request.");
        }
    }



    // https://jira.springsource.org/browse/SECOAUTH-333
    // This might be null, if the authorization was done without the redirect_uri parameter
    String redirectUriApprovalParameter = pendingOAuth2Request.getRequestParameters().get(
            OAuth2Utils.REDIRECT_URI);

    if ((redirectUri != null || redirectUriApprovalParameter != null)
            && !pendingOAuth2Request.getRedirectUri().equals(redirectUri)) {
        throw new RedirectMismatchException("Redirect URI mismatch.");
    }

    String pendingClientId = pendingOAuth2Request.getClientId();
    String clientId = tokenRequest.getClientId();
    if (clientId != null && !clientId.equals(pendingClientId)) {
        // just a sanity check.
        throw new InvalidClientException("Client ID mismatch");
    }

    // Secret is not required in the authorization request, so it won't be available
    // in the pendingAuthorizationRequest. We do want to check that a secret is provided
    // in the token request, but that happens elsewhere.

    Map<String, String> combinedParameters = new HashMap<String, String>(pendingOAuth2Request
            .getRequestParameters());
    // Combine the parameters adding the new ones last so they override if there are any clashes
    combinedParameters.putAll(parameters);

    // Make a new stored request with the combined parameters
    OAuth2Request finalStoredOAuth2Request = pendingOAuth2Request.createOAuth2Request(combinedParameters);

    Authentication userAuth = storedAuth.getUserAuthentication();

    return new OAuth2Authentication(finalStoredOAuth2Request, userAuth);

}
 
开发者ID:PacktPublishing,项目名称:OAuth-2.0-Cookbook,代码行数:82,代码来源:CustomAuthCodeTokenGranter.java


示例2: createOrUpdateClient

import org.springframework.security.oauth2.common.exceptions.InvalidClientException; //导入依赖的package包/类
private BaseClientDetails createOrUpdateClient(final BaseClientDetails client) {

        MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
        headers.add("Accept", MediaType.APPLICATION_JSON_VALUE);
        headers.add("Content-Type", MediaType.APPLICATION_JSON_VALUE);
        HttpEntity<String> postEntity = new HttpEntity<>(JSON_UTILS.serialize(client), headers);

        ResponseEntity<String> clientCreate = null;
        try {
            clientCreate = this.uaaAdminTemplate.exchange(this.uaaUrl + "/oauth/clients", HttpMethod.POST, postEntity,
                    String.class);
            if (clientCreate.getStatusCode() == HttpStatus.CREATED) {
                return JSON_UTILS.deserialize(clientCreate.getBody(), BaseClientDetails.class);
            } else {
                throw new RuntimeException("Unexpected return code for client create: " + clientCreate.getStatusCode());
            }
        } catch (InvalidClientException ex) {
            if (ex.getMessage().equals("Client already exists: " + client.getClientId())) {
                HttpEntity<String> putEntity = new HttpEntity<String>(JSON_UTILS.serialize(client), headers);
                ResponseEntity<String> clientUpdate = this.uaaAdminTemplate.exchange(
                        this.uaaUrl + "/oauth/clients/" + client.getClientId(), HttpMethod.PUT, putEntity,
                        String.class);
                if (clientUpdate.getStatusCode() == HttpStatus.OK) {
                    return JSON_UTILS.deserialize(clientUpdate.getBody(), BaseClientDetails.class);
                } else {
                    throw new RuntimeException(
                            "Unexpected return code for client update: " + clientUpdate.getStatusCode());
                }
            }
        }
        throw new RuntimeException("Unexpected return code for client creation: " + clientCreate.getStatusCode());
    }
 
开发者ID:eclipse,项目名称:keti,代码行数:33,代码来源:UAAACSClientsUtil.java


示例3: extractAuthentication

import org.springframework.security.oauth2.common.exceptions.InvalidClientException; //导入依赖的package包/类
@Override
public Authentication extractAuthentication(final Map<String, ?> authenticationAttributes) {
  if (!authenticationAttributes.containsKey(UNSPECIFIED_ID) &&
    authenticationAttributes.containsKey(CLIENT_ID)) {
    return new ClientCredentialsAuthentication((String) authenticationAttributes.get(CLIENT_ID), DEFAULT_AUTHORITIES);
  } else if (authenticationAttributes.containsKey(UNSPECIFIED_ID) &&
    authenticationAttributes.containsKey(SCHAC_HOME_KEY)) {
    return new SchacHomeAuthentication((String) authenticationAttributes.get(SCHAC_HOME_KEY),
      authenticationAttributes.get(UNSPECIFIED_ID), "N/A", DEFAULT_AUTHORITIES);
  }
  throw new InvalidClientException(String.format("Unsupported client authentication. Must contain either %s or %s and %s",
    CLIENT_ID, UNSPECIFIED_ID, SCHAC_HOME_KEY));
}
 
开发者ID:OpenConext,项目名称:OpenConext-voot,代码行数:14,代码来源:OidcSchacHomeAwareUserAuthenticationConverter.java


示例4: loadClientByClientId

import org.springframework.security.oauth2.common.exceptions.InvalidClientException; //导入依赖的package包/类
public ClientDetails loadClientByClientId(String clientId) throws InvalidClientException {
    DBObject query = new BasicDBObject(clientIdFieldName, clientId);
    DBObject entry = getClientDetailsCollection().findOne(query);
    if (entry == null) {
        throw new NoSuchClientException("No client with requested id: " + clientId);
    }
    return toClientDetails(entry);
}
 
开发者ID:cedac-software,项目名称:spring-security-mongodb,代码行数:9,代码来源:MongoClientDetailsService.java


示例5: validateGrantType

import org.springframework.security.oauth2.common.exceptions.InvalidClientException; //导入依赖的package包/类
protected void validateGrantType(String grantType, ClientDetails clientDetails) {
	Collection<String> authorizedGrantTypes = clientDetails.getAuthorizedGrantTypes();
	if (authorizedGrantTypes != null && !authorizedGrantTypes.isEmpty()
			&& !authorizedGrantTypes.contains(grantType)) {
		throw new InvalidClientException("Unauthorized grant type: " + grantType);
	}
}
 
开发者ID:jungyang,项目名称:oauth-client-master,代码行数:8,代码来源:AbstractTokenGranter.java


示例6: loadClientByClientId

import org.springframework.security.oauth2.common.exceptions.InvalidClientException; //导入依赖的package包/类
public ClientDetails loadClientByClientId(String clientId) throws InvalidClientException {
	ClientDetails details;
	try {
		details = jdbcTemplate.queryForObject(selectClientDetailsSql, new ClientDetailsRowMapper(), clientId);
	}
	catch (EmptyResultDataAccessException e) {
		throw new NoSuchClientException("No client with requested id: " + clientId);
	}

	return details;
}
 
开发者ID:jungyang,项目名称:oauth-client-master,代码行数:12,代码来源:JdbcClientDetailsService.java


示例7: createTokenRequest

import org.springframework.security.oauth2.common.exceptions.InvalidClientException; //导入依赖的package包/类
public TokenRequest createTokenRequest(Map<String, String> requestParameters, ClientDetails authenticatedClient) {

		String clientId = requestParameters.get(OAuth2Utils.CLIENT_ID);
		if (clientId == null) {
			// if the clientId wasn't passed in in the map, we add pull it from the authenticated client object
			clientId = authenticatedClient.getClientId();
		} else {
			// otherwise, make sure that they match
			if (!clientId.equals(authenticatedClient.getClientId())) {
				throw new InvalidClientException("Given client ID does not match authenticated client");
			}
		}
		Set<String> scopes = OAuth2Utils.parseParameterList(requestParameters.get(OAuth2Utils.SCOPE));
		String grantType = requestParameters.get(OAuth2Utils.GRANT_TYPE);
		
		ClientDetails clientDetails = clientDetailsService.loadClientByClientId(clientId);

		if ((scopes == null || scopes.isEmpty())) {
			// If no scopes are specified in the incoming data, use the default values registered with the client
			// (the spec allows us to choose between this option and rejecting the request completely, so we'll take the
			// least obnoxious choice as a default).
			scopes = clientDetails.getScope();
		}

		TokenRequest tokenRequest = new TokenRequest(requestParameters, clientId, scopes, grantType);
		
		return tokenRequest;
	}
 
开发者ID:jungyang,项目名称:oauth-client-master,代码行数:29,代码来源:DefaultOAuth2RequestFactory.java


示例8: writeInvalidClient

import org.springframework.security.oauth2.common.exceptions.InvalidClientException; //导入依赖的package包/类
@Test
public void writeInvalidClient() throws IOException {
	OAuth2Exception oauthException = new InvalidClientException(DETAILS);
	String expected = createResponse(oauthException.getOAuth2ErrorCode());
	converter.write(oauthException, contentType, outputMessage);
	assertEquals(expected, getOutput());
}
 
开发者ID:jungyang,项目名称:oauth-client-master,代码行数:8,代码来源:JaxbOAuth2ExceptionMessageConverterTests.java


示例9: readInvalidClient

import org.springframework.security.oauth2.common.exceptions.InvalidClientException; //导入依赖的package包/类
@Test
public void readInvalidClient() throws IOException {
	String accessToken = createResponse(OAuth2Exception.INVALID_CLIENT);
	when(inputMessage.getBody()).thenReturn(createInputStream(accessToken));
	@SuppressWarnings("unused")
	InvalidClientException result = (InvalidClientException) converter.read(InvalidClientException.class,
			inputMessage);
}
 
开发者ID:jungyang,项目名称:oauth-client-master,代码行数:9,代码来源:JaxbOAuth2ExceptionMessageConverterTests.java


示例10: testCommenceWithOAuth2Exception

import org.springframework.security.oauth2.common.exceptions.InvalidClientException; //导入依赖的package包/类
@Test
public void testCommenceWithOAuth2Exception() throws Exception {
	request.addHeader("Accept", MediaType.APPLICATION_JSON_VALUE);
	entryPoint.commence(request, response, new BadCredentialsException("Bad", new InvalidClientException(
			"Bad client")));
	assertEquals(HttpServletResponse.SC_UNAUTHORIZED, response.getStatus());
	assertEquals("{\"error\":\"invalid_client\",\"error_description\":\"Bad client\"}", response.getContentAsString());
	assertEquals(MediaType.APPLICATION_JSON_VALUE, response.getContentType());
	assertEquals(null, response.getErrorMessage());
}
 
开发者ID:jungyang,项目名称:oauth-client-master,代码行数:11,代码来源:OAuth2AuthenticationEntryPointTests.java


示例11: testGrantTypeNotSupported

import org.springframework.security.oauth2.common.exceptions.InvalidClientException; //导入依赖的package包/类
@Test(expected = InvalidClientException.class)
public void testGrantTypeNotSupported() {
	ResourceOwnerPasswordTokenGranter granter = new ResourceOwnerPasswordTokenGranter(
			authenticationManager, providerTokenServices,
			clientDetailsService, requestFactory);
	client.setAuthorizedGrantTypes(Collections
			.singleton("client_credentials"));
	granter.grant("password", tokenRequest);
}
 
开发者ID:jungyang,项目名称:oauth-client-master,代码行数:10,代码来源:ResourceOwnerPasswordTokenGranterTests.java


示例12: testErrorPage

import org.springframework.security.oauth2.common.exceptions.InvalidClientException; //导入依赖的package包/类
@Test
public void testErrorPage() throws Exception {
	request.setContextPath("/foo");
	request.setAttribute("error", new InvalidClientException("FOO"));
	ModelAndView result = endpoint.handleError(request);
	result.getView().render(result.getModel(), request , response);
	String content = response.getContentAsString();
	assertTrue("Wrong content: " + content, content.contains("OAuth Error"));
	assertTrue("Wrong content: " + content, content.contains("invalid_client"));
}
 
开发者ID:jungyang,项目名称:oauth-client-master,代码行数:11,代码来源:WhitelabelApprovalEndpointTests.java


示例13: readValueInvalidClient

import org.springframework.security.oauth2.common.exceptions.InvalidClientException; //导入依赖的package包/类
@Test
public void readValueInvalidClient() throws Exception {
	String accessToken = createResponse(OAuth2Exception.INVALID_CLIENT);
	InvalidClientException result = (InvalidClientException) mapper.readValue(accessToken, OAuth2Exception.class);
	assertEquals(DETAILS,result.getMessage());
	assertEquals(null,result.getAdditionalInformation());
}
 
开发者ID:jungyang,项目名称:oauth-client-master,代码行数:8,代码来源:OAuth2ExceptionDeserializerTests.java


示例14: readValueWithAdditionalDetails

import org.springframework.security.oauth2.common.exceptions.InvalidClientException; //导入依赖的package包/类
@Test
public void readValueWithAdditionalDetails() throws Exception {
	String accessToken = "{\"error\": \"invalid_client\", \"error_description\": \"some detail\", \"foo\": \"bar\"}";
	InvalidClientException result = (InvalidClientException) mapper.readValue(accessToken, OAuth2Exception.class);
	assertEquals(DETAILS,result.getMessage());
	assertEquals("{foo=bar}",result.getAdditionalInformation().toString());
}
 
开发者ID:jungyang,项目名称:oauth-client-master,代码行数:8,代码来源:OAuth2ExceptionDeserializerTests.java


示例15: writeValueAsStringWithAdditionalDetails

import org.springframework.security.oauth2.common.exceptions.InvalidClientException; //导入依赖的package包/类
@Test
public void writeValueAsStringWithAdditionalDetails() throws Exception {
	oauthException = new InvalidClientException(DETAILS);
	oauthException.addAdditionalInformation("foo", "bar");
	String expected = "{\"error\":\"invalid_client\",\"error_description\":\"some detail\",\"foo\":\"bar\"}";
	assertEquals(expected,mapper.writeValueAsString(oauthException));
}
 
开发者ID:jungyang,项目名称:oauth-client-master,代码行数:8,代码来源:OAuth2ExceptionSerializerTests.java


示例16: testExceptionDeserialization

import org.springframework.security.oauth2.common.exceptions.InvalidClientException; //导入依赖的package包/类
@Test
public void testExceptionDeserialization() throws Exception {
	Map<String, String> exception = MapBuilder.create("error", "invalid_client").add("error_description", "FOO")
			.build();
	OAuth2Exception result = OAuth2Exception.valueOf(exception);
	// System.err.println(result);
	assertEquals("FOO", result.getMessage());
	assertEquals("invalid_client", result.getOAuth2ErrorCode());
	assertTrue(result instanceof InvalidClientException);
}
 
开发者ID:jungyang,项目名称:oauth-client-master,代码行数:11,代码来源:DefaultOAuth2SerializationServiceTests.java


示例17: testExceptionSerialization

import org.springframework.security.oauth2.common.exceptions.InvalidClientException; //导入依赖的package包/类
@Test
public void testExceptionSerialization() throws Exception {
	InvalidClientException exception = new InvalidClientException("FOO");
	exception.addAdditionalInformation("foo", "bar");
	String result = new ObjectMapper().writeValueAsString(exception);
	// System.err.println(result);
	assertTrue("Wrong result: "+result, result.contains("\"error\":\"invalid_client\""));
	assertTrue("Wrong result: "+result, result.contains("\"error_description\":\"FOO\""));
	assertTrue("Wrong result: "+result, result.contains("\"foo\":\"bar\""));
}
 
开发者ID:jungyang,项目名称:oauth-client-master,代码行数:11,代码来源:JsonSerializationTests.java


示例18: testExceptionDeserialization

import org.springframework.security.oauth2.common.exceptions.InvalidClientException; //导入依赖的package包/类
@Test
public void testExceptionDeserialization() throws Exception {
	String exception = "{\"error\": \"invalid_client\", \"error_description\": \"FOO\", \"foo\": \"bar\"}";
	OAuth2Exception result = new ObjectMapper().readValue(exception, OAuth2Exception.class);
	// System.err.println(result);
	assertEquals("FOO", result.getMessage());
	assertEquals("invalid_client", result.getOAuth2ErrorCode());
	assertEquals("{foo=bar}", result.getAdditionalInformation().toString());
	assertTrue(result instanceof InvalidClientException);
}
 
开发者ID:jungyang,项目名称:oauth-client-master,代码行数:11,代码来源:JsonSerializationTests.java


示例19: getPublicKeyEndpoint

import org.springframework.security.oauth2.common.exceptions.InvalidClientException; //导入依赖的package包/类
/** Returns the configured endpoint URI to retrieve the public key. */
private String getPublicKeyEndpoint() {
    String tokenEndpointUrl = oAuth2Properties.getSignatureVerification().getPublicKeyEndpointUri();
    if (tokenEndpointUrl == null) {
        throw new InvalidClientException("no token endpoint configured in application properties");
    }
    return tokenEndpointUrl;
}
 
开发者ID:jhipster,项目名称:generator-jhipster,代码行数:9,代码来源:_UaaSignatureVerifierClient.java


示例20: getClientSecret

import org.springframework.security.oauth2.common.exceptions.InvalidClientException; //导入依赖的package包/类
protected String getClientSecret() {
    String clientSecret = oAuth2Properties.getWebClientConfiguration().getSecret();
    if(clientSecret == null) {
        throw new InvalidClientException("no client-secret configured in application properties");
    }
    return clientSecret;
}
 
开发者ID:jhipster,项目名称:generator-jhipster,代码行数:8,代码来源:_OAuth2TokenEndpointClientAdapter.java



注:本文中的org.springframework.security.oauth2.common.exceptions.InvalidClientException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java User类代码示例发布时间:2022-05-22
下一篇:
Java IDLNameTranslatorImpl类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap