+ LoginContext loginContext = loginAsDataAdmin();
+ return Subject.doAs(loginContext.getSubject(), new PrivilegedAction<Session>() {
+
+ @Override
+ public Session run() {
+ try {
+ return repository.login(workspaceName);
+ } catch (RepositoryException e) {
+ throw new IllegalStateException("Cannot open admin session", e);
+ } finally {
+ try {
+ loginContext.logout();
+ } catch (LoginException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+ }
+
+ });
+ }
+
+ static LoginContext loginAsDataAdmin() {