jdk/src/java.security.jgss/share/classes/com/sun/security/sasl/gsskerb/FactoryImpl.java
changeset 26667 66b7d29b75f7
parent 26666 c005611e8f69
parent 26660 5e174bbfc03a
child 26668 1b1ec4291abc
equal deleted inserted replaced
26666:c005611e8f69 26667:66b7d29b75f7
     1 /*
       
     2  * Copyright (c) 2000, 2006, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.  Oracle designates this
       
     8  * particular file as subject to the "Classpath" exception as provided
       
     9  * by Oracle in the LICENSE file that accompanied this code.
       
    10  *
       
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    14  * version 2 for more details (a copy is included in the LICENSE file that
       
    15  * accompanied this code).
       
    16  *
       
    17  * You should have received a copy of the GNU General Public License version
       
    18  * 2 along with this work; if not, write to the Free Software Foundation,
       
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    20  *
       
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    22  * or visit www.oracle.com if you need additional information or have any
       
    23  * questions.
       
    24  */
       
    25 
       
    26 package com.sun.security.sasl.gsskerb;
       
    27 
       
    28 import javax.security.sasl.*;
       
    29 import com.sun.security.sasl.util.PolicyUtils;
       
    30 
       
    31 import java.util.Map;
       
    32 import javax.security.auth.callback.CallbackHandler;
       
    33 
       
    34 /**
       
    35   * Client/server factory for GSSAPI (Kerberos V5) SASL client/server mechs.
       
    36   * See GssKrb5Client/GssKrb5Server for input requirements.
       
    37   *
       
    38   * @author Rosanna Lee
       
    39   */
       
    40 public final class FactoryImpl implements SaslClientFactory, SaslServerFactory {
       
    41     private static final String myMechs[] = {
       
    42         "GSSAPI"};
       
    43 
       
    44     private static final int mechPolicies[] = {
       
    45         PolicyUtils.NOPLAINTEXT|PolicyUtils.NOANONYMOUS|PolicyUtils.NOACTIVE
       
    46     };
       
    47 
       
    48     private static final int GSS_KERB_V5 = 0;
       
    49 
       
    50     public FactoryImpl() {
       
    51     }
       
    52 
       
    53     public SaslClient createSaslClient(String[] mechs,
       
    54         String authorizationId,
       
    55         String protocol,
       
    56         String serverName,
       
    57         Map<String,?> props,
       
    58         CallbackHandler cbh) throws SaslException {
       
    59 
       
    60             for (int i = 0; i < mechs.length; i++) {
       
    61                 if (mechs[i].equals(myMechs[GSS_KERB_V5])
       
    62                     && PolicyUtils.checkPolicy(mechPolicies[GSS_KERB_V5], props)) {
       
    63                     return new GssKrb5Client(
       
    64                         authorizationId,
       
    65                         protocol,
       
    66                         serverName,
       
    67                         props,
       
    68                         cbh);
       
    69                 }
       
    70             }
       
    71             return null;
       
    72     };
       
    73 
       
    74     public SaslServer createSaslServer(String mech,
       
    75         String protocol,
       
    76         String serverName,
       
    77         Map<String,?> props,
       
    78         CallbackHandler cbh) throws SaslException {
       
    79             if (mech.equals(myMechs[GSS_KERB_V5])
       
    80                 && PolicyUtils.checkPolicy(mechPolicies[GSS_KERB_V5], props)) {
       
    81                 if (cbh == null) {
       
    82                     throw new SaslException(
       
    83                 "Callback handler with support for AuthorizeCallback required");
       
    84                 }
       
    85                 return new GssKrb5Server(
       
    86                     protocol,
       
    87                     serverName,
       
    88                     props,
       
    89                     cbh);
       
    90             }
       
    91             return null;
       
    92     };
       
    93 
       
    94     public String[] getMechanismNames(Map<String,?> props) {
       
    95         return PolicyUtils.filterMechs(myMechs, mechPolicies, props);
       
    96     }
       
    97 }