Search in sources :

Example 1 with Claims

use of org.eclipse.microprofile.jwt.Claims in project tomee by apache.

the class JWTCallerPrincipal method getClaim.

@Override
public Object getClaim(final String claimName) {
    Claims claimType = Claims.UNKNOWN;
    Object claim = null;
    try {
        claimType = Claims.valueOf(claimName);
    } catch (IllegalArgumentException e) {
    }
    // Handle the jose4j NumericDate types and
    switch(claimType) {
        case auth_time:
        case updated_at:
            try {
                claim = claimsSet.getClaimValue(claimType.name(), Long.class);
                if (claim == null) {
                    claim = 0L;
                }
            } catch (final MalformedClaimException e) {
                logger.log(Level.FINEST, "Can't retrieve 'updated_at' a malformed claim.", e);
            }
            break;
        case groups:
            claim = getGroups();
            break;
        case aud:
            claim = getAudience();
            break;
        case UNKNOWN:
            claim = claimsSet.getClaimValue(claimName);
            break;
        default:
            claim = claimsSet.getClaimValue(claimType.name());
    }
    return claim;
}
Also used : JwtClaims(org.jose4j.jwt.JwtClaims) Claims(org.eclipse.microprofile.jwt.Claims) MalformedClaimException(org.jose4j.jwt.MalformedClaimException) JsonObject(javax.json.JsonObject)

Example 2 with Claims

use of org.eclipse.microprofile.jwt.Claims in project wildfly-swarm by wildfly-swarm.

the class DefaultJWTCallerPrincipal method getClaim.

@Override
public Object getClaim(String claimName) {
    Claims claimType = Claims.UNKNOWN;
    Object claim = null;
    try {
        claimType = Claims.valueOf(claimName);
    } catch (IllegalArgumentException e) {
    }
    // Handle the jose4j NumericDate types and
    switch(claimType) {
        case exp:
        case iat:
        case auth_time:
        case nbf:
        case updated_at:
            try {
                claim = claimsSet.getClaimValue(claimType.name(), Long.class);
                if (claim == null) {
                    claim = new Long(0);
                }
            } catch (MalformedClaimException e) {
            }
            break;
        case groups:
            claim = getGroups();
            break;
        case aud:
            claim = getAudience();
            break;
        case UNKNOWN:
            claim = claimsSet.getClaimValue(claimName);
            break;
        default:
            claim = claimsSet.getClaimValue(claimType.name());
    }
    return claim;
}
Also used : JwtClaims(org.jose4j.jwt.JwtClaims) Claims(org.eclipse.microprofile.jwt.Claims) MalformedClaimException(org.jose4j.jwt.MalformedClaimException) JsonObject(javax.json.JsonObject)

Example 3 with Claims

use of org.eclipse.microprofile.jwt.Claims in project smallrye-jwt by smallrye.

the class DefaultJWTCallerPrincipal method getClaimValue.

@Override
protected Object getClaimValue(String claimName) {
    Claims claimType = getClaimType(claimName);
    Object claim = null;
    // Handle the jose4j NumericDate types and
    switch(claimType) {
        case exp:
        case iat:
        case auth_time:
        case nbf:
        case updated_at:
            try {
                claim = claimsSet.getClaimValue(claimType.name(), Long.class);
                if (claim == null) {
                    claim = 0L;
                }
            } catch (MalformedClaimException e) {
                PrincipalLogging.log.getGroupsFailure(claimName, e);
            }
            break;
        case groups:
            claim = getGroups();
            break;
        case aud:
            claim = getAudience();
            break;
        case UNKNOWN:
            claim = claimsSet.getClaimValue(claimName);
            break;
        default:
            claim = claimsSet.getClaimValue(claimType.name());
    }
    return claim;
}
Also used : JwtClaims(org.jose4j.jwt.JwtClaims) Claims(org.eclipse.microprofile.jwt.Claims) MalformedClaimException(org.jose4j.jwt.MalformedClaimException)

Aggregations

Claims (org.eclipse.microprofile.jwt.Claims)3 JwtClaims (org.jose4j.jwt.JwtClaims)3 MalformedClaimException (org.jose4j.jwt.MalformedClaimException)3 JsonObject (javax.json.JsonObject)2