jdk/src/share/classes/com/sun/security/auth/module/SolarisLoginModule.java
author weijun
Thu, 08 May 2014 22:30:31 +0800
changeset 24271 19000122bb5e
parent 23010 6dadb192ad81
permissions -rw-r--r--
8039951: com.sun.security.auth.module missing classes on some platforms Reviewed-by: mullan
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
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * <p> This <code>LoginModule</code> imports a user's Solaris
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * <code>Principal</code> information (<code>SolarisPrincipal</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * <code>SolarisNumericUserPrincipal</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * and <code>SolarisNumericGroupPrincipal</code>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * and associates them with the current <code>Subject</code>.
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * <code>com.sun.security.auth.module.UnixLoginModule</code>.
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.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 */
20742
4ae78e8060d6 8008662: Add @jdk.Exported to JDK-specific/exported APIs
alanb
parents: 9035
diff changeset
    55
@jdk.Exported(false)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
@Deprecated
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * Initialize this <code>LoginModule</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * @param subject the <code>Subject</code> to be authenticated. <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * @param callbackHandler a <code>CallbackHandler</code> for communicating
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     *                  with the end user (prompting for usernames and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     *                  passwords, for example). <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * @param sharedState shared <code>LoginModule</code> state. <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * @param options options specified in the login
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     *                  <code>Configuration</code> for this particular
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     *                  <code>LoginModule</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    public void initialize(Subject subject, CallbackHandler callbackHandler,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                           Map<String,?> sharedState,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                           Map<String,?> options)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        this.subject = subject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        this.callbackHandler = callbackHandler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        this.sharedState = sharedState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        this.options = options;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        // initialize any configured options
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        debug = "true".equalsIgnoreCase((String)options.get("debug"));
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
     * Authenticate the user (first phase).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * <p> The implementation of this method attempts to retrieve the user's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * Solaris <code>Subject</code> information by making a native Solaris
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * system call.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * @exception FailedLoginException if attempts to retrieve the underlying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     *          system information fail.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * @return true in all cases (this <code>LoginModule</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     *          should not be ignored).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    public boolean login() throws LoginException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        long[] solarisGroups = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
24271
19000122bb5e 8039951: com.sun.security.auth.module missing classes on some platforms
weijun
parents: 23010
diff changeset
   132
        try {
19000122bb5e 8039951: com.sun.security.auth.module missing classes on some platforms
weijun
parents: 23010
diff changeset
   133
            ss = new SolarisSystem();
19000122bb5e 8039951: com.sun.security.auth.module missing classes on some platforms
weijun
parents: 23010
diff changeset
   134
        } catch (UnsatisfiedLinkError ule) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            succeeded = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            throw new FailedLoginException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                                ("Failed in attempt to import " +
24271
19000122bb5e 8039951: com.sun.security.auth.module missing classes on some platforms
weijun
parents: 23010
diff changeset
   138
                                "the underlying system identity information" +
19000122bb5e 8039951: com.sun.security.auth.module missing classes on some platforms
weijun
parents: 23010
diff changeset
   139
                                " on " + System.getProperty("os.name"));
19000122bb5e 8039951: com.sun.security.auth.module missing classes on some platforms
weijun
parents: 23010
diff changeset
   140
        }
19000122bb5e 8039951: com.sun.security.auth.module missing classes on some platforms
weijun
parents: 23010
diff changeset
   141
        userPrincipal = new SolarisPrincipal(ss.getUsername());
19000122bb5e 8039951: com.sun.security.auth.module missing classes on some platforms
weijun
parents: 23010
diff changeset
   142
        UIDPrincipal = new SolarisNumericUserPrincipal(ss.getUid());
19000122bb5e 8039951: com.sun.security.auth.module missing classes on some platforms
weijun
parents: 23010
diff changeset
   143
        GIDPrincipal = new SolarisNumericGroupPrincipal(ss.getGid(), true);
19000122bb5e 8039951: com.sun.security.auth.module missing classes on some platforms
weijun
parents: 23010
diff changeset
   144
        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
   145
            solarisGroups = ss.getGroups();
19000122bb5e 8039951: com.sun.security.auth.module missing classes on some platforms
weijun
parents: 23010
diff changeset
   146
            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
   147
                SolarisNumericGroupPrincipal ngp =
19000122bb5e 8039951: com.sun.security.auth.module missing classes on some platforms
weijun
parents: 23010
diff changeset
   148
                    new SolarisNumericGroupPrincipal
19000122bb5e 8039951: com.sun.security.auth.module missing classes on some platforms
weijun
parents: 23010
diff changeset
   149
                    (solarisGroups[i], false);
19000122bb5e 8039951: com.sun.security.auth.module missing classes on some platforms
weijun
parents: 23010
diff changeset
   150
                if (!ngp.getName().equals(GIDPrincipal.getName()))
19000122bb5e 8039951: com.sun.security.auth.module missing classes on some platforms
weijun
parents: 23010
diff changeset
   151
                    supplementaryGroups.add(ngp);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            }
24271
19000122bb5e 8039951: com.sun.security.auth.module missing classes on some platforms
weijun
parents: 23010
diff changeset
   153
        if (debug) {
19000122bb5e 8039951: com.sun.security.auth.module missing classes on some platforms
weijun
parents: 23010
diff changeset
   154
            System.out.println("\t\t[SolarisLoginModule]: " +
19000122bb5e 8039951: com.sun.security.auth.module missing classes on some platforms
weijun
parents: 23010
diff changeset
   155
                    "succeeded importing info: ");
19000122bb5e 8039951: com.sun.security.auth.module missing classes on some platforms
weijun
parents: 23010
diff changeset
   156
            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
   157
            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
   158
            solarisGroups = ss.getGroups();
19000122bb5e 8039951: com.sun.security.auth.module missing classes on some platforms
weijun
parents: 23010
diff changeset
   159
            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
   160
                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
   161
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        }
24271
19000122bb5e 8039951: com.sun.security.auth.module missing classes on some platforms
weijun
parents: 23010
diff changeset
   163
        succeeded = true;
19000122bb5e 8039951: com.sun.security.auth.module missing classes on some platforms
weijun
parents: 23010
diff changeset
   164
        return true;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * Commit the authentication (second phase).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * <p> This method is called if the LoginContext's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * overall authentication succeeded
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * (the relevant REQUIRED, REQUISITE, SUFFICIENT and OPTIONAL LoginModules
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * succeeded).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * <p> If this LoginModule's own authentication attempt
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * succeeded (the importing of the Solaris authentication information
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * succeeded), then this method associates the Solaris Principals
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * with the <code>Subject</code> currently tied to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * <code>LoginModule</code>.  If this LoginModule's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * authentication attempted failed, then this method removes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * any state that was originally saved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * @exception LoginException if the commit fails
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * @return true if this LoginModule's own login and commit attempts
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     *          succeeded, or false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    public boolean commit() throws LoginException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        if (succeeded == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            if (debug) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                System.out.println("\t\t[SolarisLoginModule]: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                    "did not add any Principals to Subject " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                    "because own authentication failed.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        if (subject.isReadOnly()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            throw new LoginException ("Subject is Readonly");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        if (!subject.getPrincipals().contains(userPrincipal))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            subject.getPrincipals().add(userPrincipal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        if (!subject.getPrincipals().contains(UIDPrincipal))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            subject.getPrincipals().add(UIDPrincipal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        if (!subject.getPrincipals().contains(GIDPrincipal))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            subject.getPrincipals().add(GIDPrincipal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        for (int i = 0; i < supplementaryGroups.size(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            if (!subject.getPrincipals().contains(supplementaryGroups.get(i)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                subject.getPrincipals().add(supplementaryGroups.get(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        if (debug) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            System.out.println("\t\t[SolarisLoginModule]: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                               "added SolarisPrincipal,");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            System.out.println("\t\t\t\tSolarisNumericUserPrincipal,");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            System.out.println("\t\t\t\tSolarisNumericGroupPrincipal(s),");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            System.out.println("\t\t\t to Subject");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        commitSucceeded = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * Abort the authentication (second phase).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * <p> This method is called if the LoginContext's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * overall authentication failed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * (the relevant REQUIRED, REQUISITE, SUFFICIENT and OPTIONAL LoginModules
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * did not succeed).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * <p> This method cleans up any state that was originally saved
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * as part of the authentication attempt from the <code>login</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * and <code>commit</code> methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * @exception LoginException if the abort fails
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * @return false if this LoginModule's own login and/or commit attempts
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     *          failed, and true otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    public boolean abort() throws LoginException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        if (debug) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            System.out.println("\t\t[SolarisLoginModule]: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                "aborted authentication attempt");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        if (succeeded == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        } else if (succeeded == true && commitSucceeded == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            // Clean out state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            succeeded = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            ss = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            userPrincipal = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            UIDPrincipal = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            GIDPrincipal = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            supplementaryGroups =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                        new LinkedList<SolarisNumericGroupPrincipal>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            // overall authentication succeeded and commit succeeded,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            // but someone else's commit failed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            logout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * Logout the user
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * <p> This method removes the Principals associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * with the <code>Subject</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * @exception LoginException if the logout fails
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * @return true in all cases (this <code>LoginModule</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     *          should not be ignored).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    public boolean logout() throws LoginException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        if (debug) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            System.out.println("\t\t[SolarisLoginModule]: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                "Entering logout");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        if (subject.isReadOnly()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            throw new LoginException ("Subject is Readonly");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        // remove the added Principals from the Subject
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        subject.getPrincipals().remove(userPrincipal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        subject.getPrincipals().remove(UIDPrincipal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        subject.getPrincipals().remove(GIDPrincipal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        for (int i = 0; i < supplementaryGroups.size(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            subject.getPrincipals().remove(supplementaryGroups.get(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        // clean out state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        ss = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        succeeded = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        commitSucceeded = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        userPrincipal = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        UIDPrincipal = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        GIDPrincipal = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        supplementaryGroups = new LinkedList<SolarisNumericGroupPrincipal>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        if (debug) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            System.out.println("\t\t[SolarisLoginModule]: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                "logged out Subject");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
}