Search in sources :

Example 1 with Claim

use of org.eclipse.microprofile.jwt.Claim in project Payara by payara.

the class CdiExtension method checkInjectIntoRightScope.

public <T> void checkInjectIntoRightScope(@Observes ProcessInjectionTarget<T> eventIn, BeanManager beanManager) {
    // JDK8 u60 workaround
    ProcessInjectionTarget<T> event = eventIn;
    for (InjectionPoint injectionPoint : event.getInjectionTarget().getInjectionPoints()) {
        Claim claim = hasClaim(injectionPoint);
        if (claim != null) {
            // MP-JWT 1.0 7.1.3.
            Bean<?> bean = injectionPoint.getBean();
            Class<?> scope = bean != null ? injectionPoint.getBean().getScope() : null;
            if (scope != null && (scope.equals(ApplicationScoped.class) || scope.equals(SessionScoped.class))) {
                throw new DeploymentException("Can't inject using qualifier " + Claim.class + " in a target with scope " + scope);
            }
            if (!claim.value().equals("") && claim.standard() != UNKNOWN && !claim.value().equals(claim.standard().name())) {
                throw new DeploymentException("Claim value " + claim.value() + " should be equal to claim standard " + claim.standard().name() + " or one of those should be left at their default value");
            }
        }
    }
}
Also used : SessionScoped(javax.enterprise.context.SessionScoped) InjectionPoint(javax.enterprise.inject.spi.InjectionPoint) DeploymentException(javax.enterprise.inject.spi.DeploymentException) ApplicationScoped(javax.enterprise.context.ApplicationScoped) Claim(org.eclipse.microprofile.jwt.Claim)

Example 2 with Claim

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

the class JsonValueProducer method getName.

String getName(InjectionPoint ip) {
    String name = null;
    for (Annotation ann : ip.getQualifiers()) {
        if (ann instanceof Claim) {
            Claim claim = (Claim) ann;
            name = claim.standard() == Claims.UNKNOWN ? claim.value() : claim.standard().name();
        }
    }
    return name;
}
Also used : JsonString(javax.json.JsonString) Annotation(java.lang.annotation.Annotation) Claim(org.eclipse.microprofile.jwt.Claim)

Example 3 with Claim

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

the class MPJWTExtension method processClaimInjections.

/**
 * Handle the non-{@linkplain Provider}, {@linkplain org.eclipse.microprofile.jwt.ClaimValue}, and
 * {@linkplain javax.json.JsonValue} claim injection types.
 * @see RawClaimTypeProducer
 *
 * @param pip - the injection point event information
 */
void processClaimInjections(@Observes ProcessInjectionPoint pip) {
    log.debugf("pipRaw: %s", pip.getInjectionPoint());
    InjectionPoint ip = pip.getInjectionPoint();
    if (ip.getAnnotated().isAnnotationPresent(Claim.class)) {
        Claim claim = ip.getAnnotated().getAnnotation(Claim.class);
        if (ip.getType() instanceof Class) {
            Class rawClass = (Class) ip.getType();
            // Primative types
            if (Modifier.isFinal(rawClass.getModifiers())) {
                rawTypes.add(ip.getType());
                rawTypeQualifiers.add(claim);
                log.debugf("+++ Added Claim raw type: %s", ip.getType());
                Class declaringClass = ip.getMember().getDeclaringClass();
                Annotation[] appScoped = declaringClass.getAnnotationsByType(ApplicationScoped.class);
                Annotation[] sessionScoped = declaringClass.getAnnotationsByType(SessionScoped.class);
                if ((appScoped != null && appScoped.length > 0) || (sessionScoped != null && sessionScoped.length > 0)) {
                    String err = String.format("A raw type cannot be injected into application/session scope: IP=%s", ip);
                    pip.addDefinitionError(new DeploymentException(err));
                }
            }
        // This handles collections of primative types
        } else if (isRawParameterizedType(ip.getType())) {
            log.debugf("+++ Added Claim ParameterizedType: %s", ip.getType());
            rawTypes.add(ip.getType());
            rawTypeQualifiers.add(claim);
        }
    } else {
        log.debugf("Skipping pip: %s, type: %s/%s", ip, ip.getType(), ip.getType().getClass());
    }
}
Also used : ProcessInjectionPoint(javax.enterprise.inject.spi.ProcessInjectionPoint) InjectionPoint(javax.enterprise.inject.spi.InjectionPoint) DeploymentException(javax.enterprise.inject.spi.DeploymentException) Claim(org.eclipse.microprofile.jwt.Claim) Annotation(java.lang.annotation.Annotation)

Example 4 with Claim

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

the class MPJWTExtension method processClaimProviderInjections.

/**
 * Collect the types of all {@linkplain Provider} injection points annotated with {@linkplain Claim}.
 *
 * @param pip - the injection point event information
 */
void processClaimProviderInjections(@Observes ProcessInjectionPoint<?, ? extends Provider> pip) {
    log.debugf("pip: %s", pip.getInjectionPoint());
    final InjectionPoint ip = pip.getInjectionPoint();
    if (ip.getAnnotated().isAnnotationPresent(Claim.class)) {
        Claim claim = ip.getAnnotated().getAnnotation(Claim.class);
        if (claim.value().length() == 0 && claim.standard() == Claims.UNKNOWN) {
            pip.addDefinitionError(new DeploymentException("@Claim at: " + ip + " has no name or valid standard enum setting"));
        }
        boolean usesEnum = claim.standard() != Claims.UNKNOWN;
        final String claimName = usesEnum ? claim.standard().name() : claim.value();
        log.debugf("Checking Provider Claim(%s), ip: %s", claimName, ip);
        ClaimIP claimIP = claims.get(claimName);
        Type matchType = ip.getType();
        // The T from the Provider<T> injection site
        Type actualType = ((ParameterizedType) matchType).getActualTypeArguments()[0];
        // Don't add Optional or JsonValue as this is handled specially
        if (!optionalOrJsonValue(actualType)) {
            rawTypes.add(actualType);
        } else if (!actualType.getTypeName().startsWith("javax.json.Json")) {
            // Validate that this is not an Optional<JsonValue>
            Type innerType = ((ParameterizedType) actualType).getActualTypeArguments()[0];
            if (!innerType.getTypeName().startsWith("javax.json.Json")) {
                providerOptionalTypes.add(actualType);
                providerQualifiers.add(claim);
            }
        }
        rawTypeQualifiers.add(claim);
        ClaimIPType key = new ClaimIPType(claimName, actualType);
        if (claimIP == null) {
            claimIP = new ClaimIP(actualType, actualType, false, claim);
            claimIP.setProviderSite(true);
            claims.put(key, claimIP);
        }
        claimIP.getInjectionPoints().add(ip);
        log.debugf("+++ Added Provider Claim(%s) ip: %s", claimName, ip);
    }
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) ProcessInjectionPoint(javax.enterprise.inject.spi.ProcessInjectionPoint) InjectionPoint(javax.enterprise.inject.spi.InjectionPoint) DeploymentException(javax.enterprise.inject.spi.DeploymentException) Claim(org.eclipse.microprofile.jwt.Claim)

Example 5 with Claim

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

the class RawClaimTypeProducer method getName.

String getName(InjectionPoint ip) {
    String name = null;
    for (Annotation ann : ip.getQualifiers()) {
        if (ann instanceof Claim) {
            Claim claim = (Claim) ann;
            name = claim.standard() == Claims.UNKNOWN ? claim.value() : claim.standard().name();
        }
    }
    return name;
}
Also used : Annotation(java.lang.annotation.Annotation) Claim(org.eclipse.microprofile.jwt.Claim)

Aggregations

Claim (org.eclipse.microprofile.jwt.Claim)10 Annotation (java.lang.annotation.Annotation)5 InjectionPoint (javax.enterprise.inject.spi.InjectionPoint)5 ParameterizedType (java.lang.reflect.ParameterizedType)3 Type (java.lang.reflect.Type)3 DeploymentException (javax.enterprise.inject.spi.DeploymentException)3 Optional (java.util.Optional)2 ApplicationScoped (javax.enterprise.context.ApplicationScoped)2 ProcessInjectionPoint (javax.enterprise.inject.spi.ProcessInjectionPoint)2 JsonObject (javax.json.JsonObject)2 JsonString (javax.json.JsonString)2 ClaimValue (org.eclipse.microprofile.jwt.ClaimValue)2 JWTAuthenticationMechanism (fish.payara.microprofile.jwtauth.eesecurity.JWTAuthenticationMechanism)1 SignedJWTIdentityStore (fish.payara.microprofile.jwtauth.eesecurity.SignedJWTIdentityStore)1 ClaimAnnotationLiteral (fish.payara.microprofile.jwtauth.jwt.ClaimAnnotationLiteral)1 ClaimValueImpl (fish.payara.microprofile.jwtauth.jwt.ClaimValueImpl)1 JWTInjectableType (fish.payara.microprofile.jwtauth.jwt.JWTInjectableType)1 JsonWebTokenImpl (fish.payara.microprofile.jwtauth.jwt.JsonWebTokenImpl)1 Arrays.asList (java.util.Arrays.asList)1 Collections (java.util.Collections)1