use of org.eclipse.microprofile.jwt.Claim in project smallrye-jwt by smallrye.
the class ProviderExtensionSupport 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) {
CDILogging.log.pip(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(CDIMessages.msg.claimHasNoNameOrValidStandardEnumSetting(ip));
}
boolean usesEnum = claim.standard() != Claims.UNKNOWN;
final String claimName = usesEnum ? claim.standard().name() : claim.value();
CDILogging.log.checkingProviderClaim(claimName, ip);
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 (isOptional(actualType)) {
// Validate that this is not an Optional<JsonValue>
Type innerType = ((ParameterizedType) actualType).getActualTypeArguments()[0];
if (!isJson(innerType)) {
providerOptionalTypes.add(actualType);
providerQualifiers.add(claim);
}
}
}
}
use of org.eclipse.microprofile.jwt.Claim in project smallrye-jwt by smallrye.
the class ProviderExtensionSupport method addTypeToClaimProducer.
/**
* Replace the general producer method BeanAttributes with one bound to the collected injection site
* types to properly reflect all of the type locations the producer method applies to.
*
* @param pba the ProcessBeanAttributes
* @see ProviderBeanAttributes
*/
public void addTypeToClaimProducer(@Observes ProcessBeanAttributes pba) {
if (!providerOptionalTypes.isEmpty() && pba.getAnnotated().isAnnotationPresent(Claim.class)) {
Claim claim = pba.getAnnotated().getAnnotation(Claim.class);
if (claim.value().length() == 0 && claim.standard() == Claims.UNKNOWN) {
CDILogging.log.addTypeToClaimProducer(pba.getAnnotated());
BeanAttributes delegate = pba.getBeanAttributes();
if (delegate.getTypes().contains(Optional.class)) {
pba.setBeanAttributes(new ProviderBeanAttributes(delegate, providerOptionalTypes, providerQualifiers));
}
}
}
}
use of org.eclipse.microprofile.jwt.Claim in project smallrye-jwt by smallrye.
the class RawClaimTypeProducer method getClaimAsSet.
@Produces
@Claim("")
Set<String> getClaimAsSet(InjectionPoint ip) {
CDILogging.log.getClaimAsSet(ip);
if (currentToken == null) {
return null;
}
String name = getName(ip);
return (Set<String>) JsonUtils.convert(Set.class, currentToken.getClaim(name));
}
use of org.eclipse.microprofile.jwt.Claim in project smallrye-jwt by smallrye.
the class RawClaimTypeProducer method getClaimAsBoolean.
@Produces
@Claim("")
Boolean getClaimAsBoolean(InjectionPoint ip) {
CDILogging.log.getClaimAsBoolean(ip);
if (currentToken == null) {
return null;
}
String name = getName(ip);
Optional<Object> optValue = currentToken.claim(name);
Boolean returnValue = null;
if (optValue.isPresent()) {
Object value = optValue.get();
if (value instanceof JsonValue) {
final JsonValue.ValueType valueType = ((JsonValue) value).getValueType();
if (valueType.equals(JsonValue.ValueType.TRUE)) {
returnValue = true;
} else if (valueType.equals(JsonValue.ValueType.FALSE)) {
returnValue = false;
}
} else {
returnValue = Boolean.valueOf(value.toString());
}
}
return returnValue;
}
use of org.eclipse.microprofile.jwt.Claim in project smallrye-jwt by smallrye.
the class RawClaimTypeProducer method getName.
static 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