Skip to content

Commit f1012c1

Browse files
committed
Polish
1 parent 031c9bf commit f1012c1

File tree

8 files changed

+30
-35
lines changed

8 files changed

+30
-35
lines changed

spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/MvcEndpointSecurityInterceptor.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2016 the original author or authors.
2+
* Copyright 2012-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -128,7 +128,8 @@ private void logUnauthorizedAttempt() {
128128
private class AuthoritiesValidator {
129129

130130
private boolean hasAuthority(String role) {
131-
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
131+
Authentication authentication = SecurityContextHolder.getContext()
132+
.getAuthentication();
132133
if (authentication != null) {
133134
for (GrantedAuthority authority : authentication.getAuthorities()) {
134135
if (authority.getAuthority().equals(role)) {

spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/MvcEndpointSecurityInterceptorTests.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2016 the original author or authors.
2+
* Copyright 2012-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -130,23 +130,27 @@ public void sensitiveEndpointIfRoleIsNotCorrectShouldNotAllowAccess()
130130
}
131131

132132
@Test
133-
public void sensitiveEndpointIfRoleNotCorrectShouldCheckAuthorities() throws Exception {
133+
public void sensitiveEndpointIfRoleNotCorrectShouldCheckAuthorities()
134+
throws Exception {
134135
Principal principal = mock(Principal.class);
135136
this.request.setUserPrincipal(principal);
136137
Authentication authentication = mock(Authentication.class);
137-
Set<SimpleGrantedAuthority> authorities = Collections.singleton(new SimpleGrantedAuthority("SUPER_HERO"));
138+
Set<SimpleGrantedAuthority> authorities = Collections
139+
.singleton(new SimpleGrantedAuthority("SUPER_HERO"));
138140
doReturn(authorities).when(authentication).getAuthorities();
139141
SecurityContextHolder.getContext().setAuthentication(authentication);
140142
assertThat(this.securityInterceptor.preHandle(this.request, this.response,
141143
this.handlerMethod)).isTrue();
142144
}
143145

144146
@Test
145-
public void sensitiveEndpointIfRoleAndAuthoritiesNotCorrectShouldNotAllowAccess() throws Exception {
147+
public void sensitiveEndpointIfRoleAndAuthoritiesNotCorrectShouldNotAllowAccess()
148+
throws Exception {
146149
Principal principal = mock(Principal.class);
147150
this.request.setUserPrincipal(principal);
148151
Authentication authentication = mock(Authentication.class);
149-
Set<SimpleGrantedAuthority> authorities = Collections.singleton(new SimpleGrantedAuthority("HERO"));
152+
Set<SimpleGrantedAuthority> authorities = Collections
153+
.singleton(new SimpleGrantedAuthority("HERO"));
150154
doReturn(authorities).when(authentication).getAuthorities();
151155
SecurityContextHolder.getContext().setAuthentication(authentication);
152156
assertThat(this.securityInterceptor.preHandle(this.request, this.response,

spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/NoSpringSecurityMvcEndpointSecurityInterceptorTests.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2016 the original author or authors.
2+
* Copyright 2012-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -39,6 +39,8 @@
3939
import static org.mockito.Mockito.mock;
4040

4141
/**
42+
* Tests for {@link MvcEndpointSecurityInterceptor} when Spring Security is not available.
43+
*
4244
* @author Madhura Bhave
4345
*/
4446
@RunWith(ModifiedClassPathRunner.class)
@@ -77,7 +79,8 @@ public void setup() throws Exception {
7779
}
7880

7981
@Test
80-
public void sensitiveEndpointIfRoleNotPresentShouldNotValidateAuthorities() throws Exception {
82+
public void sensitiveEndpointIfRoleNotPresentShouldNotValidateAuthorities()
83+
throws Exception {
8184
Principal principal = mock(Principal.class);
8285
this.request.setUserPrincipal(principal);
8386
this.servletContext.declareRoles("HERO");
@@ -105,5 +108,5 @@ private static class TestMvcEndpoint extends EndpointMvcAdapter {
105108
}
106109

107110
}
108-
}
109111

112+
}

spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnBeanTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2016 the original author or authors.
2+
* Copyright 2012-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/websocket/WebSocketAutoConfigurationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2016 the original author or authors.
2+
* Copyright 2012-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

spring-boot-integration-tests/spring-boot-integration-tests-embedded-servlet-container/src/test/java/org/springframework/boot/context/embedded/ApplicationBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2016 the original author or authors.
2+
* Copyright 2012-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/AbstractDependencyFilterMojo.java

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package org.springframework.boot.maven;
1818

19-
import java.util.Iterator;
19+
import java.util.LinkedHashSet;
2020
import java.util.List;
2121
import java.util.Set;
2222
import java.util.StringTokenizer;
@@ -87,29 +87,15 @@ protected void setExcludeArtifactIds(String excludeArtifactIds) {
8787
this.excludeArtifactIds = excludeArtifactIds;
8888
}
8989

90-
@SuppressWarnings("unchecked")
9190
protected Set<Artifact> filterDependencies(Set<Artifact> dependencies,
9291
FilterArtifacts filters) throws MojoExecutionException {
93-
List<ArtifactsFilter> artifactsFilters = filters.getFilters();
9492
try {
95-
for (ArtifactsFilter filter : artifactsFilters) {
96-
Set<Artifact> result = filter.filter(dependencies);
97-
applyFiltering(dependencies, result);
98-
}
99-
return dependencies;
100-
}
101-
catch (ArtifactFilterException e) {
102-
throw new MojoExecutionException(e.getMessage(), e);
93+
Set<Artifact> filtered = new LinkedHashSet<Artifact>(dependencies);
94+
filtered.retainAll(filters.filter(dependencies));
95+
return filtered;
10396
}
104-
}
105-
106-
private void applyFiltering(Set<Artifact> original, Set<Artifact> filtered) {
107-
Iterator<Artifact> iterator = original.iterator();
108-
while (iterator.hasNext()) {
109-
Artifact element = iterator.next();
110-
if (!filtered.contains(element)) {
111-
iterator.remove();
112-
}
97+
catch (ArtifactFilterException ex) {
98+
throw new MojoExecutionException(ex.getMessage(), ex);
11399
}
114100
}
115101

spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/DependencyFilterMojoTests.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public void filterGroupIdKeepOrder() throws MojoExecutionException {
103103
}
104104

105105
@Test
106-
public void filterExcludeKeepOrder() throws MojoExecutionException {
106+
public void filterExcludeKeepOrder() throws MojoExecutionException {
107107
Exclude exclude = new Exclude();
108108
exclude.setGroupId("com.bar");
109109
exclude.setArtifactId("two");
@@ -121,7 +121,8 @@ private static Artifact createArtifact(String groupId, String artifactId) {
121121
return createArtifact(groupId, artifactId, null);
122122
}
123123

124-
private static Artifact createArtifact(String groupId, String artifactId, String scope) {
124+
private static Artifact createArtifact(String groupId, String artifactId,
125+
String scope) {
125126
Artifact a = mock(Artifact.class);
126127
given(a.getGroupId()).willReturn(groupId);
127128
given(a.getArtifactId()).willReturn(artifactId);

0 commit comments

Comments
 (0)