本文整理汇总了Java中org.apache.oltu.oauth2.common.exception.OAuthSystemException类的典型用法代码示例。如果您正苦于以下问题:Java OAuthSystemException类的具体用法?Java OAuthSystemException怎么用?Java OAuthSystemException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
OAuthSystemException类属于org.apache.oltu.oauth2.common.exception包,在下文中一共展示了OAuthSystemException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onLoginFailure
import org.apache.oltu.oauth2.common.exception.OAuthSystemException; //导入依赖的package包/类
@Override
protected boolean onLoginFailure(AuthenticationToken token, AuthenticationException ae, ServletRequest request,
ServletResponse response) {
final OAuthResponse oAuthResponse;
try {
oAuthResponse = OAuthRSResponse.errorResponse(401)
.setError(OAuthError.ResourceResponse.INVALID_TOKEN)
.setErrorDescription(ae.getMessage())
.buildJSONMessage();
com.monkeyk.os.web.WebUtils.writeOAuthJsonResponse((HttpServletResponse) response, oAuthResponse);
} catch (OAuthSystemException e) {
LOGGER.error("Build JSON message error", e);
throw new IllegalStateException(e);
}
return false;
}
示例2: validateSelf
import org.apache.oltu.oauth2.common.exception.OAuthSystemException; //导入依赖的package包/类
@Override
public OAuthResponse validateSelf(ClientDetails clientDetails) throws OAuthSystemException {
//validate client_secret
final String clientSecret = oauthRequest.getClientSecret();
if (clientSecret == null || !clientSecret.equals(clientDetails.clientSecret())) {
return invalidClientSecretResponse();
}
//validate redirect_uri
final String redirectURI = oauthRequest.getRedirectURI();
if (redirectURI == null || !redirectURI.equals(clientDetails.redirectUri())) {
LOG.debug("Invalid redirect_uri '{}' by response_type = 'code', client_id = '{}'", redirectURI, clientDetails.clientId());
return invalidRedirectUriResponse();
}
//validate scope
final Set<String> scopes = oauthRequest.getScopes();
if (scopes.isEmpty() || excludeScopes(scopes, clientDetails)) {
return invalidScopeResponse();
}
return null;
}
示例3: responseApprovalDeny
import org.apache.oltu.oauth2.common.exception.OAuthSystemException; //导入依赖的package包/类
protected void responseApprovalDeny() throws IOException, OAuthSystemException {
final OAuthResponse oAuthResponse = OAuthASResponse.errorResponse(HttpServletResponse.SC_FOUND)
.setError(OAuthError.CodeResponse.ACCESS_DENIED)
.setErrorDescription("User denied access")
.location(clientDetails().redirectUri())
.setState(oauthRequest.getState())
.buildQueryMessage();
LOG.debug("'ACCESS_DENIED' response: {}", oAuthResponse);
WebUtils.writeOAuthQueryResponse(response, oAuthResponse);
//user logout when deny
final Subject subject = SecurityUtils.getSubject();
subject.logout();
LOG.debug("After 'ACCESS_DENIED' call logout. user: {}", subject.getPrincipal());
}
示例4: retrieveAuthCode
import org.apache.oltu.oauth2.common.exception.OAuthSystemException; //导入依赖的package包/类
@Override
public String retrieveAuthCode(ClientDetails clientDetails) throws OAuthSystemException {
final String clientId = clientDetails.getClientId();
final String username = currentUsername();
OauthCode oauthCode = oauthRepository.findOauthCodeByUsernameClientId(username, clientId);
if (oauthCode != null) {
//Always delete exist
LOG.debug("OauthCode ({}) is existed, remove it and create a new one", oauthCode);
oauthRepository.deleteOauthCode(oauthCode);
}
//create a new one
oauthCode = createOauthCode(clientDetails);
return oauthCode.code();
}
示例5: retrieveAccessToken
import org.apache.oltu.oauth2.common.exception.OAuthSystemException; //导入依赖的package包/类
@Override
public AccessToken retrieveAccessToken(ClientDetails clientDetails, Set<String> scopes, boolean includeRefreshToken) throws OAuthSystemException {
String scope = OAuthUtils.encodeScopes(scopes);
final String username = currentUsername();
final String clientId = clientDetails.getClientId();
final String authenticationId = authenticationIdGenerator.generate(clientId, username, scope);
AccessToken accessToken = oauthRepository.findAccessToken(clientId, username, authenticationId);
if (accessToken == null) {
accessToken = createAndSaveAccessToken(clientDetails, includeRefreshToken, username, authenticationId);
LOG.debug("Create a new AccessToken: {}", accessToken);
}
return accessToken;
}
示例6: validateSelf
import org.apache.oltu.oauth2.common.exception.OAuthSystemException; //导入依赖的package包/类
@Override
public OAuthResponse validateSelf(ClientDetails clientDetails) throws OAuthSystemException {
//validate redirect_uri
final String redirectURI = oauthRequest.getRedirectURI();
if (redirectURI == null || !redirectURI.equals(clientDetails.redirectUri())) {
LOG.debug("Invalid redirect_uri '{}' by response_type = 'code', client_id = '{}'", redirectURI, clientDetails.clientId());
return invalidRedirectUriResponse();
}
//validate scope
final Set<String> scopes = oauthRequest.getScopes();
if (scopes.isEmpty() || excludeScopes(scopes, clientDetails)) {
return invalidScopeResponse();
}
//validate state
final String state = getState();
if (StringUtils.isEmpty(state)) {
LOG.debug("Invalid 'state', it is required, but it is empty");
return invalidStateResponse();
}
return null;
}
示例7: createAndSaveAccessToken
import org.apache.oltu.oauth2.common.exception.OAuthSystemException; //导入依赖的package包/类
private AccessToken createAndSaveAccessToken(ClientDetails clientDetails, boolean includeRefreshToken, String username, String authenticationId) throws OAuthSystemException {
AccessToken accessToken = new AccessToken()
.clientId(clientDetails.getClientId())
.username(username)
.tokenId(oAuthIssuer.accessToken())
.authenticationId(authenticationId)
.updateByClientDetails(clientDetails);
if (includeRefreshToken) {
accessToken.refreshToken(oAuthIssuer.refreshToken());
}
this.oauthRepository.saveAccessToken(accessToken);
LOG.debug("Save AccessToken: {}", accessToken);
return accessToken;
}
示例8: validateSelf
import org.apache.oltu.oauth2.common.exception.OAuthSystemException; //导入依赖的package包/类
@Override
public OAuthResponse validateSelf(ClientDetails clientDetails) throws OAuthSystemException {
//validate redirect_uri
final String redirectURI = oauthRequest.getRedirectURI();
if (redirectURI == null || !redirectURI.equals(clientDetails.getRedirectUri())) {
LOG.debug("Invalid redirect_uri '{}' by response_type = 'code', client_id = '{}'", redirectURI, clientDetails.getClientId());
return invalidRedirectUriResponse();
}
//validate scope
final Set<String> scopes = oauthRequest.getScopes();
if (scopes.isEmpty() || excludeScopes(scopes, clientDetails)) {
return invalidScopeResponse();
}
//validate state
final String state = getState();
if (StringUtils.isEmpty(state)) {
LOG.debug("Invalid 'state', it is required, but it is empty");
return invalidStateResponse();
}
return null;
}
示例9: validateSelf
import org.apache.oltu.oauth2.common.exception.OAuthSystemException; //导入依赖的package包/类
@Override
protected OAuthResponse validateSelf(ClientDetails clientDetails) throws OAuthSystemException {
//validate grant_type
final String grantType = grantType();
if (!clientDetails.grantTypes().contains(grantType)) {
LOG.debug("Invalid grant_type '{}', client_id = '{}'", grantType, clientDetails.getClientId());
return invalidGrantTypeResponse(grantType);
}
//validate client_secret
final String clientSecret = oauthRequest.getClientSecret();
if (clientSecret == null || !clientSecret.equals(clientDetails.getClientSecret())) {
LOG.debug("Invalid client_secret '{}', client_id = '{}'", clientSecret, clientDetails.getClientId());
return invalidClientSecretResponse();
}
//validate scope
final Set<String> scopes = oauthRequest.getScopes();
if (scopes.isEmpty() || excludeScopes(scopes, clientDetails)) {
return invalidScopeResponse();
}
return null;
}
示例10: validateSelf
import org.apache.oltu.oauth2.common.exception.OAuthSystemException; //导入依赖的package包/类
@Override
protected OAuthResponse validateSelf(ClientDetails clientDetails) throws OAuthSystemException {
//validate grant_type
final String grantType = grantType();
if (invalidateGrantType(clientDetails, grantType)) {
return invalidGrantTypeResponse(grantType);
}
//validate client_secret
if (invalidateClientSecret(clientDetails)) {
return invalidClientSecretResponse();
}
//validate scope
if (invalidateScope(clientDetails)) {
return invalidScopeResponse();
}
//validate username,password
if (invalidUsernamePassword()) {
return invalidUsernamePasswordResponse();
}
return null;
}
示例11: validateSelf
import org.apache.oltu.oauth2.common.exception.OAuthSystemException; //导入依赖的package包/类
@Override
protected OAuthResponse validateSelf(ClientDetails clientDetails) throws OAuthSystemException {
//validate grant_type
final String grantType = grantType();
if (!clientDetails.grantTypes().contains(grantType)) {
LOG.debug("Invalid grant_type '{}', client_id = '{}'", grantType, clientDetails.clientId());
return invalidGrantTypeResponse(grantType);
}
//validate client_secret
final String clientSecret = oauthRequest.getClientSecret();
if (clientSecret == null || !clientSecret.equals(clientDetails.clientSecret())) {
LOG.debug("Invalid client_secret '{}', client_id = '{}'", clientSecret, clientDetails.clientId());
return invalidClientSecretResponse();
}
//validate scope
final Set<String> scopes = oauthRequest.getScopes();
if (scopes.isEmpty() || excludeScopes(scopes, clientDetails)) {
return invalidScopeResponse();
}
return null;
}
示例12: submitApproval
import org.apache.oltu.oauth2.common.exception.OAuthSystemException; //导入依赖的package包/类
protected boolean submitApproval() throws IOException, OAuthSystemException {
if (isPost() && !clientDetails().trusted()) {
//submit approval
final HttpServletRequest request = oauthRequest.request();
final String oauthApproval = request.getParameter(REQUEST_USER_OAUTH_APPROVAL);
if (!"true".equalsIgnoreCase(oauthApproval)) {
//Deny action
LOG.debug("User '{}' deny access", SecurityUtils.getSubject().getPrincipal());
responseApprovalDeny();
return true;
} else {
userFirstApproved = true;
return false;
}
}
return false;
}
示例13: responseApprovalDeny
import org.apache.oltu.oauth2.common.exception.OAuthSystemException; //导入依赖的package包/类
protected void responseApprovalDeny() throws IOException, OAuthSystemException {
final OAuthResponse oAuthResponse = OAuthASResponse.errorResponse(HttpServletResponse.SC_FOUND)
.setError(OAuthError.CodeResponse.ACCESS_DENIED)
.setErrorDescription("User denied access")
.location(clientDetails().getRedirectUri())
.setState(oauthRequest.getState())
.buildQueryMessage();
LOG.debug("'ACCESS_DENIED' response: {}", oAuthResponse);
WebUtils.writeOAuthQueryResponse(response, oAuthResponse);
//user logout when deny
final Subject subject = SecurityUtils.getSubject();
subject.logout();
LOG.debug("After 'ACCESS_DENIED' call logout. user: {}", subject.getPrincipal());
}
示例14: onLoginFailure
import org.apache.oltu.oauth2.common.exception.OAuthSystemException; //导入依赖的package包/类
@Override
protected boolean onLoginFailure(AuthenticationToken token, AuthenticationException ae, ServletRequest request,
ServletResponse response) {
// OAuth2Token oAuth2Token = (OAuth2Token) token;
final OAuthResponse oAuthResponse;
try {
oAuthResponse = OAuthRSResponse.errorResponse(401)
.setError(OAuthError.ResourceResponse.INVALID_TOKEN)
.setErrorDescription(ae.getMessage())
.buildJSONMessage();
com.monkeyk.os.web.WebUtils.writeOAuthJsonResponse((HttpServletResponse) response, oAuthResponse);
} catch (OAuthSystemException e) {
logger.error("Build JSON message error", e);
throw new IllegalStateException(e);
}
return false;
}
示例15: retrieve
import org.apache.oltu.oauth2.common.exception.OAuthSystemException; //导入依赖的package包/类
public AccessToken retrieve() throws OAuthSystemException {
final OauthCode oauthCode = loadOauthCode();
final String username = oauthCode.username();
final String clientId = clientDetails.clientId();
final String authenticationId = authenticationIdGenerator.generate(clientId, username, null);
AccessToken accessToken = oauthRepository.findAccessToken(clientId, username, authenticationId);
if (accessToken != null) {
LOG.debug("Delete existed AccessToken: {}", accessToken);
oauthRepository.deleteAccessToken(accessToken);
}
accessToken = createAndSaveAccessToken(clientDetails, clientDetails.supportRefreshToken(), username, authenticationId);
LOG.debug("Create a new AccessToken: {}", accessToken);
return accessToken;
}