Problem with GlassFish V2 jaas

D

Donkey Hottie

Trying to log in via jaas. My code runs fine at least in JBoss 4 and 5,
but GlassFish has a problem.

Normally the connection is made like

LoginContext lc = new LoginContext(realmName, new JAASCallbackHandler
(username, password));

However, as I have Googled, it came clear to me that GlassFish does not
want or use a CallbackHandler. It wants a Subject with Credentials.

So I have for Sun

import java.security.Principal;
import javax.resource.spi.security.PasswordCredential ;

boolean is SunJavaSystem = ... ;
LoginContext lc = null ;
if (isSunJavaSystem)
{
Set principals = new HashSet() ;
Set credentials = new HashSet() ;
principals.add(new WSPrincipal(username)) ;
credentials.add(new PasswordCredential(username,
password.toCharArray())) ;
Subject subj = new Subject(false, principals, credentials,
credentials) ;
lc = new LoginContext(realmName, subj, new JAASCallbackHandler
(username, password));
}
else
{
lc = new LoginContext(realmName, new JAASCallbackHandler(username,
password));
}

The WSPrincipal is my own class, and implements Principal. Nothing fancy,
but here it is.

public static class WSPrincipal implements Principal
{
private String name ;
public WSPrincipal(String name)
{
this.name = name ;
}

public String getName()
{
return name ;
}

@Override
public boolean equals(Object obj)
{
if (obj == null)
{
return false;
}
if (getClass() != obj.getClass())
{
return false;
}
final WSPrincipal other = (WSPrincipal) obj;
return name.equals(other.name);
}

@Override
public String toString()
{
return name;
}

@Override
public int hashCode()
{
int hash = 7;
return hash;
}
}



In the end, GlassFish do not let in. The error message is:

SEC1105: A PasswordCredential was required but not provided.

and lc.login() throws a LoginException.

Googling around did only show similar problems but no answers. Any
takers?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top