Session admin = null; try { admin = this.createAdministrativeSession(workspace); return admin.impersonate(new SimpleCredentials(serviceUserName, new char[0])); } finally {
/** * Login as an administrative user. This method is deprecated and its use * can be completely disabled by setting {@code disableLoginAdministrative} * to {@code true}. * <p> * This implementation cannot be overwritten but, unless disabled, forwards * to the {@link #createAdministrativeSession(String)} method. * * @param workspace The workspace to access or {@code null} to access the * {@link #getDefaultWorkspace() default workspace} * @return An administrative session * @throws RepositoryException If the login fails or has been disabled */ @Override public final Session loginAdministrative(final String workspace) throws RepositoryException { final boolean whitelisted = getSlingRepositoryManager().allowLoginAdministrativeForBundle(usingBundle); if(!whitelisted) { final String symbolicName = usingBundle.getSymbolicName(); logger.error("Bundle {} is NOT whitelisted to use SlingRepository.loginAdministrative", symbolicName); throw new LoginException("Bundle " + symbolicName +" is NOT whitelisted"); } else if (this.getSlingRepositoryManager().isDisableLoginAdministrative()) { logger.error("SlingRepository.loginAdministrative is disabled. Please use SlingRepository.loginService."); throw new LoginException("SlingRepository.loginAdministrative is disabled."); } logger.debug("SlingRepository.loginAdministrative is deprecated. Please use SlingRepository.loginService."); return createAdministrativeSession(workspace); }