+ // normalize password
+ if (user instanceof SimpleArgeoUser) {
+ if (user.getPassword() == null || user.getPassword().equals(""))
+ ((SimpleArgeoUser) user).setPassword(securityDao
+ .encodePassword(user.getUsername()));
+ else if (!user.getPassword().startsWith("{"))
+ ((SimpleArgeoUser) user).setPassword(securityDao
+ .encodePassword(user.getPassword()));
+ }
+ securityDao.createUser(user);
+ }
+
+ public ArgeoUser getUser(String username) {
+ return securityDao.getUser(username);
+ }
+
+ public Boolean userExists(String username) {
+ return securityDao.userExists(username);
+ }
+
+ public void updateUser(ArgeoUser user) {
+ String password = user.getPassword();
+ if (password == null)
+ password = securityDao.getUserWithPassword(user.getUsername())
+ .getPassword();
+ if (!password.startsWith("{"))
+ password = securityDao.encodePassword(user.getPassword());
+ SimpleArgeoUser simpleArgeoUser = new SimpleArgeoUser(user);
+ simpleArgeoUser.setPassword(password);
+ securityDao.updateUser(simpleArgeoUser);
+ }
+
+ public void deleteUser(String username) {
+ securityDao.deleteUser(username);
+
+ }
+
+ public void deleteRole(String role) {
+ securityDao.deleteRole(role);
+ }
+
+ public TaskExecutor createSystemAuthenticatedTaskExecutor() {
+ return new SimpleAsyncTaskExecutor() {
+ private static final long serialVersionUID = -8126773862193265020L;
+
+ @Override
+ public Thread createThread(Runnable runnable) {
+ return super
+ .createThread(wrapWithSystemAuthentication(runnable));
+ }
+
+ };
+ }
+
+ /**
+ * Wraps another runnable, adding security context <br/>
+ * TODO: secure the call to this method with Java Security
+ */
+ public Runnable wrapWithSystemAuthentication(final Runnable runnable) {
+ return new Runnable() {
+
+ public void run() {
+ SecurityContext securityContext = SecurityContextHolder
+ .getContext();
+ Authentication auth = authenticationManager
+ .authenticate(new InternalAuthentication(
+ systemAuthenticationKey));
+ securityContext.setAuthentication(auth);
+
+ runnable.run();
+ }
+ };
+ }
+
+ public Set<ArgeoUser> listUsersInRole(String role) {
+ Set<ArgeoUser> lst = securityDao.listUsersInRole(role);
+ Iterator<ArgeoUser> it = lst.iterator();
+ while (it.hasNext()) {
+ if (it.next().getUsername()
+ .equals(argeoSecurity.getSuperUsername())) {
+ it.remove();
+ break;
+ }
+ }
+ return lst;
+ }
+
+ public void updateCurrentUserNatures(Map<String, UserNature> userNatures) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public Set<ArgeoUser> listUsers() {
+ return securityDao.listUsers();
+ }
+
+ public Set<String> listEditableRoles() {
+ // TODO Auto-generated method stub
+ return securityDao.listEditableRoles();