Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
ac
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
OATS-CADC
ac
Commits
f7b8e184
Commit
f7b8e184
authored
9 years ago
by
Alinga Yeung
Browse files
Options
Downloads
Patches
Plain Diff
Story ac2. Updated Password servlet as per Brian's code review comments.
parent
2ab9e92b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
projects/cadcAccessControl-Server/src/ca/nrc/cadc/ac/server/web/users/PasswordServlet.java
+79
-68
79 additions, 68 deletions
.../src/ca/nrc/cadc/ac/server/web/users/PasswordServlet.java
with
79 additions
and
68 deletions
projects/cadcAccessControl-Server/src/ca/nrc/cadc/ac/server/web/users/PasswordServlet.java
+
79
−
68
View file @
f7b8e184
...
...
@@ -97,77 +97,88 @@ public class PasswordServlet extends HttpServlet
public
void
doPost
(
final
HttpServletRequest
request
,
final
HttpServletResponse
response
)
throws
IOException
{
response
.
setStatus
(
HttpServletResponse
.
SC_INTERNAL_SERVER_ERROR
);
final
long
start
=
System
.
currentTimeMillis
();
final
ServletLogInfo
logInfo
=
new
ServletLogInfo
(
request
);
log
.
info
(
logInfo
.
start
());
final
Subject
subject
=
AuthenticationUtil
.
getSubject
(
request
);
logInfo
.
setSubject
(
subject
);
Subject
.
doAs
(
subject
,
new
PrivilegedAction
<
Void
>()
try
{
@Override
public
Void
run
()
{
try
{
final
Set
<
HttpPrincipal
>
webPrincipals
=
subject
.
getPrincipals
(
HttpPrincipal
.
class
);
if
(
webPrincipals
.
isEmpty
())
{
response
.
setStatus
(
HttpServletResponse
.
SC_UNAUTHORIZED
);
}
else
{
User
<
HttpPrincipal
>
user
=
new
User
<
HttpPrincipal
>(
webPrincipals
.
toArray
(
new
HttpPrincipal
[
1
])[
0
]);
String
oldPassword
=
request
.
getParameter
(
"old_password"
);
String
newPassword
=
request
.
getParameter
(
"new_password"
);
if
(
StringUtil
.
hasText
(
oldPassword
))
{
if
(
StringUtil
.
hasText
(
newPassword
))
{
(
new
LdapUserPersistence
<
HttpPrincipal
>()).
setPassword
(
user
,
oldPassword
,
newPassword
);
}
else
{
throw
new
IllegalArgumentException
(
"Missing new password"
);
}
}
else
{
throw
new
IllegalArgumentException
(
"Missing old password"
);
}
}
}
catch
(
IllegalArgumentException
e
)
{
log
.
debug
(
e
.
getMessage
(),
e
);
logInfo
.
setMessage
(
e
.
getMessage
());
response
.
setStatus
(
400
);
}
catch
(
AccessControlException
e
)
{
log
.
debug
(
e
.
getMessage
(),
e
);
logInfo
.
setMessage
(
e
.
getMessage
());
response
.
setStatus
(
401
);
}
catch
(
Throwable
t
)
{
String
message
=
"Internal Server Error: "
+
t
.
getMessage
();
log
.
error
(
message
,
t
);
logInfo
.
setSuccess
(
false
);
logInfo
.
setMessage
(
message
);
response
.
setStatus
(
500
);
}
finally
{
logInfo
.
setElapsedTime
(
System
.
currentTimeMillis
()
-
start
);
log
.
info
(
logInfo
.
end
());
}
return
null
;
}
});
final
Subject
subject
=
AuthenticationUtil
.
getSubject
(
request
);
if
((
subject
==
null
)
||
(
subject
.
getPrincipals
(
HttpPrincipal
.
class
).
isEmpty
()))
{
logInfo
.
setMessage
(
"Missing subject"
);
response
.
setStatus
(
HttpServletResponse
.
SC_UNAUTHORIZED
);
}
else
{
logInfo
.
setSubject
(
subject
);
Subject
.
doAs
(
subject
,
new
PrivilegedAction
<
Void
>()
{
@Override
public
Void
run
()
{
try
{
response
.
setStatus
(
HttpServletResponse
.
SC_OK
);
final
Set
<
HttpPrincipal
>
webPrincipals
=
subject
.
getPrincipals
(
HttpPrincipal
.
class
);
User
<
HttpPrincipal
>
user
=
new
User
<
HttpPrincipal
>(
webPrincipals
.
iterator
().
next
());
String
oldPassword
=
request
.
getParameter
(
"old_password"
);
String
newPassword
=
request
.
getParameter
(
"new_password"
);
if
(
StringUtil
.
hasText
(
oldPassword
))
{
if
(
StringUtil
.
hasText
(
newPassword
))
{
(
new
LdapUserPersistence
<
HttpPrincipal
>()).
setPassword
(
user
,
oldPassword
,
newPassword
);
}
else
{
throw
new
IllegalArgumentException
(
"Missing new password"
);
}
}
else
{
throw
new
IllegalArgumentException
(
"Missing old password"
);
}
}
catch
(
IllegalArgumentException
e
)
{
log
.
debug
(
e
.
getMessage
(),
e
);
logInfo
.
setMessage
(
e
.
getMessage
());
response
.
setStatus
(
HttpServletResponse
.
SC_BAD_REQUEST
);
}
catch
(
AccessControlException
e
)
{
log
.
debug
(
e
.
getMessage
(),
e
);
logInfo
.
setMessage
(
e
.
getMessage
());
response
.
setStatus
(
HttpServletResponse
.
SC_UNAUTHORIZED
);
}
catch
(
Throwable
t
)
{
String
message
=
"Internal Server Error: "
+
t
.
getMessage
();
log
.
error
(
message
,
t
);
logInfo
.
setSuccess
(
false
);
logInfo
.
setMessage
(
message
);
response
.
setStatus
(
HttpServletResponse
.
SC_INTERNAL_SERVER_ERROR
);
}
return
null
;
}
});
}
}
catch
(
Throwable
t
)
{
String
message
=
"Internal Server Error: "
+
t
.
getMessage
();
log
.
error
(
message
,
t
);
logInfo
.
setSuccess
(
false
);
logInfo
.
setMessage
(
message
);
}
finally
{
logInfo
.
setElapsedTime
(
System
.
currentTimeMillis
()
-
start
);
log
.
info
(
logInfo
.
end
());
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment