use of org.eclipse.microprofile.jwt.Claim in project Payara by payara.
the class JwtAuthCdiExtension 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(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 MPJWTExtension 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 ClaimProviderBeanAttributes
*/
public void addTypeToClaimProducer(@Observes ProcessBeanAttributes pba) {
if (pba.getAnnotated().isAnnotationPresent(Claim.class)) {
Claim claim = pba.getAnnotated().getAnnotation(Claim.class);
if (claim.value().length() == 0 && claim.standard() == Claims.UNKNOWN) {
log.debugf("addTypeToClaimProducer: %s\n", pba.getAnnotated());
BeanAttributes delegate = pba.getBeanAttributes();
String name = delegate.getName();
if (delegate.getTypes().contains(Optional.class)) {
if (providerOptionalTypes.size() == 0) {
providerOptionalTypes.add(Optional.class);
}
pba.setBeanAttributes(new ClaimProviderBeanAttributes(delegate, providerOptionalTypes, providerQualifiers));
// This is
} else if (name != null && name.startsWith("RawClaimTypeProducer#")) {
if (rawTypes.size() == 0) {
rawTypes.add(Object.class);
}
pba.setBeanAttributes(new ClaimProviderBeanAttributes(delegate, rawTypes, rawTypeQualifiers));
log.debugf("Setup RawClaimTypeProducer BeanAttributes");
}
}
}
}
use of org.eclipse.microprofile.jwt.Claim in project wildfly-swarm by wildfly-swarm.
the class ClaimValueProducer method produce.
@Produces
@Claim("")
ClaimValue<T> produce(InjectionPoint ip) {
String name = getName(ip);
ClaimValue<Optional<T>> cv = MPJWTProducer.generalClaimValueProducer(name);
ClaimValue<T> returnValue = (ClaimValue<T>) cv;
Optional<T> value = cv.getValue();
// Pull out the ClaimValue<T> T type,
Type matchType = ip.getType();
Type actualType = Object.class;
boolean isOptional = false;
if (matchType instanceof ParameterizedType) {
actualType = ((ParameterizedType) matchType).getActualTypeArguments()[0];
isOptional = matchType.getTypeName().equals(Optional.class.getTypeName());
if (isOptional) {
actualType = ((ParameterizedType) matchType).getActualTypeArguments()[0];
}
}
if (!actualType.getTypeName().startsWith(Optional.class.getTypeName())) {
T nestedValue = value.orElse(null);
ClaimValueWrapper<T> wrapper = new ClaimValueWrapper<>(cv.getName());
wrapper.setValue(nestedValue);
returnValue = wrapper;
}
return returnValue;
}
use of org.eclipse.microprofile.jwt.Claim in project wildfly-swarm by wildfly-swarm.
the class ClaimValueProducer 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 smallrye-jwt by smallrye.
the class RawClaimTypeProducer method getClaimAsDouble.
@Produces
@Claim("")
Double getClaimAsDouble(InjectionPoint ip) {
CDILogging.log.getClaimAsDouble(ip);
if (currentToken == null) {
return null;
}
String name = getName(ip);
Optional<Object> optValue = currentToken.claim(name);
Double returnValue = null;
if (optValue.isPresent()) {
Object value = optValue.get();
if (value instanceof JsonNumber) {
JsonNumber jsonValue = (JsonNumber) value;
returnValue = jsonValue.doubleValue();
} else {
returnValue = Double.parseDouble(value.toString());
}
}
return returnValue;
}
Aggregations