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


Java OAuthIssuer类代码示例

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


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

示例1: buildAuthenticatedUserResponse

import org.apache.oltu.oauth2.as.issuer.OAuthIssuer; //导入依赖的package包/类
private Response buildAuthenticatedUserResponse(UserVO userVO) throws OAuthSystemException {
    OAuthIssuer oauthIssuerImpl = new OAuthIssuerImpl(new MD5Generator());

    OAuthResponse response = OAuthASResponse
            .tokenResponse(HttpServletResponse.SC_OK)
            .setAccessToken(oauthIssuerImpl.accessToken())
            .setExpiresIn("3600")
            .buildJSONMessage();
    return Response.status(response.getResponseStatus()).entity(response.getBody()).build();
}
 
开发者ID:SECQME,项目名称:watchoverme-server,代码行数:11,代码来源:OAuthResource.java

示例2: OAuth2Tokens

import org.apache.oltu.oauth2.as.issuer.OAuthIssuer; //导入依赖的package包/类
/**
 * Generate Constructor
 * @return new OAuth2Tokens Object with newly generated tokens
 * @throws Exception
 */
public OAuth2Tokens () throws Exception {

  OAuthIssuer oauthIssuerImpl = new OAuthIssuerImpl(new MD5Generator() );
  
  this.authorizationCode = oauthIssuerImpl.authorizationCode();
  this.accessToken = oauthIssuerImpl.accessToken();
  this.refreshToken = oauthIssuerImpl.refreshToken();
}
 
开发者ID:vangav,项目名称:vos_backend,代码行数:14,代码来源:OAuth2Tokens.java

示例3: authorize

import org.apache.oltu.oauth2.as.issuer.OAuthIssuer; //导入依赖的package包/类
@POST
@Path("/authz")
@RequiresRoles("agate-user")
public Response authorize(@Context HttpServletRequest servletRequest, @FormParam("grant") boolean grant)
  throws URISyntaxException, OAuthSystemException {
  return tryBuildResponse(servletRequest, (data) -> {
    try {
      if(!grant) {
        return buildErrorResponse(OAuthProblemException.error("access_denied", "Owner denied authorization."), data.getRequest(), data.getRedirectUri());
      }

      OAuthIssuer oAuthIssuer = new OAuthIssuerImpl(new MD5Generator());
      User user = userService.getCurrentUser();
      Authorization authorization = authorizationService.find(user.getName(), data.getClientId());

      if(authorization == null) {
        authorization = new Authorization(user.getName(), data.getClientId());
      }

      authorization.setCode(oAuthIssuer.authorizationCode());
      authorization.setScopes(data.getRequest().getScopes());
      authorization.setRedirectURI(data.getRedirectUri());
      authorizationService.save(authorization);

      long expiresIn = authorizationService.getExpirationDate(authorization).getMillis() - DateTime.now().getMillis();
      OAuthASResponse.OAuthAuthorizationResponseBuilder builder = OAuthASResponse
          .authorizationResponse(servletRequest, HttpServletResponse.SC_FOUND) //
          .setCode(authorization.getCode()) //
          .setExpiresIn(expiresIn / 1000) //
          .location(data.getRedirectUri());

      setState(builder, data.getRequest());
      OAuthResponse response = builder.buildQueryMessage();
      return Response.status(response.getResponseStatus()).location(new URI(response.getLocationUri())).build();
    } catch(URISyntaxException | OAuthSystemException e) {
      throw Throwables.propagate(e);
    }
  });
}
 
开发者ID:obiba,项目名称:agate,代码行数:40,代码来源:OAuthResource.java

示例4: token

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


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