jdk/src/jdk.security.auth/share/classes/com/sun/security/auth/module/SolarisLoginModule.java
author weijun
Fri, 17 Jun 2016 09:46:34 +0800
changeset 39047 cf08ea56b4de
parent 34894 3248b89d1921
child 44665 4bfab66ae1cb
permissions -rw-r--r--
8146619: Re-examine supportness of public classes in com.sun.security.auth.** Reviewed-by: xuelei
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 20742
diff changeset
     2
 * Copyright (c) 2000, 2013, 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
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package com.sun.security.auth.module;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import javax.security.auth.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import javax.security.auth.callback.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import javax.security.auth.login.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.security.auth.spi.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import com.sun.security.auth.SolarisPrincipal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import com.sun.security.auth.SolarisNumericUserPrincipal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import com.sun.security.auth.SolarisNumericGroupPrincipal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
/**
30044
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
    39
 * This {@code LoginModule} imports a user's Solaris
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
    40
 * {@code Principal} information ({@code SolarisPrincipal},
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
    41
 * {@code SolarisNumericUserPrincipal},
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
    42
 * and {@code SolarisNumericGroupPrincipal})
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
    43
 * and associates them with the current {@code Subject}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * <p> This LoginModule recognizes the debug option.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * If set to true in the login Configuration,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * debug messages will be output to the output stream, System.out.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * @deprecated  As of JDK1.4, replaced by
30044
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
    49
 * {@code com.sun.security.auth.module.UnixLoginModule}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *             This LoginModule is entirely deprecated and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *             is here to allow for a smooth transition to the new
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *             UnixLoginModule.
39047
cf08ea56b4de 8146619: Re-examine supportness of public classes in com.sun.security.auth.**
weijun
parents: 34894
diff changeset
    53
 * This class is subject to removal in a future version of Java SE.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 */
39047
cf08ea56b4de 8146619: Re-examine supportness of public classes in com.sun.security.auth.**
weijun
parents: 34894
diff changeset
    56
@Deprecated(since="1.4", forRemoval=true)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
public class SolarisLoginModule implements LoginModule {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    // initial state
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    private Subject subject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    private CallbackHandler callbackHandler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    private Map<String, ?> sharedState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    private Map<String, ?> options;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    // configurable option
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    private boolean debug = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    // SolarisSystem to retrieve underlying system info
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    private SolarisSystem ss;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    // the authentication status
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    private boolean succeeded = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    private boolean commitSucceeded = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    // Underlying system info
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    private SolarisPrincipal userPrincipal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    private SolarisNumericUserPrincipal UIDPrincipal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    private SolarisNumericGroupPrincipal GIDPrincipal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    private LinkedList<SolarisNumericGroupPrincipal> supplementaryGroups =
7970
af1579474d16 7008728: diamond conversion of basic security, permissions, authentication
smarks
parents: 5506
diff changeset
    80
                new LinkedList<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    /**
30044
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
    83
     * Initialize this {@code LoginModule}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     *
30044
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
    85
     * @param subject the {@code Subject} to be authenticated.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     *
30044
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
    87
     * @param callbackHandler a {@code CallbackHandler} for communicating
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     *                  with the end user (prompting for usernames and
30044
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
    89
     *                  passwords, for example).
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     *
30044
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
    91
     * @param sharedState shared {@code LoginModule} state.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * @param options options specified in the login
30044
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
    94
     *                  {@code Configuration} for this particular
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
    95
     *                  {@code LoginModule}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    public void initialize(Subject subject, CallbackHandler callbackHandler,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                           Map<String,?> sharedState,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                           Map<String,?> options)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        this.subject = subject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        this.callbackHandler = callbackHandler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        this.sharedState = sharedState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        this.options = options;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        // initialize any configured options
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        debug = "true".equalsIgnoreCase((String)options.get("debug"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * Authenticate the user (first phase).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * <p> The implementation of this method attempts to retrieve the user's
30044
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
   115
     * Solaris {@code Subject} information by making a native Solaris
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * system call.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * @exception FailedLoginException if attempts to retrieve the underlying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     *          system information fail.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     *
30044
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
   121
     * @return true in all cases (this {@code LoginModule}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     *          should not be ignored).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    public boolean login() throws LoginException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        long[] solarisGroups = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
24271
19000122bb5e 8039951: com.sun.security.auth.module missing classes on some platforms
weijun
parents: 23010
diff changeset
   128
        try {
19000122bb5e 8039951: com.sun.security.auth.module missing classes on some platforms
weijun
parents: 23010
diff changeset
   129
            ss = new SolarisSystem();
19000122bb5e 8039951: com.sun.security.auth.module missing classes on some platforms
weijun
parents: 23010
diff changeset
   130
        } catch (UnsatisfiedLinkError ule) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            succeeded = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            throw new FailedLoginException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                                ("Failed in attempt to import " +
24271
19000122bb5e 8039951: com.sun.security.auth.module missing classes on some platforms
weijun
parents: 23010
diff changeset
   134
                                "the underlying system identity information" +
19000122bb5e 8039951: com.sun.security.auth.module missing classes on some platforms
weijun
parents: 23010
diff changeset
   135
                                " on " + System.getProperty("os.name"));
19000122bb5e 8039951: com.sun.security.auth.module missing classes on some platforms
weijun
parents: 23010
diff changeset
   136
        }
19000122bb5e 8039951: com.sun.security.auth.module missing classes on some platforms
weijun
parents: 23010
diff changeset
   137
        userPrincipal = new SolarisPrincipal(ss.getUsername());
19000122bb5e 8039951: com.sun.security.auth.module missing classes on some platforms
weijun
parents: 23010
diff changeset
   138
        UIDPrincipal = new SolarisNumericUserPrincipal(ss.getUid());
19000122bb5e 8039951: com.sun.security.auth.module missing classes on some platforms
weijun
parents: 23010
diff changeset
   139
        GIDPrincipal = new SolarisNumericGroupPrincipal(ss.getGid(), true);
19000122bb5e 8039951: com.sun.security.auth.module missing classes on some platforms
weijun
parents: 23010
diff changeset
   140
        if (ss.getGroups() != null && ss.getGroups().length > 0)
19000122bb5e 8039951: com.sun.security.auth.module missing classes on some platforms
weijun
parents: 23010
diff changeset
   141
            solarisGroups = ss.getGroups();
19000122bb5e 8039951: com.sun.security.auth.module missing classes on some platforms
weijun
parents: 23010
diff changeset
   142
            for (int i = 0; i < solarisGroups.length; i++) {
19000122bb5e 8039951: com.sun.security.auth.module missing classes on some platforms
weijun
parents: 23010
diff changeset
   143
                SolarisNumericGroupPrincipal ngp =
19000122bb5e 8039951: com.sun.security.auth.module missing classes on some platforms
weijun
parents: 23010
diff changeset
   144
                    new SolarisNumericGroupPrincipal
19000122bb5e 8039951: com.sun.security.auth.module missing classes on some platforms
weijun
parents: 23010
diff changeset
   145
                    (solarisGroups[i], false);
19000122bb5e 8039951: com.sun.security.auth.module missing classes on some platforms
weijun
parents: 23010
diff changeset
   146
                if (!ngp.getName().equals(GIDPrincipal.getName()))
19000122bb5e 8039951: com.sun.security.auth.module missing classes on some platforms
weijun
parents: 23010
diff changeset
   147
                    supplementaryGroups.add(ngp);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            }
24271
19000122bb5e 8039951: com.sun.security.auth.module missing classes on some platforms
weijun
parents: 23010
diff changeset
   149
        if (debug) {
19000122bb5e 8039951: com.sun.security.auth.module missing classes on some platforms
weijun
parents: 23010
diff changeset
   150
            System.out.println("\t\t[SolarisLoginModule]: " +
19000122bb5e 8039951: com.sun.security.auth.module missing classes on some platforms
weijun
parents: 23010
diff changeset
   151
                    "succeeded importing info: ");
19000122bb5e 8039951: com.sun.security.auth.module missing classes on some platforms
weijun
parents: 23010
diff changeset
   152
            System.out.println("\t\t\tuid = " + ss.getUid());
19000122bb5e 8039951: com.sun.security.auth.module missing classes on some platforms
weijun
parents: 23010
diff changeset
   153
            System.out.println("\t\t\tgid = " + ss.getGid());
19000122bb5e 8039951: com.sun.security.auth.module missing classes on some platforms
weijun
parents: 23010
diff changeset
   154
            solarisGroups = ss.getGroups();
19000122bb5e 8039951: com.sun.security.auth.module missing classes on some platforms
weijun
parents: 23010
diff changeset
   155
            for (int i = 0; i < solarisGroups.length; i++) {
19000122bb5e 8039951: com.sun.security.auth.module missing classes on some platforms
weijun
parents: 23010
diff changeset
   156
                System.out.println("\t\t\tsupp gid = " + solarisGroups[i]);
19000122bb5e 8039951: com.sun.security.auth.module missing classes on some platforms
weijun
parents: 23010
diff changeset
   157
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        }
24271
19000122bb5e 8039951: com.sun.security.auth.module missing classes on some platforms
weijun
parents: 23010
diff changeset
   159
        succeeded = true;
19000122bb5e 8039951: com.sun.security.auth.module missing classes on some platforms
weijun
parents: 23010
diff changeset
   160
        return true;
2
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
     * Commit the authentication (second phase).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * <p> This method is called if the LoginContext's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * overall authentication succeeded
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * (the relevant REQUIRED, REQUISITE, SUFFICIENT and OPTIONAL LoginModules
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * succeeded).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * <p> If this LoginModule's own authentication attempt
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * succeeded (the importing of the Solaris authentication information
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * succeeded), then this method associates the Solaris Principals
30044
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
   174
     * with the {@code Subject} currently tied to the
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
   175
     * {@code LoginModule}.  If this LoginModule's
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * authentication attempted failed, then this method removes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * any state that was originally saved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * @exception LoginException if the commit fails
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * @return true if this LoginModule's own login and commit attempts
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     *          succeeded, or false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    public boolean commit() throws LoginException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        if (succeeded == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            if (debug) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                System.out.println("\t\t[SolarisLoginModule]: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                    "did not add any Principals to Subject " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                    "because own authentication failed.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        if (subject.isReadOnly()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            throw new LoginException ("Subject is Readonly");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        if (!subject.getPrincipals().contains(userPrincipal))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            subject.getPrincipals().add(userPrincipal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        if (!subject.getPrincipals().contains(UIDPrincipal))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            subject.getPrincipals().add(UIDPrincipal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        if (!subject.getPrincipals().contains(GIDPrincipal))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            subject.getPrincipals().add(GIDPrincipal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        for (int i = 0; i < supplementaryGroups.size(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            if (!subject.getPrincipals().contains(supplementaryGroups.get(i)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                subject.getPrincipals().add(supplementaryGroups.get(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        if (debug) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            System.out.println("\t\t[SolarisLoginModule]: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                               "added SolarisPrincipal,");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            System.out.println("\t\t\t\tSolarisNumericUserPrincipal,");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            System.out.println("\t\t\t\tSolarisNumericGroupPrincipal(s),");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            System.out.println("\t\t\t to Subject");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        commitSucceeded = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * Abort the authentication (second phase).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * <p> This method is called if the LoginContext's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * overall authentication failed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * (the relevant REQUIRED, REQUISITE, SUFFICIENT and OPTIONAL LoginModules
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * did not succeed).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * <p> This method cleans up any state that was originally saved
30044
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
   229
     * as part of the authentication attempt from the {@code login}
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
   230
     * and {@code commit} methods.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * @exception LoginException if the abort fails
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * @return false if this LoginModule's own login and/or commit attempts
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     *          failed, and true otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    public boolean abort() throws LoginException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        if (debug) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            System.out.println("\t\t[SolarisLoginModule]: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                "aborted authentication attempt");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        if (succeeded == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        } else if (succeeded == true && commitSucceeded == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            // Clean out state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            succeeded = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            ss = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            userPrincipal = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            UIDPrincipal = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            GIDPrincipal = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            supplementaryGroups =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                        new LinkedList<SolarisNumericGroupPrincipal>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            // overall authentication succeeded and commit succeeded,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            // but someone else's commit failed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            logout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * Logout the user
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * <p> This method removes the Principals associated
30044
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
   267
     * with the {@code Subject}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * @exception LoginException if the logout fails
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     *
30044
bab15bbe2ca3 8078528: clean out tidy warnings from security.auth
avstepan
parents: 25859
diff changeset
   271
     * @return true in all cases (this {@code LoginModule}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     *          should not be ignored).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    public boolean logout() throws LoginException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        if (debug) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            System.out.println("\t\t[SolarisLoginModule]: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                "Entering logout");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        if (subject.isReadOnly()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            throw new LoginException ("Subject is Readonly");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        // remove the added Principals from the Subject
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        subject.getPrincipals().remove(userPrincipal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        subject.getPrincipals().remove(UIDPrincipal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        subject.getPrincipals().remove(GIDPrincipal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        for (int i = 0; i < supplementaryGroups.size(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            subject.getPrincipals().remove(supplementaryGroups.get(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        // clean out state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        ss = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        succeeded = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        commitSucceeded = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        userPrincipal = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        UIDPrincipal = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        GIDPrincipal = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        supplementaryGroups = new LinkedList<SolarisNumericGroupPrincipal>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        if (debug) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            System.out.println("\t\t[SolarisLoginModule]: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                "logged out Subject");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
}