You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@felix.apache.org by "Alec de Zegher (JIRA)" <ji...@apache.org> on 2014/01/22 18:05:21 UTC
[jira] [Updated] (FELIX-4399) UserAdmin MongoDB plugin cannot
return role when properties or members is null
[ https://issues.apache.org/jira/browse/FELIX-4399?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Alec de Zegher updated FELIX-4399:
----------------------------------
Description:
When fetching a role with no properties or roles from mongodb, a null object is returned by the DB. This causes a null pointer exception and as a result no roles are returned.
This can be solved by modifying following three methods in MongoSerializerHelper.java to:
/**
* Deserializes the given {@link DBObject} into the given {@link Dictionary}.
*
* @param dictionary the dictionary to fill;
* @param object the {@link DBObject} to deserialize.
*/
private void deserializeDictionary(Dictionary dictionary, DBObject object) {
if(object != null) {
for (String key : object.keySet()) {
dictionary.put(KeyCodec.decode(key), object.get(key));
}
}
}
/**
* Serializes a given array of {@link Role}s to an list for storing in a {@link DBObject}.
*
* @param members the {@link Role}s to serialize, cannot be <code>null</code>.
* @return the "serialized" array, never <code>null</code>.
*/
private List<String> getRoleNames(Role[] members) {
List<String> result = new ArrayList<String>();
if (members != null) {
for (Role member : members) {
result.add(member.getName());
}
}
return result;
}
/**
* Returns all roles mentioned in the given list.
*
* @param list the list with role names to convert.
* @return a list with {@link Role}s, never <code>null</code>.
*/
private List<Role> getRoles(BasicDBList list) {
List<Role> result = new ArrayList<Role>();
if(list !=null) {
for (int i = 0, size = list.size(); i < size; i++) {
final String memberName = (String) list.get(i);
result.add(findExistingMember(memberName));
}
}
return result;
}
was:
When fetching a role with no properties or roles from mongodb, a null object is returned by the DB. This causes a null pointer exception.
This can be solved by changing two methods in MongoSerializerHelper.java to:
private void deserializeDictionary(Dictionary dictionary, DBObject object) {
if(object != null) {
for (String key : object.keySet()) {
dictionary.put(KeyCodec.decode(key), object.get(key));
}
}
}
private List<Role> getRoles(BasicDBList list) {
List<Role> result = new ArrayList<Role>();
if(list !=null) {
for (int i = 0, size = list.size(); i < size; i++) {
final String memberName = (String) list.get(i);
result.add(findExistingMember(memberName));
}
}
return result;
}
> UserAdmin MongoDB plugin cannot return role when properties or members is null
> ------------------------------------------------------------------------------
>
> Key: FELIX-4399
> URL: https://issues.apache.org/jira/browse/FELIX-4399
> Project: Felix
> Issue Type: Bug
> Components: User Admin
> Environment: MongoDB 32-bit, v2.4.9
> Java 1.7
> UserAdmin 1.0.3
> Reporter: Alec de Zegher
> Original Estimate: 5m
> Remaining Estimate: 5m
>
> When fetching a role with no properties or roles from mongodb, a null object is returned by the DB. This causes a null pointer exception and as a result no roles are returned.
> This can be solved by modifying following three methods in MongoSerializerHelper.java to:
> /**
> * Deserializes the given {@link DBObject} into the given {@link Dictionary}.
> *
> * @param dictionary the dictionary to fill;
> * @param object the {@link DBObject} to deserialize.
> */
> private void deserializeDictionary(Dictionary dictionary, DBObject object) {
> if(object != null) {
> for (String key : object.keySet()) {
> dictionary.put(KeyCodec.decode(key), object.get(key));
> }
> }
> }
>
> /**
> * Serializes a given array of {@link Role}s to an list for storing in a {@link DBObject}.
> *
> * @param members the {@link Role}s to serialize, cannot be <code>null</code>.
> * @return the "serialized" array, never <code>null</code>.
> */
> private List<String> getRoleNames(Role[] members) {
> List<String> result = new ArrayList<String>();
> if (members != null) {
> for (Role member : members) {
> result.add(member.getName());
> }
> }
> return result;
> }
>
> /**
> * Returns all roles mentioned in the given list.
> *
> * @param list the list with role names to convert.
> * @return a list with {@link Role}s, never <code>null</code>.
> */
> private List<Role> getRoles(BasicDBList list) {
> List<Role> result = new ArrayList<Role>();
> if(list !=null) {
> for (int i = 0, size = list.size(); i < size; i++) {
> final String memberName = (String) list.get(i);
> result.add(findExistingMember(memberName));
> }
> }
> return result;
> }
--
This message was sent by Atlassian JIRA
(v6.1.5#6160)