當前位置: 首頁>>代碼示例>>Java>>正文


Java JwtClaims.getClaimValue方法代碼示例

本文整理匯總了Java中org.jose4j.jwt.JwtClaims.getClaimValue方法的典型用法代碼示例。如果您正苦於以下問題:Java JwtClaims.getClaimValue方法的具體用法?Java JwtClaims.getClaimValue怎麽用?Java JwtClaims.getClaimValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.jose4j.jwt.JwtClaims的用法示例。


在下文中一共展示了JwtClaims.getClaimValue方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: SSOData

import org.jose4j.jwt.JwtClaims; //導入方法依賴的package包/類
/**********************************************
 * Constructors
 **********************************************/

public SSOData(final JwtClaims jwtClaims) throws MalformedClaimException {

  Objects.requireNonNull(jwtClaims);

  this.instanceID = jwtClaims.getClaimValue(KEY_INSTANCE_ID, String.class);
  this.userID = jwtClaims.getClaimValue(KEY_USER_ID, String.class);
  this.userExternalID = jwtClaims.getClaimValue(KEY_USER_EXTERNAL_ID, String.class);
  this.userFirstName = jwtClaims.getClaimValue(KEY_USER_FIRST_NAME, String.class);
  this.userLastName = jwtClaims.getClaimValue(KEY_USER_LAST_NAME, String.class);
  this.userRole = jwtClaims.getClaimValue(KEY_USER_ROLE, String.class);
  this.userLocale = jwtClaims.getClaimValue(KEY_USER_LOCALE, String.class);
  this.issuer = jwtClaims.getClaimValue(KEY_ISSUER, String.class);
  this.audience = jwtClaims.getClaimValue(KEY_AUDIENCE, String.class);
  this.instanceName = jwtClaims.getClaimValue(KEY_INSTANCE_NAME, String.class);
  this.userFullName = jwtClaims.getClaimValue(KEY_USER_FULL_NAME, String.class);
  this.entityType = jwtClaims.getClaimValue(KEY_ENTITY_TYPE, String.class);
  this.themeTextColor = jwtClaims.getClaimValue(KEY_THEME_TEXT_COLOR, String.class);
  this.themeBackgroundColor = jwtClaims.getClaimValue(KEY_THEME_BACKGROUND_COLOR, String.class);
  this.tags = jwtClaims.getClaimValue(KEY_TAGS, List.class);
}
 
開發者ID:Staffbase,項目名稱:plugins-sdk-java,代碼行數:25,代碼來源:SSOData.java

示例2: toUserInfo

import org.jose4j.jwt.JwtClaims; //導入方法依賴的package包/類
private static UserInfo toUserInfo(JwtClaims jwtClaims) {
  try {
    List<String> audiences = jwtClaims.getAudience();
    if (audiences == null || audiences.isEmpty()) {
      throw new UnauthenticatedException("Missing audience field");
    }

    String email = jwtClaims.getClaimValue(EMAIL_CLAIM_NAME, String.class);

    String subject = jwtClaims.getSubject();
    if (subject == null) {
      throw new UnauthenticatedException("Missing subject field");
    }

    String issuer = jwtClaims.getIssuer();
    if (issuer == null) {
      throw new UnauthenticatedException("Missing issuer field");
    }

    return new UserInfo(audiences, email, subject, issuer);
  } catch (MalformedClaimException exception) {
    throw new UnauthenticatedException("Cannot read malformed claim", exception);
  }
}
 
開發者ID:cloudendpoints,項目名稱:endpoints-management-java,代碼行數:25,代碼來源:Authenticator.java

示例3: validateToken

import org.jose4j.jwt.JwtClaims; //導入方法依賴的package包/類
/**
 * Check if it was issued by the server and if it's not expired 
 * @param java_web_token
 * @throws InvalidJwtException if the token is invalid
 */
private String validateToken(String java_web_token) throws InvalidJwtException {
	String username = null;
	RsaJsonWebKey rsaJsonWebKey = RsaKeyProducer.produce();

	System.out.println("RSA hash code... " + rsaJsonWebKey.hashCode());

	JwtConsumer jwtConsumer = new JwtConsumerBuilder()
			.setRequireSubject() // the JWT must have a subject claim
			.setVerificationKey(rsaJsonWebKey.getKey()) // verify the signature with the public key
			.build(); // create the JwtConsumer instance

	try {
		//  Validate the JWT and process it to the Claims
		JwtClaims jwtClaims = jwtConsumer.processToClaims(java_web_token);
		username = (String) jwtClaims.getClaimValue("sub");
		System.out.println("JWT validation succeeded! " + jwtClaims);
	} catch (InvalidJwtException e) {
		e.printStackTrace(); //on purpose
		throw e;
	}
	return username;
}
 
開發者ID:danielemaddaluno,項目名稱:jaxrs-jws-jwt-web,代碼行數:28,代碼來源:AuthenticationFilter.java

示例4: verifyToken

import org.jose4j.jwt.JwtClaims; //導入方法依賴的package包/類
public static User verifyToken(String data) {
	JwtConsumer jwtConsumer = new JwtConsumerBuilder()
			.setRequireExpirationTime() // the JWT must have an expiration time
			.setMaxFutureValidityInMinutes(60*24) // but the  expiration time can't be too crazy
			.setAllowedClockSkewInSeconds(30) // allow some leeway in validating time based claims to account for clock skew
			.setRequireSubject() // the JWT must have a subject claim
			.setExpectedIssuer("server") // whom the JWT needs to have been issued by
			.setExpectedAudience("client") // to whom the JWT is intended for
			.setVerificationKey(new HmacKey(secret.getBytes())) // verify the signature with the public key
			.build(); // create the JwtConsumer instance

	try
	{
		//  Validate the JWT and process it to the Claims
		JwtClaims jwtClaims = jwtConsumer.processToClaims(data);
		ObjectMapper mapper = new ObjectMapper();
		String json = (String) jwtClaims.getClaimValue("userData");
		byte[] bytes = json.getBytes("UTF-8");
		return mapper.readValue(bytes, User.class);
	}
	catch (Exception e) {
		return null;
	}

}
 
開發者ID:proyectos-ce,項目名稱:moncha-server,代碼行數:26,代碼來源:TokenProvider.java

示例5: getName

import org.jose4j.jwt.JwtClaims; //導入方法依賴的package包/類
/**
 * This just parses the token without validation to extract one of the following in order to obtain
 * the name to be used for the principal:
 * upn
 * preferred_username
 * subject
 *
 * If there is an exception it sets the name to INVALID_TOKEN_NAME and saves the exception for access
 * via {@link #getJwtException()}
 *
 * @return the name to use for the principal
 */
public String getName() {
    if (name == null) {
        name = "INVALID_TOKEN_NAME";
        try {
            // Build a JwtConsumer that doesn't check signatures or do any validation.
            JwtConsumer firstPassJwtConsumer = new JwtConsumerBuilder()
                    .setSkipAllValidators()
                    .setDisableRequireSignature()
                    .setSkipSignatureVerification()
                    .build();

            //The first JwtConsumer is basically just used to parse the JWT into a JwtContext object.
            JwtContext jwtContext = firstPassJwtConsumer.process(bearerToken);
            JwtClaims claimsSet = jwtContext.getJwtClaims();
            // We have to determine the unique name to use as the principal name. It comes from upn, preferred_username, sub in that order
            name = claimsSet.getClaimValue("upn", String.class);
            if (name == null) {
                name = claimsSet.getClaimValue("preferred_username", String.class);
                if (name == null) {
                    name = claimsSet.getSubject();
                }
            }
        } catch (Exception e) {
            jwtException = e;
        }
    }
    return name;
}
 
開發者ID:wildfly-swarm,項目名稱:wildfly-swarm,代碼行數:41,代碼來源:JWTCredential.java

示例6: verify

import org.jose4j.jwt.JwtClaims; //導入方法依賴的package包/類
/**
 * Verify and parse a single-sign-on attempt coming from the staffbase app.
 *
 * @param raw the raw JWT string
 * @return the parsed data from the sign-on attempt
 * @throws SSOException if the verification of the sign-on attempt fails
 */
public SSOData verify(final String raw) throws SSOException {

  if (logger.isDebugEnabled()) {
    logger.debug("Attempting to decrypt SSO JWT. "
        + "[raw=" + raw + "]");
  }

  Objects.requireNonNull(raw);

  try {

    // Process and verify the request on the basis of jwt verification
    final JwtClaims jwtClaims = this.jwtConsumer
        .process(raw)
        .getJwtClaims();

    // Add the instance id verification step
    final String instanceId = jwtClaims.getClaimValue(EXPECTED_CLAIM_INSTANCE_ID, String.class);
    if (instanceId == null || instanceId.isEmpty()) {
      if (logger.isFatalEnabled()) {
        logger.fatal("Encountered illegal sso attempt. "
            + "Bad instance_id. "
            + "[instance_id=" + instanceId + "]");
      }

      throw new SSOException("Missing or malformed instnance_id.");
    }

    if (logger.isDebugEnabled()) {
      logger.debug("Verification of single-sign-on JWT succeeded. "
          + "[raw=" + raw + "] "
          + "[claims=" + jwtClaims + "]");
    }

    // Parse and return the container data.
    return new SSOData(jwtClaims);
  } catch (final MalformedClaimException malformationException) {
    if (logger.isFatalEnabled()) {
      logger.fatal("Encountered malformed sso attempt.", malformationException);
    }

    throw new SSOException(malformationException.getMessage(), malformationException);
  } catch (final InvalidJwtException invalidJwtException) {
    if (logger.isFatalEnabled()) {
      logger.fatal("Encountered illegal sso attempt.", invalidJwtException);
    }

    throw new SSOException(invalidJwtException.getMessage(), invalidJwtException);
  }
}
 
開發者ID:Staffbase,項目名稱:plugins-sdk-java,代碼行數:58,代碼來源:SSOFacade.java

示例7: getUsernameFromToken

import org.jose4j.jwt.JwtClaims; //導入方法依賴的package包/類
public String getUsernameFromToken(String token) throws InvalidJwtException {
    JwtConsumer jwtConsumer = new JwtConsumerBuilder().setEvaluationTime(NumericDate.now())
        .setVerificationKey(signatureKey).build();
    JwtClaims jwtClaims = jwtConsumer.processToClaims(token);
    return (String) jwtClaims.getClaimValue("username");
}
 
開發者ID:tosinoni,項目名稱:SECP,代碼行數:7,代碼來源:TokenController.java


注:本文中的org.jose4j.jwt.JwtClaims.getClaimValue方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。