Here you can find the source of serverLogin(final String serverPrincipal, final String serverPassword)
Parameter | Description |
---|---|
serverPrincipal | server principal |
serverPassword | server passsword |
Parameter | Description |
---|---|
LoginException | on error |
public static LoginContext serverLogin(final String serverPrincipal, final String serverPassword) throws LoginException
//package com.java2s; /*//from w w w. j a v a 2s . c o m * DavMail POP/IMAP/SMTP/CalDav/LDAP Exchange Gateway * Copyright (C) 2012 Mickael Guessant * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import javax.security.auth.callback.*; import javax.security.auth.login.LoginContext; import javax.security.auth.login.LoginException; import java.io.IOException; public class Main { /** * Create server side Kerberos login context for provided credentials. * * @param serverPrincipal server principal * @param serverPassword server passsword * @return LoginContext server login context * @throws LoginException on error */ public static LoginContext serverLogin(final String serverPrincipal, final String serverPassword) throws LoginException { LoginContext serverLoginContext = new LoginContext("spnego-server", new CallbackHandler() { public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { for (Callback callback : callbacks) { if (callback instanceof NameCallback) { final NameCallback nameCallback = (NameCallback) callback; nameCallback.setName(serverPrincipal); } else if (callback instanceof PasswordCallback) { final PasswordCallback passCallback = (PasswordCallback) callback; passCallback.setPassword(serverPassword .toCharArray()); } else { throw new UnsupportedCallbackException( callback); } } } }); serverLoginContext.login(); return serverLoginContext; } }