mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-16 21:42:27 +00:00
- md is not concurrency safe, so the whole thing needs to be synchronized or we need a pool, like ThreadLocal
- There's a convenience method that creates hex string
This commit is contained in:
1 parent
cc90da3533
commit
a091493c7a
1 file changed
+3
-12
@@ -11,6 +11,7 @@ import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import hudson.Extension;
|
||||
import hudson.Util;
|
||||
import hudson.model.Hudson;
|
||||
import hudson.model.ModelObject;
|
||||
|
||||
@@ -64,7 +65,7 @@ public class DefaultCrumbIssuer extends CrumbIssuer {
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected String issueCrumb(ServletRequest request, String salt) {
|
||||
protected synchronized String issueCrumb(ServletRequest request, String salt) {
|
||||
if (request instanceof HttpServletRequest) {
|
||||
if (md != null) {
|
||||
HttpServletRequest req = (HttpServletRequest) request;
|
||||
@@ -79,17 +80,7 @@ public class DefaultCrumbIssuer extends CrumbIssuer {
|
||||
}
|
||||
|
||||
md.update(buffer.toString().getBytes());
|
||||
byte[] crumbBytes = md.digest(salt.getBytes());
|
||||
|
||||
StringBuilder hexString = new StringBuilder();
|
||||
for (int i = 0; i < crumbBytes.length; i++) {
|
||||
String hex = Integer.toHexString(0xFF & crumbBytes[i]);
|
||||
if (hex.length() == 1) {
|
||||
hexString.append('0');
|
||||
}
|
||||
hexString.append(hex);
|
||||
}
|
||||
return hexString.toString();
|
||||
return Util.toHexString(md.digest(salt.getBytes()));
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
Reference in new issue
Block a user