jdk/test/com/sun/security/auth/module/LdapLoginModule/CheckConfigs.java
author ohair
Wed, 06 Apr 2011 22:06:11 -0700
changeset 9035 1255eb81cc2f
parent 7970 af1579474d16
permissions -rw-r--r--
7033660: Update copyright year to 2011 on any files changed in 2011 Reviewed-by: dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
9035
1255eb81cc2f 7033660: Update copyright year to 2011 on any files changed in 2011
ohair
parents: 7970
diff changeset
     2
 * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @author Vincent Ryan
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @bug 4814522
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * @summary Check that an LdapLoginModule can be initialized using various
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *          JAAS configurations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 *          (LdapLoginModule replaces the JndiLoginModule for LDAP access)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * Run this test twice, once using the default security manager:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * @run main/othervm CheckConfigs
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * @run main/othervm/policy=CheckConfigs.policy CheckConfigs
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.util.Collections;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.util.HashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import javax.naming.CommunicationException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import javax.security.auth.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import javax.security.auth.login.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import javax.security.auth.callback.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import com.sun.security.auth.module.LdapLoginModule;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
public class CheckConfigs {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    public static void main(String[] args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        SecurityManager securityManager = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        System.out.println(securityManager == null
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
            ? "[security manager is not running]"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
            : "[security manager is running: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
                securityManager.getClass().getName() + "]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        init();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        checkConfigModes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    private static void init() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    private static void checkConfigModes() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        LoginContext ldapLogin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        // search-first mode
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        System.out.println("Testing search-first mode...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
            ldapLogin = new LoginContext(LdapConfiguration.LOGIN_CONFIG_NAME,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
                null, new TestCallbackHandler(), new SearchFirstMode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            ldapLogin.login();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            throw new SecurityException("expected a LoginException");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        } catch (LoginException le) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            // expected behaviour (because no LDAP server is available)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            if (!(le.getCause() instanceof CommunicationException)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
                throw le;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        // authentication-first mode
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        System.out.println("\nTesting authentication-first mode...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            ldapLogin = new LoginContext(LdapConfiguration.LOGIN_CONFIG_NAME,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                null, new TestCallbackHandler(), new AuthFirstMode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            ldapLogin.login();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            throw new SecurityException("expected a LoginException");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        } catch (LoginException le) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            // expected behaviour (because no LDAP server is available)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            if (!(le.getCause() instanceof CommunicationException)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                throw le;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        // authentication-only mode
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        System.out.println("\nTesting authentication-only mode...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            ldapLogin = new LoginContext(LdapConfiguration.LOGIN_CONFIG_NAME,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                null, new TestCallbackHandler(), new AuthOnlyMode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            ldapLogin.login();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            throw new SecurityException("expected a LoginException");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        } catch (LoginException le) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            // expected behaviour (because no LDAP server is available)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            if (!(le.getCause() instanceof CommunicationException)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                throw le;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    private static class TestCallbackHandler implements CallbackHandler {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        public void handle(Callback[] callbacks)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                throws IOException, UnsupportedCallbackException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            for (int i = 0; i < callbacks.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                if (callbacks[i] instanceof NameCallback) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                    ((NameCallback)callbacks[i]).setName("myname");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                } else if (callbacks[i] instanceof PasswordCallback) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                    ((PasswordCallback)callbacks[i])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                        .setPassword("mypassword".toCharArray());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                    throw new UnsupportedCallbackException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                        (callbacks[i], "Unrecognized callback");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
class LdapConfiguration extends Configuration {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    // The JAAS configuration name for ldap-based authentication
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    public static final String LOGIN_CONFIG_NAME = "TestAuth";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    // The JAAS configuration for ldap-based authentication
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    protected static AppConfigurationEntry[] entries;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    // The classname of the login module for ldap-based authentication
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    protected static final String LDAP_LOGIN_MODULE =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        LdapLoginModule.class.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * Gets the JAAS configuration for ldap-based authentication
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    public AppConfigurationEntry[] getAppConfigurationEntry(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        return name.equals(LOGIN_CONFIG_NAME) ? entries : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * Refreshes the configuration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    public void refresh() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        // the configuration is fixed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
 * This class defines the JAAS configuration for ldap-based authentication.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
 * It is equivalent to the following textual configuration entry:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
 *     TestAuth {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
 *         com.sun.security.auth.module.LdapLoginModule REQUIRED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
 *             userProvider="ldap://localhost:23456/dc=example,dc=com"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
 *             userFilter="(&(uid={USERNAME})(objectClass=inetOrgPerson))"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
 *             authzIdentity="{EMPLOYEENUMBER}"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
 *             debug=true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
 *     };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
class SearchFirstMode extends LdapConfiguration {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    public SearchFirstMode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
7970
af1579474d16 7008728: diamond conversion of basic security, permissions, authentication
smarks
parents: 5506
diff changeset
   181
        Map<String, String> options = new HashMap<>(4);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        options.put("userProvider", "ldap://localhost:23456/dc=example,dc=com");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        options.put("userFilter",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            "(&(uid={USERNAME})(objectClass=inetOrgPerson))");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        options.put("authzIdentity", "{EMPLOYEENUMBER}");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        options.put("debug", "true");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        entries = new AppConfigurationEntry[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            new AppConfigurationEntry(LDAP_LOGIN_MODULE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                AppConfigurationEntry.LoginModuleControlFlag.REQUIRED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                    options)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
 * This class defines the JAAS configuration for ldap-based authentication.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
 * It is equivalent to the following textual configuration entry:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
 *     TestAuth {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
 *         com.sun.security.auth.module.LdapLoginModule REQUIRED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
 *             userProvider="ldap://localhost:23456/dc=example,dc=com"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
 *             authIdentity="{USERNAME}"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
 *             userFilter="(&(|(samAccountName={USERNAME})(userPrincipalName={USERNAME})(cn={USERNAME}))(objectClass=user))"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
 *             useSSL=false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
 *             debug=true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
 *     };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
class AuthFirstMode extends LdapConfiguration {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    public AuthFirstMode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
7970
af1579474d16 7008728: diamond conversion of basic security, permissions, authentication
smarks
parents: 5506
diff changeset
   216
        Map<String, String> options = new HashMap<>(5);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        options.put("userProvider", "ldap://localhost:23456/dc=example,dc=com");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        options.put("authIdentity", "{USERNAME}");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        options.put("userFilter",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            "(&(|(samAccountName={USERNAME})(userPrincipalName={USERNAME})" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            "(cn={USERNAME}))(objectClass=user))");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        options.put("useSSL", "false");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        options.put("debug", "true");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        entries = new AppConfigurationEntry[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            new AppConfigurationEntry(LDAP_LOGIN_MODULE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                AppConfigurationEntry.LoginModuleControlFlag.REQUIRED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                    options)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
 * This class defines the JAAS configuration for ldap-based authentication.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
 * It is equivalent to the following textual configuration entry:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
 *     TestAuth {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
 *         com.sun.security.auth.module.LdapLoginModule REQUIRED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
 *             userProvider="ldap://localhost:23456 ldap://localhost:23457"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
 *             authIdentity="cn={USERNAME},ou=people,dc=example,dc=com"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
 *             authzIdentity="staff"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
 *             debug=true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
 *     };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
class AuthOnlyMode extends LdapConfiguration {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    public AuthOnlyMode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
7970
af1579474d16 7008728: diamond conversion of basic security, permissions, authentication
smarks
parents: 5506
diff changeset
   251
        Map<String, String> options = new HashMap<>(4);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        options.put("userProvider",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            "ldap://localhost:23456 ldap://localhost:23457");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        options.put("authIdentity",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            "cn={USERNAME},ou=people,dc=example,dc=com");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        options.put("authzIdentity", "staff");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        options.put("debug", "true");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        entries = new AppConfigurationEntry[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            new AppConfigurationEntry(LDAP_LOGIN_MODULE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                AppConfigurationEntry.LoginModuleControlFlag.REQUIRED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                    options)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
}