link start!
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*
|
||||
* Could not load the following classes:
|
||||
* javax.baja.util.Lexicon
|
||||
*/
|
||||
package com.tridium.fox.kerberos;
|
||||
|
||||
import com.tridium.fox.kerberos.KerberosAuthenticator;
|
||||
import com.tridium.fox.message.FoxMessage;
|
||||
import com.tridium.fox.session.FoxSession;
|
||||
import java.security.PrivilegedAction;
|
||||
import javax.baja.util.Lexicon;
|
||||
import org.ietf.jgss.GSSContext;
|
||||
import org.ietf.jgss.GSSManager;
|
||||
import org.ietf.jgss.GSSName;
|
||||
import org.ietf.jgss.Oid;
|
||||
|
||||
public class GSSDelegCredAction
|
||||
implements PrivilegedAction {
|
||||
private static final String KERB_DELEG_CRED = "fox.kerberos.gss.delegating";
|
||||
private static final String KERB_NO_TOKEN = "fox.kerberos.gss.noToken";
|
||||
private static final String KERB_CTX_ESTABLISHED = "fox.kerberos.gss.contextEstablished";
|
||||
private static final String KERB_ERR_NO_DELEG = "fox.kerberos.gss.couldNotDelegate";
|
||||
String serverPrincipal;
|
||||
FoxSession session;
|
||||
static /* synthetic */ Class class$com$tridium$fox$kerberos$GSSDelegCredAction;
|
||||
|
||||
public GSSDelegCredAction(String string, FoxSession foxSession) {
|
||||
this.serverPrincipal = string;
|
||||
this.session = foxSession;
|
||||
}
|
||||
|
||||
public Object run() {
|
||||
Lexicon lexicon = Lexicon.make((Class)(class$com$tridium$fox$kerberos$GSSDelegCredAction == null ? (class$com$tridium$fox$kerberos$GSSDelegCredAction = GSSDelegCredAction.class$("com.tridium.fox.kerberos.GSSDelegCredAction")) : class$com$tridium$fox$kerberos$GSSDelegCredAction));
|
||||
KerberosAuthenticator.log.trace(lexicon.getText(KERB_DELEG_CRED));
|
||||
try {
|
||||
Oid oid = new Oid("1.2.840.113554.1.2.2");
|
||||
GSSManager gSSManager = GSSManager.getInstance();
|
||||
GSSName gSSName = gSSManager.createName(this.serverPrincipal, null);
|
||||
gSSName = gSSName.canonicalize(oid);
|
||||
GSSContext gSSContext = gSSManager.createContext(gSSName, oid, null, 0);
|
||||
gSSContext.requestCredDeleg(true);
|
||||
gSSContext.requestMutualAuth(true);
|
||||
byte[] byArray = new byte[]{};
|
||||
while (!gSSContext.isEstablished()) {
|
||||
FoxMessage foxMessage;
|
||||
if ((byArray = gSSContext.initSecContext(byArray, 0, byArray.length)) != null) {
|
||||
foxMessage = new FoxMessage();
|
||||
foxMessage.add("token", byArray);
|
||||
this.session.setState("client.tune sendToken ");
|
||||
this.session.sendTuning("clientToken", foxMessage);
|
||||
}
|
||||
if (gSSContext.isEstablished()) continue;
|
||||
this.session.setState("client.tune receiveToken");
|
||||
foxMessage = this.session.receiveTuning("serverToken");
|
||||
byArray = foxMessage.getBlob("token", null);
|
||||
if (byArray != null) continue;
|
||||
KerberosAuthenticator.log.warning(lexicon.getText(KERB_NO_TOKEN));
|
||||
return null;
|
||||
}
|
||||
KerberosAuthenticator.log.trace(lexicon.getText(KERB_CTX_ESTABLISHED, new Object[]{gSSContext.getSrcName(), gSSContext.getTargName()}));
|
||||
}
|
||||
catch (Exception exception) {
|
||||
KerberosAuthenticator.log.error(lexicon.getText(KERB_ERR_NO_DELEG, new Object[]{exception.toString()}));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
static /* synthetic */ Class class$(String string) {
|
||||
try {
|
||||
return Class.forName(string);
|
||||
}
|
||||
catch (ClassNotFoundException classNotFoundException) {
|
||||
throw new NoClassDefFoundError(classNotFoundException.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*
|
||||
* Could not load the following classes:
|
||||
* javax.baja.log.Log
|
||||
* javax.baja.security.BICredentials
|
||||
* javax.baja.security.BUsernameAndPassword
|
||||
* javax.baja.security.kerberos.BKerberosCredentials
|
||||
* javax.baja.util.Lexicon
|
||||
*/
|
||||
package com.tridium.fox.kerberos;
|
||||
|
||||
import com.sun.security.jgss.GSSUtil;
|
||||
import com.tridium.fox.kerberos.GSSDelegCredAction;
|
||||
import com.tridium.fox.kerberos.KerberosCallbackHandler;
|
||||
import com.tridium.fox.kerberos.KerberosConfig;
|
||||
import com.tridium.fox.message.FoxMessage;
|
||||
import com.tridium.fox.session.FoxSession;
|
||||
import javax.baja.log.Log;
|
||||
import javax.baja.security.BICredentials;
|
||||
import javax.baja.security.BUsernameAndPassword;
|
||||
import javax.baja.security.kerberos.BKerberosCredentials;
|
||||
import javax.baja.util.Lexicon;
|
||||
import javax.security.auth.Subject;
|
||||
import javax.security.auth.login.LoginContext;
|
||||
import javax.security.auth.login.LoginException;
|
||||
|
||||
public class KerberosAuthenticator {
|
||||
private static final String KERB_AUTH_STARTED = "fox.kerberos.authStarted";
|
||||
private static final String KERB_USER_KERB = "fox.kerberos.user.kerberos";
|
||||
private static final String KERB_USER_LOCAL = "fox.kerberos.user.local";
|
||||
private static final String KERB_LOGIN = "fox.kerberos.login";
|
||||
private static final String KERB_LOGIN_FAILED = "fox.kerberos.loginFailed";
|
||||
static final Lexicon lex = Lexicon.make((Class)(class$com$tridium$fox$kerberos$KerberosAuthenticator == null ? (class$com$tridium$fox$kerberos$KerberosAuthenticator = KerberosAuthenticator.class$("com.tridium.fox.kerberos.KerberosAuthenticator")) : class$com$tridium$fox$kerberos$KerberosAuthenticator));
|
||||
static final Log log = Log.getLog((String)"fox.kerberos");
|
||||
static /* synthetic */ Class class$com$tridium$fox$kerberos$KerberosAuthenticator;
|
||||
|
||||
public static void authenticate(FoxSession foxSession, FoxMessage foxMessage, BICredentials bICredentials) throws Exception {
|
||||
Object object;
|
||||
log.trace(lex.getText(KERB_AUTH_STARTED));
|
||||
boolean bl = false;
|
||||
String string = "";
|
||||
String string2 = "";
|
||||
if (bICredentials instanceof BUsernameAndPassword) {
|
||||
object = (BUsernameAndPassword)bICredentials;
|
||||
string = object.getUsername();
|
||||
if (string.startsWith("kerberos:")) {
|
||||
bl = true;
|
||||
string = string.substring(string.indexOf(":") + 1);
|
||||
}
|
||||
string2 = object.getPassword().getValue();
|
||||
} else if (bICredentials instanceof BKerberosCredentials) {
|
||||
bl = true;
|
||||
} else {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
object = new FoxMessage();
|
||||
String string3 = bl ? "authInputKerb" : "authInputLocal";
|
||||
((FoxMessage)object).add("authInput", string3);
|
||||
foxSession.setState("client.tune send firstMessage: userType=" + string3);
|
||||
foxSession.sendTuning("authMessage1", (FoxMessage)object);
|
||||
if (bl) {
|
||||
log.trace(lex.getText(KERB_USER_KERB, new Object[]{string}));
|
||||
String string4 = foxMessage.getString("realm");
|
||||
String string5 = foxMessage.getString("kdc");
|
||||
String string6 = foxMessage.getString("server") + "@" + string4;
|
||||
System.setProperty("java.security.krb5.realm", string4);
|
||||
System.setProperty("java.security.krb5.kdc", string5);
|
||||
if (bICredentials instanceof BKerberosCredentials) {
|
||||
BKerberosCredentials bKerberosCredentials = (BKerberosCredentials)bICredentials;
|
||||
Subject subject = GSSUtil.createSubject(bKerberosCredentials.getCredential().getName(), bKerberosCredentials.getCredential());
|
||||
Subject.doAs(subject, new GSSDelegCredAction(string6, foxSession));
|
||||
bKerberosCredentials.destroyTicket();
|
||||
} else {
|
||||
try {
|
||||
string = string + "@" + string4;
|
||||
LoginContext loginContext = KerberosAuthenticator.kerberosClientLogin(string, string2, foxSession);
|
||||
Subject.doAs(loginContext.getSubject(), new GSSDelegCredAction(string6, foxSession));
|
||||
loginContext.logout();
|
||||
}
|
||||
catch (LoginException loginException) {
|
||||
FoxMessage foxMessage2 = new FoxMessage();
|
||||
byte[] byArray = new byte[]{};
|
||||
foxMessage2.add("token", byArray);
|
||||
foxSession.setState("client.tune sendLogin");
|
||||
foxSession.sendTuning("clientToken", foxMessage2);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
log.trace(lex.getText(KERB_USER_LOCAL, new Object[]{string}));
|
||||
FoxMessage foxMessage3 = new FoxMessage();
|
||||
foxMessage3.add("username", string);
|
||||
foxMessage3.add("password", string2);
|
||||
foxSession.setState("client.tune sendLogin");
|
||||
foxSession.sendTuning("login", foxMessage3);
|
||||
}
|
||||
}
|
||||
|
||||
private static LoginContext kerberosClientLogin(String string, String string2, FoxSession foxSession) throws LoginException {
|
||||
log.trace(lex.getText(KERB_LOGIN));
|
||||
KerberosConfig kerberosConfig = new KerberosConfig(string);
|
||||
LoginContext loginContext = null;
|
||||
try {
|
||||
loginContext = new LoginContext("com.tridium.fox.session.KerberosAuthenticator", null, new KerberosCallbackHandler(string, string2), kerberosConfig);
|
||||
loginContext.login();
|
||||
}
|
||||
catch (LoginException loginException) {
|
||||
log.error(lex.getText(KERB_LOGIN_FAILED));
|
||||
throw loginException;
|
||||
}
|
||||
return loginContext;
|
||||
}
|
||||
|
||||
static /* synthetic */ Class class$(String string) {
|
||||
try {
|
||||
return Class.forName(string);
|
||||
}
|
||||
catch (ClassNotFoundException classNotFoundException) {
|
||||
throw new NoClassDefFoundError(classNotFoundException.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*
|
||||
* Could not load the following classes:
|
||||
* javax.baja.security.BICredentials
|
||||
* javax.baja.security.BUsernameAndPassword
|
||||
*/
|
||||
package com.tridium.fox.kerberos;
|
||||
|
||||
import java.io.IOException;
|
||||
import javax.baja.security.BICredentials;
|
||||
import javax.baja.security.BUsernameAndPassword;
|
||||
import javax.security.auth.callback.Callback;
|
||||
import javax.security.auth.callback.CallbackHandler;
|
||||
import javax.security.auth.callback.NameCallback;
|
||||
import javax.security.auth.callback.PasswordCallback;
|
||||
import javax.security.auth.callback.UnsupportedCallbackException;
|
||||
|
||||
public class KerberosCallbackHandler
|
||||
implements CallbackHandler {
|
||||
String username = "";
|
||||
String password = "";
|
||||
|
||||
public KerberosCallbackHandler(BICredentials bICredentials) {
|
||||
if (bICredentials instanceof BUsernameAndPassword) {
|
||||
BUsernameAndPassword bUsernameAndPassword = (BUsernameAndPassword)bICredentials;
|
||||
this.username = bUsernameAndPassword.getUsername();
|
||||
this.password = bUsernameAndPassword.getPassword().getValue();
|
||||
}
|
||||
}
|
||||
|
||||
public KerberosCallbackHandler(String string, String string2) {
|
||||
this.username = string;
|
||||
this.password = string2;
|
||||
}
|
||||
|
||||
public void handle(Callback[] callbackArray) throws IOException, UnsupportedCallbackException {
|
||||
for (int i = 0; i < callbackArray.length; ++i) {
|
||||
Callback callback;
|
||||
if (callbackArray[i] instanceof NameCallback) {
|
||||
callback = (NameCallback)callbackArray[i];
|
||||
((NameCallback)callback).setName(this.username);
|
||||
continue;
|
||||
}
|
||||
if (callbackArray[i] instanceof PasswordCallback) {
|
||||
callback = (PasswordCallback)callbackArray[i];
|
||||
((PasswordCallback)callback).setPassword(this.password.toCharArray());
|
||||
continue;
|
||||
}
|
||||
throw new UnsupportedCallbackException(callbackArray[i], "Unrecognized callback.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.tridium.fox.kerberos;
|
||||
|
||||
import java.util.HashMap;
|
||||
import javax.security.auth.login.AppConfigurationEntry;
|
||||
import javax.security.auth.login.Configuration;
|
||||
|
||||
public class KerberosConfig
|
||||
extends Configuration {
|
||||
AppConfigurationEntry entry = null;
|
||||
String principal = null;
|
||||
boolean useTicketCache = false;
|
||||
boolean doNotPrompt = false;
|
||||
boolean isInitiator = true;
|
||||
boolean storeKey = false;
|
||||
|
||||
public KerberosConfig(String string) {
|
||||
this.principal = string;
|
||||
this.init();
|
||||
}
|
||||
|
||||
public KerberosConfig(boolean bl, boolean bl2) {
|
||||
this.useTicketCache = bl;
|
||||
this.doNotPrompt = bl2;
|
||||
this.init();
|
||||
}
|
||||
|
||||
public void setUseTicketCache(boolean bl) {
|
||||
this.useTicketCache = bl;
|
||||
this.init();
|
||||
}
|
||||
|
||||
public void setDoNotPrompt(boolean bl) {
|
||||
this.doNotPrompt = bl;
|
||||
this.init();
|
||||
}
|
||||
|
||||
public void setIsInitiator(boolean bl) {
|
||||
this.isInitiator = bl;
|
||||
if (!bl) {
|
||||
this.storeKey = true;
|
||||
}
|
||||
this.init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
HashMap<String, String> hashMap = new HashMap<String, String>();
|
||||
if (this.principal != null) {
|
||||
hashMap.put("principal", this.principal);
|
||||
}
|
||||
hashMap.put("useTicketCache", Boolean.toString(this.useTicketCache));
|
||||
hashMap.put("doNotPrompt", Boolean.toString(this.doNotPrompt));
|
||||
hashMap.put("isInitiator", Boolean.toString(this.isInitiator));
|
||||
hashMap.put("storeKey", Boolean.toString(this.storeKey));
|
||||
hashMap.put("refreshKrb5Config", "true");
|
||||
this.entry = new AppConfigurationEntry("com.sun.security.auth.module.Krb5LoginModule", AppConfigurationEntry.LoginModuleControlFlag.REQUIRED, hashMap);
|
||||
}
|
||||
|
||||
public AppConfigurationEntry[] getAppConfigurationEntry(String string) {
|
||||
AppConfigurationEntry[] appConfigurationEntryArray = new AppConfigurationEntry[]{this.entry};
|
||||
return appConfigurationEntryArray;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user