Skip to content

Commit

Permalink
Merge branch '2.10.x' of https://github.com/geonetwork/core-geonetwork
Browse files Browse the repository at this point in the history
…into 2.10.x
  • Loading branch information
josegar74 committed Jun 29, 2015
2 parents f0547db + 9422889 commit 6c0a18c
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 27 deletions.
75 changes: 75 additions & 0 deletions jeeves/src/main/java/jeeves/guiservices/session/JeevesUser.java
Expand Up @@ -204,6 +204,81 @@ public JeevesUser setId(String id) {
return this;
}

@Override
public int hashCode() {
int hash = 3;
hash = 97 * hash + (this.username != null ? this.username.hashCode() : 0);
hash = 97 * hash + (this.email != null ? this.email.hashCode() : 0);
hash = 97 * hash + (this.name != null ? this.name.hashCode() : 0);
hash = 97 * hash + (this.surname != null ? this.surname.hashCode() : 0);
hash = 97 * hash + (this.profile != null ? this.profile.hashCode() : 0);
hash = 97 * hash + (this.address != null ? this.address.hashCode() : 0);
hash = 97 * hash + (this.city != null ? this.city.hashCode() : 0);
hash = 97 * hash + (this.state != null ? this.state.hashCode() : 0);
hash = 97 * hash + (this.zip != null ? this.zip.hashCode() : 0);
hash = 97 * hash + (this.country != null ? this.country.hashCode() : 0);
hash = 97 * hash + (this.organisation != null ? this.organisation.hashCode() : 0);
hash = 97 * hash + (this.password != null ? this.password.hashCode() : 0);
hash = 97 * hash + (this.kind != null ? this.kind.hashCode() : 0);
hash = 97 * hash + (this.id != null ? this.id.hashCode() : 0);
return hash;
}

@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final JeevesUser other = (JeevesUser) obj;
if ((this.username == null) ? (other.username != null) : !this.username.equals(other.username)) {
return false;
}
if ((this.email == null) ? (other.email != null) : !this.email.equals(other.email)) {
return false;
}
if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) {
return false;
}
if ((this.surname == null) ? (other.surname != null) : !this.surname.equals(other.surname)) {
return false;
}
if ((this.profile == null) ? (other.profile != null) : !this.profile.equals(other.profile)) {
return false;
}
if ((this.address == null) ? (other.address != null) : !this.address.equals(other.address)) {
return false;
}
if ((this.city == null) ? (other.city != null) : !this.city.equals(other.city)) {
return false;
}
if ((this.state == null) ? (other.state != null) : !this.state.equals(other.state)) {
return false;
}
if ((this.zip == null) ? (other.zip != null) : !this.zip.equals(other.zip)) {
return false;
}
if ((this.country == null) ? (other.country != null) : !this.country.equals(other.country)) {
return false;
}
if ((this.organisation == null) ? (other.organisation != null) : !this.organisation.equals(other.organisation)) {
return false;
}
if ((this.password == null) ? (other.password != null) : !this.password.equals(other.password)) {
return false;
}
if ((this.kind == null) ? (other.kind != null) : !this.kind.equals(other.kind)) {
return false;
}
if ((this.id == null) ? (other.id != null) : !this.id.equals(other.id)) {
return false;
}
return true;
}


@Override
public String toString() {
return getClass().getSimpleName() + "[" +
Expand Down
67 changes: 40 additions & 27 deletions web/src/main/java/org/fao/geonet/services/user/PwUpdate.java
Expand Up @@ -20,14 +20,12 @@
//=== Contact: Jeroen Ticheler - FAO - Viale delle Terme di Caracalla 2,
//=== Rome - Italy. email: geonetwork@osgeo.org
//==============================================================================

package org.fao.geonet.services.user;

import javax.servlet.ServletContext;

import jeeves.constants.Jeeves;
import jeeves.exceptions.UserNotFoundEx;
import jeeves.interfaces.Service;
import jeeves.resources.dbms.Dbms;
import jeeves.server.ServiceConfig;
import jeeves.server.UserSession;
Expand All @@ -43,36 +41,51 @@
* Update the password of logged user.
*/
public class PwUpdate extends NotInReadOnlyModeService {
//--------------------------------------------------------------------------
//---
//--- Init
//---
//--------------------------------------------------------------------------

public void init(String appPath, ServiceConfig params) throws Exception {}
private static final int MIN_PW_LEN = 6;

//--------------------------------------------------------------------------
//---
//--- Init
//---
//--------------------------------------------------------------------------
public void init(String appPath, ServiceConfig params) throws Exception {
}

//--------------------------------------------------------------------------
//---
//--- Service
//---
//--------------------------------------------------------------------------
public Element serviceSpecificExec(Element params, ServiceContext context) throws Exception {
String password = Util.getParam(params, Params.PASSWORD);
ServletContext servletContext = context.getServlet().getServletContext();
String newPassword = Util.getParam(params, Params.NEW_PASSWORD);

validateNewPassword(newPassword);

Dbms dbms = (Dbms) context.getResourceManager().open(Geonet.Res.MAIN_DB);

UserSession session = context.getUserSession();
String currentUserId = session.getUserId();

if (currentUserId == null) {
throw new UserNotFoundEx(null);
}

//--------------------------------------------------------------------------
//---
//--- Service
//---
//--------------------------------------------------------------------------
int iUserId = Integer.parseInt(currentUserId);
PasswordUtil.updatePasswordWithNew(true, password, newPassword, iUserId, servletContext, dbms);

public Element serviceSpecificExec(Element params, ServiceContext context) throws Exception
{
String password = Util.getParam(params, Params.PASSWORD);
ServletContext servletContext = context.getServlet().getServletContext();
String newPassword = Util.getParam(params, Params.NEW_PASSWORD);
return new Element(Jeeves.Elem.RESPONSE);
}

Dbms dbms = (Dbms) context.getResourceManager().open (Geonet.Res.MAIN_DB);
private void validateNewPassword(String newpw) {

UserSession session = context.getUserSession();
String currentUserId = session.getUserId();
if (newpw.trim().length() < MIN_PW_LEN) {
throw new IllegalArgumentException("New password is too short.");
}

if (currentUserId == null) throw new UserNotFoundEx(null);
}

int iUserId = Integer.parseInt(currentUserId);
PasswordUtil.updatePasswordWithNew(true, password, newPassword, iUserId, servletContext, dbms);
}

return new Element(Jeeves.Elem.RESPONSE);
}
}

0 comments on commit 6c0a18c

Please sign in to comment.