/** Test apply on a List. */ @Test public void apply_onList() { List<Integer> args = Arrays.asList(argsArray); List<Integer> expected = Arrays.asList(expectedArray); List<Integer> actual = AdapterUtils.apply(args, filter); Assert.assertEquals(expected, actual); }
protected void completeAuthentication(BearerTokenRequestAuthenticator bearer, String method) { RefreshableKeycloakSecurityContext session = new RefreshableKeycloakSecurityContext( deployment, null, bearer.getTokenString(), bearer.getToken(), null, null, null); final KeycloakPrincipal<RefreshableKeycloakSecurityContext> principal = new KeycloakPrincipal<RefreshableKeycloakSecurityContext>( AdapterUtils.getPrincipalName(deployment, bearer.getToken()), session); completeBearerAuthentication(principal, method); }
public static KeycloakPrincipal<RefreshableKeycloakSecurityContext> getPrincipalFromCookie( KeycloakDeployment deployment, HttpFacade facade, AdapterTokenStore tokenStore) { OIDCHttpFacade.Cookie cookie = facade.getRequest().getCookie(AdapterConstants.KEYCLOAK_ADAPTER_STATE_COOKIE); if (cookie == null) { log.debug("Not found adapter state cookie in current request"); return null; } String cookieVal = cookie.getValue(); String[] tokens = cookieVal.split(DELIM); if (tokens.length != 3) { log.warnf( "Invalid format of %s cookie. Count of tokens: %s, expected 3", AdapterConstants.KEYCLOAK_ADAPTER_STATE_COOKIE, tokens.length); return null; } String accessTokenString = tokens[0]; String idTokenString = tokens[1]; String refreshTokenString = tokens[2]; try { // Skip check if token is active now. It's supposed to be done later by the caller AccessToken accessToken = AdapterRSATokenVerifier.verifyToken(accessTokenString, deployment, false, true); IDToken idToken; if (idTokenString != null && idTokenString.length() > 0) { try { JWSInput input = new JWSInput(idTokenString); idToken = input.readJsonContent(IDToken.class); } catch (JWSInputException e) { throw new VerificationException(e); } } else { idToken = null; } log.debug("Token Verification succeeded!"); RefreshableKeycloakSecurityContext secContext = new RefreshableKeycloakSecurityContext( deployment, tokenStore, accessTokenString, accessToken, idTokenString, idToken, refreshTokenString); return new KeycloakPrincipal<RefreshableKeycloakSecurityContext>( AdapterUtils.getPrincipalName(deployment, accessToken), secContext); } catch (VerificationException ve) { log.warn("Failed verify token", ve); return null; } }
/** Test apply on a tree. */ @Test public void apply_onTree() { Tree<Integer> tree = new Tree<Integer>(10); tree.setName("tree"); // $NON-NLS-1$ tree.add(1); tree.add(-2); Tree<Integer> result = AdapterUtils.apply(tree, filter); Assert.assertNotNull(result.getAnyNodeOf((1))); Assert.assertNull(result.getAnyNodeOf(-2)); }
/** Test apply on a Set. */ @Test public void apply_onSet() { Set<Integer> set = new HashSet<Integer>(); set.add(-8); set.add(0); set.add(5); set.add(3); Set<Integer> result = AdapterUtils.apply(set, filter); Assert.assertEquals(2, result.size()); Assert.assertTrue(result.contains(3)); Assert.assertTrue(result.contains(5)); }
/** Test concat. */ @SuppressWarnings("nls") @Test public void testConcat() { @SuppressWarnings("rawtypes") List<Class> list = new ArrayList<Class>(); list.add(Integer.class); list.add(String.class); list.add(Class.class); String actual = AdapterUtils.concat(list, "name", Class.class, "-"); String expected = "java.lang.Integer-java.lang.String-java.lang.Class"; Assert.assertEquals(expected, actual); }
/** Test getName. */ @Test public void testGetName() { @SuppressWarnings("rawtypes") List<Class> list = new ArrayList<Class>(); list.add(Integer.class); list.add(String.class); list.add(Class.class); List<String> names = AdapterUtils.getName(list, Class.class); Assert.assertEquals(3, names.size()); for (int i = 0; i < list.size(); i++) { Assert.assertEquals(list.get(i).getName(), names.get(i)); } }
/** Test apply on a Set. */ @Test public void apply_onMap() { Map<Integer, Integer> map = new HashMap<Integer, Integer>(); int[] numbers = {-8, -12, 0, 5, 8}; for (int i = 0; i < numbers.length; i++) { map.put(numbers[i], numbers[i]); } Map<Integer, Integer> result = AdapterUtils.apply(map, filter); Assert.assertEquals(numbers.length, result.size()); Assert.assertEquals(null, result.get(-8)); Assert.assertEquals(null, result.get(-12)); Assert.assertEquals(null, result.get(0)); Assert.assertEquals(new Integer(5), result.get(5)); Assert.assertEquals(new Integer(8), result.get(8)); }
protected void completeAuthentication(OAuthRequestAuthenticator oauth) { RefreshableKeycloakSecurityContext session = new RefreshableKeycloakSecurityContext( deployment, tokenStore, oauth.getTokenString(), oauth.getToken(), oauth.getIdTokenString(), oauth.getIdToken(), oauth.getRefreshToken()); final KeycloakPrincipal<RefreshableKeycloakSecurityContext> principal = new KeycloakPrincipal<RefreshableKeycloakSecurityContext>( AdapterUtils.getPrincipalName(deployment, oauth.getToken()), session); completeOAuthAuthentication(principal); }
public static Object invoke( final Method method, final ObjectAdapter adapter, final ObjectAdapter[] argumentAdapters) { return MethodExtensions.invoke( method, AdapterUtils.unwrap(adapter), AdapterUtils.unwrap(argumentAdapters)); }
public static Object invoke( final Method method, final ObjectAdapter adapter, final ObjectAdapter arg0Adapter) { return invoke(method, adapter, AdapterUtils.unwrap(arg0Adapter)); }
public static Object invoke(final Method method, final ObjectAdapter adapter, final Object arg0) { return MethodExtensions.invoke(method, AdapterUtils.unwrap(adapter), new Object[] {arg0}); }
public static void invokeAll(final List<Method> methods, final ObjectAdapter adapter) { MethodUtil.invoke(methods, AdapterUtils.unwrap(adapter)); }
/** Test apply on an array. */ @Test public void apply_onArray() { Integer[] actuals = AdapterUtils.apply(argsArray, new Integer[0], filter); Assert.assertArrayEquals(expectedArray, actuals); }
/** Test apply on a tree. */ @Test public void apply_voidOnCollection() { Object[] objects = {new Object(), new Object()}; List<Object> list = Arrays.asList(objects); AdapterUtils.apply(list, print); }
/** Test apply on a tree. */ @Test public void apply_voidOnArray() { Object[] objects = {new Object(), new Object()}; AdapterUtils.apply(objects, print); }