added OAuth filter logging
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
@@ -127,9 +141,13 @@ public abstract class OAuthAuthorizationFilter implements AuthorizationFilter {
|
||||
WebTarget target = client.target(this.tokenUrl);
|
||||
|
||||
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");
|
||||
@@ -152,5 +170,10 @@ public abstract class OAuthAuthorizationFilter implements AuthorizationFilter {
|
||||
}
|
||||
|
||||
protected abstract Form createForm();
|
||||
|
||||
protected void extendRefreshFormSensitive(Form form) {
|
||||
}
|
||||
|
||||
protected abstract void extendFormSensitive(Form form);
|
||||
|
||||
}
|
||||
|
||||
@@ -37,5 +37,9 @@ public class OAuthClientCredentialAuthorizationFilter extends OAuthAuthorization
|
||||
protected Form createForm() {
|
||||
return new Form().param("grant_type", "client_credentials");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void extendFormSensitive(Form form) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user