Use diamond type
This commit is contained in:
@@ -76,7 +76,7 @@ public class SecurityConfig implements ConfigAttribute {
|
||||
|
||||
public static List<ConfigAttribute> createList(String... attributeNames) {
|
||||
Assert.notNull(attributeNames, "You must supply an array of attribute names");
|
||||
List<ConfigAttribute> attributes = new ArrayList<ConfigAttribute>(
|
||||
List<ConfigAttribute> attributes = new ArrayList<>(
|
||||
attributeNames.length);
|
||||
|
||||
for (String attribute : attributeNames) {
|
||||
|
||||
+1
-1
@@ -75,7 +75,7 @@ public class Jsr250MethodSecurityMetadataSource extends
|
||||
if (annotations == null || annotations.length == 0) {
|
||||
return null;
|
||||
}
|
||||
List<ConfigAttribute> attributes = new ArrayList<ConfigAttribute>();
|
||||
List<ConfigAttribute> attributes = new ArrayList<>();
|
||||
|
||||
for (Annotation a : annotations) {
|
||||
if (a instanceof DenyAll) {
|
||||
|
||||
+1
-1
@@ -84,7 +84,7 @@ class SecuredAnnotationMetadataExtractor implements AnnotationMetadataExtractor<
|
||||
|
||||
public Collection<ConfigAttribute> extractAttributes(Secured secured) {
|
||||
String[] attributeTokens = secured.value();
|
||||
List<ConfigAttribute> attributes = new ArrayList<ConfigAttribute>(
|
||||
List<ConfigAttribute> attributes = new ArrayList<>(
|
||||
attributeTokens.length);
|
||||
|
||||
for (String token : attributeTokens) {
|
||||
|
||||
+1
-1
@@ -158,7 +158,7 @@ public abstract class SecurityExpressionRoot implements SecurityExpressionOperat
|
||||
|
||||
private Set<String> getAuthoritySet() {
|
||||
if (roles == null) {
|
||||
roles = new HashSet<String>();
|
||||
roles = new HashSet<>();
|
||||
Collection<? extends GrantedAuthority> userAuthorities = authentication
|
||||
.getAuthorities();
|
||||
|
||||
|
||||
+6
-6
@@ -115,7 +115,7 @@ public class RoleHierarchyImpl implements RoleHierarchy {
|
||||
return AuthorityUtils.NO_AUTHORITIES;
|
||||
}
|
||||
|
||||
Set<GrantedAuthority> reachableRoles = new HashSet<GrantedAuthority>();
|
||||
Set<GrantedAuthority> reachableRoles = new HashSet<>();
|
||||
|
||||
for (GrantedAuthority authority : authorities) {
|
||||
addReachableRoles(reachableRoles, authority);
|
||||
@@ -132,7 +132,7 @@ public class RoleHierarchyImpl implements RoleHierarchy {
|
||||
+ " in zero or more steps.");
|
||||
}
|
||||
|
||||
List<GrantedAuthority> reachableRoleList = new ArrayList<GrantedAuthority>(
|
||||
List<GrantedAuthority> reachableRoleList = new ArrayList<>(
|
||||
reachableRoles.size());
|
||||
reachableRoleList.addAll(reachableRoles);
|
||||
|
||||
@@ -190,7 +190,7 @@ public class RoleHierarchyImpl implements RoleHierarchy {
|
||||
Set<GrantedAuthority> rolesReachableInOneStepSet;
|
||||
|
||||
if (!this.rolesReachableInOneStepMap.containsKey(higherRole)) {
|
||||
rolesReachableInOneStepSet = new HashSet<GrantedAuthority>();
|
||||
rolesReachableInOneStepSet = new HashSet<>();
|
||||
this.rolesReachableInOneStepMap.put(higherRole,
|
||||
rolesReachableInOneStepSet);
|
||||
}
|
||||
@@ -212,17 +212,17 @@ public class RoleHierarchyImpl implements RoleHierarchy {
|
||||
* detected)
|
||||
*/
|
||||
private void buildRolesReachableInOneOrMoreStepsMap() {
|
||||
this.rolesReachableInOneOrMoreStepsMap = new HashMap<GrantedAuthority, Set<GrantedAuthority>>();
|
||||
this.rolesReachableInOneOrMoreStepsMap = new HashMap<>();
|
||||
// iterate over all higher roles from rolesReachableInOneStepMap
|
||||
|
||||
for (GrantedAuthority role : this.rolesReachableInOneStepMap.keySet()) {
|
||||
Set<GrantedAuthority> rolesToVisitSet = new HashSet<GrantedAuthority>();
|
||||
Set<GrantedAuthority> rolesToVisitSet = new HashSet<>();
|
||||
|
||||
if (this.rolesReachableInOneStepMap.containsKey(role)) {
|
||||
rolesToVisitSet.addAll(this.rolesReachableInOneStepMap.get(role));
|
||||
}
|
||||
|
||||
Set<GrantedAuthority> visitedRolesSet = new HashSet<GrantedAuthority>();
|
||||
Set<GrantedAuthority> visitedRolesSet = new HashSet<>();
|
||||
|
||||
while (!rolesToVisitSet.isEmpty()) {
|
||||
// take a role from the rolesToVisit set
|
||||
|
||||
+1
-1
@@ -161,7 +161,7 @@ public abstract class AbstractSecurityInterceptor implements InitializingBean,
|
||||
return;
|
||||
}
|
||||
|
||||
Set<ConfigAttribute> unsupportedAttrs = new HashSet<ConfigAttribute>();
|
||||
Set<ConfigAttribute> unsupportedAttrs = new HashSet<>();
|
||||
|
||||
for (ConfigAttribute attr : attributeDefs) {
|
||||
if (!this.runAsManager.supports(attr)
|
||||
|
||||
+1
-1
@@ -91,7 +91,7 @@ public class AfterInvocationProviderManager implements AfterInvocationManager,
|
||||
|
||||
public void setProviders(List<?> newList) {
|
||||
checkIfValidList(newList);
|
||||
providers = new ArrayList<AfterInvocationProvider>(newList.size());
|
||||
providers = new ArrayList<>(newList.size());
|
||||
|
||||
for (Object currentObject : newList) {
|
||||
Assert.isInstanceOf(AfterInvocationProvider.class, currentObject,
|
||||
|
||||
+1
-1
@@ -71,7 +71,7 @@ public class RunAsManagerImpl implements RunAsManager, InitializingBean {
|
||||
|
||||
public Authentication buildRunAs(Authentication authentication, Object object,
|
||||
Collection<ConfigAttribute> attributes) {
|
||||
List<GrantedAuthority> newAuthorities = new ArrayList<GrantedAuthority>();
|
||||
List<GrantedAuthority> newAuthorities = new ArrayList<>();
|
||||
|
||||
for (ConfigAttribute attribute : attributes) {
|
||||
if (this.supports(attribute)) {
|
||||
|
||||
+1
-1
@@ -95,7 +95,7 @@ public final class DelegatingMethodSecurityMetadataSource extends
|
||||
|
||||
@Override
|
||||
public Collection<ConfigAttribute> getAllConfigAttributes() {
|
||||
Set<ConfigAttribute> set = new HashSet<ConfigAttribute>();
|
||||
Set<ConfigAttribute> set = new HashSet<>();
|
||||
for (MethodSecurityMetadataSource s : methodSecurityMetadataSources) {
|
||||
Collection<ConfigAttribute> attrs = s.getAllConfigAttributes();
|
||||
if (attrs != null) {
|
||||
|
||||
+4
-4
@@ -50,10 +50,10 @@ public class MapBasedMethodSecurityMetadataSource extends
|
||||
private ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader();
|
||||
|
||||
/** Map from RegisteredMethod to ConfigAttribute list */
|
||||
protected final Map<RegisteredMethod, List<ConfigAttribute>> methodMap = new HashMap<RegisteredMethod, List<ConfigAttribute>>();
|
||||
protected final Map<RegisteredMethod, List<ConfigAttribute>> methodMap = new HashMap<>();
|
||||
|
||||
/** Map from RegisteredMethod to name pattern used for registration */
|
||||
private final Map<RegisteredMethod, String> nameMap = new HashMap<RegisteredMethod, String>();
|
||||
private final Map<RegisteredMethod, String> nameMap = new HashMap<>();
|
||||
|
||||
// ~ Methods
|
||||
// ========================================================================================================
|
||||
@@ -150,7 +150,7 @@ public class MapBasedMethodSecurityMetadataSource extends
|
||||
}
|
||||
|
||||
Method[] methods = javaType.getMethods();
|
||||
List<Method> matchingMethods = new ArrayList<Method>();
|
||||
List<Method> matchingMethods = new ArrayList<>();
|
||||
|
||||
for (Method m : methods) {
|
||||
if (m.getName().equals(mappedName) || isMatch(m.getName(), mappedName)) {
|
||||
@@ -236,7 +236,7 @@ public class MapBasedMethodSecurityMetadataSource extends
|
||||
*/
|
||||
@Override
|
||||
public Collection<ConfigAttribute> getAllConfigAttributes() {
|
||||
Set<ConfigAttribute> allAttributes = new HashSet<ConfigAttribute>();
|
||||
Set<ConfigAttribute> allAttributes = new HashSet<>();
|
||||
|
||||
for (List<ConfigAttribute> attributeList : methodMap.values()) {
|
||||
allAttributes.addAll(attributeList);
|
||||
|
||||
+1
-1
@@ -84,7 +84,7 @@ public class PrePostAnnotationSecurityMetadataSource extends
|
||||
String postAuthorizeAttribute = postAuthorize == null ? null : postAuthorize
|
||||
.value();
|
||||
|
||||
ArrayList<ConfigAttribute> attrs = new ArrayList<ConfigAttribute>(2);
|
||||
ArrayList<ConfigAttribute> attrs = new ArrayList<>(2);
|
||||
|
||||
PreInvocationAttribute pre = attributeFactory.createPreInvocationAttribute(
|
||||
preFilterAttribute, filterObject, preAuthorizeAttribute);
|
||||
|
||||
@@ -66,7 +66,7 @@ public class UnanimousBased extends AbstractAccessDecisionManager {
|
||||
int grant = 0;
|
||||
int abstain = 0;
|
||||
|
||||
List<ConfigAttribute> singleAttributeList = new ArrayList<ConfigAttribute>(1);
|
||||
List<ConfigAttribute> singleAttributeList = new ArrayList<>(1);
|
||||
singleAttributeList.add(null);
|
||||
|
||||
for (ConfigAttribute attribute : attributes) {
|
||||
|
||||
+1
-1
@@ -66,7 +66,7 @@ public abstract class AbstractAuthenticationToken implements Authentication,
|
||||
"Authorities collection cannot contain any null elements");
|
||||
}
|
||||
}
|
||||
ArrayList<GrantedAuthority> temp = new ArrayList<GrantedAuthority>(
|
||||
ArrayList<GrantedAuthority> temp = new ArrayList<>(
|
||||
authorities.size());
|
||||
temp.addAll(authorities);
|
||||
this.authorities = Collections.unmodifiableList(temp);
|
||||
|
||||
+2
-2
@@ -181,7 +181,7 @@ public abstract class AbstractJaasAuthenticationProvider
|
||||
|
||||
// Create a set to hold the authorities, and add any that have already been
|
||||
// applied.
|
||||
authorities = new HashSet<GrantedAuthority>();
|
||||
authorities = new HashSet<>();
|
||||
|
||||
// Get the subject principals and pass them to each of the AuthorityGranters
|
||||
Set<Principal> principals = loginContext.getSubject().getPrincipals();
|
||||
@@ -203,7 +203,7 @@ public abstract class AbstractJaasAuthenticationProvider
|
||||
// Convert the authorities set back to an array and apply it to the token.
|
||||
JaasAuthenticationToken result = new JaasAuthenticationToken(
|
||||
request.getPrincipal(), request.getCredentials(),
|
||||
new ArrayList<GrantedAuthority>(authorities), loginContext);
|
||||
new ArrayList<>(authorities), loginContext);
|
||||
|
||||
// Publish the success event
|
||||
publishSuccessEvent(result);
|
||||
|
||||
+2
-2
@@ -116,8 +116,8 @@ public final class DelegatingSecurityContextCallable<V> implements Callable<V> {
|
||||
*/
|
||||
public static <V> Callable<V> create(Callable<V> delegate,
|
||||
SecurityContext securityContext) {
|
||||
return securityContext == null ? new DelegatingSecurityContextCallable<V>(
|
||||
delegate) : new DelegatingSecurityContextCallable<V>(delegate,
|
||||
return securityContext == null ? new DelegatingSecurityContextCallable<>(
|
||||
delegate) : new DelegatingSecurityContextCallable<>(delegate,
|
||||
securityContext);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -354,7 +354,7 @@ class ComparableVersion implements Comparable<ComparableVersion> {
|
||||
|
||||
ListItem list = items;
|
||||
|
||||
Stack<Item> stack = new Stack<Item>();
|
||||
Stack<Item> stack = new Stack<>();
|
||||
stack.push(list);
|
||||
|
||||
boolean isDigit = false;
|
||||
|
||||
@@ -55,7 +55,7 @@ public abstract class AuthorityUtils {
|
||||
*/
|
||||
public static Set<String> authorityListToSet(
|
||||
Collection<? extends GrantedAuthority> userAuthorities) {
|
||||
Set<String> set = new HashSet<String>(userAuthorities.size());
|
||||
Set<String> set = new HashSet<>(userAuthorities.size());
|
||||
|
||||
for (GrantedAuthority authority : userAuthorities) {
|
||||
set.add(authority.getAuthority());
|
||||
@@ -65,7 +65,7 @@ public abstract class AuthorityUtils {
|
||||
}
|
||||
|
||||
public static List<GrantedAuthority> createAuthorityList(String... roles) {
|
||||
List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>(roles.length);
|
||||
List<GrantedAuthority> authorities = new ArrayList<>(roles.length);
|
||||
|
||||
for (String role : roles) {
|
||||
authorities.add(new SimpleGrantedAuthority(role));
|
||||
|
||||
+2
-2
@@ -47,7 +47,7 @@ public class MapBasedAttributes2GrantedAuthoritiesMapper implements
|
||||
* Map the given array of attributes to Spring Security GrantedAuthorities.
|
||||
*/
|
||||
public List<GrantedAuthority> getGrantedAuthorities(Collection<String> attributes) {
|
||||
ArrayList<GrantedAuthority> gaList = new ArrayList<GrantedAuthority>();
|
||||
ArrayList<GrantedAuthority> gaList = new ArrayList<>();
|
||||
for (String attribute : attributes) {
|
||||
Collection<GrantedAuthority> c = attributes2grantedAuthoritiesMap
|
||||
.get(attribute);
|
||||
@@ -107,7 +107,7 @@ public class MapBasedAttributes2GrantedAuthoritiesMapper implements
|
||||
* @return Collection containing the GrantedAuthority Collection
|
||||
*/
|
||||
private Collection<GrantedAuthority> getGrantedAuthorityCollection(Object value) {
|
||||
Collection<GrantedAuthority> result = new ArrayList<GrantedAuthority>();
|
||||
Collection<GrantedAuthority> result = new ArrayList<>();
|
||||
addGrantedAuthorityCollection(result, value);
|
||||
return result;
|
||||
}
|
||||
|
||||
+1
-1
@@ -62,7 +62,7 @@ public class SimpleAttributes2GrantedAuthoritiesMapper implements
|
||||
* GrantedAuthorities.
|
||||
*/
|
||||
public List<GrantedAuthority> getGrantedAuthorities(Collection<String> attributes) {
|
||||
List<GrantedAuthority> result = new ArrayList<GrantedAuthority>(attributes.size());
|
||||
List<GrantedAuthority> result = new ArrayList<>(attributes.size());
|
||||
for (String attribute : attributes) {
|
||||
result.add(getGrantedAuthority(attribute));
|
||||
}
|
||||
|
||||
+1
-1
@@ -54,7 +54,7 @@ public final class SimpleAuthorityMapper implements GrantedAuthoritiesMapper,
|
||||
*/
|
||||
public Set<GrantedAuthority> mapAuthorities(
|
||||
Collection<? extends GrantedAuthority> authorities) {
|
||||
HashSet<GrantedAuthority> mapped = new HashSet<GrantedAuthority>(
|
||||
HashSet<GrantedAuthority> mapped = new HashSet<>(
|
||||
authorities.size());
|
||||
for (GrantedAuthority authority : authorities) {
|
||||
mapped.add(mapAuthority(authority.getAuthority()));
|
||||
|
||||
+1
-1
@@ -41,7 +41,7 @@ public class SimpleMappableAttributesRetriever implements MappableAttributesRetr
|
||||
}
|
||||
|
||||
public void setMappableAttributes(Set<String> aMappableRoles) {
|
||||
this.mappableAttributes = new HashSet<String>();
|
||||
this.mappableAttributes = new HashSet<>();
|
||||
this.mappableAttributes.addAll(aMappableRoles);
|
||||
this.mappableAttributes = Collections.unmodifiableSet(this.mappableAttributes);
|
||||
}
|
||||
|
||||
+1
-1
@@ -31,7 +31,7 @@ final class InheritableThreadLocalSecurityContextHolderStrategy implements
|
||||
// ~ Static fields/initializers
|
||||
// =====================================================================================
|
||||
|
||||
private static final ThreadLocal<SecurityContext> contextHolder = new InheritableThreadLocal<SecurityContext>();
|
||||
private static final ThreadLocal<SecurityContext> contextHolder = new InheritableThreadLocal<>();
|
||||
|
||||
// ~ Methods
|
||||
// ========================================================================================================
|
||||
|
||||
+1
-1
@@ -32,7 +32,7 @@ final class ThreadLocalSecurityContextHolderStrategy implements
|
||||
// ~ Static fields/initializers
|
||||
// =====================================================================================
|
||||
|
||||
private static final ThreadLocal<SecurityContext> contextHolder = new ThreadLocal<SecurityContext>();
|
||||
private static final ThreadLocal<SecurityContext> contextHolder = new ThreadLocal<>();
|
||||
|
||||
// ~ Methods
|
||||
// ========================================================================================================
|
||||
|
||||
+2
-2
@@ -91,7 +91,7 @@ public class AnnotationParameterNameDiscoverer implements ParameterNameDiscovere
|
||||
private final Set<String> annotationClassesToUse;
|
||||
|
||||
public AnnotationParameterNameDiscoverer(String... annotationClassToUse) {
|
||||
this(new HashSet<String>(Arrays.asList(annotationClassToUse)));
|
||||
this(new HashSet<>(Arrays.asList(annotationClassToUse)));
|
||||
}
|
||||
|
||||
public AnnotationParameterNameDiscoverer(Set<String> annotationClassesToUse) {
|
||||
@@ -210,4 +210,4 @@ public class AnnotationParameterNameDiscoverer implements ParameterNameDiscovere
|
||||
*/
|
||||
Annotation[][] findParameterAnnotations(T t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -81,7 +81,7 @@ public class DefaultSecurityParameterNameDiscoverer extends
|
||||
addDiscoverer(discover);
|
||||
}
|
||||
|
||||
Set<String> annotationClassesToUse = new HashSet<String>(2);
|
||||
Set<String> annotationClassesToUse = new HashSet<>(2);
|
||||
annotationClassesToUse.add("org.springframework.security.access.method.P");
|
||||
annotationClassesToUse.add(P.class.getName());
|
||||
if (DATA_PARAM_PRESENT) {
|
||||
@@ -91,4 +91,4 @@ public class DefaultSecurityParameterNameDiscoverer extends
|
||||
addDiscoverer(new AnnotationParameterNameDiscoverer(annotationClassesToUse));
|
||||
addDiscoverer(new DefaultParameterNameDiscoverer());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+5
-5
@@ -56,8 +56,8 @@ public class SessionRegistryImpl implements SessionRegistry,
|
||||
// ========================================================================================================
|
||||
|
||||
public SessionRegistryImpl() {
|
||||
this.principals = new ConcurrentHashMap<Object, Set<String>>();
|
||||
this.sessionIds = new ConcurrentHashMap<String, SessionInformation>();
|
||||
this.principals = new ConcurrentHashMap<>();
|
||||
this.sessionIds = new ConcurrentHashMap<>();
|
||||
}
|
||||
|
||||
public SessionRegistryImpl(ConcurrentMap<Object, Set<String>> principals, Map<String, SessionInformation> sessionIds) {
|
||||
@@ -66,7 +66,7 @@ public class SessionRegistryImpl implements SessionRegistry,
|
||||
}
|
||||
|
||||
public List<Object> getAllPrincipals() {
|
||||
return new ArrayList<Object>(principals.keySet());
|
||||
return new ArrayList<>(principals.keySet());
|
||||
}
|
||||
|
||||
public List<SessionInformation> getAllSessions(Object principal,
|
||||
@@ -77,7 +77,7 @@ public class SessionRegistryImpl implements SessionRegistry,
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
List<SessionInformation> list = new ArrayList<SessionInformation>(
|
||||
List<SessionInformation> list = new ArrayList<>(
|
||||
sessionsUsedByPrincipal.size());
|
||||
|
||||
for (String sessionId : sessionsUsedByPrincipal) {
|
||||
@@ -135,7 +135,7 @@ public class SessionRegistryImpl implements SessionRegistry,
|
||||
Set<String> sessionsUsedByPrincipal = principals.get(principal);
|
||||
|
||||
if (sessionsUsedByPrincipal == null) {
|
||||
sessionsUsedByPrincipal = new CopyOnWriteArraySet<String>();
|
||||
sessionsUsedByPrincipal = new CopyOnWriteArraySet<>();
|
||||
Set<String> prevSessionsUsedByPrincipal = principals.putIfAbsent(principal,
|
||||
sessionsUsedByPrincipal);
|
||||
if (prevSessionsUsedByPrincipal != null) {
|
||||
|
||||
@@ -159,7 +159,7 @@ public class User implements UserDetails, CredentialsContainer {
|
||||
Assert.notNull(authorities, "Cannot pass a null GrantedAuthority collection");
|
||||
// Ensure array iteration order is predictable (as per
|
||||
// UserDetails.getAuthorities() contract and SEC-717)
|
||||
SortedSet<GrantedAuthority> sortedAuthorities = new TreeSet<GrantedAuthority>(
|
||||
SortedSet<GrantedAuthority> sortedAuthorities = new TreeSet<>(
|
||||
new AuthorityComparator());
|
||||
|
||||
for (GrantedAuthority grantedAuthority : authorities) {
|
||||
@@ -367,7 +367,7 @@ public class User implements UserDetails, CredentialsContainer {
|
||||
* additional attributes for this user)
|
||||
*/
|
||||
public UserBuilder roles(String... roles) {
|
||||
List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>(
|
||||
List<GrantedAuthority> authorities = new ArrayList<>(
|
||||
roles.length);
|
||||
for (String role : roles) {
|
||||
Assert.isTrue(!role.startsWith("ROLE_"), role
|
||||
@@ -400,7 +400,7 @@ public class User implements UserDetails, CredentialsContainer {
|
||||
* @see #roles(String...)
|
||||
*/
|
||||
public UserBuilder authorities(Collection<? extends GrantedAuthority> authorities) {
|
||||
this.authorities = new ArrayList<GrantedAuthority>(authorities);
|
||||
this.authorities = new ArrayList<>(authorities);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -193,7 +193,7 @@ public class JdbcDaoImpl extends JdbcDaoSupport
|
||||
|
||||
UserDetails user = users.get(0); // contains no GrantedAuthority[]
|
||||
|
||||
Set<GrantedAuthority> dbAuthsSet = new HashSet<GrantedAuthority>();
|
||||
Set<GrantedAuthority> dbAuthsSet = new HashSet<>();
|
||||
|
||||
if (this.enableAuthorities) {
|
||||
dbAuthsSet.addAll(loadUserAuthorities(user.getUsername()));
|
||||
@@ -203,7 +203,7 @@ public class JdbcDaoImpl extends JdbcDaoSupport
|
||||
dbAuthsSet.addAll(loadGroupAuthorities(user.getUsername()));
|
||||
}
|
||||
|
||||
List<GrantedAuthority> dbAuths = new ArrayList<GrantedAuthority>(dbAuthsSet);
|
||||
List<GrantedAuthority> dbAuths = new ArrayList<>(dbAuthsSet);
|
||||
|
||||
addCustomAuthorities(user.getUsername(), dbAuths);
|
||||
|
||||
|
||||
+2
-2
@@ -33,7 +33,7 @@ public class UserAttribute {
|
||||
// ~ Instance fields
|
||||
// ================================================================================================
|
||||
|
||||
private List<GrantedAuthority> authorities = new Vector<GrantedAuthority>();
|
||||
private List<GrantedAuthority> authorities = new Vector<>();
|
||||
private String password;
|
||||
private boolean enabled = true;
|
||||
|
||||
@@ -66,7 +66,7 @@ public class UserAttribute {
|
||||
* @since 1.1
|
||||
*/
|
||||
public void setAuthoritiesAsString(List<String> authoritiesAsStrings) {
|
||||
setAuthorities(new ArrayList<GrantedAuthority>(authoritiesAsStrings.size()));
|
||||
setAuthorities(new ArrayList<>(authoritiesAsStrings.size()));
|
||||
for (String authority : authoritiesAsStrings) {
|
||||
addAuthority(new SimpleGrantedAuthority(authority));
|
||||
}
|
||||
|
||||
+1
-1
@@ -37,7 +37,7 @@ public class UserAttributeEditor extends PropertyEditorSupport {
|
||||
String[] tokens = StringUtils.commaDelimitedListToStringArray(s);
|
||||
UserAttribute userAttrib = new UserAttribute();
|
||||
|
||||
List<String> authoritiesAsStrings = new ArrayList<String>();
|
||||
List<String> authoritiesAsStrings = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < tokens.length; i++) {
|
||||
String currentToken = tokens[i].trim();
|
||||
|
||||
+1
-1
@@ -95,7 +95,7 @@ public final class SecurityJackson2Modules {
|
||||
* @return List of available security modules in classpath.
|
||||
*/
|
||||
public static List<Module> getModules(ClassLoader loader) {
|
||||
List<Module> modules = new ArrayList<Module>();
|
||||
List<Module> modules = new ArrayList<>();
|
||||
for (String className : securityJackson2ModuleClasses) {
|
||||
Module module = loadAndGetInstance(className, loader);
|
||||
if (module != null) {
|
||||
|
||||
+1
-1
@@ -43,7 +43,7 @@ class UnmodifiableSetDeserializer extends JsonDeserializer<Set> {
|
||||
public Set deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
|
||||
ObjectMapper mapper = (ObjectMapper) jp.getCodec();
|
||||
JsonNode node = mapper.readTree(jp);
|
||||
Set<Object> resultSet = new HashSet<Object>();
|
||||
Set<Object> resultSet = new HashSet<>();
|
||||
if (node != null) {
|
||||
if (node instanceof ArrayNode) {
|
||||
ArrayNode arrayNode = (ArrayNode) node;
|
||||
|
||||
+1
-1
@@ -48,7 +48,7 @@ import org.springframework.util.Assert;
|
||||
public class InMemoryUserDetailsManager implements UserDetailsManager {
|
||||
protected final Log logger = LogFactory.getLog(getClass());
|
||||
|
||||
private final Map<String, MutableUserDetails> users = new HashMap<String, MutableUserDetails>();
|
||||
private final Map<String, MutableUserDetails> users = new HashMap<>();
|
||||
|
||||
private AuthenticationManager authenticationManager;
|
||||
|
||||
|
||||
+1
-1
@@ -57,7 +57,7 @@ public class BusinessServiceImpl<E extends Entity> implements BusinessService {
|
||||
}
|
||||
|
||||
public List<Object> methodReturningAList(String userName, String arg2) {
|
||||
return new ArrayList<Object>();
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
public Object[] methodReturningAnArray(Object[] someArray) {
|
||||
|
||||
+1
-1
@@ -51,7 +51,7 @@ public class ExpressionProtectedBusinessServiceImpl implements BusinessService {
|
||||
}
|
||||
|
||||
public List<Object> methodReturningAList(String userName, String arg2) {
|
||||
return new ArrayList<Object>();
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
@PostFilter("filterObject == 'bob'")
|
||||
|
||||
+1
-1
@@ -57,7 +57,7 @@ public class Jsr250BusinessServiceImpl implements BusinessService {
|
||||
}
|
||||
|
||||
public List<?> methodReturningAList(String userName, String arg2) {
|
||||
return new ArrayList<Object>();
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
public Object[] methodReturningAnArray(Object[] someArray) {
|
||||
|
||||
+1
-1
@@ -35,7 +35,7 @@ public class Jsr250VoterTests {
|
||||
// SEC-1443
|
||||
@Test
|
||||
public void supportsMultipleRolesCorrectly() throws Exception {
|
||||
List<ConfigAttribute> attrs = new ArrayList<ConfigAttribute>();
|
||||
List<ConfigAttribute> attrs = new ArrayList<>();
|
||||
Jsr250Voter voter = new Jsr250Voter();
|
||||
|
||||
attrs.add(new Jsr250SecurityConfig("A"));
|
||||
|
||||
+1
-1
@@ -50,7 +50,7 @@ public class MethodExpressionVoterTests {
|
||||
|
||||
@Test
|
||||
public void hasRoleExpressionDeniesUserWithoutRole() throws Exception {
|
||||
List<ConfigAttribute> cad = new ArrayList<ConfigAttribute>(1);
|
||||
List<ConfigAttribute> cad = new ArrayList<>(1);
|
||||
cad.add(new PreInvocationExpressionAttribute(null, null, "hasRole('joedoesnt')"));
|
||||
MethodInvocation mi = new SimpleMethodInvocation(new TargetImpl(),
|
||||
methodTakingAnArray());
|
||||
|
||||
+2
-2
@@ -63,7 +63,7 @@ public abstract class HierarchicalRolesTestHelper {
|
||||
return null;
|
||||
}
|
||||
|
||||
List<String> result = new ArrayList<String>(authorities.size());
|
||||
List<String> result = new ArrayList<>(authorities.size());
|
||||
for (GrantedAuthority authority : authorities) {
|
||||
result.add(authority.getAuthority());
|
||||
}
|
||||
@@ -71,7 +71,7 @@ public abstract class HierarchicalRolesTestHelper {
|
||||
}
|
||||
|
||||
public static List<GrantedAuthority> createAuthorityList(final String... roles) {
|
||||
List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>(roles.length);
|
||||
List<GrantedAuthority> authorities = new ArrayList<>(roles.length);
|
||||
|
||||
for (final String role : roles) {
|
||||
// Use non SimpleGrantedAuthority (SEC-863)
|
||||
|
||||
+1
-1
@@ -35,7 +35,7 @@ public class RoleHierarchyImplTests {
|
||||
@Test
|
||||
public void testRoleHierarchyWithNullOrEmptyAuthorities() {
|
||||
List<GrantedAuthority> authorities0 = null;
|
||||
List<GrantedAuthority> authorities1 = new ArrayList<GrantedAuthority>();
|
||||
List<GrantedAuthority> authorities1 = new ArrayList<>();
|
||||
|
||||
RoleHierarchyImpl roleHierarchyImpl = new RoleHierarchyImpl();
|
||||
roleHierarchyImpl.setHierarchy("ROLE_A > ROLE_B");
|
||||
|
||||
+5
-5
@@ -85,22 +85,22 @@ public class TestHelperTests {
|
||||
Collection<GrantedAuthority> authorities5 = AuthorityUtils.createAuthorityList(
|
||||
"ROLE_A", "ROLE_A");
|
||||
|
||||
List<String> authoritiesStrings1 = new ArrayList<String>();
|
||||
List<String> authoritiesStrings1 = new ArrayList<>();
|
||||
authoritiesStrings1.add("ROLE_A");
|
||||
authoritiesStrings1.add("ROLE_B");
|
||||
|
||||
List<String> authoritiesStrings2 = new ArrayList<String>();
|
||||
List<String> authoritiesStrings2 = new ArrayList<>();
|
||||
authoritiesStrings2.add("ROLE_B");
|
||||
authoritiesStrings2.add("ROLE_A");
|
||||
|
||||
List<String> authoritiesStrings3 = new ArrayList<String>();
|
||||
List<String> authoritiesStrings3 = new ArrayList<>();
|
||||
authoritiesStrings3.add("ROLE_A");
|
||||
authoritiesStrings3.add("ROLE_C");
|
||||
|
||||
List<String> authoritiesStrings4 = new ArrayList<String>();
|
||||
List<String> authoritiesStrings4 = new ArrayList<>();
|
||||
authoritiesStrings4.add("ROLE_A");
|
||||
|
||||
List<String> authoritiesStrings5 = new ArrayList<String>();
|
||||
List<String> authoritiesStrings5 = new ArrayList<>();
|
||||
authoritiesStrings5.add("ROLE_A");
|
||||
authoritiesStrings5.add("ROLE_A");
|
||||
|
||||
|
||||
+1
-1
@@ -60,7 +60,7 @@ public class AbstractAclVoterTests {
|
||||
public void correctArgumentIsSelectedFromMultipleArgs() throws Exception {
|
||||
voter.setProcessDomainObjectClass(String.class);
|
||||
MethodInvocation mi = MethodInvocationUtils.create(new TestClass(),
|
||||
"methodTakingAListAndAString", new ArrayList<Object>(), "The Argument");
|
||||
"methodTakingAListAndAString", new ArrayList<>(), "The Argument");
|
||||
assertThat(voter.getDomainObjectInstance(mi)).isEqualTo("The Argument");
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -38,7 +38,7 @@ import org.springframework.security.core.Authentication;
|
||||
* @author Ben Alex
|
||||
*/
|
||||
public class AffirmativeBasedTests {
|
||||
private final List<ConfigAttribute> attrs = new ArrayList<ConfigAttribute>();
|
||||
private final List<ConfigAttribute> attrs = new ArrayList<>();
|
||||
private final Authentication user = new TestingAuthenticationToken("somebody",
|
||||
"password", "ROLE_1", "ROLE_2");
|
||||
private AffirmativeBased mgr;
|
||||
|
||||
+2
-3
@@ -27,7 +27,6 @@ import org.junit.Test;
|
||||
import org.springframework.context.MessageSource;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.AuthenticationException;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
|
||||
/**
|
||||
* Tests {@link ProviderManager}.
|
||||
@@ -318,12 +317,12 @@ public class ProviderManagerTests {
|
||||
|
||||
private TestingAuthenticationToken createAuthenticationToken() {
|
||||
return new TestingAuthenticationToken("name", "password",
|
||||
new ArrayList<GrantedAuthority>(0));
|
||||
new ArrayList<>(0));
|
||||
}
|
||||
|
||||
private ProviderManager makeProviderManager() throws Exception {
|
||||
MockProvider provider1 = new MockProvider();
|
||||
List<AuthenticationProvider> providers = new ArrayList<AuthenticationProvider>();
|
||||
List<AuthenticationProvider> providers = new ArrayList<>();
|
||||
providers.add(provider1);
|
||||
|
||||
return new ProviderManager(providers);
|
||||
|
||||
+2
-2
@@ -561,14 +561,14 @@ public class DaoAuthenticationProviderTests {
|
||||
|
||||
int sampleSize = 100;
|
||||
|
||||
List<Long> userFoundTimes = new ArrayList<Long>(sampleSize);
|
||||
List<Long> userFoundTimes = new ArrayList<>(sampleSize);
|
||||
for (int i = 0; i < sampleSize; i++) {
|
||||
long start = System.currentTimeMillis();
|
||||
provider.authenticate(foundUser);
|
||||
userFoundTimes.add(System.currentTimeMillis() - start);
|
||||
}
|
||||
|
||||
List<Long> userNotFoundTimes = new ArrayList<Long>(sampleSize);
|
||||
List<Long> userNotFoundTimes = new ArrayList<>(sampleSize);
|
||||
for (int i = 0; i < sampleSize; i++) {
|
||||
long start = System.currentTimeMillis();
|
||||
try {
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@ import org.springframework.security.core.userdetails.UserCache;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
|
||||
public class MockUserCache implements UserCache {
|
||||
private Map<String, UserDetails> cache = new HashMap<String, UserDetails>();
|
||||
private Map<String, UserDetails> cache = new HashMap<>();
|
||||
|
||||
public UserDetails getUserFromCache(String username) {
|
||||
return (User) cache.get(username);
|
||||
|
||||
+3
-4
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.security.authentication.jaas;
|
||||
|
||||
import java.security.Principal;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
@@ -44,8 +43,8 @@ public class SecurityContextLoginModuleTests {
|
||||
// ================================================================================================
|
||||
|
||||
private SecurityContextLoginModule module = null;
|
||||
private Subject subject = new Subject(false, new HashSet<Principal>(),
|
||||
new HashSet<Object>(), new HashSet<Object>());
|
||||
private Subject subject = new Subject(false, new HashSet<>(),
|
||||
new HashSet<>(), new HashSet<>());
|
||||
private UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken(
|
||||
"principal", "credentials");
|
||||
|
||||
@@ -127,7 +126,7 @@ public class SecurityContextLoginModuleTests {
|
||||
public void testNullAuthenticationInSecurityContextIgnored() throws Exception {
|
||||
this.module = new SecurityContextLoginModule();
|
||||
|
||||
Map<String, String> options = new HashMap<String, String>();
|
||||
Map<String, String> options = new HashMap<>();
|
||||
options.put("ignoreMissingAuthentication", "true");
|
||||
|
||||
this.module.initialize(this.subject, null, null, options);
|
||||
|
||||
+1
-1
@@ -32,7 +32,7 @@ public class TestAuthorityGranter implements AuthorityGranter {
|
||||
// ========================================================================================================
|
||||
|
||||
public Set<String> grant(Principal principal) {
|
||||
Set<String> rtnSet = new HashSet<String>();
|
||||
Set<String> rtnSet = new HashSet<>();
|
||||
|
||||
if (principal.getName().equals("TEST_PRINCIPAL")) {
|
||||
rtnSet.add("ROLE_TEST1");
|
||||
|
||||
+1
-1
@@ -58,7 +58,7 @@ public class RememberMeAuthenticationTokenTests {
|
||||
}
|
||||
|
||||
try {
|
||||
List<GrantedAuthority> authsContainingNull = new ArrayList<GrantedAuthority>();
|
||||
List<GrantedAuthority> authsContainingNull = new ArrayList<>();
|
||||
authsContainingNull.add(null);
|
||||
new RememberMeAuthenticationToken("key", "Test", authsContainingNull);
|
||||
fail("Should have thrown IllegalArgumentException");
|
||||
|
||||
+8
-8
@@ -78,29 +78,29 @@ public class DelegatingSecurityContextCallableTests {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void constructorNullDelegate() {
|
||||
new DelegatingSecurityContextCallable<Object>(null);
|
||||
new DelegatingSecurityContextCallable<>(null);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void constructorNullDelegateNonNullSecurityContext() {
|
||||
new DelegatingSecurityContextCallable<Object>(null, securityContext);
|
||||
new DelegatingSecurityContextCallable<>(null, securityContext);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void constructorNullDelegateAndSecurityContext() {
|
||||
new DelegatingSecurityContextCallable<Object>(null, null);
|
||||
new DelegatingSecurityContextCallable<>(null, null);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void constructorNullSecurityContext() {
|
||||
new DelegatingSecurityContextCallable<Object>(delegate, null);
|
||||
new DelegatingSecurityContextCallable<>(delegate, null);
|
||||
}
|
||||
|
||||
// --- call ---
|
||||
|
||||
@Test
|
||||
public void call() throws Exception {
|
||||
callable = new DelegatingSecurityContextCallable<Object>(delegate,
|
||||
callable = new DelegatingSecurityContextCallable<>(delegate,
|
||||
securityContext);
|
||||
assertWrapped(callable);
|
||||
}
|
||||
@@ -108,7 +108,7 @@ public class DelegatingSecurityContextCallableTests {
|
||||
@Test
|
||||
public void callDefaultSecurityContext() throws Exception {
|
||||
SecurityContextHolder.setContext(securityContext);
|
||||
callable = new DelegatingSecurityContextCallable<Object>(delegate);
|
||||
callable = new DelegatingSecurityContextCallable<>(delegate);
|
||||
SecurityContextHolder.clearContext(); // ensure callable is what sets up the
|
||||
// SecurityContextHolder
|
||||
assertWrapped(callable);
|
||||
@@ -119,7 +119,7 @@ public class DelegatingSecurityContextCallableTests {
|
||||
public void callOnSameThread() throws Exception {
|
||||
originalSecurityContext = securityContext;
|
||||
SecurityContextHolder.setContext(originalSecurityContext);
|
||||
callable = new DelegatingSecurityContextCallable<Object>(delegate,
|
||||
callable = new DelegatingSecurityContextCallable<>(delegate,
|
||||
securityContext);
|
||||
assertWrapped(callable.call());
|
||||
}
|
||||
@@ -156,7 +156,7 @@ public class DelegatingSecurityContextCallableTests {
|
||||
// SEC-2682
|
||||
@Test
|
||||
public void toStringDelegates() {
|
||||
callable = new DelegatingSecurityContextCallable<Object>(delegate,
|
||||
callable = new DelegatingSecurityContextCallable<>(delegate,
|
||||
securityContext);
|
||||
assertThat(callable.toString()).isEqualTo(delegate.toString());
|
||||
}
|
||||
|
||||
+1
-1
@@ -128,7 +128,7 @@ public class SimpleRoles2GrantedAuthoritiesMapperTests {
|
||||
String[] expectedGas) {
|
||||
List<GrantedAuthority> result = mapper
|
||||
.getGrantedAuthorities(Arrays.asList(roles));
|
||||
Collection<String> resultColl = new ArrayList<String>(result.size());
|
||||
Collection<String> resultColl = new ArrayList<>(result.size());
|
||||
for (int i = 0; i < result.size(); i++) {
|
||||
resultColl.add(result.get(i).getAuthority());
|
||||
}
|
||||
|
||||
+1
-1
@@ -30,7 +30,7 @@ import org.springframework.security.core.authority.AuthorityUtils;
|
||||
* @author Luke Taylor
|
||||
*/
|
||||
public class MockUserDetailsService implements UserDetailsService {
|
||||
private Map<String, User> users = new HashMap<String, User>();
|
||||
private Map<String, User> users = new HashMap<>();
|
||||
private List<GrantedAuthority> auths = AuthorityUtils
|
||||
.createAuthorityList("ROLE_USER");
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ public class UserTests {
|
||||
@Test
|
||||
public void hashLookupOnlyDependsOnUsername() throws Exception {
|
||||
User user1 = new User("rod", "koala", true, true, true, true, ROLE_12);
|
||||
Set<UserDetails> users = new HashSet<UserDetails>();
|
||||
Set<UserDetails> users = new HashSet<>();
|
||||
users.add(user1);
|
||||
|
||||
assertThat(users).contains(new User("rod", "koala", true, true, true, true,
|
||||
|
||||
+1
-2
@@ -26,7 +26,6 @@ import org.junit.Test;
|
||||
import org.skyscreamer.jsonassert.JSONAssert;
|
||||
|
||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||
import org.springframework.security.core.userdetails.User;
|
||||
|
||||
@@ -138,7 +137,7 @@ public class UsernamePasswordAuthenticationTokenMixinTests extends AbstractMixin
|
||||
NonUserPrincipal principal = new NonUserPrincipal();
|
||||
principal.setUsername("admin");
|
||||
UsernamePasswordAuthenticationToken token =
|
||||
new UsernamePasswordAuthenticationToken(principal, null, new ArrayList<GrantedAuthority>());
|
||||
new UsernamePasswordAuthenticationToken(principal, null, new ArrayList<>());
|
||||
String actualJson = mapper.writeValueAsString(token);
|
||||
JSONAssert.assertEquals(AUTHENTICATED_NON_USER_PRINCIPAL_JSON, actualJson, true);
|
||||
}
|
||||
|
||||
+1
-1
@@ -359,7 +359,7 @@ public class JdbcUserDetailsManagerTests {
|
||||
}
|
||||
|
||||
private class MockUserCache implements UserCache {
|
||||
private Map<String, UserDetails> cache = new HashMap<String, UserDetails>();
|
||||
private Map<String, UserDetails> cache = new HashMap<>();
|
||||
|
||||
public UserDetails getUserFromCache(String username) {
|
||||
return (User) cache.get(username);
|
||||
|
||||
Reference in New Issue
Block a user