Commit b06c04dd authored by afreyssin's avatar afreyssin
Browse files

Test user name in create operation to avoid NPE (JORAM-226).

parent e3db8bad
......@@ -1012,6 +1012,9 @@ public class AdminWrapper implements AdminItf {
int serverId,
String identityClassName,
Properties prop) throws ConnectException, AdminException {
if ((name == null) || name.equals(""))
throw new AdminException("User name can not be null or empty");
Identity identity = createIdentity(name, password, identityClassName);
AdminReply reply = doRequest(new CreateUserRequest(identity, serverId, prop));
User user = new User(name, ((CreateUserReply) reply).getProxId());
......@@ -1035,7 +1038,8 @@ public class AdminWrapper implements AdminItf {
Identity identity = null;
try {
identity = (Identity) Class.forName(identityClassName).newInstance();
if (passwd != null) identity.setIdentity(user, passwd);
if (passwd != null)
identity.setIdentity(user, passwd);
else
identity.setUserName(user);
} catch (Exception e) {
......
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2004 - 2012 ScalAgent Distributed Technologies
* Copyright (C) 2004 - 2015 ScalAgent Distributed Technologies
* Copyright (C) 2004 Bull SA
*
* This library is free software; you can redistribute it and/or
......@@ -291,6 +291,9 @@ public class User extends AdministeredObject implements UserMBean {
int serverId,
String identityClassName,
Properties prop) throws ConnectException, AdminException {
if ((name == null) || name.equals(""))
throw new AdminException("User name can not be null or empty");
Identity identity = createIdentity(name, password, identityClassName);
User user = new User(name);
......
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2001 - 2012 ScalAgent Distributed Technologies
* Copyright (C) 2001 - 2015 ScalAgent Distributed Technologies
* Copyright (C) 1996 - 2000 Dyade
*
* This library is free software; you can redistribute it and/or
......@@ -839,6 +839,10 @@ public final class AdminTopic extends Topic implements AdminTopicMBean {
Identity identity = request.getIdentity();
String name = identity.getUserName();
if ((name == null) || name.equals(""))
// Should never happened as there is test client side
throw new RequestException("User cannot have a null or empty name.");
AgentId proxId = (AgentId) proxiesTable.get(name);
String info;
......@@ -1855,6 +1859,9 @@ public final class AdminTopic extends Topic implements AdminTopicMBean {
* {@inheritDoc}
*/
public void createUser(String user, String passwd, int serverId, String identityClassName) throws Exception {
if ((user == null) || user.equals(""))
throw new RequestException("User name can not be null or empty");
Identity identity = null;
try {
identity = (Identity) Class.forName(identityClassName).newInstance();
......
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2011 ScalAgent Distributed Technologies
* Copyright (C) 2011 - 2015 ScalAgent Distributed Technologies
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
......@@ -85,7 +85,11 @@ public class JoramHelper {
public final static void createUser(String userName, String userPass) {
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.DEBUG, "JoramHelper.createUser(" + userName + ')');
try {
if ((userName == null) || userName.equals(""))
throw new RequestException("User name can not be null or empty");
SimpleIdentity identity = new SimpleIdentity();
identity.setIdentity(userName, userPass);
AdminTopic.CreateUserAndSave(new CreateUserRequest(identity, AgentServer.getServerId(), null), null, "-1");
......
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2012 ScalAgent Distributed Technologies
* Copyright (C) 2012 - 2015 ScalAgent Distributed Technologies
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
......@@ -25,6 +25,7 @@ import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import org.objectweb.joram.mom.dest.AdminTopic;
import org.objectweb.joram.mom.dest.AdminTopic.DestinationDesc;
import org.objectweb.joram.mom.notifications.ClientMessages;
......@@ -142,6 +143,9 @@ public class SynchronousAgent extends Agent {
public synchronized boolean createUser(short serverId, String userName,
String password, String identityClass, Properties props)
throws Exception {
if ((userName == null) || userName.equals(""))
throw new Exception("User name can not be null or empty");
//Set identity
Identity identity = (Identity) (identityClass==null?
SimpleIdentity.class.newInstance():
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment