Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Genesys Backend
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
18
Issues
18
List
Boards
Labels
Service Desk
Milestones
Operations
Operations
Incidents
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Genesys PGR
Genesys Backend
Commits
69218799
Commit
69218799
authored
Sep 06, 2019
by
Viacheslav Pavlov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added api endpoint for confirming receipt of request
added @Transactional to request confirming
parent
7b7ec2f4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
0 deletions
+36
-0
src/main/java/org/genesys2/server/api/v1/RequestsController.java
...n/java/org/genesys2/server/api/v1/RequestsController.java
+35
-0
src/main/java/org/genesys2/server/service/impl/RequestServiceImpl.java
.../org/genesys2/server/service/impl/RequestServiceImpl.java
+1
-0
No files found.
src/main/java/org/genesys2/server/api/v1/RequestsController.java
View file @
69218799
...
...
@@ -37,7 +37,9 @@ import org.genesys2.server.service.TokenVerificationService;
import
org.genesys2.server.service.filter.MaterialRequestFilter
;
import
org.genesys2.server.service.filter.MaterialSubRequestFilter
;
import
org.genesys2.server.service.impl.EasySMTAException
;
import
org.genesys2.util.ReCaptchaUtil
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.data.domain.Sort
;
import
org.springframework.http.MediaType
;
import
org.springframework.security.access.prepost.PreAuthorize
;
...
...
@@ -55,6 +57,8 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import
io.swagger.annotations.Api
;
import
javax.servlet.http.HttpServletRequest
;
@RestController
(
"requestsApi1"
)
@PreAuthorize
(
"isAuthenticated()"
)
@RequestMapping
(
value
=
{
RequestsController
.
CONTROLLER_URL
})
...
...
@@ -66,6 +70,10 @@ public class RequestsController extends ApiBaseController {
public
static
final
String
PARAM_KEY
=
"key"
;
public
static
final
String
PARAM_TOKENUUID
=
"tokenUuid"
;
@Value
(
"${captcha.privateKey}"
)
private
String
captchaPrivateKey
;
private
final
ObjectMapper
objectMapper
=
new
ObjectMapper
();
...
...
@@ -184,6 +192,33 @@ public class RequestsController extends ApiBaseController {
throw
new
InvalidApiUsageException
(
e
.
getMessage
(),
e
);
}
}
/**
* Confirm receipt of request
*
* @return
* @throws InvalidApiUsageException
*/
@PostMapping
(
value
=
"/r/confirm"
,
produces
=
{
MediaType
.
APPLICATION_JSON_VALUE
})
public
MaterialSubRequest
confirmRequest
(
@RequestParam
(
value
=
"g-recaptcha-response"
)
final
String
captchaResponse
,
@RequestParam
(
PARAM_TOKENUUID
)
String
tokenUuid
,
@RequestParam
(
PARAM_KEY
)
String
key
,
final
HttpServletRequest
request
)
throws
IOException
{
// Validate the reCAPTCHA
if
(!
ReCaptchaUtil
.
isValid
(
captchaResponse
,
request
.
getRemoteAddr
(),
captchaPrivateKey
))
{
LOG
.
warn
(
"Invalid captcha."
);
throw
new
InvalidApiUsageException
(
"Captcha check failed."
);
}
LOG
.
info
(
"Validating request tokenUuid={}, key={}"
,
tokenUuid
,
key
);
try
{
return
requestService
.
validateReceipt
(
tokenUuid
,
key
);
}
catch
(
TokenVerificationService
.
NoSuchVerificationTokenException
|
TokenVerificationService
.
TokenExpiredException
e
)
{
throw
new
InvalidApiUsageException
(
e
.
getMessage
(),
e
);
}
}
/**
* Reload PID data
*
...
...
src/main/java/org/genesys2/server/service/impl/RequestServiceImpl.java
View file @
69218799
...
...
@@ -438,6 +438,7 @@ public class RequestServiceImpl implements RequestService {
}
@Override
@Transactional
public
MaterialSubRequest
validateReceipt
(
String
tokenUuid
,
String
key
)
throws
NoSuchVerificationTokenException
,
TokenExpiredException
{
final
VerificationToken
consumedToken
=
tokenVerificationService
.
consumeToken
(
RECEIPT_TOKENTYPE
,
tokenUuid
,
key
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment