class RestfulOAuthService {

	public Token getAccessToken(OAuthCredentialsRest credentials) {
		Token token = null;
		ClientRequest request = new ClientRequest(casOAuthURL);
		// String params = "username=" + credentials.getUsername() + "&password=" +
		// credentials.getPassword() + "&clientId=" + credentials.getKey() + "&secret="
		// + credentials.getSecret();
		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);
			// Read output in string format
			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;
	}

	public  RestfulOAuthService(String casOAuthUrl);

}