Skip to content

Commit

Permalink
Modify UserPrincipal creation.
Browse files Browse the repository at this point in the history
  • Loading branch information
totalnuob committed Nov 24, 2018
1 parent ae83c60 commit 7981a72
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ public class UserController {
private static final Logger logger = LoggerFactory.getLogger(UserController.class);

@GetMapping("/user/me")
@PreAuthorize("hasRole('STARTUP')")
@PreAuthorize("hasRoles('CORPORATE', 'STARTUP')")
public UserSummary getCurrentUser(@CurrentUser UserPrincipal currentUser) {
UserSummary userSummary = new UserSummary(currentUser.getId(), currentUser.getUsername(), currentUser.getName(),
RoleName.ROLE_STARTUP.name());
currentUser.getRole().getName().name());
return userSummary;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.hack.junction.sharecity.model.AppUser;
import com.hack.junction.sharecity.model.Role;
import com.hack.junction.sharecity.model.User;
import lombok.AllArgsConstructor;
import lombok.Data;
Expand Down Expand Up @@ -34,6 +35,9 @@ public class UserPrincipal implements UserDetails {
@JsonIgnore
private String password;

@JsonIgnore
private Role role;

private Collection<? extends GrantedAuthority> authorities;

public static UserPrincipal create(AppUser user ) {
Expand All @@ -47,6 +51,7 @@ public static UserPrincipal create(AppUser user ) {
user.getUsername(),
user.getEmail(),
user.getPassword(),
user.getRoles().iterator().next(),
authorities
);
}
Expand Down

0 comments on commit 7981a72

Please sign in to comment.