File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\core\src\main\java\hudson\security\LegacySecurityRealm.java.html

1 /*
2 * The MIT License
3 *
4 * Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi, Seiji Sogabe
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24 package hudson.security;
25
26 import org.acegisecurity.AuthenticationManager;
27 import org.acegisecurity.Authentication;
28 import org.acegisecurity.AuthenticationException;
29 import org.springframework.web.context.WebApplicationContext;
30 import org.kohsuke.stapler.StaplerRequest;
31 import groovy.lang.Binding;
32 import hudson.model.Descriptor;
33 import hudson.util.spring.BeanBuilder;
34 import hudson.Extension;
35 import net.sf.json.JSONObject;
36
37 import javax.servlet.Filter;
38 import javax.servlet.FilterConfig;
39
40 /**
41 * {@link SecurityRealm} that accepts {@link ContainerAuthentication} object
42 * without any check (that is, by assuming that the such token is
43 * already authenticated by the container.)
44 *
45 * @author Kohsuke Kawaguchi
46 */
47 public final class LegacySecurityRealm extends SecurityRealm implements AuthenticationManager {
48 public SecurityComponents createSecurityComponents() {
49 return new SecurityComponents(this);
50 }
51
52 public Authentication authenticate(Authentication authentication) throws AuthenticationException {
53 if(authentication instanceof ContainerAuthentication)
54 return authentication;
55 else
56 return null;
57 }
58
59 /**
60 * To have the username/password authenticated by the container,
61 * submit the form to the URL defined by the servlet spec.
62 */
63 @Override
64 public String getAuthenticationGatewayUrl() {
65 return "j_security_check";
66 }
67
68 @Override
69 public String getLoginUrl() {
70 return "loginEntry";
71 }
72
73 /**
74 * Filter to run for the LegacySecurityRealm is the
75 * ChainServletFilter legacy from /WEB-INF/security/SecurityFilters.groovy.
76 */
77 @Override
78 public Filter createFilter(FilterConfig filterConfig) {
79 Binding binding = new Binding();
80 SecurityComponents sc = this.createSecurityComponents();
81 binding.setVariable("securityComponents", sc);
82 binding.setVariable("securityRealm",this);
83 BeanBuilder builder = new BeanBuilder();
84 builder.parse(filterConfig.getServletContext().getResourceAsStream("/WEB-INF/security/SecurityFilters.groovy"),binding);
85
86 WebApplicationContext context = builder.createApplicationContext();
87
88 return (Filter) context.getBean("legacy");
89 }
90
91 @Extension
92 public static final Descriptor<SecurityRealm> DESCRIPTOR = new Descriptor<SecurityRealm>() {
93 public SecurityRealm newInstance(StaplerRequest req, JSONObject formData) throws FormException {
94 return new LegacySecurityRealm();
95 }
96
97 public String getDisplayName() {
98 return Messages.LegacySecurityRealm_Displayname();
99 }
100
101 public String getHelpFile() {
102 return "/help/security/container-realm.html";
103 }
104 };
105 }
106