-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Better logging support by id in RequestMatcher #6308
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
import org.springframework.security.access.SecurityConfig; | ||
import org.springframework.security.config.annotation.web.HttpSecurityBuilder; | ||
import org.springframework.security.config.annotation.web.configurers.AbstractConfigAttributeRequestMatcherRegistry.UrlMapping; | ||
import org.springframework.security.web.util.matcher.AbstractRequestMatcher; | ||
import org.springframework.security.web.util.matcher.RequestMatcher; | ||
|
||
/** | ||
|
@@ -64,7 +65,7 @@ public static void permitAll( | |
} | ||
} | ||
|
||
private final static class ExactUrlRequestMatcher implements RequestMatcher { | ||
private final static class ExactUrlRequestMatcher extends AbstractRequestMatcher { | ||
private String processUrl; | ||
|
||
private ExactUrlRequestMatcher(String processUrl) { | ||
|
@@ -89,11 +90,11 @@ public boolean matches(HttpServletRequest request) { | |
@Override | ||
public String toString() { | ||
StringBuilder sb = new StringBuilder(); | ||
sb.append("ExactUrl [processUrl='").append(processUrl).append("']"); | ||
sb.append("ExactUrl [processUrl='").append(processUrl).append("', id=").append(getId()).append("]"); | ||
return sb.toString(); | ||
} | ||
} | ||
|
||
private PermitAllSupport() { | ||
} | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's use the existing formatter so this does not occur |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,25 +15,27 @@ | |
*/ | ||
package org.springframework.security.web; | ||
|
||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
import org.springframework.security.web.util.matcher.RequestMatcher; | ||
|
||
import javax.servlet.Filter; | ||
import javax.servlet.http.HttpServletRequest; | ||
import java.util.*; | ||
|
||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
|
||
import org.springframework.security.web.util.matcher.RequestMatcher; | ||
|
||
/** | ||
* Standard implementation of {@code SecurityFilterChain}. | ||
* | ||
* @author Luke Taylor | ||
* | ||
* @since 3.1 | ||
*/ | ||
public final class DefaultSecurityFilterChain implements SecurityFilterChain { | ||
public final class DefaultSecurityFilterChain implements SecurityFilterChain{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's use the existing formatter so this does not occur |
||
private static final Log logger = LogFactory.getLog(DefaultSecurityFilterChain.class); | ||
private final RequestMatcher requestMatcher; | ||
private final List<Filter> filters; | ||
private String beanName; | ||
|
||
public DefaultSecurityFilterChain(RequestMatcher requestMatcher, Filter... filters) { | ||
this(requestMatcher, Arrays.asList(filters)); | ||
|
@@ -61,4 +63,5 @@ public boolean matches(HttpServletRequest request) { | |
public String toString() { | ||
return "[ " + requestMatcher + ", " + filters + "]"; | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's use the existing formatter so this does not occur There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you mean by existing formatter?? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I meant, these whitespaces means that the code formatter we have used for this PR does not match the one used originally. Formatter can also mean any settings in your IDE that indents/formats/structures code. Please see the section on whitespaces in contributing guidelines. Hope this helps |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright 2002-2018 the original author or authors. | ||
* | ||
* 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 org.springframework.security.web.util.matcher; | ||
|
||
|
||
import java.util.UUID; | ||
/** | ||
* Abstract simple strategy to match an <tt>HttpServletRequest</tt>. | ||
* | ||
* @author Ankur Pathak | ||
* @since 5.2.0 | ||
*/ | ||
public abstract class AbstractRequestMatcher implements RequestMatcher { | ||
private final String id; | ||
|
||
public AbstractRequestMatcher(String id) { | ||
this.id = id; | ||
} | ||
|
||
public AbstractRequestMatcher() { | ||
this(UUID.randomUUID().toString().replace("-", "").substring(0, 8)); | ||
} | ||
|
||
@Override | ||
public String getId() { | ||
return id; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "RequestMatcher{" + | ||
"id='" + id + '\'' + | ||
'}'; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,6 @@ | |
|
||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
import org.springframework.security.web.util.matcher.RequestMatcher; | ||
import org.springframework.util.Assert; | ||
|
||
/** | ||
|
@@ -32,7 +31,7 @@ | |
* @author Rob Winch | ||
* @since 3.2 | ||
*/ | ||
public final class AndRequestMatcher implements RequestMatcher { | ||
public final class AndRequestMatcher extends AbstractRequestMatcher { | ||
private final Log logger = LogFactory.getLog(getClass()); | ||
|
||
private final List<RequestMatcher> requestMatchers; | ||
|
@@ -76,6 +75,6 @@ public boolean matches(HttpServletRequest request) { | |
|
||
@Override | ||
public String toString() { | ||
return "AndRequestMatcher [requestMatchers=" + requestMatchers + "]"; | ||
return "AndRequestMatcher [requestMatchers=" + requestMatchers + ", id=" + getId()+"]"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is code formatted correctly? |
||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can live away with String builder now, by-default string concatenations internally invoke string builder only. Plus it will result in cleaner code