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

Java OAuth2Constants类代码示例

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

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



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

示例1: login

import org.keycloak.OAuth2Constants; //导入依赖的package包/类
@Override
public RefreshableKeycloakSecurityContext login(String username, String password) throws VerificationException {

    final MultiValueMap<String,String> body = new LinkedMultiValueMap<>();
    final HttpHeaders headers = new HttpHeaders();

    headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
    headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
    body.set("username", username);
    body.set("password", password);
    body.set(OAuth2Constants.GRANT_TYPE, OAuth2Constants.PASSWORD);

    AccessTokenResponse response = template.postForObject(keycloakDeployment.getTokenUrl(), new HttpEntity<>(body, headers), AccessTokenResponse.class);

    return KeycloakSpringAdapterUtils.createKeycloakSecurityContext(keycloakDeployment, response);
}
 
开发者ID:Smartling,项目名称:smartling-keycloak-extras,代码行数:17,代码来源:KeycloakDirectAccessGrantService.java


示例2: consumeGrantTokenService

import org.keycloak.OAuth2Constants; //导入依赖的package包/类
protected void consumeGrantTokenService(final MultivaluedMap<String, String> mvm) {

        boolean isPublic = config.isPublicClient();

        String authorization = "";
        if (isPublic) { // if client is public access type
            mvm.putSingle(OAuth2Constants.CLIENT_ID,
                          config.getClientId());
        } else {
            authorization = BasicAuthHelper.createHeader(config.getClientId(),
                                                         config.getClientSecret());
        }

        TokenService client = createTokenService();
        AccessTokenResponse response = client.grantToken(config.getRealm(),
                                                         authorization,
                                                         mvm);

        int requestTime = Time.currentTime();
        expirationTime = requestTime + response.getExpiresIn();
        this.accessTokenResponse = response;
    }
 
开发者ID:kiegroup,项目名称:appformer,代码行数:23,代码来源:AuthTokenManager.java


示例3: testGrantPublicToken

import org.keycloak.OAuth2Constants; //导入依赖的package包/类
@Test
public void testGrantPublicToken() throws Exception {
    when(response.getExpiresIn()).thenReturn(1000l);
    when(config.isPublicClient()).thenReturn(true);
    this.tokenManager.grantToken();
    ArgumentCaptor<MultivaluedMap> mapCaptor = ArgumentCaptor.forClass(MultivaluedMap.class);
    verify(this.tokenService,
           times(1)).grantToken(eq("realm1"),
                                anyString(),
                                mapCaptor.capture());
    MultivaluedMap<String, String> mvm = mapCaptor.getValue();
    Assert.assertEquals("password",
                        mvm.get(OAuth2Constants.GRANT_TYPE).get(0));
    Assert.assertEquals("user1",
                        mvm.get("username").get(0));
    Assert.assertEquals("password1",
                        mvm.get("password").get(0));
    Assert.assertEquals("clientId1",
                        mvm.get(OAuth2Constants.CLIENT_ID).get(0));
}
 
开发者ID:kiegroup,项目名称:appformer,代码行数:21,代码来源:AuthTokenManagerTest.java


示例4: testRefreshToken

import org.keycloak.OAuth2Constants; //导入依赖的package包/类
@Test
public void testRefreshToken() throws Exception {
    when(response.getExpiresIn()).thenReturn(1000l);
    this.tokenManager.accessTokenResponse = response;
    this.tokenManager.expirationTime = 0;
    this.tokenManager.minTokenValidity = 100;
    String s = this.tokenManager.getAccessTokenString();
    ArgumentCaptor<MultivaluedMap> mapCaptor = ArgumentCaptor.forClass(MultivaluedMap.class);
    verify(this.tokenService,
           times(1)).grantToken(eq("realm1"),
                                anyString(),
                                mapCaptor.capture());
    MultivaluedMap<String, String> mvm = mapCaptor.getValue();
    Assert.assertEquals("refresh_token",
                        mvm.get(OAuth2Constants.GRANT_TYPE).get(0));
    Assert.assertEquals("refreshToken",
                        mvm.get("refresh_token").get(0));
}
 
开发者ID:kiegroup,项目名称:appformer,代码行数:19,代码来源:AuthTokenManagerTest.java


示例5: testRefreshPublicToken

import org.keycloak.OAuth2Constants; //导入依赖的package包/类
@Test
public void testRefreshPublicToken() throws Exception {
    when(response.getExpiresIn()).thenReturn(1000l);
    when(config.isPublicClient()).thenReturn(true);
    this.tokenManager.accessTokenResponse = response;
    this.tokenManager.expirationTime = 0;
    this.tokenManager.minTokenValidity = 100;
    String s = this.tokenManager.getAccessTokenString();
    ArgumentCaptor<MultivaluedMap> mapCaptor = ArgumentCaptor.forClass(MultivaluedMap.class);
    verify(this.tokenService,
           times(1)).grantToken(eq("realm1"),
                                anyString(),
                                mapCaptor.capture());
    MultivaluedMap<String, String> mvm = mapCaptor.getValue();
    Assert.assertEquals("refresh_token",
                        mvm.get(OAuth2Constants.GRANT_TYPE).get(0));
    Assert.assertEquals("refreshToken",
                        mvm.get("refresh_token").get(0));
    Assert.assertEquals("clientId1",
                        mvm.get(OAuth2Constants.CLIENT_ID).get(0));
}
 
开发者ID:kiegroup,项目名称:appformer,代码行数:22,代码来源:AuthTokenManagerTest.java


示例6: logout

import org.keycloak.OAuth2Constants; //导入依赖的package包/类
private void logout(AccessTokenResponse accessTokenResponse) {
    try(CloseableHttpClient client = HttpClientBuilder.create().build()) {
        HttpPost post = new HttpPost(KeycloakUriBuilder.fromUri(baseUrl)
                .path(ServiceUrlConstants.TOKEN_SERVICE_LOGOUT_PATH).build(LiveOak.LIVEOAK_APP_REALM));

        List<NameValuePair> formparams = new ArrayList<>();
        formparams.add(new BasicNameValuePair(OAuth2Constants.REFRESH_TOKEN, accessTokenResponse.getRefreshToken()));
        formparams.add(new BasicNameValuePair(OAuth2Constants.CLIENT_ID, "liveoak-admin-client"));
        UrlEncodedFormEntity form = new UrlEncodedFormEntity(formparams, "UTF-8");
        post.setEntity(form);

        client.execute(post);
    } catch (IOException e) {
        // Not a problem we need to report
    }

    this.accessTokenResponse = null;
}
 
开发者ID:liveoak-io,项目名称:liveoak,代码行数:19,代码来源:DirectAccessClient.java


示例7: grantTokenParameters

import org.keycloak.OAuth2Constants; //导入依赖的package包/类
/**
 * Generate parameters required for initial token grant.
 */
@Nonnull
private MultivaluedMap<String, String> grantTokenParameters()
{
  final MultivaluedHashMap<String, String> results = initParameters();
  results.put( OAuth2Constants.GRANT_TYPE, Collections.singletonList( _config.getGrantType() ) );
  results.put( "username", Collections.singletonList( _config.getUsername() ) );
  results.put( "password", Collections.singletonList( _config.getPassword() ) );
  return results;
}
 
开发者ID:realityforge,项目名称:keycloak-jaxrs-client-authfilter,代码行数:13,代码来源:Keycloak.java


示例8: initParameters

import org.keycloak.OAuth2Constants; //导入依赖的package包/类
/**
 * Initialize parameters, ensuring clientID is set if required.
 */
@Nonnull
private MultivaluedHashMap<String, String> initParameters()
{
  final MultivaluedHashMap<String, String> results = new MultivaluedHashMap<>();
  if ( _config.isPublicClient() )
  {
    results.put( OAuth2Constants.CLIENT_ID, Collections.singletonList( _config.getClientID() ) );
  }
  return results;
}
 
开发者ID:realityforge,项目名称:keycloak-jaxrs-client-authfilter,代码行数:14,代码来源:Keycloak.java


示例9: createPasswordConfig

import org.keycloak.OAuth2Constants; //导入依赖的package包/类
@Nonnull
public static KeycloakConfig createPasswordConfig( @Nonnull final String serverUrl,
                                                   @Nonnull final String realm,
                                                   @Nonnull final String clientID,
                                                   @Nonnull final String username,
                                                   @Nonnull final String password )
{
  return new KeycloakConfig( serverUrl, realm, OAuth2Constants.PASSWORD, clientID, username, password, null );
}
 
开发者ID:realityforge,项目名称:keycloak-jaxrs-client-authfilter,代码行数:10,代码来源:KeycloakConfig.java


示例10: getAuthUrl

import org.keycloak.OAuth2Constants; //导入依赖的package包/类
public String getAuthUrl(HttpServletRequest servletRequest) {
	String redirect = redirectUrl(servletRequest);
	String state = UUID.randomUUID().toString();
	String authUrl = keycloakDeployment.getAuthUrl().clone()
			.queryParam(OAuth2Constants.CLIENT_ID, keycloakDeployment.getResourceName())
			.queryParam(OAuth2Constants.REDIRECT_URI, redirect)
			.queryParam(OAuth2Constants.STATE, state)
			.build().toString();
	return authUrl;
}
 
开发者ID:mnadeem,项目名称:sonar-keycloak,代码行数:11,代码来源:KeycloakClient.java


示例11: grantToken

import org.keycloak.OAuth2Constants; //导入依赖的package包/类
@Override
public void grantToken() {
    MultivaluedMap<String, String> mvm = new CaseInsensitiveMap<String>();
    mvm.putSingle(OAuth2Constants.GRANT_TYPE,
                  "password");
    mvm.putSingle("username",
                  config.getUsername());
    mvm.putSingle("password",
                  config.getPassword());
    consumeGrantTokenService(mvm);
}
 
开发者ID:kiegroup,项目名称:appformer,代码行数:12,代码来源:AuthTokenManager.java


示例12: refreshToken

import org.keycloak.OAuth2Constants; //导入依赖的package包/类
private void refreshToken() {
    MultivaluedMap<String, String> mvm = new CaseInsensitiveMap<String>();
    mvm.putSingle(OAuth2Constants.GRANT_TYPE,
                  "refresh_token");
    mvm.putSingle("refresh_token",
                  accessTokenResponse.getRefreshToken());
    consumeGrantTokenService(mvm);
}
 
开发者ID:kiegroup,项目名称:appformer,代码行数:9,代码来源:AuthTokenManager.java


示例13: doCommenceLogin

import org.keycloak.OAuth2Constants; //导入依赖的package包/类
public HttpResponse doCommenceLogin(StaplerRequest request, StaplerResponse response,
		@Header("Referer") final String referer) throws IOException {
	request.getSession().setAttribute(REFERER_ATTRIBUTE, referer);

	String redirect = redirectUrl(request);

	String state = UUID.randomUUID().toString();

	String authUrl = getKeycloakDeployment().getAuthUrl().clone()
			.queryParam(OAuth2Constants.CLIENT_ID, getKeycloakDeployment().getResourceName())
			.queryParam(OAuth2Constants.REDIRECT_URI, redirect).queryParam(OAuth2Constants.STATE, state)
			.queryParam(OAuth2Constants.RESPONSE_TYPE, OAuth2Constants.CODE).build().toString();

	return new HttpRedirect(authUrl);

}
 
开发者ID:devlauer,项目名称:jenkins-keycloak-plugin,代码行数:17,代码来源:KeycloakSecurityRealm.java


示例14: accessToken

import org.keycloak.OAuth2Constants; //导入依赖的package包/类
public String accessToken() throws IOException {
    if (openConnections.get() == 0 && accessTokenResponse == null) {

        synchronized (this) {
            if (accessTokenResponse == null) {
                // Not connected
                int attempts = 0;
                boolean intr = false;

                try {
                    while (accessTokenResponse == null && attempts < MAX_RETRIES) {

                        try (CloseableHttpClient client = HttpClientBuilder.create().build()) {

                            HttpPost post = new HttpPost(KeycloakUriBuilder.fromUri(baseUrl)
                                    .path(ServiceUrlConstants.TOKEN_SERVICE_DIRECT_GRANT_PATH).build(LiveOak.LIVEOAK_APP_REALM));

                            List<NameValuePair> formparams = new ArrayList<>();
                            formparams.add(new BasicNameValuePair("username", "liveoak-server"));

                            String initialPassword = System.getProperty("liveoak.initial.password");
                            if (initialPassword != null) {
                                formparams.add(new BasicNameValuePair("password", initialPassword));
                            } else {
                                formparams.add(new BasicNameValuePair("password", "password"));
                            }

                            formparams.add(new BasicNameValuePair(OAuth2Constants.CLIENT_ID, "liveoak-admin-client"));
                            UrlEncodedFormEntity form = new UrlEncodedFormEntity(formparams, "UTF-8");
                            post.setEntity(form);

                            HttpResponse response = client.execute(post);
                            int status = response.getStatusLine().getStatusCode();
                            HttpEntity entity = response.getEntity();

                            if (status == 404) {
                                attempts++;
                                wait(TIMEOUT);
                                continue;
                            } else if (status != 200) {
                                String json = EntityUtils.toString(entity);
                                throw new IOException("Bad status: " + status + ", response: " + json);
                            }

                            if (entity == null) {
                                throw new IOException("No Entity");
                            }

                            accessTokenResponse = JsonSerialization.readValue(EntityUtils.toString(entity), AccessTokenResponse.class);
                        } catch (InterruptedException e) {
                            intr = true;
                        }
                    }
                } finally {
                    if (intr) Thread.currentThread().interrupt();
                }
            }
        }
    }

    openConnections.incrementAndGet();
    return accessTokenResponse.getToken();
}
 
开发者ID:liveoak-io,项目名称:liveoak,代码行数:64,代码来源:DirectAccessClient.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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