-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ALS-4980] pic sure medium findings (#144)
[ALS-4980] Add additional validation of parameters [ALS-4980] Use converter to enforce UUID
- Loading branch information
Showing
10 changed files
with
93 additions
and
39 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
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
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
23 changes: 23 additions & 0 deletions
23
pic-sure-util/src/main/java/edu/harvard/dbmi/avillach/util/converter/UUIDParamConverter.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,23 @@ | ||
package edu.harvard.dbmi.avillach.util.converter; | ||
|
||
import edu.harvard.dbmi.avillach.util.exception.ProtocolException; | ||
|
||
import javax.ws.rs.ext.ParamConverter; | ||
import java.util.UUID; | ||
|
||
public class UUIDParamConverter implements ParamConverter<UUID> { | ||
|
||
@Override | ||
public UUID fromString(String value) { | ||
try { | ||
return UUID.fromString(value); | ||
} catch (IllegalArgumentException e) { | ||
throw new ProtocolException(ProtocolException.INCORRECTLY_FORMATTED_REQUEST); | ||
} | ||
} | ||
|
||
@Override | ||
public String toString(UUID value) { | ||
return value.toString(); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...il/src/main/java/edu/harvard/dbmi/avillach/util/converter/UUIDParamConverterProvider.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,18 @@ | ||
package edu.harvard.dbmi.avillach.util.converter; | ||
|
||
import javax.ws.rs.ext.ParamConverter; | ||
import javax.ws.rs.ext.ParamConverterProvider; | ||
import javax.ws.rs.ext.Provider; | ||
import java.util.UUID; | ||
|
||
@Provider | ||
public class UUIDParamConverterProvider implements ParamConverterProvider { | ||
|
||
@Override | ||
public <T> ParamConverter<T> getConverter(Class<T> rawType, java.lang.reflect.Type genericType, java.lang.annotation.Annotation[] annotations) { | ||
if (rawType.equals(UUID.class)) { | ||
return (ParamConverter<T>) new UUIDParamConverter(); | ||
} | ||
return null; | ||
} | ||
} |