mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-06-30 15:52:15 +00:00
Remove unnecessary default constructors which throw IllegalArgumentException. Favours compile time over runtime errors.
This commit is contained in:
parent
4b4d4d3332
commit
e12c8310eb
@ -32,10 +32,6 @@ public class SecurityConfig implements ConfigAttribute {
|
|||||||
this.attrib = config;
|
this.attrib = config;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected SecurityConfig() {
|
|
||||||
throw new IllegalArgumentException("Cannot use default constructor");
|
|
||||||
}
|
|
||||||
|
|
||||||
//~ Methods ================================================================
|
//~ Methods ================================================================
|
||||||
|
|
||||||
public String getAttribute() {
|
public String getAttribute() {
|
||||||
|
@ -46,10 +46,6 @@ public class NamedEntityObjectIdentity implements AclObjectIdentity {
|
|||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected NamedEntityObjectIdentity() {
|
|
||||||
throw new IllegalArgumentException("Cannot use default constructor");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the <code>NamedEntityObjectIdentity</code> based on the passed
|
* Creates the <code>NamedEntityObjectIdentity</code> based on the passed
|
||||||
* object instance. The passed object must provide a <code>getId()</code>
|
* object instance. The passed object must provide a <code>getId()</code>
|
||||||
|
@ -45,10 +45,6 @@ public class PrincipalAcegiUserToken extends AbstractAdapterAuthenticationToken
|
|||||||
this.principal = principal;
|
this.principal = principal;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected PrincipalAcegiUserToken() {
|
|
||||||
throw new IllegalArgumentException("Cannot use default constructor");
|
|
||||||
}
|
|
||||||
|
|
||||||
//~ Methods ================================================================
|
//~ Methods ================================================================
|
||||||
|
|
||||||
public Object getCredentials() {
|
public Object getCredentials() {
|
||||||
|
@ -51,10 +51,6 @@ public class InterceptorStatusToken {
|
|||||||
this.secureObject = secureObject;
|
this.secureObject = secureObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected InterceptorStatusToken() {
|
|
||||||
throw new IllegalArgumentException("Cannot use default constructor");
|
|
||||||
}
|
|
||||||
|
|
||||||
//~ Methods ================================================================
|
//~ Methods ================================================================
|
||||||
|
|
||||||
public ConfigAttributeDefinition getAttr() {
|
public ConfigAttributeDefinition getAttr() {
|
||||||
|
@ -71,10 +71,6 @@ public class FilterInvocation {
|
|||||||
this.chain = chain;
|
this.chain = chain;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected FilterInvocation() {
|
|
||||||
throw new IllegalArgumentException("Cannot use default constructor");
|
|
||||||
}
|
|
||||||
|
|
||||||
//~ Methods ================================================================
|
//~ Methods ================================================================
|
||||||
|
|
||||||
public FilterChain getChain() {
|
public FilterChain getChain() {
|
||||||
|
@ -72,10 +72,6 @@ public class TicketResponse {
|
|||||||
this.proxyGrantingTicketIou = proxyGrantingTicketIou;
|
this.proxyGrantingTicketIou = proxyGrantingTicketIou;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected TicketResponse() {
|
|
||||||
throw new IllegalArgumentException("Cannot use default constructor");
|
|
||||||
}
|
|
||||||
|
|
||||||
//~ Methods ================================================================
|
//~ Methods ================================================================
|
||||||
|
|
||||||
public String getProxyGrantingTicketIou() {
|
public String getProxyGrantingTicketIou() {
|
||||||
|
@ -35,8 +35,6 @@ import org.springframework.util.Assert;
|
|||||||
public class User implements UserDetails {
|
public class User implements UserDetails {
|
||||||
//~ Instance fields ========================================================
|
//~ Instance fields ========================================================
|
||||||
|
|
||||||
// ~ Instance fields
|
|
||||||
// ========================================================
|
|
||||||
private String password;
|
private String password;
|
||||||
private String username;
|
private String username;
|
||||||
private GrantedAuthority[] authorities;
|
private GrantedAuthority[] authorities;
|
||||||
@ -47,12 +45,6 @@ public class User implements UserDetails {
|
|||||||
|
|
||||||
//~ Constructors ===========================================================
|
//~ Constructors ===========================================================
|
||||||
|
|
||||||
// ~ Constructors
|
|
||||||
// ===========================================================
|
|
||||||
protected User() {
|
|
||||||
throw new IllegalArgumentException("Cannot use default constructor");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct the <code>User</code> with the details required by {@link
|
* Construct the <code>User</code> with the details required by {@link
|
||||||
* DaoAuthenticationProvider}.
|
* DaoAuthenticationProvider}.
|
||||||
@ -192,8 +184,6 @@ public class User implements UserDetails {
|
|||||||
return username;
|
return username;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ~ Methods
|
|
||||||
// ================================================================
|
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
int code = 9792;
|
int code = 9792;
|
||||||
|
|
||||||
@ -260,13 +250,13 @@ public class User implements UserDetails {
|
|||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuffer sb = new StringBuffer();
|
StringBuffer sb = new StringBuffer();
|
||||||
sb.append(super.toString() + ": ");
|
sb.append(super.toString()).append(": ");
|
||||||
sb.append("Username: " + this.username + "; ");
|
sb.append("Username: ").append(this.username).append("; ");
|
||||||
sb.append("Password: [PROTECTED]; ");
|
sb.append("Password: [PROTECTED]; ");
|
||||||
sb.append("Enabled: " + this.enabled + "; ");
|
sb.append("Enabled: ").append(this.enabled).append("; ");
|
||||||
sb.append("AccountNonExpired: " + this.accountNonExpired + "; ");
|
sb.append("AccountNonExpired: ").append(this.accountNonExpired).append("; ");
|
||||||
sb.append("credentialsNonExpired: " + this.credentialsNonExpired + "; ");
|
sb.append("credentialsNonExpired: ").append(this.credentialsNonExpired).append("; ");
|
||||||
sb.append("AccountNonLocked: " + this.accountNonLocked + "; ");
|
sb.append("AccountNonLocked: ").append(this.accountNonLocked).append("; ");
|
||||||
|
|
||||||
if (this.getAuthorities() != null) {
|
if (this.getAuthorities() != null) {
|
||||||
sb.append("Granted Authorities: ");
|
sb.append("Granted Authorities: ");
|
||||||
|
@ -50,11 +50,13 @@ public class SecurityConfigTests extends TestCase {
|
|||||||
assertEquals("TEST".hashCode(), config.hashCode());
|
assertEquals("TEST".hashCode(), config.hashCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testNoArgsConstructor() {
|
public void testNoArgConstructorDoesntExist() {
|
||||||
|
Class clazz = SecurityConfig.class;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
new SecurityConfig();
|
clazz.getDeclaredConstructor((Class[])null);
|
||||||
fail("Should have thrown IllegalArgumentException");
|
fail("Should have thrown NoSuchMethodException");
|
||||||
} catch (IllegalArgumentException expected) {
|
} catch (NoSuchMethodException expected) {
|
||||||
assertTrue(true);
|
assertTrue(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -75,11 +75,13 @@ public class NamedEntityObjectIdentityTests extends TestCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDefaultConstructorRejected() {
|
public void testNoArgConstructorDoesntExist() {
|
||||||
|
Class clazz = NamedEntityObjectIdentity.class;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
new NamedEntityObjectIdentity();
|
clazz.getDeclaredConstructor((Class[])null);
|
||||||
fail("Should have thrown IllegalArgumentException");
|
fail("Should have thrown NoSuchMethodException");
|
||||||
} catch (IllegalArgumentException expected) {
|
} catch (NoSuchMethodException expected) {
|
||||||
assertTrue(true);
|
assertTrue(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -71,15 +71,6 @@ public class AbstractAdapterAuthenticationTokenTests extends TestCase {
|
|||||||
assertTrue(!token.isUserInRole("ROLE_XXXX"));
|
assertTrue(!token.isUserInRole("ROLE_XXXX"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testNoArgsConstructor() {
|
|
||||||
try {
|
|
||||||
new MockDecisionManagerImpl();
|
|
||||||
fail("Should have thrown IllegalArgumentException");
|
|
||||||
} catch (IllegalArgumentException expected) {
|
|
||||||
assertTrue(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testObjectsEquals() throws Exception {
|
public void testObjectsEquals() throws Exception {
|
||||||
MockDecisionManagerImpl token1 = new MockDecisionManagerImpl("my_password",
|
MockDecisionManagerImpl token1 = new MockDecisionManagerImpl("my_password",
|
||||||
"Test", "Password",
|
"Test", "Password",
|
||||||
@ -148,10 +139,6 @@ public class AbstractAdapterAuthenticationTokenTests extends TestCase {
|
|||||||
this.password = password;
|
this.password = password;
|
||||||
}
|
}
|
||||||
|
|
||||||
private MockDecisionManagerImpl() {
|
|
||||||
throw new IllegalArgumentException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object getCredentials() {
|
public Object getCredentials() {
|
||||||
return this.password;
|
return this.password;
|
||||||
}
|
}
|
||||||
|
@ -59,11 +59,13 @@ public class PrincipalAcegiUserTokenTests extends TestCase {
|
|||||||
assertEquals("Test", token.getName());
|
assertEquals("Test", token.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testNoArgsConstructor() {
|
public void testNoArgConstructorDoesntExist() {
|
||||||
|
Class clazz = PrincipalAcegiUserToken.class;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
new PrincipalAcegiUserToken();
|
clazz.getDeclaredConstructor((Class[])null);
|
||||||
fail("Should have thrown IllegalArgumentException");
|
fail("Should have thrown NoSuchMethodException");
|
||||||
} catch (IllegalArgumentException expected) {
|
} catch (NoSuchMethodException expected) {
|
||||||
assertTrue(true);
|
assertTrue(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,11 +48,13 @@ public class InterceptorStatusTokenTests extends TestCase {
|
|||||||
junit.textui.TestRunner.run(InterceptorStatusTokenTests.class);
|
junit.textui.TestRunner.run(InterceptorStatusTokenTests.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDefaultConstructor() {
|
public void testNoArgConstructorDoesntExist() {
|
||||||
|
Class clazz = InterceptorStatusToken.class;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
new InterceptorStatusToken();
|
clazz.getDeclaredConstructor((Class[])null);
|
||||||
fail("Should have thrown IllegalArgumentException");
|
fail("Should have thrown NoSuchMethodException");
|
||||||
} catch (IllegalArgumentException expected) {
|
} catch (NoSuchMethodException expected) {
|
||||||
assertTrue(true);
|
assertTrue(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -154,11 +154,13 @@ public class FilterInvocationDefinitionSourceEditorTests extends TestCase {
|
|||||||
assertEquals(2, map.getMapSize());
|
assertEquals(2, map.getMapSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testNoArgsConstructor() {
|
public void testNoArgConstructorDoesntExist() {
|
||||||
|
Class clazz = RegExpBasedFilterInvocationDefinitionMap.EntryHolder.class;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
new RegExpBasedFilterInvocationDefinitionMap().new EntryHolder();
|
clazz.getDeclaredConstructor((Class[])null);
|
||||||
fail("Should have thrown IllegalArgumentException");
|
fail("Should have thrown NoSuchMethodException");
|
||||||
} catch (IllegalArgumentException expected) {
|
} catch (NoSuchMethodException expected) {
|
||||||
assertTrue(true);
|
assertTrue(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -135,11 +135,13 @@ public class FilterInvocationDefinitionSourceEditorWithPathsTests
|
|||||||
assertEquals(2, map.getMapSize());
|
assertEquals(2, map.getMapSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testNoArgsConstructor() {
|
public void testNoArgConstructorDoesntExist() {
|
||||||
|
Class clazz = PathBasedFilterInvocationDefinitionMap.EntryHolder.class;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
new PathBasedFilterInvocationDefinitionMap().new EntryHolder();
|
clazz.getDeclaredConstructor((Class[])null);
|
||||||
fail("Should have thrown IllegalArgumentException");
|
fail("Should have thrown NoSuchMethodException");
|
||||||
} catch (IllegalArgumentException expected) {
|
} catch (NoSuchMethodException expected) {
|
||||||
assertTrue(true);
|
assertTrue(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -77,11 +77,13 @@ public class FilterInvocationTests extends MockObjectTestCase {
|
|||||||
fi.getFullRequestUrl());
|
fi.getFullRequestUrl());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testNoArgsConstructor() {
|
public void testNoArgConstructorDoesntExist() {
|
||||||
|
Class clazz = FilterInvocation.class;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
new FilterInvocation();
|
clazz.getDeclaredConstructor((Class[])null);
|
||||||
fail("Should have thrown IllegalArgumentException");
|
fail("Should have thrown NoSuchMethodException");
|
||||||
} catch (IllegalArgumentException expected) {
|
} catch (NoSuchMethodException expected) {
|
||||||
assertTrue(true);
|
assertTrue(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -82,11 +82,13 @@ public class TicketResponseTests extends TestCase {
|
|||||||
ticket.getProxyGrantingTicketIou());
|
ticket.getProxyGrantingTicketIou());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testNoArgConstructor() {
|
public void testNoArgConstructorDoesntExist() {
|
||||||
|
Class clazz = TicketResponse.class;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
new TicketResponse();
|
clazz.getDeclaredConstructor((Class[])null);
|
||||||
fail("Should have thrown IllegalArgumentException");
|
fail("Should have thrown NoSuchMethodException");
|
||||||
} catch (IllegalArgumentException expected) {
|
} catch (NoSuchMethodException expected) {
|
||||||
assertTrue(true);
|
assertTrue(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -101,11 +101,13 @@ public class UserTests extends TestCase {
|
|||||||
new GrantedAuthority[] {new GrantedAuthorityImpl("ROLE_ONE")})));
|
new GrantedAuthority[] {new GrantedAuthorityImpl("ROLE_ONE")})));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testNoArgConstructor() {
|
public void testNoArgConstructorDoesntExist() {
|
||||||
|
Class clazz = User.class;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
new User();
|
clazz.getDeclaredConstructor((Class[])null);
|
||||||
fail("Should have thrown IllegalArgumentException");
|
fail("Should have thrown NoSuchMethodException");
|
||||||
} catch (IllegalArgumentException expected) {
|
} catch (NoSuchMethodException expected) {
|
||||||
assertTrue(true);
|
assertTrue(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user