Nope, not paraphrasing. You can see the full error message at
bottom of the email.
The only time I have heard of the active editing context is for a
save.
Nope haven't had the chnace yet to separate this out to its own
project.
Heres the full code ( it includes our RADIUS authentication methods
which I did paste before ):
// Generated by the WebObjects Assistant Mon Feb 07 14:26:32
Australia/Sydney 2005
import com.webobjects.foundation.*;
import com.webobjects.appserver.*;
import com.webobjects.eocontrol.*;
import com.webobjects.eoaccess.*;
import net.sourceforge.jradiusclient.*;
import net.sourceforge.jradiusclient.exception.*;
public class Main extends WOComponent {
protected Application app;
protected EOEditingContext ec;
protected NSMutableDictionary bindings;
protected String userName;
protected String password;
protected String errorMessage;
protected boolean forgotPassword;
protected boolean thankyou;
protected boolean emailAddress;
protected boolean gotMobile;
private String secretHandshake;
private String hostName;
private RadiusClient rc;
private String exitCode;
//----------------------------- The Constructors
---------------------------------------------
public Main( WOContext context ) throws Exception
{
super(context);
app = (Application)Application.application();
//ec = ((Session)session()).defaultEditingContext();
ec = new EOEditingContext();
System.out.println("Editing Context just been made : " + ec);
// ((Session)session()).resetCrumbs();
secretHandshake = "*********";
hostName = "radius.uow.edu.au";
RadiusClient rc = null;
NSArray mems;
forgotPassword = false;
thankyou = false;
emailAddress = false;
gotMobile = false;
}
//------------------------------- WOComponent Functions
---------------------------------------
//Called when the Persons clicks the submit button to login
public WOComponent checkLogin() throws Exception
{
errorMessage = "";
WOComponent nextPage = null;
//If both fields have some data in them
if ( userName != null && password != null )
{
userName.trim();
password.trim();
try {
rc = new RadiusClient(hostName,
1812,1813,secretHandshake,userName);
} catch(java.net.SocketException soex) {
app.setErrorMessage("Unable to create Radius Client due to
failure to create socket!");
throw soex;
} catch(java.security.NoSuchAlgorithmException
nsaex) {
app.setErrorMessage("Unable to create Radius Client due to
failure to create MD5 MessageDigest!");
throw nsaex;
} catch(InvalidParameterException ivpex) {
app.setErrorMessage("Unable to create Radius Client due to
invalid parameter! " + ivpex.getMessage() );
throw ivpex;
}
try {
boolean returned;
if (app.debugMode )
{
returned = true;
}
else
{
returned =
authenticate(rc,password,null);
}
// Radius confirmed the userName and
password are valid
if (returned)
{
nextPage =
(Menu)pageWithName("Menu");
//check if the user is in the
recipient table
checkRecipient();
}
else
{
errorMessage = "<span class=\"failure\">User name & Password
incorrect</span>";
if (isUppercase(password)) {
errorMessage += "<span class=\"failure\"><br>Check Caps lock
is not on.</span>";
}
}
} catch(InvalidParameterException ivpex){
app.setErrorMessage(ivpex.getMessage());
} catch(java.net.UnknownHostException uhex){
app.setErrorMessage(uhex.getMessage());
} catch(java.io.IOException ioex){
app.setErrorMessage(ioex.getMessage());
} catch(RadiusException rex){
app.setErrorMessage(rex.getMessage());
}
}
else {
errorMessage = "<span class=\"failure\">Please enter
both user name & password.</span>";
}
password = "";
return nextPage;
}
//Authenticate against the RADIUS server
public static boolean authenticate(RadiusClient rc, String
userPass, byte[] callingStationId) throws
InvalidParameterException, java.net.UnknownHostException,
java.io.IOException, RadiusException
{
int returnCode;
returnCode = rc.authenticate(userPass);
boolean returned = false;
switch (returnCode){
case RadiusClient.ACCESS_ACCEPT:
System.out.println("Authenticated");
returned = true;
break;
case RadiusClient.ACCESS_REJECT:
System.out.println("Not Authenticated");
returned = false;
break;
case RadiusClient.ACCESS_CHALLENGE:
System.out.println(rc.getChallengeMessage());
break;
default:
System.out.println("How the hell did we get here?");
returned = false;
break;
}
return returned;
}
// Returns true is each character entered is in uppercase
private boolean isUppercase(String password)
{
boolean flag = true;
char[] temp = password.toCharArray();
char aChar;
for(int i = 0; i<password.length();i++)
{
aChar = temp[i];
if(Character.isLowerCase(aChar))
{
flag = false;
break;
}
}
return flag;
}
public void checkRecipient() throws Exception
{
System.out.println("Editing Context at start of checkRecipient :
" + ec);
try {
//search the recipient table for the username
Recipient r = null;
NSMutableDictionary dic = new NSMutableDictionary();
dic.setObjectForKey(userName,"logon");
NSArray temp =
EOUtilities.objectsWithFetchSpecificationAndBindings
(ec,"Recipient","RecipSearch",dic);
if( temp.count() > 0 ) {
r = (Recipient)temp.lastObject();
System.out.println("Old : " + r.surname() + r.logonIdentifier()
+ r.editingContext());
}
System.out.println("Editing after search for old : " +
ec);
//insert new row in database if recipient does not exist
if (r==null) {
System.out.println("Editin Context at start of
create : " + ec);
Company theCompany = (Company)
com.webobjects.eoaccess.EOUtilities.objectMatchingKeyAndValue
(ec,"Company","logonIdentifier","UOW");
System.out.println("Company : " +
theCompany.editingContext());
if( theCompany != null ) {
r = ( Recipient)
com.webobjects.eoaccess.EOUtilities.createAndInsertInstance
(ec,"Recipient");
System.out.println("New Recipient : " +
r.editingContext());
r.setLogonIdentifier(userName);
r.addObjectToBothSidesOfRelationshipWithKey
(theCompany,"company");
//Get their details from LDAP
//Should only be one entry returned for
1 username
//Use a new Editing Context as we us e a different Adaptor
type i.e. JNDI not JDBC, not sure if this is required but added in
case it was causing the bug
PersonLDAP person = (PersonLDAP)
EOUtilities.objectMatchingKeyAndValue(new EOEditingContext
(),"PersonLDAP","uid",userName);
r.setFirstName(person.givenName());
r.setSurname(person.sn());
r.setEmailAddress(userName +
"@uow.edu.au");
r.setDateRegistered(new NSTimestamp());
//set the session user to the new
instance of recipient
System.out.println("new : " + r.surname() + r.logonIdentifier
() + r.editingContext());
save();
}
}
System.out.println("editing Context : " + ec);
((Session)session()).setCurrentUser((Recipient)
EOUtilities.localInstanceOfObject(((Session)session
()).defaultEditingContext(),r));
}
catch (java.lang.IllegalArgumentException ex) {
}
catch (Exception e)
{
throw e;
}
}
private void save() throws Exception
{
try {
// ec.lock();
ec.saveChanges();
// ec.unlock();
} catch (Exception exception) {
app.setErrorMessage("Error when trying to add a new recipient.
save() menu.java\n");
throw exception;
}
}
}
Owen McKerrow
WebMaster, emlab
Ph : +61 02 4221 5517
http://emlab.uow.edu.au
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - -
'The test of a first-rate intelligence is the ability to hold two
opposed ideas in the mind at the same time and still be able to
function.'
-F.Scott Fitzgerald,
On 02/08/2006, at 1:09 PM, Ken Anderson wrote:
Owen,
Are you paraphrasing the error message? I have to admit, I've
never heard of a database context's "active" editing context. Is
there other code besides this? Have you isolated this code out in
a separate project?
Ken
On Aug 1, 2006, at 10:42 PM, Owen McKerrow wrote:
Hi All,
...