File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\test\src\main\java\org\jvnet\hudson\test\TestCrumbIssuer.java.html

1 /**
2 * Copyright (c) 2008-2009 Yahoo! Inc.
3 * All rights reserved.
4 * The copyrights to the contents of this file are licensed under the MIT License (http://www.opensource.org/licenses/mit-license.php)
5 */
6 package org.jvnet.hudson.test;
7
8 import javax.servlet.ServletRequest;
9
10 import net.sf.json.JSONObject;
11
12 import org.kohsuke.stapler.StaplerRequest;
13
14 import hudson.Extension;
15 import hudson.model.ModelObject;
16 import hudson.security.csrf.CrumbIssuer;
17 import hudson.security.csrf.CrumbIssuerDescriptor;
18
19 /**
20 * A crumb issuer that issues a constant crumb value. Used for unit testing.
21 * @author dty
22 */
23 public class TestCrumbIssuer extends CrumbIssuer
24 {
25 @Override
26 protected String issueCrumb( ServletRequest request, String salt )
27 {
28 return "test";
29 }
30
31 @Override
32 public boolean validateCrumb( ServletRequest request, String salt, String crumb )
33 {
34 return "test".equals(crumb);
35 }
36
37 @Extension
38 public static final class DescriptorImpl extends CrumbIssuerDescriptor<TestCrumbIssuer> implements ModelObject {
39 public DescriptorImpl()
40 {
41 super(null, null);
42 load();
43 }
44
45 @Override
46 public String getDisplayName() {
47 return "Test Crumb";
48 }
49
50 public TestCrumbIssuer newInstance(StaplerRequest req, JSONObject formData) throws FormException {
51 return new TestCrumbIssuer();
52 }
53 }
54
55 }
56