Hi guys,

I'm just trying to port parts of our codebase that runs on Magnolia 4.4.x to 
Magnolia 5.3 and I encountered a difficult problem someone might have a 
solution for.

For debugging purposes I'm using the Jackrabbit console to connect to Magnolia 
via RMI. I'm using the following filter code to generate the RMI endpoint (it 
worked well with 4.4.x):

[code]
import info.magnolia.cms.filters.AbstractMgnlFilter;
import info.magnolia.context.MgnlContext;
import org.apache.jackrabbit.rmi.remote.RemoteRepository;
import org.apache.jackrabbit.rmi.server.RemoteAdapterFactory;
import org.apache.jackrabbit.rmi.server.ServerAdapterFactory;
import org.apache.jackrabbit.servlet.ServletRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.jcr.LoginException;
import javax.jcr.Repository;
import javax.jcr.RepositoryException;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.rmi.RemoteException;
import java.rmi.server.RemoteObject;

/**
 * @author Christian Hamm
 * @date 05.12.12
 */
public class RemoteBindingFilter extends AbstractMgnlFilter {
    private static final Logger log = 
LoggerFactory.getLogger(RemoteBindingFilter.class);

    /**
     * Remote repository.
     */
    private RemoteRepository remote;
    private ServletContext servletContext;
    private FilterConfig filterConfig;

    public void init(FilterConfig filterConfig) throws ServletException {
        this.filterConfig = filterConfig;
        this.servletContext = filterConfig.getServletContext();
    }

    /**
     * Returns the configured remote repository reference. The remote
     * repository is instantiated and memorized during the first call to
     * this method.
     *
     * @return remote repository
     * @throws javax.servlet.ServletException if the repository could not be 
instantiated
     */
    protected RemoteRepository getRemoteRepository() throws ServletException {
        try {
            servletContext.setAttribute(Repository.class.getName(),
                    
MgnlContext.getJCRSession("config").getWorkspace().getSession().getRepository());

            if (MgnlContext.hasInstance())
                
servletContext.setAttribute(MgnlContext.getInstance().getClass().getName(), 
MgnlContext.getInstance());

            RemoteAdapterFactory factory = new ServerAdapterFactory();

            remote = factory.getRemoteRepository(new 
ServletRepository(filterConfig));
        } catch (RemoteException e) {
            throw new ServletException(
                    "Failed to create the remote repository reference", e);
        } catch (LoginException e) {
            log.error("Caught a LoginException: {}", e);
        } catch (RepositoryException e) {
            log.error("Caught a RepositoryException: {}", e);
        }

        log.info("Returing new repository reference {}", remote);
        return remote;
    }

    @Override
    public void doFilter(HttpServletRequest request, HttpServletResponse 
response, FilterChain chain) throws IOException, ServletException {
        log.debug("Resolving RMI endpoint");

        response.setContentType("application/octet-stream");
        ObjectOutputStream output = new 
ObjectOutputStream(response.getOutputStream());
        output.writeObject(RemoteObject.toStub(getRemoteRepository()));

        log.debug("servletContext: {}", servletContext);
        log.debug("filterConfig: {}", filterConfig);

        output.flush();
    }
}
[/code]

Connecting to the endpoint is fine but when trying to log in I only get a 
FailedLoginException:

javax.security.auth.login.FailedLoginException: Cannot login, magnolia context 
is not set

I located the code in info.magnolia.jaas.sp.jcr.JackrabbitAuthenticationModule:

[code]
...
        Context context = MgnlContext.hasInstance() ? MgnlContext.getInstance() 
: null;
        if (context == null) {
            throw new FailedLoginException("Cannot login, magnolia context is 
not set");
        }
...
[/code]

So stepping through with the debugger I have access to the MgnlContext in my 
getRemoteRepository() method but the JackrabbitAuthenticationModule it's 
[i]null[/i].

My question now is: how can I work around this and get the MgnlContext into the 
JackrabbitAuthenticationModule or provide the module with the context (or just 
construct something to supply it with the correct parameters).

Bye,

Christian

-- 
Context is everything: 
http://forum.magnolia-cms.com/forum/thread.html?threadId=e1080c2e-a4ed-4a00-a2bb-042aebbc8a19


----------------------------------------------------------------
For list details, see http://www.magnolia-cms.com/community/mailing-lists.html
Alternatively, use our forums: http://forum.magnolia-cms.com/
To unsubscribe, E-mail to: <[email protected]>
----------------------------------------------------------------

Reply via email to