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


Java OAuthASResponse类代码示例

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


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

示例1: __parseResponseType

import org.apache.oltu.oauth2.as.response.OAuthASResponse; //导入依赖的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

示例2: authorize

import org.apache.oltu.oauth2.as.response.OAuthASResponse; //导入依赖的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

示例3: createTokenResponse

import org.apache.oltu.oauth2.as.response.OAuthASResponse; //导入依赖的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

示例4: responseApprovalDeny

import org.apache.oltu.oauth2.as.response.OAuthASResponse; //导入依赖的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

示例5: authorize

import org.apache.oltu.oauth2.as.response.OAuthASResponse; //导入依赖的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

示例6: createTokenResponse

import org.apache.oltu.oauth2.as.response.OAuthASResponse; //导入依赖的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 clientDetails = clientDetails();

    final OAuthASResponse.OAuthTokenResponseBuilder builder = OAuthASResponse
            .tokenResponse(HttpServletResponse.SC_OK)
            .location(clientDetails.redirectUri())
            .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-redis,代码行数:26,代码来源:OAuthHandler.java

示例7: responseApprovalDeny

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

示例8: authorize

import org.apache.oltu.oauth2.as.response.OAuthASResponse; //导入依赖的package包/类
private String authorize(HttpServletRequest request, String redirectURI, Authentication authentication) throws OAuthSystemException {
    User principal = (User) authentication.getPrincipal();
    if (hasAuthorized(principal)) {
        // 生成code
        String code = new OAuthIssuerImpl(new MD5Generator()).authorizationCode();

        // 把授权码存入
        oAuth2Service.addCode(code, principal.getOpenId());

        // 构建oauth2授权返回信息
        OAuthResponse oauthResponse = OAuthASResponse
                .authorizationResponse(request, HttpServletResponse.SC_FOUND)
                .setCode(code)
                .location(redirectURI)
                .buildQueryMessage();
        return "redirect:" + oauthResponse.getLocationUri();
    } else {
        return "oauth2/authorize";
    }
}
 
开发者ID:microacup,项目名称:microbbs,代码行数:21,代码来源:OAuth2Server.java

示例9: handleError

import org.apache.oltu.oauth2.as.response.OAuthASResponse; //导入依赖的package包/类
/**
 * Build the error message response properly
 *
 * @param e
 * @return
 * @throws OAuthSystemException
 */
private Response handleError(UserInfoEndpointException e) throws OAuthSystemException {
    log.debug(e);
    OAuthResponse res = null;
    try {
        res =
                OAuthASResponse.errorResponse(HttpServletResponse.SC_BAD_REQUEST)
                        .setError(e.getErrorCode()).setErrorDescription(e.getErrorMessage())
                        .buildJSONMessage();
    } catch (OAuthSystemException e1) {
        log.error("Error while building the JSON message", e1);
        OAuthResponse response =
                OAuthASResponse.errorResponse(HttpServletResponse.SC_INTERNAL_SERVER_ERROR)
                        .setError(OAuth2ErrorCodes.SERVER_ERROR)
                        .setErrorDescription(e1.getMessage()).buildJSONMessage();
        return Response.status(response.getResponseStatus()).entity(response.getBody()).build();
    }
    return Response.status(res.getResponseStatus()).entity(res.getBody()).build();
}
 
开发者ID:wso2-attic,项目名称:carbon-identity,代码行数:26,代码来源:OpenIDConnectUserEndpoint.java

示例10: buildErrorResponse

import org.apache.oltu.oauth2.as.response.OAuthASResponse; //导入依赖的package包/类
private Response buildErrorResponse(OAuthProblemException e, OAuthAuthzRequest oAuthRequest, String redirectURI)
    throws OAuthSystemException, URISyntaxException {
  boolean canRedirect = !Strings.isNullOrEmpty(redirectURI);
  OAuthASResponse.OAuthErrorResponseBuilder builder = OAuthASResponse
      .errorResponse(canRedirect ? HttpServletResponse.SC_FOUND : HttpServletResponse.SC_BAD_REQUEST).error(e);
  setState(builder, oAuthRequest);
  OAuthResponse response;

  if(canRedirect) {
    builder.location(redirectURI);
    response = builder.buildQueryMessage();
    return Response.status(response.getResponseStatus()).location(new URI(response.getLocationUri())).build();
  } else {
    response = builder.buildJSONMessage();
    return Response.status(response.getResponseStatus()).entity(response.getBody()).build();
  }
}
 
开发者ID:obiba,项目名称:agate,代码行数:18,代码来源:OAuthResource.java

示例11: getAccessResponse

import org.apache.oltu.oauth2.as.response.OAuthASResponse; //导入依赖的package包/类
private Response getAccessResponse(@NotNull Ticket ticket, @Nullable Authorization authorization, String clientId) throws OAuthSystemException {
  String token = tokenUtils.makeAccessToken(ticket, clientId);
  long expiresIn = ticketService.getExpirationDate(ticket).getMillis() - DateTime.now().getMillis();

  OAuthASResponse.OAuthTokenResponseBuilder responseBuilder = OAuthASResponse.tokenResponse(HttpServletResponse.SC_OK) //
    .setAccessToken(token) //
    .setTokenType(OAuth.OAUTH_HEADER_NAME.toLowerCase()) // bug: OAUTH_BEARER_TOKEN has a wrong value
    .setExpiresIn(expiresIn / 1000 + "");

  if (authorization != null && authorization.hasScope(TokenUtils.OPENID_SCOPE)) {
    responseBuilder.setParam(TokenUtils.OPENID_TOKEN, tokenUtils.makeIDToken(authorization,
        getSupportedOpenIdScopes((s) -> authorization.hasScope(s))));
  }

  OAuthResponse response = responseBuilder.buildJSONMessage();
  return Response.status(response.getResponseStatus()).entity(response.getBody()).build();
}
 
开发者ID:obiba,项目名称:agate,代码行数:18,代码来源:OAuthResource.java

示例12: tokenToResponse

import org.apache.oltu.oauth2.as.response.OAuthASResponse; //导入依赖的package包/类
public static OAuthResponse tokenToResponse(OAuthSnsToken token, String state) throws OAuthSystemException {
    OAuthResponse.OAuthResponseBuilder _builder = OAuthASResponse.tokenResponse(HttpServletResponse.SC_OK)
            .setAccessToken(token.getAccessToken())
            .setExpiresIn(String.valueOf(OAuth.get().getModuleCfg().getAccessTokenExpireIn()))
            .setRefreshToken(token.getRefreshToken())
            .setScope(token.getScope())
            .setParam(IOAuth.Const.OPEN_ID, token.getOpenId());
    if (StringUtils.isNotBlank(state)) {
        _builder.setParam(org.apache.oltu.oauth2.common.OAuth.OAUTH_STATE, state);
    }
    return _builder.buildJSONMessage();
}
 
开发者ID:suninformation,项目名称:ymate-module-oauth,代码行数:13,代码来源:OAuthResponseUtils.java

示例13: auth

import org.apache.oltu.oauth2.as.response.OAuthASResponse; //导入依赖的package包/类
/**
 * @return 验证访问凭证是否有效
 * @throws Exception 可能产生的任何异常
 */
@RequestMapping("/auth")
@Before(SnsAccessTokenCheckInterceptor.class)
public IView auth() throws Exception {
    OAuthResponse _response = OAuthASResponse.errorResponse(HttpServletResponse.SC_OK).setError("ok").buildJSONMessage();
    return new HttpStatusView(_response.getResponseStatus(), false).writeBody(_response.getBody());
}
 
开发者ID:suninformation,项目名称:ymate-module-oauth,代码行数:11,代码来源:OAuthSnsController.java

示例14: authorize

import org.apache.oltu.oauth2.as.response.OAuthASResponse; //导入依赖的package包/类
/**
 * Must handle the grant_type as follow:
 * grant_type="authorization_code" -> response_type="code"
 * ?response_type=code&scope=read,write&client_id=[client_id]&redirect_uri=[redirect_uri]&state=[state]
 * <p/>
 * grant_type="implicit"   -> response_type="token"
 * ?response_type=token&scope=read,write&client_id=[client_id]&client_secret=[client_secret]&redirect_uri=[redirect_uri]
 * <p/>
 *
 * @param request  HttpServletRequest
 * @param response HttpServletResponse
 */
@RequestMapping("authorize")
public void authorize(HttpServletRequest request, HttpServletResponse response) throws OAuthSystemException, ServletException, IOException {

    try {
        OAuthAuthxRequest oauthRequest = new OAuthAuthxRequest(request);


        if (oauthRequest.isCode()) {
            CodeAuthorizeHandler codeAuthorizeHandler = new CodeAuthorizeHandler(oauthRequest, response);
            LOG.debug("Go to  response_type = 'code' handler: {}", codeAuthorizeHandler);
            codeAuthorizeHandler.handle();

        } else if (oauthRequest.isToken()) {
            TokenAuthorizeHandler tokenAuthorizeHandler = new TokenAuthorizeHandler(oauthRequest, response);
            LOG.debug("Go to response_type = 'token' handler: {}", tokenAuthorizeHandler);
            tokenAuthorizeHandler.handle();

        } else {
            unsupportResponseType(oauthRequest, response);
        }

    } 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,代码行数:45,代码来源:OauthAuthorizeController.java

示例15: handleUnauthorizedException

import org.apache.oltu.oauth2.as.response.OAuthASResponse; //导入依赖的package包/类
private void handleUnauthorizedException(HttpServletResponse response, Exception ex) {
    OAuthResponse oAuthResponse;
    try {
        oAuthResponse = OAuthASResponse.errorResponse(403)
                .setError(OAuthError.ResourceResponse.INVALID_TOKEN)
                .setErrorDescription(ex.getMessage())
                .buildJSONMessage();
    } catch (OAuthSystemException e) {
        throw new IllegalStateException(e);
    }

    WebUtils.writeOAuthJsonResponse(response, oAuthResponse);
}
 
开发者ID:monkeyk,项目名称:oauth2-shiro,代码行数:14,代码来源:OAuthShiroHandlerExceptionResolver.java


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