Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev auth refactoring #30

Merged
merged 3 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.bit.lot.flower.auth.common.valueobject.AuthenticationProvider;
import com.bit.lot.flower.auth.oauth.util.access.GetKakaoAccessKeyHttpUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.parameters.P;
import org.springframework.stereotype.Component;

@RequiredArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;

@FeignClient(name = "get-store-id", url = "${service.store.domain}")
public interface StoreIdFeignRequest{
@GetMapping("/stores/id")
public ResponseEntity<StoreId> request(AuthId storeUserId);
public ResponseEntity<StoreId> request(@RequestHeader Long storeUserId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@ public Authentication attemptAuthentication(HttpServletRequest request,
return storeManagerAuthenticationManager.authenticate(
new UsernamePasswordAuthenticationToken(dto.getEmail(), dto.getPassword(), null));
} catch (BadCredentialsException | IOException e) {
response.setStatus(401);
throw new BadCredentialsException("존재하지 않는 시스템 어드민 유저입니다.");
} catch (StoreManagerAuthException e) {
response.setStatus(403);
throw new StoreManagerAuthException(e.getMessage());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ public class StoreManagerStoreIdRequestImpl implements
private final StoreIdFeignRequest feignRequest;
@Override
public StoreId requestStoreId(AuthId storeManagerId) {
return feignRequest.request(storeManagerId).getBody();
return feignRequest.request(storeManagerId.getValue()).getBody();
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package com.bit.lot.flower.auth.store.repository;

import com.bit.lot.flower.auth.store.entity.StoreManagerAuth;
import com.bit.lot.flower.auth.store.valueobject.StoreManagerStatus;
import java.util.List;
import java.util.Optional;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface StoreManagerAuthRepository extends JpaRepository<StoreManagerAuth, Long> {
Optional<StoreManagerAuth> findByEmail(String email);
List<StoreManagerAuth> findAllByStatus(StoreManagerStatus storeManagerStatus, Pageable pageable);
}

Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ private void checkStoreMangerStatus(StoreManagerAuth storeManagerAuth) {
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
StoreManagerAuth storeManagerAuth = checkCredential(authentication);

checkStoreMangerStatus(storeManagerAuth);

return new UsernamePasswordAuthenticationToken(new AuthId(storeManagerAuth.getId()),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,41 @@
package com.bit.lot.flower.auth.system.admin.http;

import com.bit.lot.flower.auth.common.valueobject.AuthId;
import com.bit.lot.flower.auth.store.valueobject.StoreManagerStatus;
import com.bit.lot.flower.auth.system.admin.dto.UpdateStoreManagerStatusDto;
import com.bit.lot.flower.auth.system.admin.service.GetStoreManagerByStatusService;
import com.bit.lot.flower.auth.system.admin.service.UpdateStoreMangerStatusService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import javax.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RequiredArgsConstructor
@RestController
@Slf4j
@Api(value="system-auth")
@Api(value = "system-auth")
public class SystemAdminRestController {

private final UpdateStoreMangerStatusService<AuthId> updateStoreMangerStatusService;
private final GetStoreManagerByStatusService getStoreManagerByStatusService;

@GetMapping("/store-manager/{status}")
public ResponseEntity<List<Long>> getStoreManagerApplications(
@PathVariable StoreManagerStatus status,
Pageable pageable) {
return ResponseEntity.ok(getStoreManagerByStatusService.getIdListByStatus(status,pageable));
}


@ApiOperation(value = "시스템 관리자 스토어 매니저 인허가 처리", notes = "처리 가능한 enum type: "
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.bit.lot.flower.auth.system.admin.service;

import com.bit.lot.flower.auth.store.entity.StoreManagerAuth;
import com.bit.lot.flower.auth.store.repository.StoreManagerAuthRepository;
import com.bit.lot.flower.auth.store.valueobject.StoreManagerStatus;
import java.util.List;
import java.util.stream.Collectors;
import lombok.AllArgsConstructor;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Component;

@RequiredArgsConstructor
@Component
public class GetStoreManagerByStatusService {

private final StoreManagerAuthRepository repository;


public List<Long> getIdListByStatus(StoreManagerStatus storeManagerStatus, Pageable pageable) {
List<StoreManagerAuth> storeManagerAuthList = repository.findAllByStatus(storeManagerStatus,pageable);
return entityToIdMap(storeManagerAuthList);
}

private List<Long> entityToIdMap(List<StoreManagerAuth> storeManagerAuthLsit){
return storeManagerAuthLsit.stream().map(StoreManagerAuth::getId).collect(Collectors.toList());
}
}
5 changes: 3 additions & 2 deletions src/main/resources/application-local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ spring:
ddl-auto: update
show-sql: true


security:
oauth2:
client:
Expand Down Expand Up @@ -87,8 +88,8 @@ kakao:
service:
user:
domain: http://localhost:8600
store:
domain: http://localhost:5000
store:
domain: http://localhost:5000


management:
Expand Down
Loading