• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java OAuth2ClientSupport类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: Scim2Provisioner

import org.glassfish.jersey.client.oauth2.OAuth2ClientSupport; //导入依赖的package包/类
public Scim2Provisioner(final String target, final String oauthToken,
                        final String username, final String password,
                        final Scim2PrincipalAttributeMapper mapper) {
    final ClientConfig config = new ClientConfig();
    final ApacheConnectorProvider connectorProvider = new ApacheConnectorProvider();
    config.connectorProvider(connectorProvider);
    final Client client = ClientBuilder.newClient(config);
    
    if (StringUtils.isNotBlank(oauthToken)) {
        client.register(OAuth2ClientSupport.feature(oauthToken));
    }
    if (StringUtils.isNotBlank(username) && StringUtils.isNotBlank(password)) {
        client.register(HttpAuthenticationFeature.basic(username, password));
    }
    
    final WebTarget webTarget = client.target(target);
    this.scimService = new ScimService(webTarget);
    this.mapper = mapper;
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:20,代码来源:Scim2Provisioner.java


示例2: createFlow

import org.glassfish.jersey.client.oauth2.OAuth2ClientSupport; //导入依赖的package包/类
private void createFlow(final String redirectUri, final Set<String> scopes, final String state) {
    final String scopesString = getScopesString(scopes);
    final ClientIdentifier clientIdentifier = new ClientIdentifier(clientId, clientSecret);
    @SuppressWarnings("rawtypes")
    final OAuth2CodeGrantFlow.Builder builder = OAuth2ClientSupport.authorizationCodeGrantFlowBuilder(
            clientIdentifier, URI_AUTHENTICATION, URI_ACCESS_TOKEN);
    if (StringUtils.isNotBlank(redirectUri)) {
        builder.redirectUri(redirectUri);
    }
    if (StringUtils.isNotBlank(state)) {
        builder.property(OAuth2CodeGrantFlow.Phase.AUTHORIZATION, "state", state);
    }
    if (StringUtils.isNotBlank(scopesString)) {
        builder.scope(scopesString);
    }
    oAuthFlow = builder.build();
}
 
开发者ID:burberius,项目名称:eve-esi,代码行数:18,代码来源:OAuth.java


示例3: authenticate

import org.glassfish.jersey.client.oauth2.OAuth2ClientSupport; //导入依赖的package包/类
private void authenticate(Client client, RestSBDevice device) {
    AuthenticationScheme authScheme = device.authentication();
    if (authScheme == AuthenticationScheme.NO_AUTHENTICATION) {
        log.debug("{} scheme is specified, ignoring authentication", authScheme);
        return;
    } else if (authScheme == AuthenticationScheme.OAUTH2) {
        String token = checkNotNull(device.token());
        client.register(OAuth2ClientSupport.feature(token));
    } else if (authScheme == AuthenticationScheme.BASIC) {
        String username = device.username();
        String password = device.password() == null ? "" : device.password();
        client.register(HttpAuthenticationFeature.basic(username, password));
    } else {
        // TODO: Add support for other authentication schemes here.
        throw new IllegalArgumentException(String.format("Unsupported authentication scheme: %s",
                authScheme.name()));
    }
}
 
开发者ID:opennetworkinglab,项目名称:onos,代码行数:19,代码来源:HttpSBControllerImpl.java


示例4: getOAuthAuthenticatedTarget

import org.glassfish.jersey.client.oauth2.OAuth2ClientSupport; //导入依赖的package包/类
private WebTarget getOAuthAuthenticatedTarget(final String baseUri, final OAuthConfiguration oauthConfiguration)
        throws AuthenticationException {
    final Client client = buildIgnoreSslErrorClient(ClientBuilder.newBuilder().withConfig(clientConfig())).build();
    final String state = randomId();
    final OAuth2CodeGrantFlow oauth2GrantFlow = OAuth2ClientSupport
            .authorizationCodeGrantFlowBuilder(oauthConfiguration.clientIdentifier(),
                    oauthConfiguration.authorisationUri(), oauthConfiguration.accessTokenUri())
            .client(client).redirectUri(oauthConfiguration.redirectUri()).scope("Default")
            .refreshTokenUri(oauthConfiguration.refreshTokenUri())
            .property(Phase.ALL, OAuth2Parameters.STATE, state).build();

    final String oauthRedirectUrl = oauth2GrantFlow.start();

    logger.debug("The oauth redirect uri is: " + oauthRedirectUrl);

    URI authenticationServerUri = null;
    final Response response = client.target(oauthRedirectUrl).request().get();
    logger.debug("The response for get was : " + response.getStatus());
    authenticationServerUri = response.getLocation();

    final String authCode = oauthConfiguration.oauthUserAgent().authenticate(authenticationServerUri);

    oauth2GrantFlow.finish(authCode, state);
    final Client authorizedClient = oauth2GrantFlow.getAuthorizedClient();
    authorizedClient.register(ObjectMapperProvider.class);
    authorizedClient.register(JacksonFeature.class);
    // TODO Ask if possible bug here : Should this client have config as done in clientConfig() ?
    return authorizedClient.target(baseUri);
}
 
开发者ID:travel-cloud,项目名称:Cheddar,代码行数:30,代码来源:HttpClient.java


示例5: authorize

import org.glassfish.jersey.client.oauth2.OAuth2ClientSupport; //导入依赖的package包/类
@GET
@Path("/authorize")
@JiveSignatureValidation
public Response authorize(@Context HttpServletRequest request, @Context UriInfo uriInfo) {

    String instanceID = "TODO"; //TODO: HEADER PARAM / QUERY PARAM
    String userID = "TODO";     //TODO: HEADER PARAM / QUERY PARAM

    //TODO: PARAMETERIZE
    ClientIdentifier clientIdentifier = new ClientIdentifier(serviceConfig.getClientID(),serviceConfig.getClientSecret());
    OAuth2CodeGrantFlow flow = OAuth2ClientSupport
            .facebookFlowBuilder(clientIdentifier,uriInfo.getBaseUri() + "oauth2/"+SERVICE_NAME+"/callback")
            .scope(serviceConfig.getScope()).build();

    String authorizationUrl = flow.start();

    try {
        URI authorizationUri = new URI(authorizationUrl);

        /** LOAD INTO SESSION FOR FOLLOW-UP HIT **/
        request.getSession().setAttribute(getFlowSessionKey(),flow);
        request.getSession().setAttribute(getInstanceIDSessionKey(),instanceID);
        request.getSession().setAttribute(getUserIDSessionKey(),userID);

        //*** NOTE: 303 "See Other" NEEDED FOR JERSEY FLOW TO PICK UP
        return Response.seeOther(authorizationUri).build();
    } catch (URISyntaxException use) {
        log.error("Invalid Authorization URI: "+authorizationUrl);
        return Response.serverError().entity("Unable to Process this Request").build();
    } // end try/catch

}
 
开发者ID:jivesoftware,项目名称:jive-sdk-java-jersey,代码行数:33,代码来源:FacebookOAuth2Service.java


示例6: authorize

import org.glassfish.jersey.client.oauth2.OAuth2ClientSupport; //导入依赖的package包/类
@GET
@Path("/authorize")
public Response authorize(@Context HttpServletRequest request, @Context UriInfo uriInfo) {

    String userID = "TODO";     //TODO: HEADER/QUERY - PARAM
    String instanceID = "TODO"; //TODO: HEADER/QUERY - PARAM

    ClientIdentifier clientID = new ClientIdentifier(serviceConfig.getClientID(),serviceConfig.getClientSecret());
    OAuth2CodeGrantFlow flow = OAuth2ClientSupport.authorizationCodeGrantFlowBuilder(
            clientID,
            serviceConfig.getAuthorizeUrl(),
            serviceConfig.getTokenUrl()
        ).scope(serviceConfig.getScope())
        .redirectUri(uriInfo.getBaseUri() + "oauth2/callback")
        .build();

    String authorizationUrl = flow.start();

    try {
        URI authorizationUri = new URI(authorizationUrl);

        /** LOAD INTO SESSION FOR FOLLOW-UP HIT **/
        request.getSession().setAttribute(getFlowSessionKey(),flow);
        request.getSession().setAttribute(getInstanceIDSessionKey(),instanceID);
        request.getSession().setAttribute(getUserIDSessionKey(),userID);

        //*** NOTE: 303 "See Other" NEEDED FOR JERSEY FLOW TO PICK UP
        return Response.seeOther(new URI(authorizationUrl)).build();
    } catch (URISyntaxException use) {
        log.error("Invalid Authorization URI: "+authorizationUrl);
        return Response.serverError().entity("Unable to Process this Request").build();
    } // end try/catch

}
 
开发者ID:jivesoftware,项目名称:jive-sdk-java-jersey,代码行数:35,代码来源:JiveOAuth2Service.java


示例7: authorize

import org.glassfish.jersey.client.oauth2.OAuth2ClientSupport; //导入依赖的package包/类
@GET
@Path("/authorize")
@JiveSignatureValidation
public Response authorize(@Context HttpServletRequest request, @Context UriInfo uriInfo) {

    String instanceID = "TODO"; //TODO: HEADER PARAM / QUERY PARAM
    String userID = "TODO";     //TODO: HEADER PARAM / QUERY PARAM

    ClientIdentifier clientIdentifier = new ClientIdentifier(serviceConfig.getClientID(),serviceConfig.getClientSecret());
    OAuth2CodeGrantFlow flow = OAuth2ClientSupport
        .googleFlowBuilder(clientIdentifier, uriInfo.getBaseUri() + "oauth2/" + SERVICE_NAME + "/callback", serviceConfig.getScope())
        .build();

    String authorizationUrl = flow.start();

    try {
        URI authorizationUri = new URI(authorizationUrl);

        /** LOAD INTO SESSION FOR FOLLOW-UP HIT **/
        request.getSession().setAttribute(getFlowSessionKey(),flow);
        request.getSession().setAttribute(getInstanceIDSessionKey(),instanceID);
        request.getSession().setAttribute(getUserIDSessionKey(),userID);

        //*** NOTE: 303 "See Other" NEEDED FOR JERSEY FLOW TO PICK UP
        return Response.seeOther(authorizationUri).build();
    } catch (URISyntaxException use) {
        log.error("Invalid Authorization URI: "+authorizationUrl);
        return Response.serverError().entity("Unable to Process this Request").build();
    } // end try/catch

}
 
开发者ID:jivesoftware,项目名称:jive-sdk-java-jersey,代码行数:32,代码来源:GoogleOAuth2Service.java


示例8: simpleResourceTest

import org.glassfish.jersey.client.oauth2.OAuth2ClientSupport; //导入依赖的package包/类
@Test
public void simpleResourceTest() throws UnsupportedEncodingException
{
	
	ClientIdentifier cliendId = new ClientIdentifier(clientEntity.getClientId(), clientEntity.getClientSecret());
	
	Builder<?> flowBuilder = OAuth2ClientSupport.authorizationCodeGrantFlowBuilder(cliendId, "http://localhost:9998/testsuite/oauth2/auth", "http://localhost:9998/testsuite/oauth2/accessToken");
	OAuth2CodeGrantFlow flow = flowBuilder.scope("test1 test2").redirectUri("http://localhost:9998/testsuite").build();
	String authUrl = flow.start();
	
	Map<String, String> map = retrieveCode(authUrl);
	String code = map.get("code");
	String state = map.get("state"); 
	
	TokenResult tokenResult = flow.finish(code, state);

	client = ClientBuilder.newClient();
	client.register(LoggingFilter.class);
	client.register(OAuth2ClientSupport.feature(tokenResult.getAccessToken()));
	client.register(JacksonFeature.class);
	Invocation.Builder builder = client.target("http://localhost:9998/testsuite/rest/sample/1").request();
	Response response = builder.get();
	
	assertEquals(200, response.getStatus());
	SampleEntity entity = response.readEntity(SampleEntity.class);
	assertNotNull(entity);
}
 
开发者ID:hburgmeier,项目名称:jerseyoauth2,代码行数:28,代码来源:Jersey2Test.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java OnTextMessage类代码示例发布时间:2022-05-23
下一篇:
Java RollingLogs类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap