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


Java OAuthTokenRequest类代码示例

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


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

示例1: accessAuthorizationCodeGrant

import org.apache.oltu.oauth2.as.request.OAuthTokenRequest; //导入依赖的package包/类
private Response accessAuthorizationCodeGrant(HttpServletRequest servletRequest, OAuthTokenRequest oAuthRequest)
  throws OAuthSystemException, OAuthProblemException {
  validateClient(oAuthRequest);

  String clientId = oAuthRequest.getClientId();
  String redirectURI = oAuthRequest.getParam(OAuth.OAUTH_REDIRECT_URI);
  Authorization authorization = authorizationService.getByCode(oAuthRequest.getParam(OAuth.OAUTH_CODE));
  // verify authorization
  if(!authorization.getApplication().equals(clientId)) {
    throw OAuthProblemException
      .error("invalid_client_id", "The client ID does not match the one of the authorization");
  }
  if(!authorization.getRedirectURI().equals(redirectURI)) {
    throw OAuthProblemException
      .error("invalid_redirect_uri", "The redirect URI does not match the one of the authorization");
  }
  User user = userService.findActiveUser(authorization.getUsername());
  if(user == null) {
    throw OAuthProblemException.error("inactive_user", "The user of the authorization is not active");
  }

  Ticket ticket = ticketService.create(authorization);
  return getAccessResponse(ticket, authorization, clientId);
}
 
开发者ID:obiba,项目名称:agate,代码行数:25,代码来源:OAuthResource.java

示例2: accessPasswordGrant

import org.apache.oltu.oauth2.as.request.OAuthTokenRequest; //导入依赖的package包/类
private Response accessPasswordGrant(HttpServletRequest servletRequest, OAuthTokenRequest oAuthRequest)
  throws OAuthSystemException, OAuthProblemException {
  validateClient(oAuthRequest);

  String clientId = oAuthRequest.getClientId();
  String username = oAuthRequest.getUsername();
  String password = oAuthRequest.getPassword();
  User user = userService.findActiveUser(username);
  if(user == null) user = userService.findActiveUserByEmail(username);

  authorizationValidator.validateUser(servletRequest, username, user);
  authorizationValidator.validateApplication(servletRequest, user, clientId);

  // check authentication
  Subject subject = SecurityUtils.getSubject();
  assert user != null;
  subject.login(new UsernamePasswordToken(user.getName(), password));
  authorizationValidator.validateRealm(servletRequest, user, subject);
  subject.logout();

  Ticket ticket = ticketService.create(user.getName(), false, false, clientId);
  return getAccessResponse(ticket, null, clientId);
}
 
开发者ID:obiba,项目名称:agate,代码行数:24,代码来源:OAuthResource.java

示例3: preHandle

import org.apache.oltu.oauth2.as.request.OAuthTokenRequest; //导入依赖的package包/类
@Override
protected boolean preHandle(ServletRequest request, ServletResponse response) throws Exception {
  HttpServletRequest httpRequest = (HttpServletRequest) request;
  HttpServletResponse httpResponse = (HttpServletResponse) response;
  I18N i18n = new I18N(request.getLocale());
  try {
    OAuthTokenRequest oAuthRequest = new OAuthTokenRequest(httpRequest);
    String clientId = oAuthRequest.getClientId();
    // Check client id
    if (!oAuthService.checkClient(clientId))
      return ResponseUtils.processResponse(httpResponse, null,
          ResponseUtils.responseInvalidClient(i18n.getString("INVALID_CLIENT_ID")));
    // Check client secret
    if (!oAuthService.checkClient(clientId, oAuthRequest.getClientSecret()))
      return ResponseUtils.processResponse(httpResponse, null,
          ResponseUtils.responseUnauthClient(i18n.getString("INVALID_CLIENT_SECRET")));
    // Check grant data according to grant type
    String grantType = oAuthRequest.getGrantType();
    String authCode = oAuthRequest.getCode();
    String refreshToken = oAuthRequest.getRefreshToken();
    if (GrantType.AUTHORIZATION_CODE.toString().equals(grantType)) {
      if (!oAuthService.checkAuthCode(authCode, clientId))
        return ResponseUtils.processResponse(httpResponse, null,
            ResponseUtils.responseInvalidGrant(i18n.getString("INVALID_AUTH_CODE")));
    } else if (oAuthService.refreshTokenSupported()
        && GrantType.REFRESH_TOKEN.toString().equals(grantType)) {
      if (!oAuthService.checkRefreshToken(refreshToken, clientId))
        return ResponseUtils.processResponse(httpResponse, null,
            ResponseUtils.responseInvalidGrant(i18n.getString("INVALID_REFRESH_CODE")));
    } else {
      return ResponseUtils.processResponse(httpResponse, null,
          ResponseUtils.responseUnsuppGrant(i18n.getString("UNSUPPORT_GRANT_TYPE")));
    }
    // generate access token
    OAuthIssuerImpl oAuthIssuer = new OAuthIssuerImpl(new MD5Generator());
    String accessToken = oAuthIssuer.accessToken();
    if (GrantType.AUTHORIZATION_CODE.toString().equals(grantType))
      oAuthService.addAcessToken(accessToken, authCode);
    else
      oAuthService.refreshAccessToken(accessToken, refreshToken);
    // generate refresh token
    refreshToken = null;
    if (oAuthService.refreshTokenSupported()) {
      refreshToken = oAuthIssuer.refreshToken();
      oAuthService.addRefreshToken(refreshToken, accessToken);
    }
    // generate page content
    String expireIn = String.valueOf(oAuthService.getExpireIn(accessToken));
    return ResponseUtils.processResponse(httpResponse, null,
        OAuthASResponse.tokenResponse(HttpServletResponse.SC_OK).setExpiresIn(expireIn)
            .setAccessToken(accessToken).setRefreshToken(refreshToken));
  } catch (OAuthProblemException ex) {
    if (OAuthUtils.isEmpty(ex.getError()))
      return ResponseUtils.processResponse(httpResponse, null,
          ResponseUtils.responseInvalidRequest(ex.getDescription()));
    return ResponseUtils.processResponse(httpResponse, null,
        ResponseUtils.responseBadRequest(ex));
  }
}
 
开发者ID:hawkxu,项目名称:shiro-oltu,代码行数:60,代码来源:TokenFilter.java

示例4: token

import org.apache.oltu.oauth2.as.request.OAuthTokenRequest; //导入依赖的package包/类
@RequestMapping("/accessToken")
public HttpEntity<String> token(HttpServletRequest request) throws URISyntaxException, OAuthSystemException {

    try {
        // 构建OAuth请求
        OAuthTokenRequest oauthRequest = new OAuthTokenRequest(request);

        // 检查提交的客户端id是否正确
        if (!oAuthService.checkClientId(oauthRequest.getClientId())) {
            return buildInvalidClientIdResponse();

        }

        // 检查客户端安全KEY是否正确
        if (!oAuthService.checkClientSecret(oauthRequest.getClientSecret())) {
            return buildInvalidClientSecretResponse();
        }

        String authCode = oauthRequest.getParam(OAuth.OAUTH_CODE);
        // 检查验证类型,此处只检查AUTHORIZATION_CODE类型,其他的还有PASSWORD或REFRESH_TOKEN
        if (oauthRequest.getParam(OAuth.OAUTH_GRANT_TYPE).equals(GrantType.AUTHORIZATION_CODE.toString())) {
            if (!oAuthService.checkAuthCode(authCode)) {
                return buildBadAuthCodeResponse();
            }
            // TODO 后两种未测试
        } else if (oauthRequest.getParam(OAuth.OAUTH_GRANT_TYPE).equals(GrantType.PASSWORD.toString())) {
            if (!checkUserPassword(oauthRequest.getUsername(), oauthRequest.getPassword())) {
                return buildInvalidUserPassResponse();
            }
        } else if (oauthRequest.getParam(OAuth.OAUTH_GRANT_TYPE).equals(GrantType.REFRESH_TOKEN.toString())) {
            // https://github.com/zhouyongtao/homeinns-web
            if (!oAuthService.checkAuthCode(authCode)) {
                return buildInvalidRefreshTokenResponse();
            }
        }

        // 生成Access Token
        OAuthIssuer oauthIssuerImpl = new OAuthIssuerImpl(new MD5Generator());
        final String accessToken = oauthIssuerImpl.accessToken();
        oAuthService.addAccessToken(accessToken, oAuthService.getUsernameByAuthCode(authCode));
        final String refreshToken = oauthIssuerImpl.refreshToken();
        oAuthService.addAccessToken(refreshToken, oAuthService.getUsernameByAuthCode(authCode));

        // 生成OAuth响应
        OAuthResponse response = OAuthASResponse.tokenResponse(HttpServletResponse.SC_OK)
                .setAccessToken(accessToken).setExpiresIn(String.valueOf(oAuthService.getExpireIn()))
                .setTokenType(TokenType.BEARER.toString()).setRefreshToken(refreshToken).buildJSONMessage();

        // 根据OAuthResponse生成ResponseEntity
        return new ResponseEntity<String>(response.getBody(), HttpStatus.valueOf(response.getResponseStatus()));

    } catch (OAuthProblemException e) {
        // 构建错误响应
        OAuthResponse res = OAuthASResponse.errorResponse(HttpServletResponse.SC_BAD_REQUEST).error(e)
                .buildJSONMessage();
        return new ResponseEntity<String>(res.getBody(), HttpStatus.valueOf(res.getResponseStatus()));
    }
}
 
开发者ID:howiefh,项目名称:jee-restful-web,代码行数:59,代码来源:AccessTokenController.java

示例5: validateClient

import org.apache.oltu.oauth2.as.request.OAuthTokenRequest; //导入依赖的package包/类
private void validateClient(OAuthTokenRequest oauthRequest) {
}
 
开发者ID:opensourceBIM,项目名称:BIMserver,代码行数:3,代码来源:OAuthAccessTokenServlet.java

示例6: validateClient

import org.apache.oltu.oauth2.as.request.OAuthTokenRequest; //导入依赖的package包/类
/**
 * Verify {@link Application}'s secret key.
 *
 * @param oAuthRequest
 */
private void validateClient(OAuthTokenRequest oAuthRequest) {
  authorizationValidator.validateApplicationParameters(oAuthRequest.getClientId(), oAuthRequest.getClientSecret());
}
 
开发者ID:obiba,项目名称:agate,代码行数:9,代码来源:OAuthResource.java


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