/* ============================================================
 * AuthClient.java
 * ============================================================
 * Copyright 2013 University of Alberta
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============================================================ 
 */
package ca.ualberta.physics.cssdp.client;

import static com.jayway.restassured.RestAssured.get;
import static com.jayway.restassured.RestAssured.given;

import javax.ws.rs.WebApplicationException;

import ca.ualberta.physics.cssdp.configuration.Common;
import ca.ualberta.physics.cssdp.domain.auth.User;
import ca.ualberta.physics.cssdp.service.ServiceResponse;

import com.jayway.restassured.RestAssured;
import com.jayway.restassured.response.Response;

public class AuthClient {

	private String authUrl = Common.properties().getString("auth.api.url");

	public ServiceResponse<String> login(String username, String password) {

		Response res = given().auth().preemptive().basic(username, password)
				.post(authUrl + "/session.json");

		ServiceResponse<String> sr = new ServiceResponse<String>();
		if (res.getStatusCode() == 200) {
			sr.setPayload(res.asString());
		} else {
			sr.error("Invalid login credentials");
		}
		return sr;
	}

	public void validate(String sessionToken) {

		Response res = RestAssured.get(authUrl + "/session.json/"
				+ sessionToken + "/whois");

		if (res.statusCode() != 200) {
			throw new WebApplicationException(404);
		}
	}

	public User addUser(User newUser) {

		String location = given().content(newUser).and()
				.contentType("application/json").post(authUrl + "/user.json")
				.getHeader("location");

		User user = get(location).as(User.class);
		user.setPassword(newUser.getPassword());
		return user;

	}

	public User whois(String sessionToken) {
		Response res = RestAssured.get(authUrl + "/session.json/"
				+ sessionToken + "/whois");
		if (res.getStatusCode() == 200) {
			return res.as(User.class);
		} else {
			throw new WebApplicationException(404);
		}
	}
}

@@ -998,24 +998,82 @@
 Exception;%0A%0A
+import org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0A%0A
 import ca.ua
@@ -1345,16 +1345,102 @@
 ient %7B%0A%0A
+%09private static final Logger logger = LoggerFactory%0A%09%09%09.getLogger(AuthClient.class);%0A%0A
 %09private
@@ -1576,24 +1576,73 @@
 assword) %7B%0A%0A
+%09%09logger.debug(%22Authenticating at %22 + authUrl);%0A%0A
 %09%09Response r

add logging to debug ftp on server