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


Java MalformedClaimException类代码示例

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


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

示例1: SSOData

import org.jose4j.jwt.MalformedClaimException; //导入依赖的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.MalformedClaimException; //导入依赖的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: validateSharedResourceToken

import org.jose4j.jwt.MalformedClaimException; //导入依赖的package包/类
public static String validateSharedResourceToken(Key key, String jwt) {

        JwtConsumer jwtConsumer = new JwtConsumerBuilder()
                .setVerificationKey(key)
                .setRelaxVerificationKeyValidation()
                .build();

        try {
            JwtClaims jwtClaims = jwtConsumer.processToClaims(jwt);
            String subject = jwtClaims.getSubject();
            try (JsonReader reader = Json.createReader(new StringReader(subject))) {
                JsonObject subjectObject = reader.readObject(); // JsonParsingException
                return subjectObject.getString(SHARED_ENTITY_UUID); // Npe
            }
        } catch (InvalidJwtException | MalformedClaimException | JsonParsingException | NullPointerException e) {
            LOGGER.log(Level.SEVERE, "Cannot validate jwt token", e);
        }

        return null;

    }
 
开发者ID:polarsys,项目名称:eplmp,代码行数:22,代码来源:JWTokenFactory.java

示例4: validateEntityToken

import org.jose4j.jwt.MalformedClaimException; //导入依赖的package包/类
public static String validateEntityToken(Key key, String jwt) {

        JwtConsumer jwtConsumer = new JwtConsumerBuilder()
                .setVerificationKey(key)
                .setRelaxVerificationKeyValidation()
                .build();

        try {
            JwtClaims jwtClaims = jwtConsumer.processToClaims(jwt);
            String subject = jwtClaims.getSubject();
            try (JsonReader reader = Json.createReader(new StringReader(subject))) {
                JsonObject subjectObject = reader.readObject(); // JsonParsingException
                return subjectObject.getString(ENTITY_KEY); // Npe
            }
        } catch (InvalidJwtException | MalformedClaimException | JsonParsingException | NullPointerException e) {
            LOGGER.log(Level.SEVERE, "Cannot validate jwt token", e);
        }

        return null;

    }
 
开发者ID:polarsys,项目名称:eplmp,代码行数:22,代码来源:JWTokenFactory.java

示例5: validate

import org.jose4j.jwt.MalformedClaimException; //导入依赖的package包/类
@Override
public String validate(JwtContext jwtContext) throws MalformedClaimException
{
    JwtClaims jwtClaims = jwtContext.getJwtClaims();
    String subject = jwtClaims.getSubject();
    if (subject == null && requireSubject)
    {
        return "No Subject (sub) claim is present.";
    }
    else if (expectedSubject != null && !expectedSubject.equals(subject))
    {
        return "Subject (sub) claim value (" + subject + ") doesn't match expected value of " + expectedSubject;
    }

    return null;
}
 
开发者ID:RbkGh,项目名称:Jose4j,代码行数:17,代码来源:SubValidator.java

示例6: validate

import org.jose4j.jwt.MalformedClaimException; //导入依赖的package包/类
@Override
public String validate(JwtContext jwtContext) throws MalformedClaimException
{
    String issuer = jwtContext.getJwtClaims().getIssuer();

    if (issuer == null)
    {
        return requireIssuer ? "No Issuer (iss) claim present but was expecting " + expectedIssuer: null;
    }

    if (expectedIssuer != null && !issuer.equals(expectedIssuer))
    {
        return "Issuer (iss) claim value (" + issuer + ") doesn't match expected value of " + expectedIssuer;
    }

    return null;
}
 
开发者ID:RbkGh,项目名称:Jose4j,代码行数:18,代码来源:IssValidator.java

示例7: validateToken

import org.jose4j.jwt.MalformedClaimException; //导入依赖的package包/类
public static void validateToken(byte[] accessToken, String aud, int contentFormat) throws MalformedClaimException, JSONException, JoseException {

		if(contentFormat == MediaTypeRegistry.APPLICATION_JSON) {
			try
			{
			    JwtConsumer jwtConsumer = new JwtConsumerBuilder()
			        .setAllowedClockSkewInSeconds(30)
			        .setExpectedAudience(aud)
			        .setVerificationKey(config.getSignAndEncryptKey().getPublicKey())
			        .build();

			    //  Validate the JWT and process it to the Claims
			    JwtClaims jwtClaims = jwtConsumer.processToClaims(new String(accessToken));
			    
			    Assert.assertTrue(jwtClaims.getAudience().contains(aud));
			}
			catch (Exception e)
			{
				Assert.fail("Could not validate token.");
			}
		}
		else if(contentFormat == MediaTypeRegistry.APPLICATION_CBOR) {
			Assert.fail("Not implemented.");
		}
	}
 
开发者ID:erwah,项目名称:acetest,代码行数:26,代码来源:TestUtils.java

示例8: validateClaims

import org.jose4j.jwt.MalformedClaimException; //导入依赖的package包/类
@Override
protected Optional<String> validateClaims(JwtClaims jwtClaims) throws AuthenticationException {
    try {
        final String subject = jwtClaims.getSubject();
        if ("good-one".equals(subject)) {
            return Optional.of("good-one");
        }

        if ("bad-one".equals(subject)) {
            throw new AuthenticationException("server ran out of entropy");
        }
    } catch (MalformedClaimException e) {
        return Optional.absent();
    }

    return Optional.absent();
}
 
开发者ID:andban,项目名称:dropwizard-auth-jwt,代码行数:18,代码来源:BaseJwtAuthenticatorTest.java

示例9: authenticate

import org.jose4j.jwt.MalformedClaimException; //导入依赖的package包/类
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
    String ticket = (String) authentication.getPrincipal();

    try {
        Credential ut = jwtHelper.token2payload(ticket, Credential.class);

        if ("users.sign_in".equals(ut.getAction())) {
            User user = userService.findByToken(ut.getProvider(), ut.getToken());
            if (user != null) {
                List<GrantedAuthority> auths = new ArrayList<>();
                //todo
                return new UsernamePasswordAuthenticationToken(ut.getProvider(), ut.getToken(), auths);
            }

        }
        throw new BadCredentialsException(i18n.T("errors.user.bad_token"));


    } catch (InvalidJwtException | MalformedClaimException e) {
        throw new BadCredentialsException(i18n.T("errors.user.bad_token"), e);
    }
}
 
开发者ID:chonglou,项目名称:itpkg,代码行数:24,代码来源:AuthenticationProvider.java

示例10: token2payload

import org.jose4j.jwt.MalformedClaimException; //导入依赖的package包/类
public <T> T token2payload(String token, Class<T> clazz) throws InvalidJwtException, MalformedClaimException {
    if (!token.contains(token)) {
        return null;
    }
    JwtConsumer consumer = new JwtConsumerBuilder()
            .setRequireExpirationTime()
            .setAllowedClockSkewInSeconds(30)
            .setRequireSubject()
            .setExpectedIssuer(TOKEN_ISSUER)
            .setExpectedAudience(TOKEN_AUDIENCE)
            .setVerificationKey(getVerificationKey())
            .build();

    JwtClaims claims = consumer.processToClaims(token);
    return jsonHelper.json2object(claims.getClaimValue(CLAIM_KEY, String.class), clazz);
}
 
开发者ID:chonglou,项目名称:itpkg,代码行数:17,代码来源:JwtHelper.java

示例11: verify

import org.jose4j.jwt.MalformedClaimException; //导入依赖的package包/类
public Optional<String> verify(String securityToken) {
    try {
        JwtClaims jwtClaims = jwtConsumer.processToClaims(securityToken);
        return Optional.of(jwtClaims.getSubject());
    } catch (InvalidJwtException | MalformedClaimException e) {
        return Optional.empty();
    }
}
 
开发者ID:gchq,项目名称:stroom-stats,代码行数:9,代码来源:JwtVerifier.java

示例12: buildInternalJWTClaimsSet

import org.jose4j.jwt.MalformedClaimException; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public JwtClaims buildInternalJWTClaimsSet(final JwtClaims claims) {

    try {

        final JwtClaims newClaims = claims;
        newClaims.setSubject("internal-subject-" + newClaims.getSubject());
        newClaims.setStringListClaim(Qualifiers.ROLES, "users");
        return newClaims;
    } catch (final MalformedClaimException e) {
        throw new InternalServerErrorException(e);
    }
}
 
开发者ID:trajano,项目名称:app-ms,代码行数:17,代码来源:SampleInternalClaimsBuilder.java

示例13: JwtClaimsSetPrincipal

import org.jose4j.jwt.MalformedClaimException; //导入依赖的package包/类
/**
 * Build the principal using a map.
 *
 * @param claimsSet
 */
public JwtClaimsSetPrincipal(final JwtClaims claimsSet) {

    try {
        this.claimsSet = claimsSet;
        subject = claimsSet.getSubject();
        authority = String.format("%[email protected]%s", subject, URI.create(claimsSet.getIssuer()).getHost());

    } catch (final MalformedClaimException e) {
        throw new ExceptionInInitializerError(e);
    }
}
 
开发者ID:trajano,项目名称:app-ms,代码行数:17,代码来源:JwtClaimsSetPrincipal.java

示例14: JwtSecurityContext

import org.jose4j.jwt.MalformedClaimException; //导入依赖的package包/类
public JwtSecurityContext(final JwtClaims claims,
    final UriInfo uriInfo) {

    try {
        principal = new JwtClaimsSetPrincipal(claims);
        secure = "https".equals(uriInfo.getRequestUri().getScheme());

        roles = Collections.unmodifiableSet(claims.getStringListClaimValue(Qualifiers.ROLES).parallelStream().collect(Collectors.toSet()));
    } catch (final MalformedClaimException e) {
        throw new ExceptionInInitializerError(e);
    }
}
 
开发者ID:trajano,项目名称:app-ms,代码行数:13,代码来源:JwtSecurityContext.java

示例15: apply

import org.jose4j.jwt.MalformedClaimException; //导入依赖的package包/类
@Override
public Boolean apply(final JwtClaims claims) {

    try {
        return claimValue.equals(claims.getStringClaimValue(claimName));
    } catch (final MalformedClaimException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:trajano,项目名称:app-ms,代码行数:10,代码来源:InterceptorTest.java


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