Skip to content

Commit

Permalink
Merge pull request #158 from Funssion-SWM/user
Browse files Browse the repository at this point in the history
fix: setAuthorityOf 함수에서 여러 role 저장하게끔 수정
  • Loading branch information
goathoon authored Oct 27, 2023
2 parents 65d47f5 + 5552327 commit d1945c0
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public SaveMemberResponseDto create(HttpServletRequest request, HttpServletRespo
}
@PostMapping("/employer")
@ResponseStatus(HttpStatus.CREATED)
public SaveMemberResponseDto createEmployer(HttpServletRequest request, HttpServletResponse response, @RequestBody @Valid EmployerSaveDto employerSaveDto) throws IOException { //dto로 바꿔야함
public SaveMemberResponseDto createEmployer(HttpServletRequest request, HttpServletResponse response, @RequestBody @Valid EmployerSaveDto employerSaveDto) throws IOException {
return memberService.requestEmployerRegistration(employerSaveDto,request,response);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ public SaveMemberResponseDto save(SocialMember member) {
public SaveMemberResponseDto save(EmployerSaveDto employerSaveDto) {
SaveMemberResponseDto savedEmployer = saveEmployerInUserTable(employerSaveDto);
saveEmployerInAuthTable(employerSaveDto,savedEmployer.getId());

return savedEmployer;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package Funssion.Inforum.domain.member.service;

import Funssion.Inforum.common.constant.Role;
import Funssion.Inforum.common.dto.IsSuccessResponseDto;
import Funssion.Inforum.common.exception.badrequest.BadRequestException;
import Funssion.Inforum.common.utils.SecurityContextUtils;
Expand Down Expand Up @@ -30,6 +31,7 @@
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
Expand Down Expand Up @@ -85,7 +87,11 @@ private UsernamePasswordAuthenticationToken makeAuthentication(SaveMemberRespons

private Collection<GrantedAuthority> setAuthorityOf(SaveMemberResponseDto savedMember) {
List<GrantedAuthority> authorities = new ArrayList<>();
authorities.add(new SimpleGrantedAuthority(savedMember.getRole()));
String roles = Role.getIncludingRoles(savedMember.getRole());
for(String role : roles.split(",")){
if (!StringUtils.hasText(role)) continue;
authorities.add(new SimpleGrantedAuthority(role));
}
return authorities;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,9 @@ public OAuth2User loadUser(OAuth2UserRequest userRequest) throws OAuth2Authentic
SocialMember savedSocialMember = SocialMember.createSocialMember(email, nickname);
SaveMemberResponseDto savedResponse = memberRepository.save(savedSocialMember);
String roles = Role.addRole(Role.getIncludingRoles(savedResponse.getRole()), Role.OAUTH_FIRST_JOIN);// 최초 회원가입을 위한 임시 role 추가
log.info("roles in load user = {}",roles);
return new CustomUserDetails(String.valueOf(savedResponse.getId()),roles,oAuth2User.getAttributes());
}
else{
log.info("roles in load user = {}",Role.getIncludingRoles(socialMember.get().getRole()));
return new CustomUserDetails(String.valueOf(socialMember.get().getUserId()),Role.getIncludingRoles(socialMember.get().getRole()),oAuth2User.getAttributes());
}
}
Expand Down

0 comments on commit d1945c0

Please sign in to comment.