Anonymous type can be replaced with lambda
This commit is contained in:
committed by
Josh Cummings
parent
05f42a4995
commit
fb39d9c255
@@ -16,13 +16,11 @@
|
||||
|
||||
package org.springframework.security.web;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Proxy;
|
||||
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
@@ -48,11 +46,8 @@ import org.springframework.security.web.util.UrlUtils;
|
||||
public class FilterInvocation {
|
||||
// ~ Static fields
|
||||
// ==================================================================================================
|
||||
static final FilterChain DUMMY_CHAIN = new FilterChain() {
|
||||
public void doFilter(ServletRequest req, ServletResponse res)
|
||||
throws IOException, ServletException {
|
||||
throw new UnsupportedOperationException("Dummy filter chain");
|
||||
}
|
||||
static final FilterChain DUMMY_CHAIN = (req, res) -> {
|
||||
throw new UnsupportedOperationException("Dummy filter chain");
|
||||
};
|
||||
|
||||
// ~ Instance fields
|
||||
|
||||
+4
-7
@@ -27,7 +27,6 @@ import org.springframework.security.web.AuthenticationEntryPoint;
|
||||
import org.springframework.security.web.savedrequest.HttpSessionRequestCache;
|
||||
import org.springframework.security.web.savedrequest.RequestCache;
|
||||
import org.springframework.security.web.util.ThrowableAnalyzer;
|
||||
import org.springframework.security.web.util.ThrowableCauseExtractor;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.web.filter.GenericFilterBean;
|
||||
|
||||
@@ -241,12 +240,10 @@ public class ExceptionTranslationFilter extends GenericFilterBean {
|
||||
protected void initExtractorMap() {
|
||||
super.initExtractorMap();
|
||||
|
||||
registerExtractor(ServletException.class, new ThrowableCauseExtractor() {
|
||||
public Throwable extractCause(Throwable throwable) {
|
||||
ThrowableAnalyzer.verifyThrowableHierarchy(throwable,
|
||||
ServletException.class);
|
||||
return ((ServletException) throwable).getRootCause();
|
||||
}
|
||||
registerExtractor(ServletException.class, throwable -> {
|
||||
ThrowableAnalyzer.verifyThrowableHierarchy(throwable,
|
||||
ServletException.class);
|
||||
return ((ServletException) throwable).getRootCause();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
+2
-10
@@ -18,11 +18,8 @@ package org.springframework.security.web.authentication.rememberme;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.dao.EmptyResultDataAccessException;
|
||||
import org.springframework.dao.IncorrectResultSizeDataAccessException;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
import org.springframework.jdbc.core.support.JdbcDaoSupport;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
@@ -85,13 +82,8 @@ public class JdbcTokenRepositoryImpl extends JdbcDaoSupport implements
|
||||
public PersistentRememberMeToken getTokenForSeries(String seriesId) {
|
||||
try {
|
||||
return getJdbcTemplate().queryForObject(tokensBySeriesSql,
|
||||
new RowMapper<PersistentRememberMeToken>() {
|
||||
public PersistentRememberMeToken mapRow(ResultSet rs, int rowNum)
|
||||
throws SQLException {
|
||||
return new PersistentRememberMeToken(rs.getString(1), rs
|
||||
.getString(2), rs.getString(3), rs.getTimestamp(4));
|
||||
}
|
||||
}, seriesId);
|
||||
(rs, rowNum) -> new PersistentRememberMeToken(rs.getString(1), rs
|
||||
.getString(2), rs.getString(3), rs.getTimestamp(4)), seriesId);
|
||||
}
|
||||
catch (EmptyResultDataAccessException zeroResults) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
|
||||
+4
-6
@@ -91,11 +91,9 @@ public class JaasApiIntegrationFilter extends GenericFilterBean {
|
||||
chain.doFilter(request, response);
|
||||
return;
|
||||
}
|
||||
final PrivilegedExceptionAction<Object> continueChain = new PrivilegedExceptionAction<Object>() {
|
||||
public Object run() throws IOException, ServletException {
|
||||
chain.doFilter(request, response);
|
||||
return null;
|
||||
}
|
||||
final PrivilegedExceptionAction<Object> continueChain = () -> {
|
||||
chain.doFilter(request, response);
|
||||
return null;
|
||||
};
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
@@ -160,4 +158,4 @@ public class JaasApiIntegrationFilter extends GenericFilterBean {
|
||||
public final void setCreateEmptySubject(boolean createEmptySubject) {
|
||||
this.createEmptySubject = createEmptySubject;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
@@ -65,6 +65,7 @@ public abstract class ServerWebExchangeMatchers {
|
||||
* Matches any exchange
|
||||
* @return the matcher to use
|
||||
*/
|
||||
@SuppressWarnings("Convert2Lambda")
|
||||
public static ServerWebExchangeMatcher anyExchange() {
|
||||
// we don't use a lambda to ensure a unique equals and hashcode
|
||||
// which otherwise can cause problems with adding multiple entries to an ordered LinkedHashMap
|
||||
|
||||
+5
-10
@@ -96,17 +96,12 @@ public class ConcurrentSessionFilter extends GenericFilterBean {
|
||||
() -> expiredUrl + " isn't a valid redirect URL");
|
||||
this.expiredUrl = expiredUrl;
|
||||
this.sessionRegistry = sessionRegistry;
|
||||
this.sessionInformationExpiredStrategy = new SessionInformationExpiredStrategy() {
|
||||
|
||||
@Override
|
||||
public void onExpiredSessionDetected(SessionInformationExpiredEvent event) throws IOException, ServletException {
|
||||
HttpServletRequest request = event.getRequest();
|
||||
HttpServletResponse response = event.getResponse();
|
||||
SessionInformation info = event.getSessionInformation();
|
||||
|
||||
redirectStrategy.sendRedirect(request, response, determineExpiredUrl(request, info));
|
||||
}
|
||||
this.sessionInformationExpiredStrategy = event -> {
|
||||
HttpServletRequest request = event.getRequest();
|
||||
HttpServletResponse response = event.getResponse();
|
||||
SessionInformation info = event.getSessionInformation();
|
||||
|
||||
redirectStrategy.sendRedirect(request, response, determineExpiredUrl(request, info));
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -40,22 +40,16 @@ public class ThrowableAnalyzer {
|
||||
*
|
||||
* @see Throwable#getCause()
|
||||
*/
|
||||
public static final ThrowableCauseExtractor DEFAULT_EXTRACTOR = new ThrowableCauseExtractor() {
|
||||
public Throwable extractCause(Throwable throwable) {
|
||||
return throwable.getCause();
|
||||
}
|
||||
};
|
||||
public static final ThrowableCauseExtractor DEFAULT_EXTRACTOR = throwable -> throwable.getCause();
|
||||
|
||||
/**
|
||||
* Default extractor for {@link InvocationTargetException} instances.
|
||||
*
|
||||
* @see InvocationTargetException#getTargetException()
|
||||
*/
|
||||
public static final ThrowableCauseExtractor INVOCATIONTARGET_EXTRACTOR = new ThrowableCauseExtractor() {
|
||||
public Throwable extractCause(Throwable throwable) {
|
||||
verifyThrowableHierarchy(throwable, InvocationTargetException.class);
|
||||
return ((InvocationTargetException) throwable).getTargetException();
|
||||
}
|
||||
public static final ThrowableCauseExtractor INVOCATIONTARGET_EXTRACTOR = throwable -> {
|
||||
verifyThrowableHierarchy(throwable, InvocationTargetException.class);
|
||||
return ((InvocationTargetException) throwable).getTargetException();
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -64,21 +58,16 @@ public class ThrowableAnalyzer {
|
||||
* greater by this comparator.<br>
|
||||
* For hierarchically unrelated classes their fully qualified name will be compared.
|
||||
*/
|
||||
private static final Comparator<Class<? extends Throwable>> CLASS_HIERARCHY_COMPARATOR = new Comparator<Class<? extends Throwable>>() {
|
||||
|
||||
public int compare(Class<? extends Throwable> class1,
|
||||
Class<? extends Throwable> class2) {
|
||||
if (class1.isAssignableFrom(class2)) {
|
||||
return 1;
|
||||
}
|
||||
else if (class2.isAssignableFrom(class1)) {
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
return class1.getName().compareTo(class2.getName());
|
||||
}
|
||||
private static final Comparator<Class<? extends Throwable>> CLASS_HIERARCHY_COMPARATOR = (class1, class2) -> {
|
||||
if (class1.isAssignableFrom(class2)) {
|
||||
return 1;
|
||||
}
|
||||
else if (class2.isAssignableFrom(class1)) {
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
return class1.getName().compareTo(class2.getName());
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user