001/**
002 *
003 * Copyright the original author or authors
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 *     http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.jivesoftware.smack.sasl.javax;
018
019import java.util.Map;
020
021import javax.security.sasl.Sasl;
022
023/**
024 * Implementation of the SASL GSSAPI mechanism.
025 *
026 * @author Jay Kline
027 */
028public class SASLGSSAPIMechanism extends SASLJavaXMechanism {
029
030    public static final String NAME = GSSAPI;
031
032    static {
033        System.setProperty("javax.security.auth.useSubjectCredsOnly","false");
034        System.setProperty("java.security.auth.login.config","gss.conf");
035    }
036
037    @Override
038    public boolean authzidSupported() {
039      return true;
040    }
041
042    @Override
043    public String getName() {
044        return NAME;
045    }
046
047    @Override
048    protected Map<String, String> getSaslProps() {
049        Map<String, String> props = super.getSaslProps();
050        props.put(Sasl.SERVER_AUTH,"TRUE");
051        return props;
052    }
053
054    /**
055     * GSSAPI differs from all other SASL mechanism such that it required the FQDN host name as
056     * server name and not the serviceName (At least that is what old code comments of Smack tell
057     * us).
058     */
059    @Override
060    protected String getServerName() {
061        return host;
062    }
063
064    @Override
065    public int getPriority() {
066        return 100;
067    }
068
069    @Override
070    public SASLGSSAPIMechanism newInstance() {
071        return new SASLGSSAPIMechanism();
072    }
073
074}