Skip to content

Commit fb39d9c

Browse files
larsgreferjzheaux
authored andcommitted
Anonymous type can be replaced with lambda
1 parent 05f42a4 commit fb39d9c

File tree

53 files changed

+355
-730
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+355
-730
lines changed

acl/src/main/java/org/springframework/security/acls/jdbc/BasicLookupStrategy.java

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import java.io.Serializable;
1919
import java.lang.reflect.Field;
20-
import java.sql.PreparedStatement;
2120
import java.sql.ResultSet;
2221
import java.sql.SQLException;
2322
import java.util.ArrayList;
@@ -33,7 +32,6 @@
3332
import org.springframework.core.convert.ConversionException;
3433
import org.springframework.core.convert.ConversionService;
3534
import org.springframework.jdbc.core.JdbcTemplate;
36-
import org.springframework.jdbc.core.PreparedStatementSetter;
3735
import org.springframework.jdbc.core.ResultSetExtractor;
3836
import org.springframework.security.acls.domain.AccessControlEntryImpl;
3937
import org.springframework.security.acls.domain.AclAuthorizationStrategy;
@@ -248,14 +246,12 @@ private void lookupPrimaryKeys(final Map<Serializable, Acl> acls,
248246
String sql = computeRepeatingSql(lookupPrimaryKeysWhereClause, findNow.size());
249247

250248
Set<Long> parentsToLookup = jdbcTemplate.query(sql,
251-
new PreparedStatementSetter() {
252-
public void setValues(PreparedStatement ps) throws SQLException {
253-
int i = 0;
254-
255-
for (Long toFind : findNow) {
256-
i++;
257-
ps.setLong(i, toFind);
258-
}
249+
ps -> {
250+
int i = 0;
251+
252+
for (Long toFind : findNow) {
253+
i++;
254+
ps.setLong(i, toFind);
259255
}
260256
}, new ProcessResultSet(acls, sids));
261257

@@ -383,22 +379,20 @@ private Map<ObjectIdentity, Acl> lookupObjectIdentities(
383379
objectIdentities.size());
384380

385381
Set<Long> parentsToLookup = jdbcTemplate.query(sql,
386-
new PreparedStatementSetter() {
387-
public void setValues(PreparedStatement ps) throws SQLException {
388-
int i = 0;
389-
for (ObjectIdentity oid : objectIdentities) {
390-
// Determine prepared statement values for this iteration
391-
String type = oid.getType();
392-
393-
// No need to check for nulls, as guaranteed non-null by
394-
// ObjectIdentity.getIdentifier() interface contract
395-
String identifier = oid.getIdentifier().toString();
396-
397-
// Inject values
398-
ps.setString((2 * i) + 1, identifier);
399-
ps.setString((2 * i) + 2, type);
400-
i++;
401-
}
382+
ps -> {
383+
int i = 0;
384+
for (ObjectIdentity oid : objectIdentities) {
385+
// Determine prepared statement values for this iteration
386+
String type = oid.getType();
387+
388+
// No need to check for nulls, as guaranteed non-null by
389+
// ObjectIdentity.getIdentifier() interface contract
390+
String identifier = oid.getIdentifier().toString();
391+
392+
// Inject values
393+
ps.setString((2 * i) + 1, identifier);
394+
ps.setString((2 * i) + 2, type);
395+
i++;
402396
}
403397
}, new ProcessResultSet(acls, sids));
404398

acl/src/main/java/org/springframework/security/acls/jdbc/JdbcAclService.java

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
package org.springframework.security.acls.jdbc;
1717

1818
import java.io.Serializable;
19-
import java.sql.ResultSet;
20-
import java.sql.SQLException;
2119
import java.util.Arrays;
2220
import java.util.List;
2321
import java.util.Map;
@@ -29,7 +27,6 @@
2927
import org.springframework.core.convert.ConversionService;
3028
import org.springframework.jdbc.core.JdbcOperations;
3129
import org.springframework.jdbc.core.JdbcTemplate;
32-
import org.springframework.jdbc.core.RowMapper;
3330
import org.springframework.security.acls.domain.ObjectIdentityImpl;
3431
import org.springframework.security.acls.model.Acl;
3532
import org.springframework.security.acls.model.AclService;
@@ -95,14 +92,11 @@ public JdbcAclService(JdbcOperations jdbcOperations, LookupStrategy lookupStrate
9592
public List<ObjectIdentity> findChildren(ObjectIdentity parentIdentity) {
9693
Object[] args = { parentIdentity.getIdentifier().toString(), parentIdentity.getType() };
9794
List<ObjectIdentity> objects = jdbcOperations.query(findChildrenSql, args,
98-
new RowMapper<ObjectIdentity>() {
99-
public ObjectIdentity mapRow(ResultSet rs, int rowNum)
100-
throws SQLException {
101-
String javaType = rs.getString("class");
102-
Serializable identifier = (Serializable) rs.getObject("obj_id");
103-
identifier = aclClassIdUtils.identifierFrom(identifier, rs);
104-
return new ObjectIdentityImpl(javaType, identifier);
105-
}
95+
(rs, rowNum) -> {
96+
String javaType = rs.getString("class");
97+
Serializable identifier = (Serializable) rs.getObject("obj_id");
98+
identifier = aclClassIdUtils.identifierFrom(identifier, rs);
99+
return new ObjectIdentityImpl(javaType, identifier);
106100
});
107101

108102
if (objects.size() == 0) {

aspects/src/main/java/org/springframework/security/access/intercept/aspectj/aspect/AnnotationSecurityAspect.aj

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,7 @@ public aspect AnnotationSecurityAspect implements InitializingBean {
7272
return proceed();
7373
}
7474

75-
AspectJCallback callback = new AspectJCallback() {
76-
public Object proceedWithObject() {
77-
return proceed();
78-
}
79-
};
75+
AspectJCallback callback = () -> proceed();
8076

8177
return this.securityInterceptor.invoke(thisJoinPoint, callback);
8278
}

cas/src/test/java/org/springframework/security/cas/web/CasAuthenticationFilterTests.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,7 @@ public void testNormalOperation() throws Exception {
6767
request.addParameter("ticket", "ST-0-ER94xMJmn6pha35CQRoZ");
6868

6969
CasAuthenticationFilter filter = new CasAuthenticationFilter();
70-
filter.setAuthenticationManager(new AuthenticationManager() {
71-
public Authentication authenticate(Authentication a) {
72-
return a;
73-
}
74-
});
70+
filter.setAuthenticationManager(a -> a);
7571

7672
assertThat(filter.requiresAuthentication(request, new MockHttpServletResponse())).isTrue();
7773

@@ -83,10 +79,8 @@ public Authentication authenticate(Authentication a) {
8379
@Test(expected = AuthenticationException.class)
8480
public void testNullServiceTicketHandledGracefully() throws Exception {
8581
CasAuthenticationFilter filter = new CasAuthenticationFilter();
86-
filter.setAuthenticationManager(new AuthenticationManager() {
87-
public Authentication authenticate(Authentication a) {
88-
throw new BadCredentialsException("Rejected");
89-
}
82+
filter.setAuthenticationManager(a -> {
83+
throw new BadCredentialsException("Rejected");
9084
});
9185

9286
filter.attemptAuthentication(new MockHttpServletRequest(),

config/src/main/java/org/springframework/security/config/annotation/web/builders/WebSecurity.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,7 @@ public final class WebSecurity extends
9999

100100
private SecurityExpressionHandler<FilterInvocation> expressionHandler = defaultWebSecurityExpressionHandler;
101101

102-
private Runnable postBuildAction = new Runnable() {
103-
public void run() {
104-
}
102+
private Runnable postBuildAction = () -> {
105103
};
106104

107105
/**

config/src/main/java/org/springframework/security/config/annotation/web/configuration/WebSecurityConfigurerAdapter.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -320,12 +320,10 @@ protected UserDetailsService userDetailsService() {
320320

321321
public void init(final WebSecurity web) throws Exception {
322322
final HttpSecurity http = getHttp();
323-
web.addSecurityFilterChainBuilder(http).postBuildAction(new Runnable() {
324-
public void run() {
325-
FilterSecurityInterceptor securityInterceptor = http
326-
.getSharedObject(FilterSecurityInterceptor.class);
327-
web.securityInterceptor(securityInterceptor);
328-
}
323+
web.addSecurityFilterChainBuilder(http).postBuildAction(() -> {
324+
FilterSecurityInterceptor securityInterceptor = http
325+
.getSharedObject(FilterSecurityInterceptor.class);
326+
web.securityInterceptor(securityInterceptor);
329327
});
330328
}
331329

core/src/main/java/org/springframework/security/core/parameters/AnnotationParameterNameDiscoverer.java

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -178,19 +178,9 @@ private String findParameterName(Annotation[] parameterAnnotations) {
178178
return null;
179179
}
180180

181-
private static final ParameterNameFactory<Constructor<?>> CONSTRUCTOR_METHODPARAM_FACTORY = new ParameterNameFactory<Constructor<?>>() {
181+
private static final ParameterNameFactory<Constructor<?>> CONSTRUCTOR_METHODPARAM_FACTORY = constructor -> constructor.getParameterAnnotations();
182182

183-
public Annotation[][] findParameterAnnotations(Constructor<?> constructor) {
184-
return constructor.getParameterAnnotations();
185-
}
186-
};
187-
188-
private static final ParameterNameFactory<Method> METHOD_METHODPARAM_FACTORY = new ParameterNameFactory<Method>() {
189-
190-
public Annotation[][] findParameterAnnotations(Method method) {
191-
return method.getParameterAnnotations();
192-
}
193-
};
183+
private static final ParameterNameFactory<Method> METHOD_METHODPARAM_FACTORY = method -> method.getParameterAnnotations();
194184

195185
/**
196186
* Strategy interface for looking up the parameter names.

core/src/main/java/org/springframework/security/core/userdetails/jdbc/JdbcDaoImpl.java

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
package org.springframework.security.core.userdetails.jdbc;
1818

19-
import java.sql.ResultSet;
20-
import java.sql.SQLException;
2119
import java.util.ArrayList;
2220
import java.util.HashSet;
2321
import java.util.List;
@@ -27,7 +25,6 @@
2725
import org.springframework.context.MessageSource;
2826
import org.springframework.context.MessageSourceAware;
2927
import org.springframework.context.support.MessageSourceAccessor;
30-
import org.springframework.jdbc.core.RowMapper;
3128
import org.springframework.jdbc.core.support.JdbcDaoSupport;
3229
import org.springframework.security.core.GrantedAuthority;
3330
import org.springframework.security.core.SpringSecurityMessageSource;
@@ -225,17 +222,12 @@ public UserDetails loadUserByUsername(String username)
225222
*/
226223
protected List<UserDetails> loadUsersByUsername(String username) {
227224
return getJdbcTemplate().query(this.usersByUsernameQuery,
228-
new String[] { username }, new RowMapper<UserDetails>() {
229-
@Override
230-
public UserDetails mapRow(ResultSet rs, int rowNum)
231-
throws SQLException {
232-
String username = rs.getString(1);
233-
String password = rs.getString(2);
234-
boolean enabled = rs.getBoolean(3);
235-
return new User(username, password, enabled, true, true, true,
236-
AuthorityUtils.NO_AUTHORITIES);
237-
}
238-
225+
new String[] { username }, (rs, rowNum) -> {
226+
String username1 = rs.getString(1);
227+
String password = rs.getString(2);
228+
boolean enabled = rs.getBoolean(3);
229+
return new User(username1, password, enabled, true, true, true,
230+
AuthorityUtils.NO_AUTHORITIES);
239231
});
240232
}
241233

@@ -246,14 +238,10 @@ public UserDetails mapRow(ResultSet rs, int rowNum)
246238
*/
247239
protected List<GrantedAuthority> loadUserAuthorities(String username) {
248240
return getJdbcTemplate().query(this.authoritiesByUsernameQuery,
249-
new String[] { username }, new RowMapper<GrantedAuthority>() {
250-
@Override
251-
public GrantedAuthority mapRow(ResultSet rs, int rowNum)
252-
throws SQLException {
253-
String roleName = JdbcDaoImpl.this.rolePrefix + rs.getString(2);
254-
255-
return new SimpleGrantedAuthority(roleName);
256-
}
241+
new String[] { username }, (rs, rowNum) -> {
242+
String roleName = JdbcDaoImpl.this.rolePrefix + rs.getString(2);
243+
244+
return new SimpleGrantedAuthority(roleName);
257245
});
258246
}
259247

@@ -265,14 +253,10 @@ public GrantedAuthority mapRow(ResultSet rs, int rowNum)
265253
*/
266254
protected List<GrantedAuthority> loadGroupAuthorities(String username) {
267255
return getJdbcTemplate().query(this.groupAuthoritiesByUsernameQuery,
268-
new String[] { username }, new RowMapper<GrantedAuthority>() {
269-
@Override
270-
public GrantedAuthority mapRow(ResultSet rs, int rowNum)
271-
throws SQLException {
272-
String roleName = getRolePrefix() + rs.getString(3);
273-
274-
return new SimpleGrantedAuthority(roleName);
275-
}
256+
new String[] { username }, (rs, rowNum) -> {
257+
String roleName = getRolePrefix() + rs.getString(3);
258+
259+
return new SimpleGrantedAuthority(roleName);
276260
});
277261
}
278262

0 commit comments

Comments
 (0)