Hey there, I'm using SpringData MongoDB - latest snapshot, and Spring Security 3.0.5.
I have the following class I want to persist:
I have also created a new UserDetailsManager since there is none that uses mongoDb as a db backend.Code:@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... }
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:Code:public class UserDetailsManagerMongoImpl implements UserDetailsManager { @Autowired private MongoTemplate template; @Override public void createUser(UserDetails user) { MyUser myUser = (MyUser) user; template.insert("users", myUser); } [...] }
Note the empty authorities.Code:{ "_id" : "someId", "_class" : "com.x.y.z.MyUser", "authorities" : [ { } ], "accountEnabled" : true, "password" : "mysecret" }
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:
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.Code:// 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); } } } });
Do I have to add a converter for GrantedAuthorityImpl?
Thank you very much
Fede.


Reply With Quote
.