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


Java OAuthClient.resource方法代码示例

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


在下文中一共展示了OAuthClient.resource方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getPrincipals

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

示例2: getAuthorization

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

示例3: getAuthorizationList

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

示例4: getAuthorizationToken

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

示例5: getAuthorizationListToken

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

示例6: getRolesResponse

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

示例7: getMetaInfo

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

示例8: getRolesTokenResponse

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

示例9: execute

import org.apache.oltu.oauth2.client.OAuthClient; //导入方法依赖的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.OAuthClient.resource方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。