LegacySecurityRealm.java 1.9 KB
Newer Older
1 2 3 4 5
package hudson.security;

import org.acegisecurity.AuthenticationManager;
import org.acegisecurity.Authentication;
import org.acegisecurity.AuthenticationException;
K
kohsuke 已提交
6
import org.kohsuke.stapler.StaplerRequest;
7
import hudson.model.Descriptor;
K
kohsuke 已提交
8
import net.sf.json.JSONObject;
9 10 11 12 13 14 15

/**
 * {@link SecurityRealm} that accepts {@link ContainerAuthentication} object
 * without any check (that is, by assuming that the such token is
 * already authenticated by the container.)
 * @author Kohsuke Kawaguchi
 */
K
kohsuke 已提交
16
public final class LegacySecurityRealm extends SecurityRealm implements AuthenticationManager {
K
kohsuke 已提交
17 18
    public SecurityComponents createSecurityComponents() {
        return new SecurityComponents(this);
19 20 21 22 23 24 25 26 27
    }

    public Authentication authenticate(Authentication authentication) throws AuthenticationException {
        if(authentication instanceof ContainerAuthentication)
            return authentication;
        else
            return null;
    }

28 29 30 31 32
    /**
     * To have the username/password authenticated by the container,
     * submit the form to the URL defined by the servlet spec.
     */
    @Override
K
kohsuke 已提交
33
    public String getAuthenticationGatewayUrl() {
34 35 36
        return "j_security_check";
    }

37 38 39 40 41
    @Override
    public String getLoginUrl() {
        return "loginEntry";
    }

42 43 44 45
    public Descriptor<SecurityRealm> getDescriptor() {
        return DESCRIPTOR;
    }

K
kohsuke 已提交
46
    public static final Descriptor<SecurityRealm> DESCRIPTOR = new Descriptor<SecurityRealm>(LegacySecurityRealm.class) {
K
kohsuke 已提交
47 48 49 50
        public SecurityRealm newInstance(StaplerRequest req, JSONObject formData) throws FormException {
            return new LegacySecurityRealm();
        }

51
        public String getDisplayName() {
K
kohsuke 已提交
52 53 54 55 56
            return "Delegate to servlet container";
        }

        public String getHelpFile() {
            return "/help/security/container-realm.html";
57 58 59
        }
    };

60 61 62
    static {
        LIST.add(DESCRIPTOR);
    }
63
}