-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RID-421][#148][feat] : create launchedsequence & launchedmodule Auth… (
#149)
- Loading branch information
Showing
9 changed files
with
103 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/main/java/com/backend/curi/common/interceptor/Extractor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.backend.curi.common.interceptor; | ||
|
||
import com.backend.curi.exception.CuriException; | ||
import com.backend.curi.exception.ErrorType; | ||
import org.springframework.http.HttpStatus; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
|
||
public class Extractor { | ||
public static Long extractFromUrl(HttpServletRequest request, String point) { | ||
String requestUrl = request.getRequestURI(); | ||
String[] parts = requestUrl.split("/" +point+ "/"); | ||
if (parts.length >= 2) { | ||
String workspaceIdStr = parts[1].split("/")[0]; | ||
try { | ||
return Long.parseLong(workspaceIdStr); | ||
} catch (NumberFormatException e) { | ||
throw new CuriException(HttpStatus.BAD_REQUEST, ErrorType.INVALID_URL_ERROR); | ||
} | ||
} | ||
|
||
throw new CuriException(HttpStatus.BAD_REQUEST, ErrorType.INVALID_URL_ERROR); | ||
} | ||
} |
31 changes: 30 additions & 1 deletion
31
src/main/java/com/backend/curi/common/interceptor/LaunchedmoduleAuthInterceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,33 @@ | ||
package com.backend.curi.common.interceptor; | ||
|
||
public class LaunchedmoduleAuthInterceptor { | ||
|
||
import com.backend.curi.exception.CuriException; | ||
import com.backend.curi.exception.ErrorType; | ||
import com.backend.curi.launched.service.LaunchedModuleService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.servlet.HandlerInterceptor; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class LaunchedmoduleAuthInterceptor implements HandlerInterceptor { | ||
private final LaunchedModuleService launchedModuleService; | ||
|
||
@Override | ||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { | ||
Long workspaceId = Extractor.extractFromUrl(request, "workspaces"); | ||
Long launchedmoduleId = Extractor.extractFromUrl(request, "modules"); | ||
|
||
var launchedModule = launchedModuleService.getLaunchedModuleEntity(launchedmoduleId); | ||
if(!launchedModule.getWorkspace().getId().equals(workspaceId)){ | ||
throw new CuriException(HttpStatus.NOT_FOUND, ErrorType.MODULE_NOT_EXISTS); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
} |
31 changes: 30 additions & 1 deletion
31
src/main/java/com/backend/curi/common/interceptor/LaunchedsequenceAuthInterceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,33 @@ | ||
package com.backend.curi.common.interceptor; | ||
|
||
public class LaunchedsequenceAuthInterceptor { | ||
import com.backend.curi.exception.CuriException; | ||
import com.backend.curi.exception.ErrorType; | ||
import com.backend.curi.launched.repository.entity.LaunchedSequence; | ||
import com.backend.curi.launched.service.LaunchedSequenceService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.servlet.HandlerInterceptor; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class LaunchedsequenceAuthInterceptor implements HandlerInterceptor { | ||
|
||
private final LaunchedSequenceService launchedSequenceService; | ||
|
||
@Override | ||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { | ||
Long workspaceId = Extractor.extractFromUrl(request, "workspaces"); | ||
Long launchedsequenceId = Extractor.extractFromUrl(request, "sequences"); | ||
|
||
var launchedSequence = launchedSequenceService.getLaunchedSequenceEntity(launchedsequenceId); | ||
if(!launchedSequence.getWorkspace().getId().equals(workspaceId)){ | ||
throw new CuriException(HttpStatus.NOT_FOUND, ErrorType.SEQUENCE_NOT_EXISTS); | ||
} | ||
return true; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters