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

Java IDToken类代码示例

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

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



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

示例1: getKeycloakAuthentication

import org.keycloak.representations.IDToken; //导入依赖的package包/类
public KeycloakAuthentication getKeycloakAuthentication(HttpServletRequest request) throws Exception {
	String redirect = redirectUrl(request);

	AccessTokenResponse tokenResponse = ServerRequest.invokeAccessCodeToToken(keycloakDeployment, request.getParameter("code"), redirect, null);
	String idTokenString = tokenResponse.getIdToken();
	String refreashToken = tokenResponse.getRefreshToken();
	String tokenString = tokenResponse.getToken();
	AccessToken token = RSATokenVerifier.verifyToken(tokenString, keycloakDeployment.getRealmKey(), keycloakDeployment.getRealm());

	if (idTokenString != null) {
		JWSInput input = new JWSInput(idTokenString);
		IDToken idToken = input.readJsonContent(IDToken.class);
		return new KeycloakAuthentication(idToken, token, refreashToken);
	} 
	throw new RuntimeException("Invalid User ");
}
 
开发者ID:mnadeem,项目名称:sonar-keycloak,代码行数:17,代码来源:KeycloakClient.java


示例2: createKeycloakSecurityContext

import org.keycloak.representations.IDToken; //导入依赖的package包/类
/**
 * Creates a new {@link RefreshableKeycloakSecurityContext} from the given {@link KeycloakDeployment} and {@link AccessTokenResponse}.
 *
 * @param deployment the <code>KeycloakDeployment</code> for which to create a <code>RefreshableKeycloakSecurityContext</code> (required)
 * @param accessTokenResponse the <code>AccessTokenResponse</code> from which to create a RefreshableKeycloakSecurityContext (required)
 *
 * @return a <code>RefreshableKeycloakSecurityContext</code> created from the given <code>accessTokenResponse</code>
 * @throws VerificationException if the given <code>AccessTokenResponse</code> contains an invalid {@link IDToken}
 */
public static RefreshableKeycloakSecurityContext createKeycloakSecurityContext(KeycloakDeployment deployment, AccessTokenResponse accessTokenResponse) throws VerificationException {
    String tokenString = accessTokenResponse.getToken();
    String idTokenString = accessTokenResponse.getIdToken();
    AccessToken accessToken = RSATokenVerifier
            .verifyToken(tokenString, deployment.getRealmKey(), deployment.getRealmInfoUrl());
    IDToken idToken;

    try {
        JWSInput input = new JWSInput(idTokenString);
        idToken = input.readJsonContent(IDToken.class);
    } catch (JWSInputException e) {
        throw new VerificationException("Unable to verify ID token", e);
    }

    // FIXME: does it make sense to pass null for the token store?
    return new RefreshableKeycloakSecurityContext(deployment, null, tokenString, accessToken, idTokenString, idToken, accessTokenResponse.getRefreshToken());
}
 
开发者ID:Smartling,项目名称:smartling-keycloak-extras,代码行数:27,代码来源:KeycloakSpringAdapterUtils.java


示例3: basicWorkflow

import org.keycloak.representations.IDToken; //导入依赖的package包/类
@Test
public void basicWorkflow()
  throws Exception
{
  final SimpleAuthService authService = mock( SimpleAuthService.class );
  final SimpleSecureSessionManager sm = new SimpleSecureSessionManager();
  setField( sm, authService );

  final String userID = ValueUtil.randomString();

  final OidcKeycloakAccount account = mock( OidcKeycloakAccount.class );
  final AccessToken token = new AccessToken();
  setField( token, userID );

  final KeycloakSecurityContext context =
    new KeycloakSecurityContext( ValueUtil.randomString(), token, ValueUtil.randomString(), new IDToken() );
  when( account.getKeycloakSecurityContext() ).thenReturn( context );
  when( authService.findAccount() ).thenReturn( account );

  final SessionInfo sessionInfo = sm.createSession();
  assertNotNull( sessionInfo );
  assertEquals( sessionInfo.getUserID(), userID );
}
 
开发者ID:realityforge,项目名称:simple-session-filter,代码行数:24,代码来源:SimpleSecureSessionManagerTest.java


示例4: getCurrentUserWithAuthorities

import org.keycloak.representations.IDToken; //导入依赖的package包/类
public static User getCurrentUserWithAuthorities() {
    try {
    Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
    KeycloakPrincipal userDetails = (KeycloakPrincipal) authentication.getPrincipal();
    IDToken idToken = userDetails.getKeycloakSecurityContext().getIdToken();

    User user = new User();
    user.setEmail(idToken.getEmail());
    user.setFirstName(idToken.getGivenName());
    user.setFullName(idToken.getName());
    user.setEmail(idToken.getEmail());
    user.setGender(idToken.getGender());
    user.setLastName(idToken.getFamilyName());
    user.setLocale(idToken.getLocale());
    user.setLogin(idToken.getPreferredUsername());
    user.setPhoneNumber(idToken.getPhoneNumber());
    user.setPhoneNumberVerified(idToken.getPhoneNumberVerified());
    user.setPicture(idToken.getPicture());
    user.setProfile(idToken.getProfile());
    user.setWebsite(idToken.getWebsite());
    user.setUpdatedAt(idToken.getUpdatedAt());
    
    Collection<? extends GrantedAuthority> authorities = authentication.getAuthorities();
    user.setAuthorities(authorities);
    return user;
    } catch (Exception e) {
        return null;
    }
}
 
开发者ID:giovannicandido,项目名称:generator-spring-spa,代码行数:30,代码来源:SecurityUtils.java


示例5: handlerUserInfoRequest

import org.keycloak.representations.IDToken; //导入依赖的package包/类
@RequestMapping(value = "/info/user", method = RequestMethod.GET)
public String handlerUserInfoRequest(Model model)
{
    KeycloakAuthenticationToken authentication = (KeycloakAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
    IDToken token = authentication.getAccount().getKeycloakSecurityContext().getIdToken();

    model.addAttribute("token", token);
    model.addAttribute("claims", token.getOtherClaims());

    return "info";
}
 
开发者ID:Smartling,项目名称:keycloak-user-migration-provider,代码行数:12,代码来源:PortalController.java


示例6: getClaim

import org.keycloak.representations.IDToken; //导入依赖的package包/类
/**
 *
 * @param token token to retrieve claim from
 * @param claim the claim (field key)
 * @return string representaion of claim
 */
public static String getClaim(IDToken token, String claim) {
  if (claim == null || token == null)
      return null;
  // Get the standard claim field, if available
  if (STANDARD_CLAIMS_FIELD_MAP.containsKey(claim)) {
      return callClaimChain(token, STANDARD_CLAIMS_FIELD_MAP.get(claim));
  } else { // Otherwise look up 'other claims'
      Object otherClaim = getOtherClaimValue(token, claim);
      return otherClaim == null ? null : otherClaim.toString();
  }
}
 
开发者ID:apiman,项目名称:apiman-plugins,代码行数:18,代码来源:ClaimLookup.java


示例7: getIDToken

import org.keycloak.representations.IDToken; //导入依赖的package包/类
public static IDToken getIDToken(HttpServletRequest req) {
	if (req.getUserPrincipal() == null) {
		return null;
	}
	KeycloakSecurityContext session = ((KeycloakPrincipal<?>) req.getUserPrincipal()).getKeycloakSecurityContext();
	if (session == null) {
    	return null;
    }
	return getIDToken(req, session);
}
 
开发者ID:Blazebit,项目名称:blaze-storage,代码行数:11,代码来源:AdminClient.java


示例8: getAccountKey

import org.keycloak.representations.IDToken; //导入依赖的package包/类
@Override
public String getAccountKey(HttpServletRequest request) {
	IDToken token = AdminClient.getIDToken(request);
	
	if (token == null) {
		return null;
	}
	
	return token.getId();
}
 
开发者ID:Blazebit,项目名称:blaze-storage,代码行数:11,代码来源:KeycloakRequestAuthenticator.java


示例9: validateSession

import org.keycloak.representations.IDToken; //导入依赖的package包/类
/**
 * Validate the user's session.
 * 
 * @param httpRequest the HTTP request object; may not be null
 * @param databaseId the identifier of the database to which the caller wants to connect; may not be null
 * @return the session token, or null if the user is not authenticated
 */
private SessionToken validateSession(HttpServletRequest httpRequest, String databaseId) {
    KeycloakSecurityContext session = (KeycloakSecurityContext) httpRequest.getAttribute(KeycloakSecurityContext.class.getName());
    IDToken token = session.getIdToken();
    if (token == null) return null;

    String device = httpRequest.getHeader("X-Debezium-Device");
    String userAgent = httpRequest.getHeader("User-Agent");

    return driver.connect(token.getPreferredUsername(), device, userAgent, databaseId);
}
 
开发者ID:rhauch,项目名称:debezium-proto,代码行数:18,代码来源:Databases.java


示例10: doFinishLogin

import org.keycloak.representations.IDToken; //导入依赖的package包/类
/**
 * This is where the user comes back to at the end of the OpenID redirect
 * ping-pong.
 * 
 * @throws HttpFailure
 * @throws VerificationException
 */
public HttpResponse doFinishLogin(StaplerRequest request) {

	String redirect = redirectUrl(request);

	try {

		AccessTokenResponse tokenResponse = ServerRequest.invokeAccessCodeToToken(getKeycloakDeployment(),
				request.getParameter("code"), redirect, null);

		String tokenString = tokenResponse.getToken();
		String idTokenString = tokenResponse.getIdToken();
		String refreashToken = tokenResponse.getRefreshToken();

		AccessToken token = AdapterRSATokenVerifier.verifyToken(tokenString, getKeycloakDeployment());
		if (idTokenString != null) {
			JWSInput input = new JWSInput(idTokenString);

			IDToken idToken = input.readJsonContent(IDToken.class);
			SecurityContextHolder.getContext()
					.setAuthentication(new KeycloakAuthentication(idToken, token, refreashToken));

			User currentUser = User.current();
			if (currentUser != null) {
				currentUser.setFullName(idToken.getPreferredUsername());

				if (!currentUser.getProperty(Mailer.UserProperty.class).hasExplicitlyConfiguredAddress()) {
					currentUser.addProperty(new Mailer.UserProperty(idToken.getEmail()));
				}
			}
		}

	} catch (Exception e) {
		LOGGER.log(Level.SEVERE, "Authentication Exception ", e);
	}

	String referer = (String) request.getSession().getAttribute(REFERER_ATTRIBUTE);
	if (referer != null) {
		return HttpResponses.redirectTo(referer);
	}
	return HttpResponses.redirectToContextRoot();
}
 
开发者ID:devlauer,项目名称:jenkins-keycloak-plugin,代码行数:49,代码来源:KeycloakSecurityRealm.java


示例11: KeycloakAuthentication

import org.keycloak.representations.IDToken; //导入依赖的package包/类
public KeycloakAuthentication(IDToken idToken, AccessToken accessToken, String refreashToken) {
	super(buildRoles(accessToken));
	this.userName = idToken.getPreferredUsername();
	this.refreashToken = refreashToken;
	setAuthenticated(true);
}
 
开发者ID:devlauer,项目名称:jenkins-keycloak-plugin,代码行数:7,代码来源:KeycloakAuthentication.java


示例12: KeycloakAuthentication

import org.keycloak.representations.IDToken; //导入依赖的package包/类
public KeycloakAuthentication(IDToken idToken, AccessToken accessToken, String refreashToken) {
	buildRoles(accessToken);
	this.userName = idToken.getName();
	this.refreashToken = refreashToken;
	this.email = idToken.getEmail();
}
 
开发者ID:mnadeem,项目名称:sonar-keycloak,代码行数:7,代码来源:KeycloakAuthentication.java


示例13: setIdToken

import org.keycloak.representations.IDToken; //导入依赖的package包/类
public void setIdToken(IDToken idToken) {
    this.idToken = idToken;
}
 
开发者ID:ahus1,项目名称:keycloak-dropwizard-integration,代码行数:4,代码来源:DrawBean.java


示例14: getIdToken

import org.keycloak.representations.IDToken; //导入依赖的package包/类
public IDToken getIdToken() {
    return idToken;
}
 
开发者ID:ahus1,项目名称:keycloak-dropwizard-integration,代码行数:4,代码来源:DrawBean.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Java DeleteAction类代码示例发布时间:2022-05-22
下一篇:
Java JournalResponseProto类代码示例发布时间: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