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
12
Issues
12
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
a0fd0d58
Commit
a0fd0d58
authored
Oct 26, 2015
by
Matija Obreza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't check local reCaptcha
parent
d3055d30
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
13 deletions
+15
-13
src/main/java/org/genesys2/util/ReCaptchaUtil.java
src/main/java/org/genesys2/util/ReCaptchaUtil.java
+15
-13
No files found.
src/main/java/org/genesys2/util/ReCaptchaUtil.java
View file @
a0fd0d58
...
...
@@ -40,12 +40,25 @@ public class ReCaptchaUtil {
private
static
final
String
URL
=
"https://www.google.com/recaptcha/api/siteverify"
;
public
static
boolean
isValid
(
String
reCaptchaResponse
,
String
remoteAddr
,
String
captchaPrivateKey
)
throws
IOException
{
boolean
isLocalRequest
=
false
;
try
{
final
InetAddress
remoteInetAddr
=
InetAddress
.
getByName
(
remoteAddr
);
isLocalRequest
=
remoteInetAddr
.
isLinkLocalAddress
()
||
remoteInetAddr
.
isAnyLocalAddress
()
||
remoteInetAddr
.
isLoopbackAddress
();
LOG
.
warn
(
"Remote addr: "
+
remoteAddr
+
" "
+
remoteInetAddr
+
" isLocal="
+
isLocalRequest
);
}
catch
(
final
UnknownHostException
e1
)
{
LOG
.
warn
(
e1
.
getMessage
());
}
if
(
isLocalRequest
)
{
LOG
.
info
(
"Ignoring localhost re-captcha."
);
return
true
;
}
if
(
reCaptchaResponse
==
null
||
""
.
equals
(
reCaptchaResponse
))
{
return
false
;
}
boolean
isLocalRequest
=
false
;
URL
url
=
new
URL
(
URL
);
HttpURLConnection
connection
=
(
HttpURLConnection
)
url
.
openConnection
();
...
...
@@ -61,20 +74,9 @@ public class ReCaptchaUtil {
dataOutputStream
.
flush
();
dataOutputStream
.
close
();
try
{
final
InetAddress
remoteInetAddr
=
InetAddress
.
getByName
(
remoteAddr
);
isLocalRequest
=
remoteInetAddr
.
isLinkLocalAddress
()
||
remoteInetAddr
.
isAnyLocalAddress
()
||
remoteInetAddr
.
isLoopbackAddress
();
LOG
.
warn
(
"Remote addr: "
+
remoteAddr
+
" "
+
remoteInetAddr
+
" isLocal="
+
isLocalRequest
);
}
catch
(
final
UnknownHostException
e1
)
{
LOG
.
warn
(
e1
.
getMessage
());
}
int
responseCode
=
connection
.
getResponseCode
();
LOG
.
info
(
"Send recaptcha post request to --> "
+
url
+
"\nPost parameters : "
+
postParams
+
"\n Response Code : "
+
responseCode
);
if
(
isLocalRequest
)
{
LOG
.
info
(
"Ignoring localhost re-captcha."
);
// return true;
}
BufferedReader
in
=
new
BufferedReader
(
new
InputStreamReader
(
connection
.
getInputStream
()));
String
inputLine
;
...
...
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