jdk/src/share/classes/com/sun/security/auth/module/SolarisLoginModule.java
author ohair
Wed, 06 Apr 2011 22:06:11 -0700
changeset 9035 1255eb81cc2f
parent 7970 af1579474d16
child 20742 4ae78e8060d6
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) 2000, 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
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
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
@Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
public class SolarisLoginModule implements LoginModule {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    // initial state
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    private Subject subject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    private CallbackHandler callbackHandler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    private Map<String, ?> sharedState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    private Map<String, ?> options;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    // configurable option
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    private boolean debug = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    // SolarisSystem to retrieve underlying system info
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    private SolarisSystem ss;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    // the authentication status
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    private boolean succeeded = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    private boolean commitSucceeded = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    // Underlying system info
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    private SolarisPrincipal userPrincipal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    private SolarisNumericUserPrincipal UIDPrincipal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    private SolarisNumericGroupPrincipal GIDPrincipal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    private LinkedList<SolarisNumericGroupPrincipal> supplementaryGroups =
7970
af1579474d16 7008728: diamond conversion of basic security, permissions, authentication
smarks
parents: 5506
diff changeset
    79
                new LinkedList<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * Initialize this <code>LoginModule</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * @param subject the <code>Subject</code> to be authenticated. <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * @param callbackHandler a <code>CallbackHandler</code> for communicating
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     *                  with the end user (prompting for usernames and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     *                  passwords, for example). <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * @param sharedState shared <code>LoginModule</code> state. <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * @param options options specified in the login
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     *                  <code>Configuration</code> for this particular
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     *                  <code>LoginModule</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    public void initialize(Subject subject, CallbackHandler callbackHandler,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                           Map<String,?> sharedState,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                           Map<String,?> options)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        this.subject = subject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        this.callbackHandler = callbackHandler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        this.sharedState = sharedState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        this.options = options;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        // initialize any configured options
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        debug = "true".equalsIgnoreCase((String)options.get("debug"));
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
     * Authenticate the user (first phase).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * <p> The implementation of this method attempts to retrieve the user's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * Solaris <code>Subject</code> information by making a native Solaris
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * system call.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * @exception FailedLoginException if attempts to retrieve the underlying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     *          system information fail.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * @return true in all cases (this <code>LoginModule</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     *          should not be ignored).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    public boolean login() throws LoginException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        long[] solarisGroups = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        ss = new SolarisSystem();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        if (ss == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            succeeded = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            throw new FailedLoginException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                                ("Failed in attempt to import " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                                "the underlying system identity information");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            userPrincipal = new SolarisPrincipal(ss.getUsername());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            UIDPrincipal = new SolarisNumericUserPrincipal(ss.getUid());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            GIDPrincipal = new SolarisNumericGroupPrincipal(ss.getGid(), true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            if (ss.getGroups() != null && ss.getGroups().length > 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                solarisGroups = ss.getGroups();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                for (int i = 0; i < solarisGroups.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                    SolarisNumericGroupPrincipal ngp =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                        new SolarisNumericGroupPrincipal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                        (solarisGroups[i], false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                    if (!ngp.getName().equals(GIDPrincipal.getName()))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                        supplementaryGroups.add(ngp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            if (debug) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                System.out.println("\t\t[SolarisLoginModule]: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                        "succeeded importing info: ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                System.out.println("\t\t\tuid = " + ss.getUid());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                System.out.println("\t\t\tgid = " + ss.getGid());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                solarisGroups = ss.getGroups();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                for (int i = 0; i < solarisGroups.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                    System.out.println("\t\t\tsupp gid = " + solarisGroups[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            succeeded = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * Commit the authentication (second phase).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * <p> This method is called if the LoginContext's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * overall authentication succeeded
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * (the relevant REQUIRED, REQUISITE, SUFFICIENT and OPTIONAL LoginModules
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * succeeded).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * <p> If this LoginModule's own authentication attempt
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * succeeded (the importing of the Solaris authentication information
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * succeeded), then this method associates the Solaris Principals
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * with the <code>Subject</code> currently tied to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * <code>LoginModule</code>.  If this LoginModule's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * authentication attempted failed, then this method removes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * any state that was originally saved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * @exception LoginException if the commit fails
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * @return true if this LoginModule's own login and commit attempts
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     *          succeeded, or false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    public boolean commit() throws LoginException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        if (succeeded == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            if (debug) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                System.out.println("\t\t[SolarisLoginModule]: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                    "did not add any Principals to Subject " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                    "because own authentication failed.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        if (subject.isReadOnly()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            throw new LoginException ("Subject is Readonly");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        if (!subject.getPrincipals().contains(userPrincipal))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            subject.getPrincipals().add(userPrincipal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        if (!subject.getPrincipals().contains(UIDPrincipal))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            subject.getPrincipals().add(UIDPrincipal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        if (!subject.getPrincipals().contains(GIDPrincipal))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            subject.getPrincipals().add(GIDPrincipal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        for (int i = 0; i < supplementaryGroups.size(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            if (!subject.getPrincipals().contains(supplementaryGroups.get(i)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                subject.getPrincipals().add(supplementaryGroups.get(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        if (debug) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            System.out.println("\t\t[SolarisLoginModule]: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                               "added SolarisPrincipal,");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            System.out.println("\t\t\t\tSolarisNumericUserPrincipal,");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            System.out.println("\t\t\t\tSolarisNumericGroupPrincipal(s),");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            System.out.println("\t\t\t to Subject");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        commitSucceeded = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    }
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
     * Abort the authentication (second phase).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * <p> This method is called if the LoginContext's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * overall authentication failed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * (the relevant REQUIRED, REQUISITE, SUFFICIENT and OPTIONAL LoginModules
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * did not succeed).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * <p> This method cleans up any state that was originally saved
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * as part of the authentication attempt from the <code>login</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * and <code>commit</code> methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * @exception LoginException if the abort fails
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * @return false if this LoginModule's own login and/or commit attempts
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     *          failed, and true otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    public boolean abort() throws LoginException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        if (debug) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            System.out.println("\t\t[SolarisLoginModule]: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                "aborted authentication attempt");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        if (succeeded == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        } else if (succeeded == true && commitSucceeded == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            // Clean out state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            succeeded = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            ss = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            userPrincipal = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            UIDPrincipal = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            GIDPrincipal = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            supplementaryGroups =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                        new LinkedList<SolarisNumericGroupPrincipal>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            // overall authentication succeeded and commit succeeded,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            // but someone else's commit failed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            logout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * Logout the user
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * <p> This method removes the Principals associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * with the <code>Subject</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * @exception LoginException if the logout fails
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * @return true in all cases (this <code>LoginModule</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     *          should not be ignored).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    public boolean logout() throws LoginException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        if (debug) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            System.out.println("\t\t[SolarisLoginModule]: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                "Entering logout");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        if (subject.isReadOnly()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            throw new LoginException ("Subject is Readonly");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        // remove the added Principals from the Subject
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        subject.getPrincipals().remove(userPrincipal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        subject.getPrincipals().remove(UIDPrincipal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        subject.getPrincipals().remove(GIDPrincipal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        for (int i = 0; i < supplementaryGroups.size(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            subject.getPrincipals().remove(supplementaryGroups.get(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        // clean out state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        ss = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        succeeded = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        commitSucceeded = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        userPrincipal = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        UIDPrincipal = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        GIDPrincipal = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        supplementaryGroups = new LinkedList<SolarisNumericGroupPrincipal>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        if (debug) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            System.out.println("\t\t[SolarisLoginModule]: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                "logged out Subject");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
}