Commit ab920aed authored by Brian Long's avatar Brian Long
Browse files

added OAuth filter logging

parent ab6b0d8d
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -74,11 +74,15 @@ public class OAuthAuthorizationCodeAuthorizationFilter extends OAuthAuthorizatio
	
	@Override
	protected Form createForm() {
		Form form = new Form().param("grant_type", "authorization_code")
				.param("code", this.code);
		Form form = new Form().param("grant_type", "authorization_code");
		if (this.redirectUri != null)
			form.param("redirect_uri", this.redirectUri.toString());
		return form;
	}
	
	@Override
	protected void extendFormSensitive(Form form) {
	    form.param("code", this.code);
	}

}
+25 −2
Original line number Diff line number Diff line
@@ -27,6 +27,9 @@ import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status.Family;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider;

/**
@@ -36,6 +39,8 @@ import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider;
 */
public abstract class OAuthAuthorizationFilter implements AuthorizationFilter {
	
    private final Logger logger = LoggerFactory.getLogger(this.getClass());
    
	private final String tokenUrl;
	private final String clientId;
	private final String clientSecret;
@@ -114,11 +119,20 @@ public abstract class OAuthAuthorizationFilter implements AuthorizationFilter {
		}

		form.param("client_id", this.clientId);
		if (this.clientSecret != null)
			form.param("client_secret", this.clientSecret);
		if (this.scope != null)
			form.param("scope", this.scope);
		
		this.logger.trace("Sending OAuth request: {}", form);
		
		if (this.refreshToken != null) {
		    this.extendRefreshFormSensitive(form);
		} else {
            this.extendFormSensitive(form);
		}

        if (this.clientSecret != null)
            form.param("client_secret", this.clientSecret);
		
		Entity<Form> entity = Entity.form(form);
		
		Client client = ClientBuilder.newBuilder()
@@ -128,9 +142,13 @@ public abstract class OAuthAuthorizationFilter implements AuthorizationFilter {

		Response response = target.request().post(entity);
		
        this.logger.debug("Received OAuth response: {}", response.getStatus());

        @SuppressWarnings("unchecked")
        Map<String, Object> responseMap = response.readEntity(Map.class);

        this.logger.trace("Received OAuth response: {}", responseMap);
		
		if (response.getStatusInfo().getFamily() != Family.SUCCESSFUL) {
            String code = (String) responseMap.get("error");
            if (code != null) {
@@ -153,4 +171,9 @@ public abstract class OAuthAuthorizationFilter implements AuthorizationFilter {
	
	protected abstract Form createForm();
	
	protected void extendRefreshFormSensitive(Form form) {
	}

    protected abstract void extendFormSensitive(Form form);

}
+4 −0
Original line number Diff line number Diff line
@@ -38,4 +38,8 @@ public class OAuthClientCredentialAuthorizationFilter extends OAuthAuthorization
		return new Form().param("grant_type", "client_credentials");
	}
	
	@Override
	protected void extendFormSensitive(Form form) {
	}

}
+6 −2
Original line number Diff line number Diff line
@@ -53,8 +53,12 @@ public class OAuthPasswordGrantAuthorizationFilter extends OAuthAuthorizationFil
	@Override
	protected Form createForm() {
		return new Form().param("grant_type", "password")
				.param("username", this.username)
				.param("password", this.password);
				.param("username", this.username);
	}
	
	@Override
	protected void extendFormSensitive(Form form) {
	    form.param("password", this.password);
	}

}