me again... :(
Andreas Hartmann wrote:
Jörn Nettingsmeier wrote:
Andreas Hartmann wrote:
This sounds reasonable, and at the first glance your patch looks
very good. Maybe it would make sense to make
AbstractChangePassword.getUser()
abstract. ChangePassword.getUser() would just return the currently
logged-in user, and AdminChangePassword() would return the user
determined by the userId parameter. WDYT?
i tried it, but then it seemed better to have a variable
private User user
that defaults to null in AbstractChangePassword, and to set it to the
current user in the constuctor of ChangePassword. otherwise the code
to determine the current user would be called many times...
That can be solved by lazy loading. But communication between classes
should happen over methods, not fields - even in class hierarchies.
i don't understand... does my code (see attachment) violate this?
anyways, right now i'm totally mystified by something else. somehow the
"user" attribute is reset when the usecase moves on, but i don't know
when or by what.
i log in and call my new changePassword usecase. whenever i submit, i
get an npe:
java.lang.NullPointerException
at
org.apache.lenya.cms.ac.usecases.ChangePassword.doCheckExecutionConditions(ChangePassword.java:50)
i've added some debug statements, to see what happens to "user":
1, usecase is called:
**** user : lenya
Set this.user to "lenya".
getUser() called. Returning "lenya".
**** getUser(): lenya
all is fine and dandy so far.
2. form is completed with old and new password, and when i submit:
getUser() called. Returning "null".
****>> getUser(): null
getUser() called. Returning "null".
it seems that this variable is not persistent.
when i compare my code with the stuff in trunk, i see that it overrides
the setParameter method, but i don't understand how that could make a
difference.
please help!
jörn
--
"Open source takes the bullshit out of software."
- Charles Ferguson on TechnologyReview.com
--
Jörn Nettingsmeier, EDV-Administrator
Institut für Politikwissenschaft
Universität Duisburg-Essen, Standort Duisburg
Mail: [EMAIL PROTECTED], Telefon: 0203/379-2736
/*
* Copyright 1999-2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.lenya.cms.ac.usecases;
import org.apache.lenya.ac.User;
/**
* Usecase to change a user's password.
*/
public abstract class AbstractChangePassword extends AccessControlUsecase {
private User user;
protected static final String NEW_PASSWORD = "password";
protected static final String CONFIRM_PASSWORD = "confirmPassword";
/**
* @see org.apache.lenya.cms.usecase.AbstractUsecase#doCheckExecutionConditions()
*/
protected void doCheckExecutionConditions() throws Exception {
super.doCheckExecutionConditions();
checkNewPassword(this);
}
/**
* @see org.apache.lenya.cms.usecase.AbstractUsecase#doExecute()
*/
protected void doExecute() throws Exception {
super.doExecute();
user.setPassword(getParameterAsString(NEW_PASSWORD));
}
protected User getUser() {
System.out.println("getUser() called. Returning \"" + this.user + "\".");
return this.user;
}
protected void setUser(User newUser) {
this.user = newUser;
System.out.println("Set this.user to \"" + this.user +"\".");
}
/**
* Checks a password and a confirmed password.
* @param usecase The usecase.
*/
protected static void checkNewPassword(AccessControlUsecase usecase) {
String password = usecase.getParameterAsString(NEW_PASSWORD);
String confirmPassword = usecase.getParameterAsString(CONFIRM_PASSWORD);
if (!password.equals(confirmPassword)) {
usecase.addErrorMessage("Password and confirmed password are not equal.");
}
if (password.length() < 6) {
usecase.addErrorMessage("The password must be at least six characters long.");
}
if (!password.matches(".*\\d.*")) {
usecase.addErrorMessage("The password must contain at least one number.");
}
}
}/*
* Copyright 1999-2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.lenya.cms.ac.usecases;
import org.apache.lenya.ac.User;
/**
* Usecase to change a user's password. The old password is checked.
*/
public class ChangePassword extends AbstractChangePassword {
protected static final String OLD_PASSWORD = "oldPassword";
/* public ChangePassword() {
super();
org.apache.lenya.cms.repository.Session session = getSession();
System.out.println("******* session: " + session);
Identity identity = session.getIdentity();
System.out.println("******* identity: " + identity);
org.apache.lenya.ac.User user = identity.getUser();
setUser(user);
}
*/
protected void initParameters() {
User user = getSession().getIdentity().getUser();
System.out.println("**** user : " + user);
setUser(user);
System.out.println("**** getUser(): "+ getUser());
}
protected void doCheckExecutionConditions() throws Exception {
super.doCheckExecutionConditions();
String oldPassword = getParameterAsString(OLD_PASSWORD);
System.out.println("****>> getUser(): "+ getUser());
boolean authenticated = getUser().authenticate(oldPassword);
if (!authenticated) {
addErrorMessage("The old password is not correct.");
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]