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


Java URLConnectionClient类代码示例

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


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

示例1: makeTokenRequestWithAuthCode

import org.apache.oltu.oauth2.client.URLConnectionClient; //导入依赖的package包/类
/**
    * 根据授权码获取accessToken
    * @param authCode
    * @return
    * @throws OAuthProblemException
    * @throws OAuthSystemException
    */
private static OAuthAccessTokenResponse makeTokenRequestWithAuthCode(String authCode) throws OAuthProblemException, OAuthSystemException {

       OAuthClientRequest request = OAuthClientRequest
               .tokenLocation(ClientParams.OAUTH_SERVER_TOKEN_URL)
               .setClientId(ClientParams.CLIENT_ID)
               .setClientSecret(ClientParams.CLIENT_SECRET)
               .setGrantType(GrantType.AUTHORIZATION_CODE)
               .setCode(authCode)
               .setRedirectURI(ClientParams.OAUTH_SERVER_REDIRECT_URI)
               .buildBodyMessage();

       OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());

       OAuthAccessTokenResponse oauthResponse = oAuthClient.accessToken(request);

       System.out.println("Access Token: " + oauthResponse.getAccessToken());
       System.out.println("Expires In: " + oauthResponse.getExpiresIn());

       getAuthedService(oauthResponse.getAccessToken());

       return oauthResponse;
   }
 
开发者ID:xiaomin0322,项目名称:oauth_demo,代码行数:30,代码来源:OauthClient.java

示例2: getPrincipals

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

示例3: getAuthorization

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

示例4: getAuthorizationList

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

示例5: getAuthorizationToken

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

示例6: getAuthorizationListToken

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

示例7: getRolesResponse

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

示例8: getToken

import org.apache.oltu.oauth2.client.URLConnectionClient; //导入依赖的package包/类
public void getToken(String codeParam, String stateParam) throws WebApiClientException {
    if (!stateParameter.equals(stateParam)) {
        clientActiveState = false;
        throw new WebApiClientException("Mismatching OAuth state parameter. Expected state=" + stateParameter);
    }

    OAuthJSONAccessTokenResponse oAuthResponse = null;
    try {
        OAuthClientRequest.TokenRequestBuilder requestBuilder = OAuthClientRequest.tokenLocation(config.getTokenUrl()).setGrantType(GrantType.AUTHORIZATION_CODE).setClientId(config.getClientId()).setClientSecret(config.getoAuthSecret()).setCode(codeParam);

        OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());
        oAuthResponse = oAuthClient.accessToken(requestBuilder.setRedirectURI(config.getoAuthRedirect()).buildBodyMessage(), OAuthJSONAccessTokenResponse.class);
    } catch (OAuthProblemException | OAuthSystemException e) {
        handleException("Unable to get token", e);
    }
    this.accessToken = oAuthResponse.getAccessToken();
}
 
开发者ID:vrk-kpa,项目名称:roles-auths-client,代码行数:18,代码来源:AbstractWebApiRiClient.java

示例9: refreshOauthToken

import org.apache.oltu.oauth2.client.URLConnectionClient; //导入依赖的package包/类
/**
 * Method to refresh oauth token.
 * 
 * @param refreshToken
 *            requires a refresh token.
 * 
 * @param apiKey
 *            requires valid api key.
 * 
 * @param secret
 *            requires a valid secret.
 * 
 * @return OAuthJSONAccessTokenResponse object.
 * 
 * @throws ClientException
 *             a client exception is thrown if any error occurs.
 */
public OAuthJSONAccessTokenResponse refreshOauthToken(String refreshToken, String apiKey, String secret)
		throws ClientException {
	String oauthTokenUrl = tOneService.constructOauthUrl(new StringBuilder(TOKEN));
	try {
		OAuthClientRequest request = OAuthClientRequest.tokenLocation(oauthTokenUrl)
				.setGrantType(GrantType.REFRESH_TOKEN).setClientId(apiKey).setClientSecret(secret)
				.setRefreshToken(refreshToken).buildQueryMessage();
		OAuthClient oauthClient = new OAuthClient(new URLConnectionClient());
		return oauthClient.accessToken(request, OAuthJSONAccessTokenResponse.class);
	} catch (OAuthSystemException oauthSystemException) {
		Utility.logStackTrace(oauthSystemException);
		throw new ClientException(UNABLE_TO_GET_O_AUTH_TOKEN + oauthSystemException.getMessage());
	} catch (OAuthProblemException oauthProblemException) {
		Utility.logStackTrace(oauthProblemException);
		throw new ClientException(UNABLE_TO_GET_O_AUTH_TOKEN + oauthProblemException.getMessage());
	}
}
 
开发者ID:MediaMath,项目名称:t1-java,代码行数:35,代码来源:TerminalOne.java

示例10: getMetaInfo

import org.apache.oltu.oauth2.client.URLConnectionClient; //导入依赖的package包/类
@Override
public Object getMetaInfo(OAuthToken token){
	try{
		OAuthClientRequest req = 
				new OAuthBearerClientRequest("https://www.googleapis.com/oauth2/v1/userinfo?alt=json")
        		   .setAccessToken(token.getAccessToken())
        		   .buildQueryMessage();
    	OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());
    	OAuthResourceResponse resourceResponse = oAuthClient.resource(req, 
    											OAuth.HttpMethod.GET, OAuthResourceResponse.class);
    	ObjectMapper mapper = new ObjectMapper();
    	return mapper.readTree((resourceResponse.getBody()));
	}catch(Exception e){
		throw new RuntimeException(e);
	}
}
 
开发者ID:ohmage,项目名称:lifestreams,代码行数:17,代码来源:GoogleProfileProvider.java

示例11: getRolesTokenResponse

import org.apache.oltu.oauth2.client.URLConnectionClient; //导入依赖的package包/类
public String getRolesTokenResponse(String pathWithParams) throws WebApiClientException {
    String 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);
        result = resourceResponse.getBody();
    } catch (IOException | OAuthProblemException | OAuthSystemException e) {
        handleException(e);
    }
    return result;
}
 
开发者ID:vrk-kpa,项目名称:roles-auths-client,代码行数:15,代码来源:YpaWebApiJwtRiClient.java

示例12: getAccessToken

import org.apache.oltu.oauth2.client.URLConnectionClient; //导入依赖的package包/类
@Override
public OAuthToken getAccessToken(String code, String callback) throws OAuthSystemException, OAuthProblemException{
	OAuthClientRequest request = OAuthClientRequest
               .tokenLocation(getAccessTokenEndpoint())
               .setGrantType(GrantType.AUTHORIZATION_CODE)
               .setClientId(getApiKey())
               .setClientSecret(getApiSecret())
               .setRedirectURI(callback)
               .setCode(code)
               .buildBodyMessage();

   	OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());
   	OAuthJSONAccessTokenResponse oAuthResponse = oAuthClient.accessToken(request);
       return oAuthResponse.getOAuthToken();
}
 
开发者ID:ohmage,项目名称:lifestreams,代码行数:16,代码来源:OAuth20Provider.java

示例13: OAuthConn

import org.apache.oltu.oauth2.client.URLConnectionClient; //导入依赖的package包/类
OAuthConn(ApiConfigFile apiConfig) throws OAuthSystemException, OAuthProblemException {
	this.key = apiConfig.key;
	this.secret = apiConfig.secret;
	this.apiRoot = apiConfig.apiRoot;
	this.authPath = "token";
	oAuthClient = new OAuthClient(new URLConnectionClient());
	
	initConn();
}
 
开发者ID:Georgetown-University-Libraries,项目名称:GUExtractSierraBibs,代码行数:10,代码来源:OAuthConn.java

示例14: login

import org.apache.oltu.oauth2.client.URLConnectionClient; //导入依赖的package包/类
@Authenticate
public static String login(String serverId, String code, String locales, String redirectBase)
{
  try
  {
    String redirect = redirectBase + "/session/ologin";
    
    OauthServer server = OauthServer.get(serverId);
    /*
     * Get the access token
     */
    TokenRequestBuilder tokenBuilder = OAuthClientRequest.tokenLocation(server.getTokenLocation());
    tokenBuilder.setGrantType(GrantType.AUTHORIZATION_CODE);
    tokenBuilder.setClientId(server.getClientId());
    tokenBuilder.setClientSecret(server.getSecretKey());
    tokenBuilder.setRedirectURI(redirect);
    tokenBuilder.setCode(code);
    
    OAuthClientRequest tokenRequest = tokenBuilder.buildQueryMessage();
    tokenRequest.setHeader("Accept", "application/json");
    
    oAuthClient = new OAuthClient(new URLConnectionClient());
    accessToken = oAuthClient.accessToken(tokenRequest);
    
    /*
     * Request the user information
     */
    JSONObject object = resourceRequest(server.getProfileLocation());

    SingleActorDAOIF profile = ExternalProfile.getOrCreate(server, object);

    return SessionFacade.logIn(profile, LocaleSerializer.deserialize(locales));
  }
  catch (JSONException | OAuthSystemException | OAuthProblemException e)
  {
    throw new InvalidLoginException(e);
  }
}
 
开发者ID:terraframe,项目名称:geoprism,代码行数:39,代码来源:ExternalProfile.java

示例15: execute

import org.apache.oltu.oauth2.client.URLConnectionClient; //导入依赖的package包/类
@Override
public Object execute(Req req) throws Exception {
	String code = req.param("code");
	String state = req.param("state");

	Log.debug("Received OAuth code", "code", code, "state", state);

	if (code != null && !U.isEmpty(state)) {

		String id = clientId.str().get();
		String secret = clientSecret.str().get();

		char statePrefix = state.charAt(0);
		U.must(statePrefix == 'P' || statePrefix == 'N', "Invalid OAuth state prefix!");
		state = state.substring(1);

		U.must(stateCheck.isValidState(state, secret, req.sessionId()), "Invalid OAuth state!");

		boolean popup = statePrefix == 'P';
		Log.debug("OAuth validated", "popup", popup);

		String domain = oauthDomain.getOrNull();
		String redirectUrl = U.notEmpty(domain) ? domain + callbackPath : HttpUtils.constructUrl(req, callbackPath);

		TokenRequestBuilder reqBuilder = OAuthClientRequest.tokenLocation(provider.getTokenEndpoint())
			.setGrantType(GrantType.AUTHORIZATION_CODE).setClientId(id).setClientSecret(secret)
			.setRedirectURI(redirectUrl).setCode(code);

		OAuthClientRequest request = paramsInBody() ? reqBuilder.buildBodyMessage() : reqBuilder.buildBodyMessage();

		OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());

		String accessToken = token(request, oAuthClient);

		String profileUrl = Msc.fillIn(provider.getProfileEndpoint(), "token", accessToken);

		OAuthClientRequest bearerClientRequest = new OAuthBearerClientRequest(profileUrl).setAccessToken(
			accessToken).buildQueryMessage();

		OAuthResourceResponse res = oAuthClient.resource(bearerClientRequest,
			org.apache.oltu.oauth2.common.OAuth.HttpMethod.GET, OAuthResourceResponse.class);

		U.must(res.getResponseCode() == 200, "OAuth response error!");

		Map<String, Object> auth = JSON.parseMap(res.getBody());

		String email = (String) U.or(auth.get("email"), auth.get("emailAddress"));
		String firstName = (String) U.or(auth.get("firstName"), U.or(auth.get("first_name"), auth.get("given_name")));
		String lastName = (String) U.or(auth.get("lastName"), U.or(auth.get("last_name"), auth.get("family_name")));
		String name = U.or((String) auth.get("name"), firstName + " " + lastName);

		String username = email;
		Set<String> roles = customization.rolesProvider().getRolesForUser(req, username);

		UserInfo user = new UserInfo(username, roles, null);
		user.name = name;
		user.email = email;
		user.oauthProvider = provider.getName();
		user.oauthId = String.valueOf(auth.get("id"));

		Ctxs.required().setUser(user);

		// user.saveTo(x.token()); // FIXME use token

		return req.response().redirect("/"); // FIXME use page stack
	} else {
		String error = req.param("error");
		if (error != null) {
			Log.warn("OAuth error", "error", error);
			throw U.rte("OAuth error!");
		}
	}

	throw U.rte("Invalid OAuth request!");
}
 
开发者ID:rapidoid,项目名称:rapidoid,代码行数:76,代码来源:OAuthTokenHandler.java


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