org.eclipse.microprofile.jwt.ClaimValue Java Examples
The following examples show how to use
org.eclipse.microprofile.jwt.ClaimValue.
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 File: JWTExtension.java From hammock with Apache License 2.0 | 5 votes |
@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 #2
Source File: ClaimValueProducerIT.java From smallrye-jwt with Apache License 2.0 | 5 votes |
@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 #3
Source File: ClaimValueProducerIT.java From smallrye-jwt with Apache License 2.0 | 5 votes |
@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 File: ClaimValueProducerIT.java From smallrye-jwt with Apache License 2.0 | 5 votes |
@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 #5
Source File: ClaimValueProducerIT.java From smallrye-jwt with Apache License 2.0 | 5 votes |
@Test public void testIssuerNull() { ClaimValue<String> issuer = selectClaimValue("iss"); assertNotNull(issuer); assertEquals("iss", issuer.getName()); assertNull(issuer.getValue()); }
Example #6
Source File: ClaimInjectionTest.java From smallrye-jwt with Apache License 2.0 | 4 votes |
ClaimValue<Set<String>> getSetClaimValue() { return setClaimValue; }
Example #7
Source File: ClaimValueProducerIT.java From smallrye-jwt with Apache License 2.0 | 4 votes |
@SuppressWarnings({ "serial" }) <T> ClaimValue<Optional<T>> selectOptionalClaimValue(String name) { return weld.select(new TypeLiteral<ClaimValue<Optional<T>>>() { }, new ClaimQualifier(name, null)).get(); }
Example #8
Source File: ClaimValueProducerIT.java From smallrye-jwt with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") <T> ClaimValue<T> selectClaimValue(String name) { return weld.select(ClaimValue.class, new ClaimQualifier(name, null)).get(); }
Example #9
Source File: ClaimInjectionTest.java From smallrye-jwt with Apache License 2.0 | 4 votes |
ClaimValue<Optional<JsonObject>> getAddressClaimValueOptionalJson() { return addressClaimValueOptionalJson; }
Example #10
Source File: ClaimInjectionTest.java From smallrye-jwt with Apache License 2.0 | 4 votes |
ClaimValue<JsonObject> getAddressClaimValueJson() { return addressClaimValueJson; }
Example #11
Source File: ClaimInjectionTest.java From smallrye-jwt with Apache License 2.0 | 4 votes |
ClaimValue<Optional<Address>> getAddressClaimValueOptional() { return addressClaimValueOptional; }
Example #12
Source File: ClaimInjectionTest.java From smallrye-jwt with Apache License 2.0 | 4 votes |
ClaimValue<Address> getAddressClaimValue() { return addressClaimValue; }
Example #13
Source File: ClaimInjectionTest.java From smallrye-jwt with Apache License 2.0 | 4 votes |
ClaimValue<Optional<JsonArray>> getSetClaimValueOptionalJson() { return setClaimValueOptionalJson; }
Example #14
Source File: ClaimInjectionTest.java From smallrye-jwt with Apache License 2.0 | 4 votes |
ClaimValue<JsonArray> getSetClaimValueJson() { return setClaimValueJson; }
Example #15
Source File: ClaimInjectionTest.java From smallrye-jwt with Apache License 2.0 | 4 votes |
ClaimValue<Optional<Set<String>>> getSetClaimValueOptional() { return setClaimValueOptional; }
Example #16
Source File: ClaimValueProducer.java From smallrye-jwt with Apache License 2.0 | 4 votes |
@Produces @Claim("") <T> ClaimValue<T> produceClaim(InjectionPoint ip) { return new ClaimValueWrapper<>(ip, util); }
Example #17
Source File: ClaimInjectionTest.java From smallrye-jwt with Apache License 2.0 | 4 votes |
ClaimValue<Optional<JsonString>> getStringClaimValueOptionalJson() { return stringClaimValueOptionalJson; }
Example #18
Source File: ClaimInjectionTest.java From smallrye-jwt with Apache License 2.0 | 4 votes |
ClaimValue<JsonString> getStringClaimValueJson() { return stringClaimValueJson; }
Example #19
Source File: ClaimInjectionTest.java From smallrye-jwt with Apache License 2.0 | 4 votes |
ClaimValue<Optional<String>> getStringClaimValueOptional() { return stringClaimValueOptional; }
Example #20
Source File: ClaimInjectionTest.java From smallrye-jwt with Apache License 2.0 | 4 votes |
ClaimValue<String> getStringClaimValue() { return stringClaimValue; }
Example #21
Source File: ClaimInjectionTest.java From smallrye-jwt with Apache License 2.0 | 4 votes |
ClaimValue<Optional<JsonNumber>> getLongClaimValueOptionalJson() { return longClaimValueOptionalJson; }
Example #22
Source File: ClaimInjectionTest.java From smallrye-jwt with Apache License 2.0 | 4 votes |
ClaimValue<JsonNumber> getLongClaimValueJson() { return longClaimValueJson; }
Example #23
Source File: ClaimInjectionTest.java From smallrye-jwt with Apache License 2.0 | 4 votes |
ClaimValue<Optional<Long>> getLongClaimValueOptional() { return longClaimValueOptional; }
Example #24
Source File: ClaimInjectionTest.java From smallrye-jwt with Apache License 2.0 | 4 votes |
ClaimValue<Long> getLongClaimValue() { return longClaimValue; }
Example #25
Source File: ClaimInjectionTest.java From smallrye-jwt with Apache License 2.0 | 4 votes |
ClaimValue<Optional<JsonValue>> getBooleanClaimValueOptionalJson() { return booleanClaimValueOptionalJson; }
Example #26
Source File: ClaimInjectionTest.java From smallrye-jwt with Apache License 2.0 | 4 votes |
ClaimValue<JsonValue> getBooleanClaimValueJson() { return booleanClaimValueJson; }
Example #27
Source File: ClaimInjectionTest.java From smallrye-jwt with Apache License 2.0 | 4 votes |
ClaimValue<Optional<Boolean>> getBooleanClaimValueOptional() { return booleanClaimValueOptional; }
Example #28
Source File: ClaimInjectionTest.java From smallrye-jwt with Apache License 2.0 | 4 votes |
ClaimValue<Boolean> getBooleanClaimValue() { return booleanClaimValue; }
Example #29
Source File: ClaimValueWrapper.java From smallrye-jwt with Apache License 2.0 | 4 votes |
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; }