chiwi
May 21st, 2011, 01:11 PM
Hey there, I'm using SpringData MongoDB - latest snapshot, and Spring Security 3.0.5.
I have the following class I want to persist:
@Document
public class MyUser implements UserDetails {
@Id
private String username;
private String password;
private boolean accountEnabled = true;
private List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
...getters/setters...
}
I have also created a new UserDetailsManager since there is none that uses mongoDb as a db backend.
public class UserDetailsManagerMongoImpl implements UserDetailsManager {
@Autowired
private MongoTemplate template;
@Override
public void createUser(UserDetails user) {
MyUser myUser = (MyUser) user;
template.insert("users", myUser);
}
[...]
}
But even though I set the roles correctly to the user (i can see them when I debug the app), whenever I store the user, it doesn't persist the roles, it writes this:
{ "_id" : "someId", "_class" : "com.x.y.z.MyUser", "authorities" : [ { } ], "accountEnabled" : true, "password" : "mysecret" }
Note the empty authorities.
I started to debug the MappingMongoConverter, and found out that is converting the List<GrantedAuthority>, when it tries to convert each roles (GrantedAuthorityImpl), it skips the following code in MappingMongoConverter:
// Write the properties
entity.doWithProperties(new PropertyHandler<MongoPersistentProperty>() {
public void doWithPersistentProperty(MongoPersistentProperty prop) {
Object propertyObj;
try {
propertyObj = getProperty(obj, prop, prop.getType(), useFieldAccessOnly);
} catch (IllegalAccessException e) {
throw new MappingException(e.getMessage(), e);
} catch (InvocationTargetException e) {
throw new MappingException(e.getMessage(), e);
}
if (null != propertyObj) {
if (!isSimpleType(propertyObj.getClass())) {
writePropertyInternal(prop, propertyObj, dbo);
} else {
writeSimpleInternal(prop.getKey(), propertyObj, dbo);
}
}
}
});
this is in method protected void writeInternal(final Object obj, final DBObject dbo, MongoPersistentEntity<?> entity). I don't know if it has anything to do, but seemed strange.
Do I have to add a converter for GrantedAuthorityImpl?
Thank you very much
Fede.
I have the following class I want to persist:
@Document
public class MyUser implements UserDetails {
@Id
private String username;
private String password;
private boolean accountEnabled = true;
private List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
...getters/setters...
}
I have also created a new UserDetailsManager since there is none that uses mongoDb as a db backend.
public class UserDetailsManagerMongoImpl implements UserDetailsManager {
@Autowired
private MongoTemplate template;
@Override
public void createUser(UserDetails user) {
MyUser myUser = (MyUser) user;
template.insert("users", myUser);
}
[...]
}
But even though I set the roles correctly to the user (i can see them when I debug the app), whenever I store the user, it doesn't persist the roles, it writes this:
{ "_id" : "someId", "_class" : "com.x.y.z.MyUser", "authorities" : [ { } ], "accountEnabled" : true, "password" : "mysecret" }
Note the empty authorities.
I started to debug the MappingMongoConverter, and found out that is converting the List<GrantedAuthority>, when it tries to convert each roles (GrantedAuthorityImpl), it skips the following code in MappingMongoConverter:
// Write the properties
entity.doWithProperties(new PropertyHandler<MongoPersistentProperty>() {
public void doWithPersistentProperty(MongoPersistentProperty prop) {
Object propertyObj;
try {
propertyObj = getProperty(obj, prop, prop.getType(), useFieldAccessOnly);
} catch (IllegalAccessException e) {
throw new MappingException(e.getMessage(), e);
} catch (InvocationTargetException e) {
throw new MappingException(e.getMessage(), e);
}
if (null != propertyObj) {
if (!isSimpleType(propertyObj.getClass())) {
writePropertyInternal(prop, propertyObj, dbo);
} else {
writeSimpleInternal(prop.getKey(), propertyObj, dbo);
}
}
}
});
this is in method protected void writeInternal(final Object obj, final DBObject dbo, MongoPersistentEntity<?> entity). I don't know if it has anything to do, but seemed strange.
Do I have to add a converter for GrantedAuthorityImpl?
Thank you very much
Fede.