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");
}
}
}
}
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;
}
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());
}
}
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);
}
}
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;
}
Aggregations