PRoblem when i am trying to authinticate to AD us gss

I am trying to access active directory using JAAS nut when i run my code a get the attached message

D:\JDeveloper10G\jdk\bin>java jasldap

GSSException: No valid credentials provided (Mechanism level: Failed to find any

Kerberos Ticket)

at sun.security.jgss.krb5.Krb5InitCredential.getInstance(Krb5InitCredent

ial.java:133)

at sun.security.jgss.krb5.Krb5MechFactory.getCredentialElement(Krb5MechF

actory.java:72)

at sun.security.jgss.GSSManagerImpl.getCredentialElement(GSSManagerImpl.

java:149)

at sun.security.jgss.GSSCredentialImpl.add(GSSCredentialImpl.java:389)

at sun.security.jgss.GSSCredentialImpl.<init>(GSSCredentialImpl.java:60)

at sun.security.jgss.GSSCredentialImpl.<init>(GSSCredentialImpl.java:37)

at sun.security.jgss.GSSManagerImpl.createCredential(GSSManagerImpl.java

:96)

at sun.security.jgss.GSSContextImpl.initSecContext(GSSContextImpl.java:1

78)

at sun.security.jgss.GSSContextImpl.initSecContext(GSSContextImpl.java:1

58)

at com.sun.security.sasl.gsskerb.GssKrb5Client.evaluateChallenge(GssKrb5

Client.java:155)

at com.sun.jndi.ldap.sasl.LdapSasl.saslBind(LdapSasl.java:105)

at com.sun.jndi.ldap.LdapClient.authenticate(LdapClient.java:214)

at com.sun.jndi.ldap.LdapCtx.connect(LdapCtx.java:2637)

at com.sun.jndi.ldap.LdapCtx.<init>(LdapCtx.java:283)

at com.sun.jndi.ldap.LdapCtxFactory.getUsingURL(LdapCtxFactory.java:175)

at com.sun.jndi.ldap.LdapCtxFactory.getUsingURLs(LdapCtxFactory.java:193

)

at com.sun.jndi.ldap.LdapCtxFactory.getLdapCtxInstance(LdapCtxFactory.ja

va:136)

at com.sun.jndi.ldap.LdapCtxFactory.getInitialContext(LdapCtxFactory.jav

a:66)

at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:6

67)

at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:247

)

at javax.naming.InitialContext.init(InitialContext.java:223)

at javax.naming.InitialContext.<init>(InitialContext.java:197)

at javax.naming.directory.InitialDirContext.<init>(InitialDirContext.jav

a:82)

at searchLDAP.performSearch(searchLDAP.java:93)

at searchLDAP.run(searchLDAP.java:50)

at java.security.AccessController.doPrivileged(Native Method)

at javax.security.auth.Subject.doAs(Subject.java:337)

at actions.search(actions.java:11)

at jasldap.samaccountname(jasldap.java:14)

at jasldap.<init>(jasldap.java:6)

at jasldap.main(jasldap.java:22)

javax.naming.AuthenticationException: GSSAPI [Root exception is javax.security.s

asl.SaslException: GSS initiate failed [Caused by GSSException: No valid credent

ials provided]]

can anyone help me here

and my code is here

import java.io.*;

public class jasldap

{

public jasldap()

{

samaccountname();

}

public void samaccountname(){

actions pSA = new actions();

pSA.search("f3482","sAMAccountName");

if (searchLDAP.modException != null){

System.out.print(searchLDAP.modException);

}

}

public static void main (String[] args)

{

jasldap ld=new jasldap();

}

}

the seconed class is

import javax.security.auth.Subject;

public class actions {

KerberosaAuth pKA = new KerberosaAuth();

public String search(String sUserName, String sFilter){

pKA.KerberosAuth();

String sTRDN = sUserName;

String sResults = new String();

sResults = (Subject.doAs(pKA.lc.getSubject(), new searchLDAP(sTRDN, sFilter)).toString());

return sResults;

}

}

/-

import java.util.Hashtable;

import java.util.regex.Matcher;

import java.util.regex.Pattern;

import javax.naming.Context;

import javax.naming.NamingEnumeration;

import javax.naming.NamingException;

import javax.naming.directory.Attribute;

import javax.naming.directory.Attributes;

import javax.naming.directory.DirContext;

import javax.naming.directory.InitialDirContext;

import javax.naming.directory.SearchControls;

import javax.naming.directory.SearchResult;

class searchLDAP implements java.security.PrivilegedAction {

private static Matcher mGMatch;

private static Pattern pGPattern;

private static String sGDesc = new String();

private static String sRegex = ",DC=fgb,DC=ae";

private static String sGRegex = ",OU=Domain Groups";

private static String ssGRegex = "CN=";

private static String sReplace = "";

public String sTRUN = new String();

public String sFilter = new String();

public static String sName = new String();

private static final long serialVersionUID = 1-1;

public static String sResults = new String();

public static String ssResults = new String();

public static String sUserAttrib = "";

public static String modException;

public String sTRDN = new String();

public String sErrorResult = new String();

public static String[] sAttrIDs;

public static String sSAMField = new String();

public static String sNameField = new String();

public static String sDepartmentField = new String();

public static String sMailField = new String();

public static String sIsAccountLockedField = new String();

public static String sEmployeeIDField = new String();

public searchLDAP(String ssTRDN, String ssFilter) {

sTRDN = ssTRDN;

sFilter = ssFilter;

}

public Object run() {

performSearch(sTRDN,sFilter);

return sResults;

}

private void performSearch(String sTRDN, String sFilter) {

/* Specify the ids of the attributes to return */

sAttrIDs = new String[6];

sAttrIDs [ 0 ] = "sAMAccountName";

sAttrIDs [ 1 ] = "department";

sAttrIDs [ 2 ] = "mail";

sAttrIDs [ 3 ] = "employeeID" ;

sAttrIDs [ 4 ] = "displayName";

sAttrIDs [ 5 ] = "IsAccountLocked";

String[] sGAttrIDs = {"description"};

String[] ssGAttrIDs = new String [ 3 ];

ssGAttrIDs [ 0 ] = "memberOf";

ssGAttrIDs [ 1 ] = "userAccountControl";

ssGAttrIDs [ 2 ] = "sAMAccountName";

Hashtable env = new Hashtable(11);

env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");

env.put(Context.PROVIDER_URL,"ldap://hoadc0.fgb.ae:389/DC=fgb,DC=ae");

env.put(Context.SECURITY_AUTHENTICATION, "GSSAPI");

env.put("javax.security.sasl.server.authentication", "true");

String filter = "(&("+ sFilter+"=" + sTRDN + ")(!(objectclass=computer)))";

modException = null;

SearchControls constraints = new SearchControls();

constraints.setSearchScope(SearchControls.SUBTREE_SCOPE);

//constraints.setReturningAttributes(sAttrIDs);

constraints.setTimeLimit( 6000 );

constraints.setDerefLinkFlag( false );

constraints.setReturningObjFlag( false );

try {

/* Create initial context */

sName = null;

ssResults = null;

modException = null;

DirContext ctx = new InitialDirContext(env);

NamingEnumeration answer = ctx.search ("OU=Departments", filter , constraints );

while (answer != null && answer.hasMore()) {

/* return the partially qualified name CN="", OU="" */

SearchResult nextEntry = ( SearchResult )answer.next();

sName = (nextEntry.getName());

ssResults = sName;

Attributes aAnswer = ctx.getAttributes(sName + ",OU=Departments",sAttrIDs);

if (sTRDN.contains("*")){

}else{

int numLabels = sAttrIDs.length;

for (int i = 0; i < numLabels; i++) {

if ((aAnswer.get(sAttrIDs)) != null) {

sAttrIDs=(aAnswer.get(sAttrIDs).get().toString());

}

}

if (sAttrIDs[3].contains("employeeID")){

sAttrIDs[3]="";

}

if (sAttrIDs[5].contains("IsAccountLocked")){

sAttrIDs[5]="";

}

}

try {

Attributes aGAnswer = ctx.getAttributes(sName + ",OU=Departments",ssGAttrIDs);

if (aGAnswer.toString().contains("514")){

sResults = ((aAnswer.get("sAMAccountName").get()) + " , " + "*******ACCOUNT IS LOCKED*******");

System.out.println(sResults + '\n');

if (sTRDN.contains("*")){

}else{

sAttrIDs[5] = "ACCOUNT IS LOCKED";

}

}else{

sResults = (sName);

}

Attribute amemberOf = aGAnswer.get("memberOf");

if (amemberOf != null){

/* print each value */

NamingEnumeration eGroup = amemberOf.getAll();

while (eGroup.hasMore()) {

sGDesc = (eGroup.nextElement().toString());

pGPattern = Pattern.compile(sGRegex);

mGMatch = pGPattern.matcher(sGDesc);

while(mGMatch.find()) {

pGPattern = Pattern.compile(sRegex);

mGMatch = pGPattern.matcher(sGDesc);

sGDesc = mGMatch.replaceAll(sReplace);

Attributes aGroup = ctx.getAttributes(sGDesc, sGAttrIDs);

/* "sDesc" is the description of the group */

String sDesc = (aGroup.get("description").get().toString());

/* The following replaces the distinguished name "SGDesc" with the cn for display*/

pGPattern = Pattern.compile(ssGRegex);

mGMatch = pGPattern.matcher(sGDesc);

sGDesc = mGMatch.replaceAll(sReplace);

pGPattern = Pattern.compile(sGRegex);

mGMatch = pGPattern.matcher(sGDesc);

sGDesc = mGMatch.replaceAll(sReplace);

System.out.println(sGDesc +": "+ " (" + sDesc + " )");

}

}

}

} catch (NamingException le) {

modException = (le.toString());

sErrorResult = modException;

}

System.out.println(sName + ": "+'\n'+ "Authorization Groups: ");

if (sTRDN.contains("*")){

NamingEnumeration enumUserInfo = aAnswer.getAll();

while(enumUserInfo.hasMoreElements()) {

sResults = (enumUserInfo.nextElement().toString());

System.out.println(sResults);

}

}

}

/***************************************************/

} catch (NamingException e)

{/* open catch */

modException = (e.toString());

sErrorResult = modException;

}/* close catch */

/***************************************************/

}

}

/-

[code][b]import javax.security.auth.login.LoginContext;

import javax.security.auth.login.LoginException;

import com.sun.security.auth.callback.TextCallbackHandler;

publicclass KerberosaAuth{

/********************************************************

*Kerberos Authentication

*********************************************************/

LoginContext lc =null;

publicvoid KerberosAuth(){

java.util.Properties p =

new java.util.Properties(System.getProperties());

p.setProperty("java.security.krb5.realm","fgb.ae");

p.setProperty("java.security.krb5.kdc","hoadc0.fgb.ae");

p.setProperty("java.security.auth.login.config", (getClass().getResource("Jaas.conf")).toString());

System.setProperties(p);

try{

lc =

new LoginContext("GssConf",new TextCallbackHandler());

// Attempt authentication

lc.login();

}catch (LoginException le){

System.err.println("Authentication attempt failed: " + le);

System.exit(-1);

}

}

}[/b]

[/code]

My domain name is fgb.ae and Acive directory Domain Controloer is hoadc0

Please help me here

[12553 byte] By [Eaglesa] at [2007-10-3 2:46:38]
# 1

Are you using Windows native ticket cache ? What options have to set in your

jaas.conf file ? If you do want to use Kerberos ticket from the native ticket cache,

you'll need to set "useTicketCache=true". Alternatively, if you don't want to use

the native Kerberos ticket, you don't need to set this option, however you will get

prompted for password. .

What version of JDK are you using, and on what platform.

Please send me the details.

Seema

Seema-1a at 2007-7-14 20:35:24 > top of Java-index,Security,Kerberos & Java GSS (JGSS)...
# 2

HI Thank you for your reply, yes i am using windows ticket cahce, you will find below the jaas.conf file

/

GssConf

{com.sun.security.auth.module.Krb5LoginModule required client=TRUE useTicketCache=true doNotPrompt=true;};

LoginJaas

{com.sun.security.auth.module.Krb5LoginModule required client=TRUE useTicketCache=true doNotPrompt=true;};

Kindly find below the java version which i am using

///-- java -vesrion

Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_05-b05)

Java HotSpot(TM) Client VM (build 1.5.0_05-b05, mixed mode)

Thanl you in advance

Eaglesa at 2007-7-14 20:35:24 > top of Java-index,Security,Kerberos & Java GSS (JGSS)...
# 3

Few things to check :

- Ensure you have a valid Kerberos ticket in the native ticket cache. Check

on the encryption key used.

- Check on the Kerberos account used, it is set-up to use DES ?

Have you selected "use DES" in the account settings ?

Can you clarify the Windows platform used, Windows 2000/XP/2003 SP ?

Seema

Seema-1a at 2007-7-14 20:35:24 > top of Java-index,Security,Kerberos & Java GSS (JGSS)...
# 4
I am using windows 2000 professional
Eaglesa at 2007-7-14 20:35:24 > top of Java-index,Security,Kerberos & Java GSS (JGSS)...
# 5

Hi,

Finally kerberos worked but when i am trying to performa ldap serach i am getting the following error message,

javax.naming.AuthenticationException: GSSAPI [Root exception is javax.security.s

asl.SaslException: GSS initiate failed [Caused by GSSException: No valid credent

ials provided (Mechanism level: KDC has no support for encryption type (14))]]

[Krb5LoginModule]: Entering logout

[Krb5LoginModule]: logged out Subject

CAn you help me with it

Eaglesa at 2007-7-14 20:35:24 > top of Java-index,Security,Kerberos & Java GSS (JGSS)...
# 6

If you are using Windows 2000 SP4, you will need to add

registry key "allowtgtsessionkey" to enable Kerberos session key.

For details refer to following docs:

http://java.sun.com/j2se/1.5.0/docs/guide/security/jgss/tutorials/Troubleshooting.html

Look for "KDC has no support for encryption type" Solution 2.

Seema

Seema-1a at 2007-7-14 20:35:24 > top of Java-index,Security,Kerberos & Java GSS (JGSS)...
# 7

Hi,

Is there any other way to authenticate a user's connection to ActiveDirectory by using the session key *without* adding allowtgtsessionkey? Since MS turned this off and deemed it a security risk, I'm sure customers won't be willing to turn this on again. Currently I'm storing a username/password combo on disk which is a whole different security issue, but we can not ask customers to change this registry setting. It seems to me, without allowtgtsessionkey, java and kerberos authentication using the identity of the currently logged on user on Windows is entirely broken.

awhiga at 2007-7-14 20:35:24 > top of Java-index,Security,Kerberos & Java GSS (JGSS)...
# 8
But Microsoft broke the spec when they took the session key out of the tgt.If you want Kerberos infrastructure interoperability, that's what the registry change is for. If you're relying on MS for all of your Kerb infrastructure, you won't.
Rockwindera at 2007-7-14 20:35:24 > top of Java-index,Security,Kerberos & Java GSS (JGSS)...
# 9

Ok, I think I might need a moron's guide to allowtgtsessionkey ;-)

I am using WinXP. Prof as a client authenticating against an AD on Win2k SP4. I am getting a ticket by getting promted for username/password, but I don't get my tickets stored in the windows ticket cache.

1. So, do I have to add the registry key in both the server and the client?

2. To add the enrty, I expant the registry to HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Lsa\Kerberos\ (on my client).

3. What next? Do I right click on the "Kerberos" node and say New > DWORD > allowtgtsessionkey or do I have to choose New > key followed by a new > dword?

Help is appreciated ;-)

Santacruzshoresa at 2007-7-14 20:35:24 > top of Java-index,Security,Kerberos & Java GSS (JGSS)...
# 10

> If you are using Windows 2000 SP4, you will need to

> add

> registry key "allowtgtsessionkey" to enable Kerberos

> session key.

>

> For details refer to following docs:

> http://java.sun.com/j2se/1.5.0/docs/guide/security/jgs

> s/tutorials/Troubleshooting.html

> Look for "KDC has no support for encryption type"

> Solution 2.

>

> Seema

Can you confirm this works with Windows Server 2000?

Are there any full working examples of this?

There's another related thread here: http://forum.java.sun.com/thread.jspa?messageID=9554063

Message was edited by:

connorsadler

connorsadlera at 2007-7-14 20:35:24 > top of Java-index,Security,Kerberos & Java GSS (JGSS)...