Using modern Java features
This commit is contained in:
committed by
Josh Cummings
parent
7e01ebdd92
commit
9b603b99ab
@@ -17,7 +17,6 @@
|
||||
package org.springframework.security.access.vote;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.springframework.security.access.AccessDecisionVoter;
|
||||
import org.springframework.security.access.ConfigAttribute;
|
||||
@@ -47,9 +46,7 @@ public class DenyAgainVoter implements AccessDecisionVoter<Object> {
|
||||
|
||||
@Override
|
||||
public int vote(Authentication authentication, Object object, Collection<ConfigAttribute> attributes) {
|
||||
Iterator<ConfigAttribute> iter = attributes.iterator();
|
||||
while (iter.hasNext()) {
|
||||
ConfigAttribute attribute = iter.next();
|
||||
for (ConfigAttribute attribute : attributes) {
|
||||
if (this.supports(attribute)) {
|
||||
return ACCESS_DENIED;
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.springframework.security.access.vote;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.springframework.security.access.AccessDecisionVoter;
|
||||
import org.springframework.security.access.ConfigAttribute;
|
||||
@@ -49,9 +48,7 @@ public class DenyVoter implements AccessDecisionVoter<Object> {
|
||||
|
||||
@Override
|
||||
public int vote(Authentication authentication, Object object, Collection<ConfigAttribute> attributes) {
|
||||
Iterator<ConfigAttribute> iter = attributes.iterator();
|
||||
while (iter.hasNext()) {
|
||||
ConfigAttribute attribute = iter.next();
|
||||
for (ConfigAttribute attribute : attributes) {
|
||||
if (this.supports(attribute)) {
|
||||
return ACCESS_DENIED;
|
||||
}
|
||||
|
||||
@@ -222,16 +222,13 @@ public class DefaultJaasAuthenticationProviderTests {
|
||||
public void javadocExample() {
|
||||
String resName = "/" + getClass().getName().replace('.', '/') + ".xml";
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(resName);
|
||||
context.registerShutdownHook();
|
||||
try {
|
||||
try (context) {
|
||||
context.registerShutdownHook();
|
||||
this.provider = context.getBean(DefaultJaasAuthenticationProvider.class);
|
||||
Authentication auth = this.provider.authenticate(this.token);
|
||||
assertThat(auth.isAuthenticated()).isEqualTo(true);
|
||||
assertThat(auth.getPrincipal()).isEqualTo(this.token.getPrincipal());
|
||||
}
|
||||
finally {
|
||||
context.close();
|
||||
}
|
||||
}
|
||||
|
||||
private void verifyFailedLogin() {
|
||||
|
||||
@@ -174,8 +174,7 @@ public class JaasAuthenticationProviderTests {
|
||||
assertThat(set.contains("ROLE_TEST2")).withFailMessage("GrantedAuthorities should contain ROLE_TEST2").isTrue();
|
||||
boolean foundit = false;
|
||||
for (GrantedAuthority a : list) {
|
||||
if (a instanceof JaasGrantedAuthority) {
|
||||
JaasGrantedAuthority grant = (JaasGrantedAuthority) a;
|
||||
if (a instanceof JaasGrantedAuthority grant) {
|
||||
assertThat(grant.getPrincipal()).withFailMessage("Principal was null on JaasGrantedAuthority")
|
||||
.isNotNull();
|
||||
foundit = true;
|
||||
|
||||
@@ -30,8 +30,7 @@ public class TestCallbackHandler implements JaasAuthenticationCallbackHandler {
|
||||
|
||||
@Override
|
||||
public void handle(Callback callback, Authentication auth) {
|
||||
if (callback instanceof TextInputCallback) {
|
||||
TextInputCallback tic = (TextInputCallback) callback;
|
||||
if (callback instanceof TextInputCallback tic) {
|
||||
tic.setText(auth.getPrincipal().toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ import static org.mockito.Mockito.verifyNoInteractions;
|
||||
*/
|
||||
public class SpringAuthorizationEventPublisherTests {
|
||||
|
||||
Supplier<Authentication> authentication = () -> TestAuthentication.authenticatedUser();
|
||||
Supplier<Authentication> authentication = TestAuthentication::authenticatedUser;
|
||||
|
||||
ApplicationEventPublisher applicationEventPublisher;
|
||||
|
||||
|
||||
@@ -68,13 +68,7 @@ final class StaticFinalReflectionUtils {
|
||||
field.set(null, newValue);
|
||||
}
|
||||
}
|
||||
catch (SecurityException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
catch (IllegalAccessException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
catch (IllegalArgumentException ex) {
|
||||
catch (SecurityException | IllegalAccessException | IllegalArgumentException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ class ThreadLocalSecurityContextHolderStrategyTests {
|
||||
void deferredContextValidates() {
|
||||
this.strategy.setDeferredContext(() -> null);
|
||||
Supplier<SecurityContext> deferredContext = this.strategy.getDeferredContext();
|
||||
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> deferredContext.get());
|
||||
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(deferredContext::get);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user