[BAEL-1411] Format code

This commit is contained in:
linhvovn 2017-12-31 23:32:33 +08:00
parent 1b7e6957bb
commit 2bac6f88e7
7 changed files with 145 additions and 147 deletions

View File

@ -10,6 +10,5 @@ import org.springframework.security.access.prepost.PreAuthorize;
@Target(ElementType.METHOD) @Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@PreAuthorize("hasRole('VIEWER')") @PreAuthorize("hasRole('VIEWER')")
public @interface IsViewer public @interface IsViewer {
{
} }

View File

@ -52,7 +52,7 @@ public class UserRoleService {
} }
@PreAuthorize("hasAuthority('SYS_ADMIN')") @PreAuthorize("hasAuthority('SYS_ADMIN')")
public String getUsernameInLowerCase(){ public String getUsernameLC() {
return getUsername().toLowerCase(); return getUsername().toLowerCase();
} }
@ -67,8 +67,8 @@ public class UserRoleService {
return securityContext return securityContext
.getAuthentication() .getAuthentication()
.getAuthorities() .getAuthorities()
.stream().map(auth -> auth.getAuthority()) .stream()
.collect(Collectors.joining(",")); .map(auth -> auth.getAuthority()).collect(Collectors.joining(","));
} }
@PostAuthorize("returnObject.username == authentication.principal.nickName") @PostAuthorize("returnObject.username == authentication.principal.nickName")
@ -83,8 +83,7 @@ public class UserRoleService {
@PreFilter(value = "filterObject != authentication.principal.username", filterTarget = "usernames") @PreFilter(value = "filterObject != authentication.principal.username", filterTarget = "usernames")
public String joinUsernamesAndRoles(List<String> usernames, List<String> roles) { public String joinUsernamesAndRoles(List<String> usernames, List<String> roles) {
return usernames.stream().collect(Collectors.joining(";")) return usernames.stream().collect(Collectors.joining(";")) + ":" + roles.stream().collect(Collectors.joining(";"));
+":"+roles.stream().collect(Collectors.joining(";"));
} }
@PostFilter("filterObject != authentication.principal.username") @PostFilter("filterObject != authentication.principal.username")

View File

@ -81,7 +81,7 @@ public class TestMethodSecurity{
@Test @Test
@WithMockUser(username = "JOHN", authorities = { "SYS_ADMIN" }) @WithMockUser(username = "JOHN", authorities = { "SYS_ADMIN" })
public void givenAuthoritySysAdmin_whenCallGetUsernameInLowerCase_thenReturnUsername() { public void givenAuthoritySysAdmin_whenCallGetUsernameInLowerCase_thenReturnUsername() {
String username = userRoleService.getUsernameInLowerCase(); String username = userRoleService.getUsernameLC();
assertEquals("john", username); assertEquals("john", username);
} }