Skip to content

Commit e45eb1f

Browse files
kazuki43zoojgrandja
authored andcommitted
Add isDebugEnabled
Fixes spring-atticgh-1040
1 parent c055eb6 commit e45eb1f

File tree

6 files changed

+37
-16
lines changed

6 files changed

+37
-16
lines changed

spring-security-oauth2/src/main/java/org/springframework/security/oauth2/client/token/OAuth2AccessTokenSupport.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
package org.springframework.security.oauth2.client.token;
22

3-
import java.io.IOException;
4-
import java.net.HttpURLConnection;
5-
import java.util.ArrayList;
6-
import java.util.Arrays;
7-
import java.util.List;
8-
93
import org.apache.commons.logging.Log;
104
import org.apache.commons.logging.LogFactory;
115
import org.springframework.http.HttpHeaders;
@@ -37,6 +31,12 @@
3731
import org.springframework.web.client.RestOperations;
3832
import org.springframework.web.client.RestTemplate;
3933

34+
import java.io.IOException;
35+
import java.net.HttpURLConnection;
36+
import java.util.ArrayList;
37+
import java.util.Arrays;
38+
import java.util.List;
39+
4040
/**
4141
* Base support logic for obtaining access tokens.
4242
*
@@ -218,6 +218,9 @@ public void doWithRequest(ClientHttpRequest request) throws IOException {
218218
request.getHeaders().putAll(this.headers);
219219
request.getHeaders().setAccept(
220220
Arrays.asList(MediaType.APPLICATION_JSON, MediaType.APPLICATION_FORM_URLENCODED));
221+
if (logger.isDebugEnabled()) {
222+
logger.debug("Encoding and sending form: " + form);
223+
}
221224
FORM_MESSAGE_CONVERTER.write(this.form, MediaType.APPLICATION_FORM_URLENCODED, request);
222225
}
223226
}

spring-security-oauth2/src/main/java/org/springframework/security/oauth2/provider/approval/JdbcApprovalStore.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,9 @@ public void setRefreshApprovalStatement(String refreshApprovalStatement) {
113113

114114
@Override
115115
public boolean addApprovals(final Collection<Approval> approvals) {
116-
logger.debug(String.format("adding approvals: [%s]", approvals));
116+
if (logger.isDebugEnabled()) {
117+
logger.debug(String.format("adding approvals: [%s]", approvals));
118+
}
117119
boolean success = true;
118120
for (Approval approval : approvals) {
119121
if (!updateApproval(refreshApprovalStatement, approval)) {
@@ -127,7 +129,9 @@ public boolean addApprovals(final Collection<Approval> approvals) {
127129

128130
@Override
129131
public boolean revokeApprovals(Collection<Approval> approvals) {
130-
logger.debug(String.format("Revoking approvals: [%s]", approvals));
132+
if (logger.isDebugEnabled()) {
133+
logger.debug(String.format("Revoking approvals: [%s]", approvals));
134+
}
131135
boolean success = true;
132136
for (final Approval approval : approvals) {
133137
if (handleRevocationsAsExpiry) {
@@ -171,7 +175,9 @@ public void setValues(PreparedStatement ps) throws SQLException {
171175
ps.setTimestamp(1, new Timestamp(new Date().getTime()));
172176
}
173177
});
174-
logger.debug(deleted + " expired approvals deleted");
178+
if (logger.isDebugEnabled()) {
179+
logger.debug(deleted + " expired approvals deleted");
180+
}
175181
}
176182
catch (DataAccessException ex) {
177183
logger.error("Error purging expired approvals", ex);
@@ -186,7 +192,9 @@ public List<Approval> getApprovals(String userName, String clientId) {
186192
}
187193

188194
private boolean updateApproval(final String sql, final Approval approval) {
189-
logger.debug(String.format("refreshing approval: [%s]", approval));
195+
if (logger.isDebugEnabled()) {
196+
logger.debug(String.format("refreshing approval: [%s]", approval));
197+
}
190198
int refreshed = jdbcTemplate.update(sql, new PreparedStatementSetter() {
191199
@Override
192200
public void setValues(PreparedStatement ps) throws SQLException {

spring-security-oauth2/src/main/java/org/springframework/security/oauth2/provider/approval/TokenStoreUserApprovalHandler.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,13 @@ public AuthorizationRequest checkForPreApproval(AuthorizationRequest authorizati
139139
}
140140

141141
OAuth2AccessToken accessToken = tokenStore.getAccessToken(authentication);
142-
logger.debug("Existing access token=" + accessToken);
142+
if (logger.isDebugEnabled()) {
143+
logger.debug("Existing access token=" + accessToken);
144+
}
143145
if (accessToken != null && !accessToken.isExpired()) {
144-
logger.debug("User already approved with token=" + accessToken);
146+
if (logger.isDebugEnabled()) {
147+
logger.debug("User already approved with token=" + accessToken);
148+
}
145149
// A token was already granted and is still valid, so this is already approved
146150
approved = true;
147151
}

spring-security-oauth2/src/main/java/org/springframework/security/oauth2/provider/endpoint/AuthorizationEndpoint.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,9 @@ public View approveOrDeny(@RequestParam Map<String, String> approvalParameters,
241241
// We need explicit approval from the user.
242242
private ModelAndView getUserApprovalPageResponse(Map<String, Object> model,
243243
AuthorizationRequest authorizationRequest, Authentication principal) {
244-
logger.debug("Loading user approval page: " + userApprovalPage);
244+
if (logger.isDebugEnabled()) {
245+
logger.debug("Loading user approval page: " + userApprovalPage);
246+
}
245247
model.putAll(userApprovalHandler.getUserApprovalRequest(authorizationRequest, principal));
246248
return new ModelAndView(userApprovalPage, model);
247249
}

spring-security-oauth2/src/main/java/org/springframework/security/oauth2/provider/token/AbstractTokenGranter.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,10 @@ public OAuth2AccessToken grant(String grantType, TokenRequest tokenRequest) {
5959
String clientId = tokenRequest.getClientId();
6060
ClientDetails client = clientDetailsService.loadClientByClientId(clientId);
6161
validateGrantType(grantType, client);
62-
63-
logger.debug("Getting access token for: " + clientId);
62+
63+
if (logger.isDebugEnabled()) {
64+
logger.debug("Getting access token for: " + clientId);
65+
}
6466

6567
return getAccessToken(client, tokenRequest);
6668

spring-security-oauth2/src/main/java/org/springframework/security/oauth2/provider/token/RemoteTokenServices.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,9 @@ public OAuth2Authentication loadAuthentication(String accessToken) throws Authen
106106
Map<String, Object> map = postForMap(checkTokenEndpointUrl, formData, headers);
107107

108108
if (map.containsKey("error")) {
109-
logger.debug("check_token returned error: " + map.get("error"));
109+
if (logger.isDebugEnabled()) {
110+
logger.debug("check_token returned error: " + map.get("error"));
111+
}
110112
throw new InvalidTokenException(accessToken);
111113
}
112114

0 commit comments

Comments
 (0)