6 Replies Latest reply on Mar 29, 2012 12:06 PM by djg2002

    Configuring Modeshape AuthenticationProvider

    djg2002

      RE: http://stackoverflow.com/questions/9872703/configuring-modeshape-authenticationprovider answered by Randall

       

      My full config (intentionally simple) is below.  I don't think Spring is the issue as I'd expect Modeshape to instantiate the CustomSecurityContext class, but I'm not seeing any errors saying 'Unable to initialize authentication provider'.

       

      One thing is we're using LogBack under slf4j - do you thinkg your log4j messages are getting lost?

       

      Anyway, it seems everything is still going via anonymous access as I am able to work with the default workspace, and create workspaces, but when I call getAccessibleWorkspaces() I don't get anything but the default workspace name returned.

       

       

      <?xml version="1.0" encoding="UTF-8"?>

      <configuration xmlns:mode="http://www.modeshape.org/1.0"

                     xmlns:jcr="http://www.jcp.org/jcr/1.0">

       

                <mode:repositories>

              <mode:repository jcr:name="tbuk_repository" mode:source="file_system_source">

                  <mode:authenticationProviders>

                      <mode:authenticationProvider jcr:name="customModeshapeAuthenticationProvider"

                                                   mode:classname="com.uk.tech.jcr.security.CustomSecurityContext" />

                  </mode:authenticationProviders>

       

                  <mode:options jcr:primaryType="mode:options">

                      <jaasLoginConfigName jcr:primaryType="mode:option"  mode:value="modeshape-jcr" />

                  </mode:options>

       

              </mode:repository>

       

                </mode:repositories>

       

          <mode:sources jcr:primaryType="nt:unstructured">

                    <mode:source jcr:name="file_system_source"

                           mode:classname="org.modeshape.connector.filesystem.FileSystemSource"

                           mode:workspaceRootPath="c:/tbuk"

                           mode:temporaryStoragePath="c:/tbuk/temp"

                           mode:defaultWorkspaceName="tbuk_workspace"

                           mode:creatingWorkspacesAllowed="true"

                           mode:updatesAllowed="true"

                           mode:extraPropertiesBehavior="store"

                           mode:retryLimit="3" />

          </mode:sources>

       

      </configuration>

        • 1. Re: Configuring Modeshape AuthenticationProvider
          rhauch

          How are you starting the ModeShape engine? If you are creating the engine with your code, are you checking whether the engine has any problems (see here)?

           

          I double-checked the code, and any problems with the provider will be recorded in the engine's problems, which is available via JcrEngine.getProblems() method.

          • 2. Re: Configuring Modeshape AuthenticationProvider
            djg2002

            I lazy init the repository using ServiceLoader:

             

             

            I've not worked with the JcrEngine at all - is it possible to get hold of a reference to it from the session or repository so I can check problems?

                /**
                 * Configure and connect to a JCR repository.
                 *
                 * @return Reference to a repository
                 */
                public Repository initRepository() {
            
                    final String JCR_CONFIG_FILE_URL = "/modeshape_config.xml";
            
                    final String jcrConfigFile = "file:" + this.getClass().getResource(JCR_CONFIG_FILE_URL).getPath();
            
                    final Properties parameters = new Properties();
                    parameters.setProperty("org.modeshape.jcr.URL", jcrConfigFile);
            
                    log.info("Configuring JCR Repository using " + parameters.toString());
            
                    for (RepositoryFactory factory : ServiceLoader.load(RepositoryFactory.class)) {
                        try {
                            Repository repo = factory.getRepository(parameters);
                            printRepoDetails(repo, parameters, factory);
            
                            if (repo != null) {
                                repositoryFactory = factory; // Keep reference to allow clean shutdown.  Not part of JCR 2.0
                                repositoryName = String.valueOf(repo.getDescriptor("custom.rep.name"));
            
                                log.info("Repository configured successfully: " + repositoryName);
            
                                return repo;
                            }
                        }
                        catch (RepositoryException e) {
                            log.error("RepositoryException getting repository: " + String.valueOf(e.toString()));
            
                        }
                        catch (Exception e) {
                            log.error("Exception getting repository: " + String.valueOf(e.toString()));
                        }
                    }
            
                    log.warn("Failed to configure JCR Repository");
            
                    return null;
                }
            
            • 3. Re: Configuring Modeshape AuthenticationProvider
              rhauch

              Can you log a bug report in JIRA for your issue? Basically, we need to be logging the problems.

              • 4. Re: Configuring Modeshape AuthenticationProvider
                djg2002

                Can do, although its probably me not knowing my way round JCR enough than it being a bug....

                 

                How do I get a reference to the (Modeshape)JcrEngine to call getProblems() from the factory or repository (or session)?  Once I've had a good look, if it looks like a problem I'll add a ticket.

                 

                Thanks again!...

                • 5. Re: Configuring Modeshape AuthenticationProvider
                  rhauch

                  Can do, although its probably me not knowing my way round JCR enough than it being a bug....

                  Yes, I think there's still a classloading issue, and the log message would just make it more apparent that it's not able to find and instantiate your authentication provider implementation class and, hopefully, an exception that says why.

                   

                  How do I get a reference to the (Modeshape)JcrEngine to call getProblems() from the factory or repository (or session)?  Once I've had a good look, if it looks like a problem I'll add a ticket.

                   

                  Our RepositoryFactory is an instance of org.modeshape.jcr.JcrRepositoryFactory, and it has a public method called "getRepositories(String url)" that takes the same URL you passed into the RepositoryFactory via the Properties object. The "getRepositories(...)" method returns an org.modeshape.jcr.api.Repositories instance that should actually be the JcrEngine instance that has a "getProblems()". It's convoluted because that's not really the intended way for it to be used.

                   

                  Alternatively, you could create a JcrEngine with your configuration (in your real environment, see the code reference I gave earlier) and then just get the problems. Note that this would be a different JcrEngine instance, but it might suffice for figuring out this issue.

                  • 6. Re: Configuring Modeshape AuthenticationProvider
                    djg2002

                    Randall - Thanks for this, I've been away for a couple of days so only just had a chance to look at this but it was a class loader (/Spring configuration in my case) issue as you suggested.