users@glassfish.java.net

Error creating custom realm on Glassfish 3.1.2.2 (Build 5)

From: <forums_at_java.net>
Date: Mon, 24 Dec 2012 02:22:46 -0600 (CST)

Dear All, I have been trying to create a custom realm on Glassfish 3.1.2.2
(Build 5) using the Admin console and I got this error below: *Creation of
Authrealm engcustomrealm failed.
com.sun.enterprise.security.auth.realm.BadRealmException:
java.lang.ClassNotFoundException: com.samplerealm.SimpleRealm not found by
org.glassfish.main.security [271]* I had previously created a jar file for
the custom realm and dropped it in the folder: C:\Program
Files\glassfish-3.1.2.2\glassfish\domains\domain1\lib as well updating the
file C:\Program Files\glassfish-3.1.2.2\glassfish\domains\domain1\login.conf
with the details of the new realm The jar file contents are as follows:
package com.samplerealm; import
com.sun.enterprise.security.auth.realm.IASRealm; import
com.sun.enterprise.security.auth.realm.InvalidOperationException; import
com.sun.enterprise.security.auth.realm.NoSuchUserException; import
java.util.Enumeration; import java.util.Vector; public class SimpleRealm
extends IASRealm { @Override public String getAuthType() { return "simple"; }
@Override public Enumeration getGroupNames(String string) throws
InvalidOperationException, NoSuchUserException { Vector vector = new
Vector(); vector.add("Users"); vector.add("Admin"); return vector.elements();
} @Override public String getJAASContext() { return "simpleRealm"; } public
boolean loginUser(String userName, char[] password) { boolean loginSuccessful
= false; if ("glassfish".equals(userName) &&
"secret".equals(password.toString())) { loginSuccessful = true; } return
loginSuccessful; } } package com.samplerealm; import
com.sun.appserv.security.AppservPasswordLoginModule; import
com.sun.enterprise.security.auth.realm.InvalidOperationException; import
com.sun.enterprise.security.auth.realm.NoSuchUserException; import
java.util.Enumeration; import javax.security.auth.login.LoginException;
public class SimpleLoginModule extends AppservPasswordLoginModule { @Override
protected void authenticateUser() throws LoginException { Enumeration
userGroupsEnum = null; String[] userGroupsArray = null; SimpleRealm
simpleRealm; if (!(_currentRealm instanceof SimpleRealm)) { throw new
LoginException(); } else { simpleRealm = (SimpleRealm) _currentRealm; } if
(simpleRealm.loginUser(_username, _passwd)) { try { userGroupsEnum =
simpleRealm.getGroupNames(_username); } catch (InvalidOperationException e) {
throw new LoginException(e.getMessage()); } catch (NoSuchUserException e) {
throw new LoginException(e.getMessage()); } userGroupsArray = new String[2];
int i = 0; while (userGroupsEnum.hasMoreElements()) { userGroupsArray[i++] =
((String) userGroupsEnum.nextElement()); } } else { throw new
LoginException(); } commitUserAuthentication(userGroupsArray); } } Expecting
your contributions guys Regards, Tony

--
[Message sent by forum member 'jaaxton']
View Post: http://forums.java.net/node/893435