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


Java OAuth类代码示例

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


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

示例1: writeOAuthJsonResponse

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

示例2: createToken

import org.apache.oltu.oauth2.common.OAuth; //导入依赖的package包/类
@Override
protected AuthenticationToken createToken(ServletRequest request, ServletResponse response) throws Exception {

    HttpServletRequest httpRequest = (HttpServletRequest) request;

    final String accessToken = getAccessToken(httpRequest);
    final AccessToken token = rsService.loadAccessTokenByTokenId(accessToken);

    String username = null;
    if (token != null) {
        LOGGER.debug("Set username and clientId from AccessToken: {}", token);
        username = token.username();
        httpRequest.setAttribute(OAuth.OAUTH_CLIENT_ID, token.clientId());
    } else {
        LOGGER.debug("Not found AccessToken by access_token: {}", accessToken);
    }

    return new OAuth2Token(accessToken, resourceId)
            .setUserId(username);
}
 
开发者ID:monkeyk,项目名称:oauth2-shiro,代码行数:21,代码来源:OAuth2Filter.java

示例3: createToken

import org.apache.oltu.oauth2.common.OAuth; //导入依赖的package包/类
@Override
protected AuthenticationToken createToken(ServletRequest request, ServletResponse response) throws Exception {

    HttpServletRequest httpRequest = (HttpServletRequest) request;

    final String accessToken = httpRequest.getParameter(OAuth.OAUTH_ACCESS_TOKEN);
    final AccessToken token = rsService.loadAccessTokenByTokenId(accessToken);

    String username = null;
    if (token != null) {
        username = token.username();
        logger.debug("Set username[{}] and clientId[{}] to request that from AccessToken: {}", username, token.clientId(), token);
        httpRequest.setAttribute(OAuth.OAUTH_CLIENT_ID, token.clientId());
    } else {
        logger.debug("Not found AccessToken by access_token: {}", accessToken);
    }

    return new OAuth2Token(accessToken, resourceId)
            .setUserId(username);
}
 
开发者ID:monkeyk,项目名称:oauth2-shiro-redis,代码行数:21,代码来源:OAuth2Filter.java

示例4: getPrincipals

import org.apache.oltu.oauth2.common.OAuth; //导入依赖的package包/类
@Override
public List<Principal> getPrincipals(String requestId) throws WebApiClientException {
    List<Principal> result = null;
    try {
        OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());
        String pathWithParams = getPathWithParams("/service/hpa/api/delegate/" + getOauthSessionId(), requestId);

        OAuthClientRequest bearerClientRequest = new OAuthBearerClientRequest(new URL(config.getBaseUrl(), pathWithParams).toString()).setAccessToken(accessToken).buildQueryMessage();
        bearerClientRequest.setHeader("X-AsiointivaltuudetAuthorization", getAuthorizationValue(bearerClientRequest.getLocationUri().substring(config.getBaseUrl().toString().length())));

        OAuthResourceResponse resourceResponse = oAuthClient.resource(bearerClientRequest, OAuth.HttpMethod.GET, OAuthResourceResponse.class);

        JavaType resultType = mapper.getTypeFactory().constructParametricType(ArrayList.class, Principal.class);
        return mapper.readValue(resourceResponse.getBody(), resultType);
    } catch (IOException | OAuthSystemException | OAuthProblemException e) {
        handleException(e);
    }
    return result;
}
 
开发者ID:vrk-kpa,项目名称:roles-auths-client,代码行数:20,代码来源:AbstractHpaWebApiRiClient.java

示例5: getAuthorization

import org.apache.oltu.oauth2.common.OAuth; //导入依赖的package包/类
@Override
public Authorization getAuthorization(String principalId, String requestId, String... issues)
        throws WebApiClientException {
    Authorization result = null;
    try {
        OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());
        String pathWithParams = getPathWithParams("/service/hpa/api/authorization/" + getOauthSessionId() + "/" + principalId, requestId, issues);

        OAuthClientRequest bearerClientRequest = new OAuthBearerClientRequest(new URL(config.getBaseUrl(), pathWithParams).toString()).setAccessToken(accessToken).buildQueryMessage();
        bearerClientRequest.setHeader("X-AsiointivaltuudetAuthorization", getAuthorizationValue(bearerClientRequest.getLocationUri().substring(config.getBaseUrl().toString().length())));

        OAuthResourceResponse resourceResponse = oAuthClient.resource(bearerClientRequest, OAuth.HttpMethod.GET, OAuthResourceResponse.class);

        result = mapper.readValue(resourceResponse.getBody(), Authorization.class);
    } catch (IOException | OAuthProblemException | OAuthSystemException e) {
        handleException(e);
    }
    return result;
}
 
开发者ID:vrk-kpa,项目名称:roles-auths-client,代码行数:20,代码来源:HpaWebApiRiClient.java

示例6: getAuthorizationList

import org.apache.oltu.oauth2.common.OAuth; //导入依赖的package包/类
@Override
public AuthorizationList getAuthorizationList(String principalId, String requestId)
        throws WebApiClientException {
    AuthorizationList result = null;
    try {
        OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());
        String pathWithParams = getPathWithParams("/service/hpa/api/authorizationlist/" + getOauthSessionId() + "/" + principalId, requestId);

        OAuthClientRequest bearerClientRequest = new OAuthBearerClientRequest(new URL(config.getBaseUrl(), pathWithParams).toString()).setAccessToken(accessToken).buildQueryMessage();
        bearerClientRequest.setHeader("X-AsiointivaltuudetAuthorization", getAuthorizationValue(bearerClientRequest.getLocationUri().substring(config.getBaseUrl().toString().length())));

        OAuthResourceResponse resourceResponse = oAuthClient.resource(bearerClientRequest, OAuth.HttpMethod.GET, OAuthResourceResponse.class);

        result = mapper.readValue(resourceResponse.getBody(), AuthorizationList.class);
    } catch (IOException | OAuthProblemException | OAuthSystemException e) {
        handleException(e);
    }
    return result;
}
 
开发者ID:vrk-kpa,项目名称:roles-auths-client,代码行数:20,代码来源:HpaWebApiRiClient.java

示例7: getAuthorizationToken

import org.apache.oltu.oauth2.common.OAuth; //导入依赖的package包/类
@Override
public String getAuthorizationToken(String principalId, String requestId, String... issues) throws WebApiClientException {
    try {
        OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());
        String pathWithParams = getPathWithParams("/service/hpa/api/authorization/jwt/" + getOauthSessionId() + "/" + principalId, requestId, issues);

        OAuthClientRequest bearerClientRequest = new OAuthBearerClientRequest(new URL(config.getBaseUrl(), pathWithParams).toString()).setAccessToken(accessToken).buildQueryMessage();
        bearerClientRequest.setHeader("X-AsiointivaltuudetAuthorization", getAuthorizationValue(bearerClientRequest.getLocationUri().substring(config.getBaseUrl().toString().length())));

        OAuthResourceResponse resourceResponse = oAuthClient.resource(bearerClientRequest, OAuth.HttpMethod.GET, OAuthResourceResponse.class);
        return resourceResponse.getBody();
    } catch (IOException | OAuthProblemException | OAuthSystemException e) {
        handleException(e);
    }
    handleException(new WebApiClientException("Could not get Authorization token"));
    // should not get here
    return null;
}
 
开发者ID:vrk-kpa,项目名称:roles-auths-client,代码行数:19,代码来源:HpaWebApiJwtRiClient.java

示例8: getAuthorizationListToken

import org.apache.oltu.oauth2.common.OAuth; //导入依赖的package包/类
@Override
public String getAuthorizationListToken(String principalId, String requestId) throws WebApiClientException {
    try {
        OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());
        String pathWithParams = getPathWithParams("/service/hpa/api/authorizationlist/jwt/" + getOauthSessionId() + "/" + principalId, requestId);

        OAuthClientRequest bearerClientRequest = new OAuthBearerClientRequest(new URL(config.getBaseUrl(), pathWithParams).toString()).setAccessToken(accessToken).buildQueryMessage();
        bearerClientRequest.setHeader("X-AsiointivaltuudetAuthorization", getAuthorizationValue(bearerClientRequest.getLocationUri().substring(config.getBaseUrl().toString().length())));

        OAuthResourceResponse resourceResponse = oAuthClient.resource(bearerClientRequest, OAuth.HttpMethod.GET, OAuthResourceResponse.class);

        return resourceResponse.getBody();
    } catch (IOException | OAuthProblemException | OAuthSystemException e) {
        handleException(e);
    }
    handleException(new WebApiClientException("Could not get AuthorizationList token"));
    // should not get here
    return null;
}
 
开发者ID:vrk-kpa,项目名称:roles-auths-client,代码行数:20,代码来源:HpaWebApiJwtRiClient.java

示例9: getRolesResponse

import org.apache.oltu.oauth2.common.OAuth; //导入依赖的package包/类
public List<YpaOrganization> getRolesResponse(String pathWithParams) throws WebApiClientException {
    List<YpaOrganization> result = null;
    OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());
    try {
        OAuthClientRequest bearerClientRequest = new OAuthBearerClientRequest(new URL(config.getBaseUrl(), pathWithParams).toString()).setAccessToken(accessToken).buildQueryMessage();
        bearerClientRequest.setHeader("X-AsiointivaltuudetAuthorization", getAuthorizationValue(bearerClientRequest.getLocationUri().substring(config.getBaseUrl().toString().length())));

        OAuthResourceResponse resourceResponse = oAuthClient.resource(bearerClientRequest, OAuth.HttpMethod.GET, OAuthResourceResponse.class);

        JavaType resultType = mapper.getTypeFactory().constructParametricType(ArrayList.class, YpaOrganization.class);
        result = mapper.readValue(resourceResponse.getBody(), resultType);
    } catch (IOException | OAuthProblemException | OAuthSystemException e) {
        handleException(e);
    }
    return result;
}
 
开发者ID:vrk-kpa,项目名称:roles-auths-client,代码行数:17,代码来源:YpaWebApiRiClient.java

示例10: oAuthFaileResponse

import org.apache.oltu.oauth2.common.OAuth; //导入依赖的package包/类
/**
 * oAuth认证失败时的输出
 * @param res
 * @throws OAuthSystemException
 * @throws IOException
 */
private void oAuthFaileResponse(HttpServletResponse res) throws OAuthSystemException, IOException {
    OAuthResponse oauthResponse = OAuthRSResponse
            .errorResponse(HttpServletResponse.SC_UNAUTHORIZED)
            .setRealm(Constants.RESOURCE_SERVER_NAME)
            .setError(OAuthError.ResourceResponse.INVALID_TOKEN)
            .buildHeaderMessage();
    HttpHeaders responseHeaders = new HttpHeaders();
    responseHeaders.add("Content-Type", "application/json; charset=utf-8");
    Gson gson = new GsonBuilder().create();
    res.addHeader(OAuth.HeaderType.WWW_AUTHENTICATE, oauthResponse.getHeader(OAuth.HeaderType.WWW_AUTHENTICATE));
    PrintWriter writer = res.getWriter();
    writer.write(gson.toJson(getStatus(HttpStatus.UNAUTHORIZED.value(),Constants.INVALID_ACCESS_TOKEN)));
    writer.flush();
    writer.close();
}
 
开发者ID:xiaomin0322,项目名称:oauth_demo,代码行数:22,代码来源:Oauth2Filter.java

示例11: onAccessDenied

import org.apache.oltu.oauth2.common.OAuth; //导入依赖的package包/类
@Override
protected boolean onAccessDenied(ServletRequest request, ServletResponse response)
    throws Exception {
  String error = request.getParameter(OAuthError.OAUTH_ERROR);
  String description = request.getParameter(OAuthError.OAUTH_ERROR_DESCRIPTION);
  if (!OAuthUtils.isEmpty(error))
    return processAuthorizationError(request, response, error, description);
  if (!OAuthUtils.isEmpty(state) && !state.equals(request.getParameter(OAuth.OAUTH_STATE)))
    return processAuthorizationError(request, response, OAuthError.CodeResponse.SERVER_ERROR,
        "server response state inconsistent with sent state");
  Subject subject = getSubject(request, response);
  if (!subject.isAuthenticated()) {
    if (OAuthUtils.isEmpty(request.getParameter(OAuth.OAUTH_CODE))) {
      saveRequestAndRedirectToLogin(request, response);
      return false;
    }
  }
  return executeLogin(request, response);
}
 
开发者ID:hawkxu,项目名称:shiro-oltu,代码行数:20,代码来源:OAuthAuthenticationFilter.java

示例12: buildAuthenticationInfo

import org.apache.oltu.oauth2.common.OAuth; //导入依赖的package包/类
/**
 * create authentication info, by default, this create
 * SimpleAuthenticationInfo with principals using access token as primary
 * principal and a map contains attributes {@link OAuth#OAUTH_ACCESS_TOKEN}
 * and {@link OAuth#OAUTH_EXPIRES_IN} and {@link OAuth#OAUTH_REFRESH_TOKEN}
 * and {@link OAuthConstants#OAUTH_TOKEN_TIME} and
 * {@link OAuthConstants#OAUTH_SCOPES}, the credentials set to byte array of
 * access token. if sub-class override requestAttributes and returned
 * attributes contains key {@link OAuthConstants#OAUTH_PRINCIPAL}, then the
 * value will be used as primary principal.
 * 
 * @param clientToken
 *          the client token
 * @param oAuthResponse
 *          OAuth access token response
 * @return authentication info
 */
protected AuthenticationInfo buildAuthenticationInfo(OAuthClientToken clientToken,
    OAuthAccessTokenResponse oAuthResponse) {
  String accessToken = oAuthResponse.getAccessToken();
  Date tokenTime = new Date();
  Map<String, Object> attributes = requestAttributes(oAuthResponse);
  if (attributes == null)
    attributes = new HashMap<String, Object>();
  else
    attributes = new HashMap<String, Object>(attributes);
  List<Object> principals = new ArrayList<Object>();
  if (attributes.containsKey(OAuthConstants.OAUTH_PRINCIPAL))
    principals.add(attributes.get(OAuthConstants.OAUTH_PRINCIPAL));
  else
    principals.add(accessToken);
  attributes.put(OAuth.OAUTH_ACCESS_TOKEN, accessToken);
  attributes.put(OAuth.OAUTH_EXPIRES_IN, oAuthResponse.getExpiresIn());
  attributes.put(OAuth.OAUTH_REFRESH_TOKEN, oAuthResponse.getRefreshToken());
  attributes.put(OAuthConstants.OAUTH_TOKEN_TIME, tokenTime);
  attributes.put(OAuthConstants.OAUTH_SCOPES, clientToken.getScopes());
  principals.add(attributes);
  PrincipalCollection collection = new SimplePrincipalCollection(principals, getName());
  return new SimpleAuthenticationInfo(collection, accessToken);
}
 
开发者ID:hawkxu,项目名称:shiro-oltu,代码行数:41,代码来源:OAuthAuthorizeRealm.java

示例13: login

import org.apache.oltu.oauth2.common.OAuth; //导入依赖的package包/类
@GetMapping("/login")
public String login(HttpServletRequest request) {
    try {
        OAuthClientRequest oauthResponse = OAuthClientRequest
                .authorizationLocation(authorize_url)
                .setResponseType(OAuth.OAUTH_CODE)
                .setClientId(clientId)
                .setRedirectURI(server + OAUTH_WEIBO_CALLBACK)
                .setState(STATE_LOGIN)
                .buildQueryMessage();
        WebUtils.setSessionAttribute(request, "state", STATE_LOGIN);
        return "redirect:"+oauthResponse.getLocationUri();
    } catch (OAuthSystemException e) {
        e.printStackTrace();
    }

    return "redirect:/500";
}
 
开发者ID:microacup,项目名称:microbbs,代码行数:19,代码来源:WeiboOAuthClient.java

示例14: login

import org.apache.oltu.oauth2.common.OAuth; //导入依赖的package包/类
@PostMapping("/login")
public String login(HttpServletRequest request) {
    String username = request.getParameter("username");
    String password = request.getParameter("password");
    String redirectURI = request.getParameter(OAuth.OAUTH_REDIRECT_URI);

    UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken(username, password);
    authRequest.setDetails(authenticationDetailsSource.buildDetails(request));
    try {
        Authentication authentication = authenticationManager.authenticate(authRequest);
        if (authentication != null && authentication.isAuthenticated()) {
            SecurityContextHolder.getContext().setAuthentication(authentication);
        }
    } catch (BadCredentialsException er) {
        // nothing here
    }

    StringBuilder sb = new StringBuilder();
    sb.append("/oauth2/authorize").append("?")
            .append(OAuth.OAUTH_CLIENT_ID).append("=").append(request.getParameter(OAuth.OAUTH_CLIENT_ID)).append("&")
            .append(OAuth.OAUTH_RESPONSE_TYPE).append("=").append(request.getParameter(OAuth.OAUTH_RESPONSE_TYPE)).append("&")
            .append(OAuth.OAUTH_SCOPE).append("=").append(request.getParameter(OAuth.OAUTH_SCOPE)).append("&")
            .append(OAuth.OAUTH_STATE).append("=").append(request.getParameter(OAuth.OAUTH_STATE)).append("&")
            .append(OAuth.OAUTH_REDIRECT_URI).append("=").append(request.getParameter(OAuth.OAUTH_REDIRECT_URI));
    return "redirect:" + sb.toString();
}
 
开发者ID:microacup,项目名称:microbbs,代码行数:27,代码来源:OAuth2Server.java

示例15: send

import org.apache.oltu.oauth2.common.OAuth; //导入依赖的package包/类
public void send(Activity activity, String jSONBody) throws OAuthSystemException, OAuthProblemException {
    OAuthClientRequest bearerRequest = new OAuthBearerClientRequest(RUNKEEPER_API_URL + "/fitnessActivities")
            .setAccessToken(accessToken).buildQueryMessage();
    bearerRequest.setBody(jSONBody);
    bearerRequest.setHeader(OAuth.HeaderType.CONTENT_TYPE, NEW_ACTIVITY_CONTENT_TYPE);

    // Seems not to be needed although it's specified here: http://developer.runkeeper.com/healthgraph/example-api-calls
    //bearerRequest.setHeader("accept", "application/vnd.com.runkeeper.FitnessActivity+json");
    //bearerRequest.setHeader("Content-Length", "" + jSONBody.length());

    ConnectivityManager connMgr = (ConnectivityManager)
            activity.getSystemService(activity.getBaseContext().CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();

    if (networkInfo != null && networkInfo.isConnected()) {
        FetchContent fetcher =  new FetchContent(bearerRequest);
        fetcher.execute(MainActivity.AUTHORIZATION_URL);
    } else { }
}
 
开发者ID:flooose,项目名称:gpxkept,代码行数:20,代码来源:RunKeeperRequest.java


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