Java Code Examples for org.eclipse.microprofile.jwt.ClaimValue

The following examples show how to use org.eclipse.microprofile.jwt.ClaimValue. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: smallrye-jwt   Source File: ClaimValueProducerIT.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testIssuerNull() {
    ClaimValue<String> issuer = selectClaimValue("iss");
    assertNotNull(issuer);
    assertEquals("iss", issuer.getName());
    assertNull(issuer.getValue());
}
 
Example 2
Source Project: smallrye-jwt   Source File: ClaimValueProducerIT.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testIssuerInjected() {
    jwtProducer = weld.select(PrincipalProducer.class).get();
    jwtProducer.setJsonWebToken(jwt);
    Mockito.when(jwt.claim(Claims.iss.name())).thenReturn(Optional.of("issuer1"));
    ClaimValue<String> issuer = selectClaimValue("iss");

    assertNotNull(issuer);
    assertEquals("iss", issuer.getName());
    assertEquals("issuer1", issuer.getValue());
}
 
Example 3
Source Project: smallrye-jwt   Source File: ClaimValueProducerIT.java    License: Apache License 2.0 5 votes vote down vote up
@Test(expected = NoSuchElementException.class)
public void testOptionalIssuerNotPresent() {
    ClaimValue<Optional<String>> issuer = selectOptionalClaimValue("iss");

    assertNotNull(issuer);
    assertEquals("iss", issuer.getName());
    assertTrue(!issuer.getValue().isPresent());
    issuer.getValue().get();
}
 
Example 4
Source Project: smallrye-jwt   Source File: ClaimValueProducerIT.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testOptionalIssuerInjected() {
    jwtProducer = weld.select(PrincipalProducer.class).get();
    jwtProducer.setJsonWebToken(jwt);
    Mockito.when(jwt.claim(Claims.iss.name())).thenReturn(Optional.of("issuer1"));
    ClaimValue<Optional<String>> issuer = selectOptionalClaimValue("iss");

    assertNotNull(issuer);
    assertEquals("iss", issuer.getName());
    assertTrue(issuer.getValue().isPresent());
    assertEquals("issuer1", issuer.getValue().get());
}
 
Example 5
Source Project: hammock   Source File: JWTExtension.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Object apply(CreationalContext<Object> cc, BiFunctionBean<?> bean) {
    BeanManager beanManager = CDI.current().getBeanManager();
    InjectionPoint ip = (InjectionPoint) beanManager.getInjectableReference(new EmptyInjectionPoint(bean), cc);
    ClaimDefinition claimDefinition = toDefinition(ip);
    JWTPrincipal jwtPrincipal = CDI.current().select(JWTPrincipal.class).get();
    HammockClaimValue value = new HammockClaimValue<>(jwtPrincipal, claimDefinition);
    if (claimDefinition.returnType instanceof ParameterizedType &&
            ((Class)((ParameterizedType)claimDefinition.returnType).getRawType()).isAssignableFrom(ClaimValue.class)) {
        return value;
    }
    else {
        return value.getValue();
    }
}
 
Example 6
Source Project: smallrye-jwt   Source File: ClaimValueProducer.java    License: Apache License 2.0 4 votes vote down vote up
@Produces
@Claim("")
<T> ClaimValue<T> produceClaim(InjectionPoint ip) {
    return new ClaimValueWrapper<>(ip, util);
}
 
Example 7
Source Project: smallrye-jwt   Source File: ClaimValueWrapper.java    License: Apache License 2.0 4 votes vote down vote up
private Class<?> unwrapType(final Type type, final InjectionPoint injectionPoint) {
    if (type instanceof ParameterizedType) {
        final ParameterizedType parameterizedType = (ParameterizedType) type;
        if (parameterizedType.getActualTypeArguments().length == 1) {
            final Type rawType = parameterizedType.getRawType();
            final Type actualType = parameterizedType.getActualTypeArguments()[0];

            if (rawType == ClaimValue.class) {
                return unwrapType(actualType, injectionPoint);
            }

            if (rawType == Optional.class) {
                // Needs to be improved, so we don't have a separate boolean flag if Optional. Kept this way to minimize code changes.
                return unwrapType(actualType, injectionPoint);
            }

            if (rawType instanceof Class && Set.class.isAssignableFrom((Class<?>) rawType)) {
                return (Class<?>) rawType;
            }

            if (rawType == Provider.class || rawType == Instance.class) {
                return unwrapType(actualType, injectionPoint);
            }
        }
    } else if (type instanceof Class) {
        final Class<?> klass = (Class<?>) type;
        if (Long.class.isAssignableFrom(klass) || klass == long.class ||
                Boolean.class.isAssignableFrom(klass) || klass == boolean.class ||
                String.class.isAssignableFrom(klass) ||
                JsonValue.class.isAssignableFrom(klass) ||
                ClaimValue.class.isAssignableFrom(klass) ||
                Optional.class.isAssignableFrom(klass)) {

            return klass;
        }
    }

    // We should throw DeploymentException here, but we never had validation on supported injection types, do it is
    // possible to inject non supported types as long as you get the right type from the claim set.
    //throw new DeploymentException("Type " + type + " not supported for @ClaimValue injection " + injectionPoint);
    return null;
}
 
Example 8
Source Project: smallrye-jwt   Source File: ClaimInjectionTest.java    License: Apache License 2.0 4 votes vote down vote up
ClaimValue<Boolean> getBooleanClaimValue() {
    return booleanClaimValue;
}
 
Example 9
Source Project: smallrye-jwt   Source File: ClaimInjectionTest.java    License: Apache License 2.0 4 votes vote down vote up
ClaimValue<Optional<Boolean>> getBooleanClaimValueOptional() {
    return booleanClaimValueOptional;
}
 
Example 10
Source Project: smallrye-jwt   Source File: ClaimInjectionTest.java    License: Apache License 2.0 4 votes vote down vote up
ClaimValue<JsonValue> getBooleanClaimValueJson() {
    return booleanClaimValueJson;
}
 
Example 11
Source Project: smallrye-jwt   Source File: ClaimInjectionTest.java    License: Apache License 2.0 4 votes vote down vote up
ClaimValue<Optional<JsonValue>> getBooleanClaimValueOptionalJson() {
    return booleanClaimValueOptionalJson;
}
 
Example 12
Source Project: smallrye-jwt   Source File: ClaimInjectionTest.java    License: Apache License 2.0 4 votes vote down vote up
ClaimValue<Long> getLongClaimValue() {
    return longClaimValue;
}
 
Example 13
Source Project: smallrye-jwt   Source File: ClaimInjectionTest.java    License: Apache License 2.0 4 votes vote down vote up
ClaimValue<Optional<Long>> getLongClaimValueOptional() {
    return longClaimValueOptional;
}
 
Example 14
Source Project: smallrye-jwt   Source File: ClaimInjectionTest.java    License: Apache License 2.0 4 votes vote down vote up
ClaimValue<JsonNumber> getLongClaimValueJson() {
    return longClaimValueJson;
}
 
Example 15
Source Project: smallrye-jwt   Source File: ClaimInjectionTest.java    License: Apache License 2.0 4 votes vote down vote up
ClaimValue<Optional<JsonNumber>> getLongClaimValueOptionalJson() {
    return longClaimValueOptionalJson;
}
 
Example 16
Source Project: smallrye-jwt   Source File: ClaimInjectionTest.java    License: Apache License 2.0 4 votes vote down vote up
ClaimValue<String> getStringClaimValue() {
    return stringClaimValue;
}
 
Example 17
Source Project: smallrye-jwt   Source File: ClaimInjectionTest.java    License: Apache License 2.0 4 votes vote down vote up
ClaimValue<Optional<String>> getStringClaimValueOptional() {
    return stringClaimValueOptional;
}
 
Example 18
Source Project: smallrye-jwt   Source File: ClaimInjectionTest.java    License: Apache License 2.0 4 votes vote down vote up
ClaimValue<JsonString> getStringClaimValueJson() {
    return stringClaimValueJson;
}
 
Example 19
Source Project: smallrye-jwt   Source File: ClaimInjectionTest.java    License: Apache License 2.0 4 votes vote down vote up
ClaimValue<Optional<JsonString>> getStringClaimValueOptionalJson() {
    return stringClaimValueOptionalJson;
}
 
Example 20
Source Project: smallrye-jwt   Source File: ClaimInjectionTest.java    License: Apache License 2.0 4 votes vote down vote up
ClaimValue<Set<String>> getSetClaimValue() {
    return setClaimValue;
}
 
Example 21
Source Project: smallrye-jwt   Source File: ClaimInjectionTest.java    License: Apache License 2.0 4 votes vote down vote up
ClaimValue<Optional<Set<String>>> getSetClaimValueOptional() {
    return setClaimValueOptional;
}
 
Example 22
Source Project: smallrye-jwt   Source File: ClaimInjectionTest.java    License: Apache License 2.0 4 votes vote down vote up
ClaimValue<JsonArray> getSetClaimValueJson() {
    return setClaimValueJson;
}
 
Example 23
Source Project: smallrye-jwt   Source File: ClaimInjectionTest.java    License: Apache License 2.0 4 votes vote down vote up
ClaimValue<Optional<JsonArray>> getSetClaimValueOptionalJson() {
    return setClaimValueOptionalJson;
}
 
Example 24
Source Project: smallrye-jwt   Source File: ClaimInjectionTest.java    License: Apache License 2.0 4 votes vote down vote up
ClaimValue<Address> getAddressClaimValue() {
    return addressClaimValue;
}
 
Example 25
Source Project: smallrye-jwt   Source File: ClaimInjectionTest.java    License: Apache License 2.0 4 votes vote down vote up
ClaimValue<Optional<Address>> getAddressClaimValueOptional() {
    return addressClaimValueOptional;
}
 
Example 26
Source Project: smallrye-jwt   Source File: ClaimInjectionTest.java    License: Apache License 2.0 4 votes vote down vote up
ClaimValue<JsonObject> getAddressClaimValueJson() {
    return addressClaimValueJson;
}
 
Example 27
Source Project: smallrye-jwt   Source File: ClaimInjectionTest.java    License: Apache License 2.0 4 votes vote down vote up
ClaimValue<Optional<JsonObject>> getAddressClaimValueOptionalJson() {
    return addressClaimValueOptionalJson;
}
 
Example 28
Source Project: smallrye-jwt   Source File: ClaimValueProducerIT.java    License: Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
<T> ClaimValue<T> selectClaimValue(String name) {
    return weld.select(ClaimValue.class, new ClaimQualifier(name, null)).get();
}
 
Example 29
Source Project: smallrye-jwt   Source File: ClaimValueProducerIT.java    License: Apache License 2.0 4 votes vote down vote up
@SuppressWarnings({ "serial" })
<T> ClaimValue<Optional<T>> selectOptionalClaimValue(String name) {
    return weld.select(new TypeLiteral<ClaimValue<Optional<T>>>() {
    },
            new ClaimQualifier(name, null)).get();
}