src/java.security.sasl/share/classes/javax/security/sasl/AuthorizeCallback.java
author herrick
Fri, 21 Jun 2019 08:29:09 -0400
branchJDK-8200758-branch
changeset 57419 44c2481650ce
parent 47216 71c04702a3d5
permissions -rw-r--r--
8225092: Several jpackage tests failes when run with jcov enabled Submitted-by: almatvee Reviewed-by: herrick, almatvee
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
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 javax.security.sasl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import javax.security.auth.callback.Callback;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
/**
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
    31
  * This callback is used by {@code SaslServer} to determine whether
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
  * one entity (identified by an authenticated authentication id)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
  * can act on
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
  * behalf of another entity (identified by an authorization id).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
  *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
  * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
  *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
  * @author Rosanna Lee
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
  * @author Rob Weltman
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
public class AuthorizeCallback implements Callback, java.io.Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
     * The (authenticated) authentication id to check.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    private String authenticationID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
     * The authorization id to check.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    private String authorizationID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     * The id of the authorized entity. If null, the id of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     * the authorized entity is authorizationID.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    private String authorizedID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * A flag indicating whether the authentication id is allowed to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * act on behalf of the authorization id.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    private boolean authorized;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    /**
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
    69
     * Constructs an instance of {@code AuthorizeCallback}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * @param authnID   The (authenticated) authentication id.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * @param authzID   The authorization id.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    public AuthorizeCallback(String authnID, String authzID) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        authenticationID = authnID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        authorizationID = authzID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * Returns the authentication id to check.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * @return The authentication id to check.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    public String getAuthenticationID() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        return authenticationID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * Returns the authorization id to check.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * @return The authentication id to check.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    public String getAuthorizationID() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        return authorizationID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * Determines whether the authentication id is allowed to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * act on behalf of the authorization id.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     *
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
    99
     * @return {@code true} if authorization is allowed; {@code false} otherwise
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * @see #setAuthorized(boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * @see #getAuthorizedID()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    public boolean isAuthorized() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        return authorized;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * Sets whether the authorization is allowed.
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   109
     * @param ok {@code true} if authorization is allowed; {@code false} otherwise
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * @see #isAuthorized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * @see #setAuthorizedID(java.lang.String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    public void setAuthorized(boolean ok) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        authorized = ok;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * Returns the id of the authorized user.
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   119
     * @return The id of the authorized user. {@code null} means the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * authorization failed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * @see #setAuthorized(boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * @see #setAuthorizedID(java.lang.String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    public String getAuthorizedID() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        if (!authorized) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        return (authorizedID == null) ? authorizationID : authorizedID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * Sets the id of the authorized entity. Called by handler only when the id
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * is different from getAuthorizationID(). For example, the id
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * might need to be canonicalized for the environment in which it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * will be used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * @param id The id of the authorized user.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * @see #setAuthorized(boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * @see #getAuthorizedID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    public void setAuthorizedID(String id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        authorizedID = id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    private static final long serialVersionUID = -2353344186490470805L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
}