当前位置: 首页>>代码示例>>Java>>正文


Java OAuthResponse类代码示例

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


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

示例1: onLoginFailure

import org.apache.oltu.oauth2.common.message.OAuthResponse; //导入依赖的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;
}
 
开发者ID:monkeyk,项目名称:oauth2-shiro,代码行数:22,代码来源:OAuth2Filter.java

示例2: __parseResponseType

import org.apache.oltu.oauth2.common.message.OAuthResponse; //导入依赖的package包/类
private OAuthResponse __parseResponseType(HttpServletRequest request, ResponseType _responseType, IOAuth.IOAuthAuthzHelper _authzHelper, OAuthAuthzRequest _oauthRequest, String _redirectURI, String _scope, String uid, String state) throws Exception {
    OAuthResponse _response;
    switch (_responseType) {
        case CODE:
            _response = OAuthASResponse.authorizationResponse(request, HttpServletResponse.SC_FOUND)
                    .location(_redirectURI)
                    .setCode(_authzHelper.createOrUpdateAuthCode(_redirectURI, _scope).getCode())
                    .setParam(org.apache.oltu.oauth2.common.OAuth.OAUTH_STATE, state)
                    .buildQueryMessage();
            break;
        case TOKEN:
            _response = OAuthResponseUtils.tokenToResponse(OAuth.get().tokenHelper(_oauthRequest.getClientId(), _oauthRequest.getClientSecret(), _oauthRequest.getParam(org.apache.oltu.oauth2.common.OAuth.OAUTH_CODE), uid).createOrUpdateAccessToken(), state);
            break;
        default:
            _response = OAuthResponseUtils.badRequest(OAuthError.CodeResponse.UNSUPPORTED_RESPONSE_TYPE);
    }
    return _response;
}
 
开发者ID:suninformation,项目名称:ymate-module-oauth,代码行数:19,代码来源:OAuthSnsController.java

示例3: userinfo

import org.apache.oltu.oauth2.common.message.OAuthResponse; //导入依赖的package包/类
/**
 * @param accountToken 网页授权接口调用凭证
 * @param openId       用户的唯一标识
 * @return 返回用户信息 (OAuth2授权需scope=snsapi_userinfo)
 * @throws Exception 可能产生的任何异常
 */
@RequestMapping("/userinfo")
@Before(SnsAccessTokenCheckInterceptor.class)
@ContextParam(@ParamItem(key = IOAuth.Const.SCOPE, value = IOAuth.Scope.SNSAPI_USERINFO))
public IView userinfo(@RequestParam(IOAuth.Const.ACCESS_TOKEN) String accountToken, @RequestParam(IOAuth.Const.OPEN_ID) String openId) throws Exception {
    OAuthResponse _response = null;
    try {
        if (StringUtils.isBlank(openId)) {
            _response = OAuthResponseUtils.badRequest(IOAuth.Const.INVALID_USER);
        }
        IOAuthUserInfoAdapter _adapter = OAuth.get().getModuleCfg().getUserInfoAdapter();
        if (_adapter != null) {
            return View.jsonView(_adapter.getUserInfo(OAuth.get().resourceHelper(accountToken, openId).getOAuthClientUser().getUid()));
        }
        _response = OAuthResponseUtils.unauthorizedClient(OAuthError.ResourceResponse.INVALID_REQUEST);
    } catch (Exception e) {
        _response = OAuthResponseUtils.badRequest(IOAuth.Const.INVALID_USER);
    }
    return new HttpStatusView(_response.getResponseStatus(), false).writeBody(_response.getBody());
}
 
开发者ID:suninformation,项目名称:ymate-module-oauth,代码行数:26,代码来源:OAuthSnsController.java

示例4: writeOAuthJsonResponse

import org.apache.oltu.oauth2.common.message.OAuthResponse; //导入依赖的package包/类
public static void writeOAuthJsonResponse(HttpServletResponse response, OAuthResponse oAuthResponse) {

        final int responseStatus = oAuthResponse.getResponseStatus();
        try {

            final Map<String, String> headers = oAuthResponse.getHeaders();
            for (String key : headers.keySet()) {
                response.addHeader(key, headers.get(key));
            }
            // CORS setting
            response.setHeader("Access-Control-Allow-Origin", "*");

            response.setContentType(OAuth.ContentType.JSON);    //json
            response.setStatus(responseStatus);

            final PrintWriter out = response.getWriter();
            out.print(oAuthResponse.getBody());
            out.flush();
        } catch (IOException e) {
            throw new IllegalStateException("Write OAuthResponse error", e);
        }
    }
 
开发者ID:monkeyk,项目名称:oauth2-shiro,代码行数:23,代码来源:WebUtils.java

示例5: writeOAuthQueryResponse

import org.apache.oltu.oauth2.common.message.OAuthResponse; //导入依赖的package包/类
public static void writeOAuthQueryResponse(HttpServletResponse response, OAuthResponse oAuthResponse) {
    final String locationUri = oAuthResponse.getLocationUri();
    try {

        final Map<String, String> headers = oAuthResponse.getHeaders();
        for (String key : headers.keySet()) {
            response.addHeader(key, headers.get(key));
        }

        response.setStatus(oAuthResponse.getResponseStatus());
        response.sendRedirect(locationUri);

    } catch (IOException e) {
        throw new IllegalStateException("Write OAuthResponse error", e);
    }
}
 
开发者ID:monkeyk,项目名称:oauth2-shiro,代码行数:17,代码来源:WebUtils.java

示例6: authorize

import org.apache.oltu.oauth2.common.message.OAuthResponse; //导入依赖的package包/类
/**
 * Handle grant_types as follows:
 * <p/>
 * grant_type=authorization_code
 * grant_type=password
 * grant_type=refresh_token
 * grant_type=client_credentials
 *
 * @param request  HttpServletRequest
 * @param response HttpServletResponse
 * @throws OAuthSystemException
 */
@RequestMapping("token")
public void authorize(HttpServletRequest request, HttpServletResponse response) throws OAuthSystemException {
    try {
        OAuthTokenxRequest tokenRequest = new OAuthTokenxRequest(request);

        OAuthTokenHandleDispatcher tokenHandleDispatcher = new OAuthTokenHandleDispatcher(tokenRequest, response);
        tokenHandleDispatcher.dispatch();

    } catch (OAuthProblemException e) {
        //exception
        OAuthResponse oAuthResponse = OAuthASResponse
                .errorResponse(HttpServletResponse.SC_FOUND)
                .location(e.getRedirectUri())
                .error(e)
                .buildJSONMessage();
        WebUtils.writeOAuthJsonResponse(response, oAuthResponse);
    }

}
 
开发者ID:monkeyk,项目名称:oauth2-shiro,代码行数:32,代码来源:OauthTokenController.java

示例7: validateSelf

import org.apache.oltu.oauth2.common.message.OAuthResponse; //导入依赖的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;
}
 
开发者ID:monkeyk,项目名称:oauth2-shiro,代码行数:25,代码来源:CodeClientDetailsValidator.java

示例8: validateSelf

import org.apache.oltu.oauth2.common.message.OAuthResponse; //导入依赖的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;
}
 
开发者ID:monkeyk,项目名称:oauth2-shiro,代码行数:26,代码来源:ClientCredentialsClientDetailsValidator.java

示例9: validateSelf

import org.apache.oltu.oauth2.common.message.OAuthResponse; //导入依赖的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;
}
 
开发者ID:monkeyk,项目名称:oauth2-shiro,代码行数:27,代码来源:PasswordClientDetailsValidator.java

示例10: createTokenResponse

import org.apache.oltu.oauth2.common.message.OAuthResponse; //导入依赖的package包/类
/**
 * Create  AccessToken response
 *
 * @param accessToken AccessToken
 * @param queryOrJson True is QueryMessage, false is JSON message
 * @return OAuthResponse
 * @throws org.apache.oltu.oauth2.common.exception.OAuthSystemException
 */
protected OAuthResponse createTokenResponse(AccessToken accessToken, boolean queryOrJson) throws OAuthSystemException {
    final ClientDetails tempClientDetails = clientDetails();

    final OAuthASResponse.OAuthTokenResponseBuilder builder = OAuthASResponse
            .tokenResponse(HttpServletResponse.SC_OK)
            .location(tempClientDetails.getRedirectUri())
            .setAccessToken(accessToken.tokenId())
            .setExpiresIn(String.valueOf(accessToken.currentTokenExpiredSeconds()))
            .setTokenType(accessToken.tokenType());

    final String refreshToken = accessToken.refreshToken();
    if (StringUtils.isNotEmpty(refreshToken)) {
        builder.setRefreshToken(refreshToken);
    }

    return queryOrJson ? builder.buildQueryMessage() : builder.buildJSONMessage();
}
 
开发者ID:monkeyk,项目名称:oauth2-shiro,代码行数:26,代码来源:OAuthHandler.java

示例11: responseApprovalDeny

import org.apache.oltu.oauth2.common.message.OAuthResponse; //导入依赖的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());
    }
 
开发者ID:monkeyk,项目名称:oauth2-shiro,代码行数:18,代码来源:AbstractAuthorizeHandler.java

示例12: onLoginFailure

import org.apache.oltu.oauth2.common.message.OAuthResponse; //导入依赖的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;
    }
 
开发者ID:monkeyk,项目名称:oauth2-shiro-redis,代码行数:23,代码来源:OAuth2Filter.java

示例13: authorize

import org.apache.oltu.oauth2.common.message.OAuthResponse; //导入依赖的package包/类
/**
 * Handle grant_types as follows:
 * <p/>
 * grant_type=authorization_code
 * grant_type=password
 * grant_type=refresh_token
 * grant_type=client_credentials
 *
 * @param request  HttpServletRequest
 * @param response HttpServletResponse
 * @throws Exception
 */
@RequestMapping("token")
public void authorize(HttpServletRequest request, HttpServletResponse response) throws Exception {
    try {
        OAuthTokenxRequest tokenRequest = new OAuthTokenxRequest(request);

        OAuthTokenHandleDispatcher tokenHandleDispatcher = new OAuthTokenHandleDispatcher(tokenRequest, response);
        tokenHandleDispatcher.dispatch();

    } catch (OAuthProblemException e) {
        //exception
        OAuthResponse oAuthResponse = OAuthASResponse
                .errorResponse(HttpServletResponse.SC_FOUND)
                .location(e.getRedirectUri())
                .error(e)
                .buildJSONMessage();
        WebUtils.writeOAuthJsonResponse(response, oAuthResponse);
    }

}
 
开发者ID:monkeyk,项目名称:oauth2-shiro-redis,代码行数:32,代码来源:OauthTokenController.java

示例14: validateSelf

import org.apache.oltu.oauth2.common.message.OAuthResponse; //导入依赖的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;
}
 
开发者ID:monkeyk,项目名称:oauth2-shiro-redis,代码行数:25,代码来源:CodeClientDetailsValidator.java

示例15: validateSelf

import org.apache.oltu.oauth2.common.message.OAuthResponse; //导入依赖的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;
}
 
开发者ID:monkeyk,项目名称:oauth2-shiro-redis,代码行数:26,代码来源:ClientCredentialsClientDetailsValidator.java


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