RestfulOAuthService { public Token getAccessToken(OAuthCredentialsRest credentials) { Token token = null; ClientRequest request = new ClientRequest(casOAuthURL); request.formParameter("username", credentials.getUsername()); request.formParameter("password", credentials.getPassword()); request.formParameter("clientId", credentials.getKey()); request.formParameter("secret", credentials.getSecret()); try { ClientResponse<String> response = request.post(String.class); log.debug("Status code: {}", response.getStatus()); if (response.getStatus() == STATUS_SUCCESS) { Matcher matcher = Pattern.compile(".*action=\".*/(.*?)\".*").matcher(response.getEntity()); if (matcher.matches()) token = new Token(matcher.group(1), ""); } else { log.warn("Invalid response code {} from CAS server!", response.getStatus()); log.info("Response: {}", response.getEntity()); } response.releaseConnection(); } catch (Exception e) { log.error("Error while retrieving access token", e); } return token; } RestfulOAuthService(String casOAuthUrl); Token getAccessToken(OAuthCredentialsRest credentials); boolean removeAccessToken(String token);  }
@Test public void testGetAccessToken() { String casOAuthUrl = "https: RestfulOAuthService service = new RestfulOAuthService(casOAuthUrl); OAuthCredentialsRest credentials = new OAuthCredentialsRest("admin", "secret", "dummyClientName", "testservice1", "testsecret1"); Token accessToken = service.getAccessToken(credentials); assertNotNull(accessToken); }