+/*
+ * Copyright (C) 2007-2012 Mathieu Baudier
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.argeo.jackrabbit.remote;
import java.io.Serializable;
import org.argeo.jcr.JcrUtils;
/**
- * To be injected, typically of scope="session". Implements an open session in
- * view patter: a new JCR session is created for each request
+ * Implements an open session in view patter: a new JCR session is created for
+ * each request
*/
public class SimpleSessionProvider implements SessionProvider, Serializable {
private static final long serialVersionUID = 2270957712453841368L;
if (openSessionInView) {
JackrabbitSession session = (JackrabbitSession) rep
.login(workspace);
- writeRemoteRoles(session);
+ if (session.getWorkspace().getName().equals(securityWorkspace))
+ writeRemoteRoles(session);
return session;
} else {
// since sessions is transient it can't be restored from the session
try {
JackrabbitSession session = (JackrabbitSession) rep.login(
null, workspace);
- writeRemoteRoles(session);
+ if (session.getWorkspace().getName()
+ .equals(securityWorkspace))
+ writeRemoteRoles(session);
if (log.isTraceEnabled())
log.trace("User " + session.getUserID()
+ " logged into " + request.getServletPath());
protected void writeRemoteRoles(JackrabbitSession session)
throws RepositoryException {
- if (!session.getWorkspace().getName().equals(securityWorkspace))
- return;
-
// retrieve roles
String userId = session.getUserID();
UserManager userManager = session.getUserManager();
public void init() {
}
- public void dispose() {
+ public void destroy() {
if (sessions != null)
for (String workspace : sessions.keySet()) {
Session session = sessions.get(workspace);
}
}
}
+
+ /**
+ * If set to true a new session will be created each time (the default),
+ * otherwise a single session is cached by workspace and the object should
+ * be of scope session (not supported)
+ */
+ public void setOpenSessionInView(Boolean openSessionInView) {
+ this.openSessionInView = openSessionInView;
+ }
+
+ public void setSecurityWorkspace(String securityWorkspace) {
+ this.securityWorkspace = securityWorkspace;
+ }
+
}