-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into chore/add-tests-update-endorsement-status
- Loading branch information
Showing
9 changed files
with
173 additions
and
52 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
22 changes: 22 additions & 0 deletions
22
skill-tree/src/main/java/com/RDS/skilltree/Config/WebMvcConfig.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,22 @@ | ||
package com.RDS.skilltree.Config; | ||
|
||
import com.RDS.skilltree.utils.UUIDValidationInterceptor; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
|
||
@Configuration | ||
public class WebMvcConfig implements WebMvcConfigurer { | ||
private final UUIDValidationInterceptor uuidValidationInterceptor; | ||
|
||
@Autowired | ||
public WebMvcConfig(UUIDValidationInterceptor uuidValidationInterceptor) { | ||
this.uuidValidationInterceptor = uuidValidationInterceptor; | ||
} | ||
|
||
@Override | ||
public void addInterceptors(InterceptorRegistry registry) { | ||
registry.addInterceptor(uuidValidationInterceptor).addPathPatterns("/v1/endorsements"); | ||
} | ||
} |
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
27 changes: 26 additions & 1 deletion
27
skill-tree/src/main/java/com/RDS/skilltree/utils/UUIDValidationInterceptor.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,16 +1,41 @@ | ||
package com.RDS.skilltree.utils; | ||
|
||
import com.RDS.skilltree.Exceptions.InvalidParameterException; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import java.util.regex.Pattern; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.servlet.HandlerInterceptor; | ||
|
||
@Component | ||
public class UUIDValidationInterceptor implements HandlerInterceptor { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(UUIDValidationInterceptor.class); | ||
private static final Pattern UUID_REGEX = | ||
Pattern.compile( | ||
"^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$"); | ||
|
||
@Override | ||
public boolean preHandle( | ||
HttpServletRequest request, HttpServletResponse response, Object handler) { | ||
// Add logic during implementation | ||
String skillID = request.getParameter("skillID"); | ||
String userID = request.getParameter("userID"); | ||
|
||
if (skillID != null && !skillID.isEmpty() && !isValidUUID(skillID)) { | ||
throw new InvalidParameterException("skillID", "Invalid UUID format"); | ||
} | ||
|
||
if (userID != null && !userID.isEmpty() && !isValidUUID(userID)) { | ||
throw new InvalidParameterException("userID", "Invalid UUID format"); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
private boolean isValidUUID(String uuidString) { | ||
|
||
return UUID_REGEX.matcher(uuidString).matches(); | ||
} | ||
} |
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
Oops, something went wrong.