Cleanup redundant type casts

This commit is contained in:
Lars Grefer 2019-07-04 19:04:19 +02:00 committed by Rob Winch
parent 43737a56bd
commit c5b5cc507c
31 changed files with 38 additions and 42 deletions

View File

@ -455,7 +455,7 @@ public class BasicLookupStrategy implements LookupStrategy {
// Now we have the parent (if there is one), create the true AclImpl
AclImpl result = new AclImpl(inputAcl.getObjectIdentity(),
(Long) inputAcl.getId(), aclAuthorizationStrategy, grantingStrategy,
inputAcl.getId(), aclAuthorizationStrategy, grantingStrategy,
parent, null, inputAcl.isEntriesInheriting(), inputAcl.getOwner());
// Copy the "aces" from the input to the destination

View File

@ -118,7 +118,7 @@ public class JdbcAclService implements AclService {
Assert.isTrue(map.containsKey(object),
() -> "There should have been an Acl entry for ObjectIdentity " + object);
return (Acl) map.get(object);
return map.get(object);
}
public Acl readAclById(ObjectIdentity object) throws NotFoundException {

View File

@ -501,13 +501,13 @@ public class AclImplTests {
assertThat(acl.isSidLoaded(BEN)).isTrue();
assertThat(acl.isSidLoaded(null)).isTrue();
assertThat(acl.isSidLoaded(new ArrayList<>(0))).isTrue();
assertThat(acl.isSidLoaded(Arrays.asList((Sid) new GrantedAuthoritySid(
assertThat(acl.isSidLoaded(Arrays.asList(new GrantedAuthoritySid(
"ROLE_IGNORED"), new GrantedAuthoritySid("ROLE_IGNORED"))))
.isTrue();
assertThat(acl.isSidLoaded(Arrays.asList((Sid) new GrantedAuthoritySid(
assertThat(acl.isSidLoaded(Arrays.asList(new GrantedAuthoritySid(
"ROLE_GENERAL"), new GrantedAuthoritySid("ROLE_IGNORED"))))
.isFalse();
assertThat(acl.isSidLoaded(Arrays.asList((Sid) new GrantedAuthoritySid(
assertThat(acl.isSidLoaded(Arrays.asList(new GrantedAuthoritySid(
"ROLE_IGNORED"), new GrantedAuthoritySid("ROLE_GENERAL"))))
.isFalse();
}

View File

@ -319,7 +319,7 @@ public class JdbcMutableAclServiceTests extends
Acl acl = jdbcMutableAclService.readAclById(getTopParentOid());
assertThat(acl).isNotNull();
assertThat(getTopParentOid()).isEqualTo(((MutableAcl) acl).getObjectIdentity());
assertThat(getTopParentOid()).isEqualTo(acl.getObjectIdentity());
}
@Test

View File

@ -17,7 +17,6 @@
package org.springframework.security.cas.jackson2;
import com.fasterxml.jackson.core.Version;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import org.jasig.cas.client.authentication.AttributePrincipalImpl;
import org.jasig.cas.client.validation.AssertionImpl;
@ -48,7 +47,7 @@ public class CasJackson2Module extends SimpleModule {
@Override
public void setupModule(SetupContext context) {
SecurityJackson2Modules.enableDefaultTyping((ObjectMapper) context.getOwner());
SecurityJackson2Modules.enableDefaultTyping(context.getOwner());
context.setMixInAnnotations(AssertionImpl.class, AssertionImplMixin.class);
context.setMixInAnnotations(AttributePrincipalImpl.class, AttributePrincipalImplMixin.class);
context.setMixInAnnotations(CasAuthenticationToken.class, CasAuthenticationTokenMixin.class);

View File

@ -287,6 +287,6 @@ public class AuthenticationManagerBuilder
private <C extends UserDetailsAwareConfigurer<AuthenticationManagerBuilder, ? extends UserDetailsService>> C apply(
C configurer) throws Exception {
this.defaultUserDetailsService = configurer.getUserDetailsService();
return (C) super.apply(configurer);
return super.apply(configurer);
}
}

View File

@ -2072,11 +2072,11 @@ public class OAuth2ResourceServerConfigurerTests {
}
private <T> T bean(Class<T> beanClass) {
return (T) this.spring.getContext().getBean(beanClass);
return this.spring.getContext().getBean(beanClass);
}
private <T> T verifyBean(Class<T> beanClass) {
return (T) verify(this.spring.getContext().getBean(beanClass));
return verify(this.spring.getContext().getBean(beanClass));
}
private String json(String name) throws IOException {

View File

@ -23,7 +23,7 @@ public final class ExpressionUtils {
public static boolean evaluateAsBoolean(Expression expr, EvaluationContext ctx) {
try {
return ((Boolean) expr.getValue(ctx, Boolean.class)).booleanValue();
return expr.getValue(ctx, Boolean.class).booleanValue();
}
catch (EvaluationException e) {
throw new IllegalArgumentException("Failed to evaluate expression '"

View File

@ -98,7 +98,7 @@ public class MapBasedMethodSecurityMetadataSource extends
Class<?> clazz) {
RegisteredMethod registeredMethod = new RegisteredMethod(method, clazz);
if (methodMap.containsKey(registeredMethod)) {
return (List<ConfigAttribute>) methodMap.get(registeredMethod);
return methodMap.get(registeredMethod);
}
// Search superclass
if (clazz.getSuperclass() != null) {
@ -166,7 +166,7 @@ public class MapBasedMethodSecurityMetadataSource extends
// register all matching methods
for (Method method : matchingMethods) {
RegisteredMethod registeredMethod = new RegisteredMethod(method, javaType);
String regMethodName = (String) this.nameMap.get(registeredMethod);
String regMethodName = this.nameMap.get(registeredMethod);
if ((regMethodName == null)
|| (!regMethodName.equals(name) && (regMethodName.length() <= name

View File

@ -17,7 +17,6 @@
package org.springframework.security.jackson2;
import com.fasterxml.jackson.core.Version;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import org.springframework.security.authentication.AnonymousAuthenticationToken;
import org.springframework.security.authentication.BadCredentialsException;
@ -54,7 +53,7 @@ public class CoreJackson2Module extends SimpleModule {
@Override
public void setupModule(SetupContext context) {
SecurityJackson2Modules.enableDefaultTyping((ObjectMapper) context.getOwner());
SecurityJackson2Modules.enableDefaultTyping(context.getOwner());
context.setMixInAnnotations(AnonymousAuthenticationToken.class, AnonymousAuthenticationTokenMixin.class);
context.setMixInAnnotations(RememberMeAuthenticationToken.class, RememberMeAuthenticationTokenMixin.class);
context.setMixInAnnotations(SimpleGrantedAuthority.class, SimpleGrantedAuthorityMixin.class);

View File

@ -58,7 +58,7 @@ public class AnonymousAuthenticationTokenTests {
try {
new AnonymousAuthenticationToken("key", "Test",
(List<GrantedAuthority>) null);
null);
fail("Should have thrown IllegalArgumentException");
}
catch (IllegalArgumentException expected) {

View File

@ -21,7 +21,6 @@ package org.springframework.security.authentication.dao;
import java.util.HashMap;
import java.util.Map;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserCache;
import org.springframework.security.core.userdetails.UserDetails;
@ -29,7 +28,7 @@ public class MockUserCache implements UserCache {
private Map<String, UserDetails> cache = new HashMap<>();
public UserDetails getUserFromCache(String username) {
return (User) cache.get(username);
return cache.get(username);
}
public void putUserInCache(UserDetails user) {

View File

@ -62,7 +62,7 @@ public abstract class AbstractDelegatingSecurityContextScheduledExecutorServiceT
@Test
public void scheduleCallable() {
when(
(ScheduledFuture<Object>) delegate.schedule(wrappedCallable, 1,
delegate.schedule(wrappedCallable, 1,
TimeUnit.SECONDS)).thenReturn(expectedResult);
ScheduledFuture<Object> result = executor.schedule(callable, 1, TimeUnit.SECONDS);
assertThat(result).isEqualTo(expectedResult);

View File

@ -40,7 +40,7 @@ public class KeyBasedPersistenceTokenServiceTests {
service.setServerSecret("MY:SECRET$$$#");
service.setServerInteger(Integer.valueOf(454545));
try {
SecureRandom rnd = (SecureRandom) fb.getObject();
SecureRandom rnd = fb.getObject();
service.setSecureRandom(rnd);
service.afterPropertiesSet();
}

View File

@ -406,7 +406,7 @@ public class JdbcUserDetailsManagerTests {
private Map<String, UserDetails> cache = new HashMap<>();
public UserDetails getUserFromCache(String username) {
return (User) cache.get(username);
return cache.get(username);
}
public void putUserInCache(UserDetails user) {

View File

@ -120,7 +120,7 @@ public class LdapShaPasswordEncoder implements PasswordEncoder {
sha.update(salt);
}
byte[] hash = combineHashAndSalt(sha.digest(), (byte[]) salt);
byte[] hash = combineHashAndSalt(sha.digest(), salt);
String prefix;

View File

@ -62,7 +62,7 @@ public class PythonInterpreterPreInvocationAdvice implements
throw new IllegalStateException("Python script did not set the permit flag");
}
return (Boolean) Py.tojava(allowed, Boolean.class);
return Py.tojava(allowed, Boolean.class);
}
private Map<String, Object> createArgumentMap(MethodInvocation mi) {

View File

@ -24,7 +24,6 @@ import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.keygen.KeyGenerators;
import org.springframework.security.crypto.password.LdapShaPasswordEncoder;
import org.springframework.security.crypto.password.NoOpPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.ldap.AbstractLdapIntegrationTests;
import org.springframework.ldap.core.DirContextAdapter;
@ -122,7 +121,7 @@ public class PasswordComparisonAuthenticatorTests extends AbstractLdapIntegratio
@Test(expected = IllegalArgumentException.class)
public void testPasswordEncoderCantBeNull() {
authenticator.setPasswordEncoder((PasswordEncoder) null);
authenticator.setPasswordEncoder(null);
}
@Test

View File

@ -274,7 +274,7 @@ public class LdapUserDetailsManager implements UserDetailsManager {
ListIterator<ModificationItem> modIt = mods.listIterator();
while (modIt.hasNext()) {
ModificationItem mod = (ModificationItem) modIt.next();
ModificationItem mod = modIt.next();
Attribute a = mod.getAttribute();
if ("objectclass".equalsIgnoreCase(a.getID())) {
modIt.remove();

View File

@ -38,7 +38,7 @@ public class IndexPage {
public static <T> T to(WebDriver driver, int port, Class<T> page) {
driver.get("http://localhost:" + port +"/");
return (T) PageFactory.initElements(driver, page);
return PageFactory.initElements(driver, page);
}
public IndexPage assertAt() {

View File

@ -102,7 +102,7 @@ public class ContactDaoSpring extends JdbcDaoSupport implements ContactDao {
return null;
}
else {
return (Contact) list.get(0);
return list.get(0);
}
}

View File

@ -112,7 +112,7 @@ public class DocumentDaoImpl extends JdbcDaoSupport implements DocumentDao {
.getLong("id")));
}
});
return (AbstractElement[]) directories.toArray(new AbstractElement[] {});
return directories.toArray(new AbstractElement[] {});
}
List<AbstractElement> directories = getJdbcTemplate().query(
SELECT_FROM_DIRECTORY, new Object[] { directory.getId() },
@ -140,7 +140,7 @@ public class DocumentDaoImpl extends JdbcDaoSupport implements DocumentDao {
});
// Add the File elements after the Directory elements
directories.addAll(files);
return (AbstractElement[]) directories.toArray(new AbstractElement[] {});
return directories.toArray(new AbstractElement[] {});
}
public void update(File file) {

View File

@ -48,7 +48,7 @@ public class SecureDocumentDaoImpl extends DocumentDaoImpl implements SecureDocu
}
public String[] getUsers() {
return (String[]) getJdbcTemplate().query(SELECT_FROM_USERS,
return getJdbcTemplate().query(SELECT_FROM_USERS,
new RowMapper<String>() {
public String mapRow(ResultSet rs, int rowNumber) throws SQLException {
return rs.getString("USERNAME");

View File

@ -122,7 +122,7 @@ public abstract class WebTestUtils {
if (springSecurityFilterChain == null) {
return null;
}
List<Filter> filters = (List<Filter>) ReflectionTestUtils
List<Filter> filters = ReflectionTestUtils
.invokeMethod(springSecurityFilterChain, "getFilters", request);
if (filters == null) {
return null;

View File

@ -89,7 +89,7 @@ public class WebXmlMappableAttributesRetriever implements ResourceLoaderAware,
NodeList roles = secRoleElt.getElementsByTagName("role-name");
if (roles.getLength() > 0) {
String roleName = ((Element) roles.item(0)).getTextContent().trim();
String roleName = roles.item(0).getTextContent().trim();
roleNames.add(roleName);
logger.info("Retrieved role-name '" + roleName + "' from web.xml");
}

View File

@ -84,7 +84,7 @@ public class DigestAuthenticationEntryPoint implements AuthenticationEntryPoint,
public void commence(HttpServletRequest request, HttpServletResponse response,
AuthenticationException authException) throws IOException, ServletException {
HttpServletResponse httpResponse = (HttpServletResponse) response;
HttpServletResponse httpResponse = response;
// compute a nonce (do not use remote IP address due to proxy farms)
// format of nonce is:

View File

@ -177,7 +177,7 @@ public class FastHttpDateFormat {
Long cachedDate = null;
try {
cachedDate = (Long) parseCache.get(value);
cachedDate = parseCache.get(value);
}
catch (Exception ignored) {
}

View File

@ -47,12 +47,12 @@ public class DefaultServerRedirectStrategyTests {
@Test(expected = IllegalArgumentException.class)
public void sendRedirectWhenLocationNullThenException() {
this.strategy.sendRedirect(this.exchange, (URI) null);
this.strategy.sendRedirect(this.exchange, null);
}
@Test(expected = IllegalArgumentException.class)
public void sendRedirectWhenExchangeNullThenException() {
this.strategy.sendRedirect((ServerWebExchange) null, this.location);
this.strategy.sendRedirect(null, this.location);
}
@Test

View File

@ -56,7 +56,7 @@ public class RedirectServerAuthenticationEntryPointTests {
@Test(expected = IllegalArgumentException.class)
public void constructorStringWhenNullLocationThenException() {
new RedirectServerAuthenticationEntryPoint((String) null);
new RedirectServerAuthenticationEntryPoint(null);
}
@Test

View File

@ -56,7 +56,7 @@ public class RedirectServerAuthenticationFailureHandlerTests {
@Test(expected = IllegalArgumentException.class)
public void constructorStringWhenNullLocationThenException() {
new RedirectServerAuthenticationEntryPoint((String) null);
new RedirectServerAuthenticationEntryPoint(null);
}
@Test

View File

@ -45,7 +45,7 @@ public class HttpStatusServerAccessDeniedHandlerTests {
@Test(expected = IllegalArgumentException.class)
public void constructorHttpStatusWhenNullThenException() {
new HttpStatusServerAccessDeniedHandler((HttpStatus) null);
new HttpStatusServerAccessDeniedHandler(null);
}
@Test