X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.jcr%2Fsrc%2Forg%2Fargeo%2Fjcr%2FJcrUtils.java;h=94b1dfdfae31488762ab6ede2cfcb3580eeb3458;hb=905c6bcd909d84c6e980994d9eeed22a0bf237af;hp=416d035f8b5925555e421c46ede06e21e85dd231;hpb=00d7430765eba4f0c13f8300515a679a808bc7b1;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.jcr/src/org/argeo/jcr/JcrUtils.java b/org.argeo.jcr/src/org/argeo/jcr/JcrUtils.java index 416d035f8..94b1dfdfa 100644 --- a/org.argeo.jcr/src/org/argeo/jcr/JcrUtils.java +++ b/org.argeo.jcr/src/org/argeo/jcr/JcrUtils.java @@ -38,6 +38,7 @@ import java.util.Map; import java.util.TreeMap; import javax.jcr.Binary; +import javax.jcr.Credentials; import javax.jcr.NamespaceRegistry; import javax.jcr.NoSuchWorkspaceException; import javax.jcr.Node; @@ -1067,16 +1068,25 @@ public class JcrUtils { */ public static Session loginOrCreateWorkspace(Repository repository, String workspaceName) throws RepositoryException { + return loginOrCreateWorkspace(repository, workspaceName, null); + } + + /** + * Login to a workspace with implicit credentials, creates the workspace with + * these credentials if it does not already exist. + */ + public static Session loginOrCreateWorkspace(Repository repository, String workspaceName, Credentials credentials) + throws RepositoryException { Session workspaceSession = null; Session defaultSession = null; try { try { - workspaceSession = repository.login(workspaceName); + workspaceSession = repository.login(credentials, workspaceName); } catch (NoSuchWorkspaceException e) { // try to create workspace - defaultSession = repository.login(); + defaultSession = repository.login(credentials); defaultSession.getWorkspace().createWorkspace(workspaceName); - workspaceSession = repository.login(workspaceName); + workspaceSession = repository.login(credentials, workspaceName); } return workspaceSession; } finally {