@Test public void testAuthentication() throws HttpAction { final IpClient client = new IpClient(new SimpleTestTokenAuthenticator()); final MockWebContext context = MockWebContext.create(); context.setRemoteAddress(IP); final TokenCredentials credentials = client.getCredentials(context); final CommonProfile profile = client.getUserProfile(credentials, context); assertEquals(IP, profile.getId()); }
private void checkProfile(final DefaultRolesPermissionsAuthorizationGenerator generator) { final CommonProfile profile = new CommonProfile(); generator.generate(profile); final Set<String> roles = profile.getRoles(); assertEquals(2, roles.size()); assertTrue(roles.containsAll(DEFAULT_ROLES_LIST)); final Set<String> permissions = profile.getPermissions(); assertEquals(2, permissions.size()); assertTrue(permissions.containsAll(DEFAULT_PERMISSIONS_LIST)); }
@Override public void validate(final TokenCredentials credentials) throws HttpAction { if (credentials == null) { throw new CredentialsException("credentials must not be null"); } if (CommonHelper.isBlank(credentials.getToken())) { throw new CredentialsException("token must not be blank"); } final String token = credentials.getToken(); final CommonProfile profile = new CommonProfile(); profile.setId(token); credentials.setUserProfile(profile); }
@Test public void testAuthentication() throws RequiresHttpAction, UnsupportedEncodingException { final CookieClient client = new CookieClient(USERNAME, new SimpleTestTokenAuthenticator()); final MockWebContext context = MockWebContext.create(); final Cookie c = new Cookie( USERNAME, Base64.getEncoder() .encodeToString(getClass().getName().getBytes(HttpConstants.UTF8_ENCODING))); context.getRequestCookies().add(c); final TokenCredentials credentials = client.getCredentials(context); final CommonProfile profile = client.getUserProfile(credentials, context); assertEquals(c.getValue(), profile.getId()); }
private void checkEmptyProfile(final DefaultRolesPermissionsAuthorizationGenerator generator) { final CommonProfile profile = new CommonProfile(); generator.generate(profile); assertEquals(0, profile.getRoles().size()); assertEquals(0, profile.getPermissions().size()); }