本文整理汇总了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);
}
示例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);
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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.");
}
}
示例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();
}
示例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);
}
}
示例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);
}
示例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();
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}