jackrabbit-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bertrand LEGA <legabertr...@yahoo.fr>
Subject Re: JAAS support
Date Fri, 04 Mar 2005 09:13:27 GMT
Index: java/org/apache/jackrabbit/core/RepositoryImpl.java
===================================================================
--- java/org/apache/jackrabbit/core/RepositoryImpl.java	(revision 156033)
+++ java/org/apache/jackrabbit/core/RepositoryImpl.java	(working copy)
@@ -52,7 +52,10 @@
 import javax.jcr.observation.EventIterator;
 import javax.jcr.observation.EventListener;
 import javax.security.auth.login.LoginContext;
+
+import java.io.BufferedWriter;
 import java.io.File;
+import java.io.FileWriter;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
@@ -97,6 +100,11 @@
     // configuration of the repository
     private final RepositoryConfig repConfig;
 
+	/**
+     * The name of the jaas config system property.
+     */
+    private static final String SYS_JAAS_CONFIG = "java.security.auth.login.config";
+
     // the master filesystem
     private final FileSystem repStore;
 
@@ -648,6 +656,28 @@
     //-----------------------------------------------------------< Repository >
     /**
      * @see Repository#login(Credentials, String)
+     * As the current implementation uses the <code>com.sun.security.auth.login.ConfigFile</code>

+     * as the current provider for the login configuration, the application 
+     * needs to have the environment variable ??? to be set 
+     * with the config file.
+     * Example :  
+     * <code>
+     *    System.setProperty("java.security.auth.login.config", "c:\\temp\\jaas.config" )
;
+     * </code>
+     * The file C:\temp\jaas.config is supposed to give the login module implementation.

+     * 
+     * Exmaple of jaas.config 
+     * <code>
+     *    Jackrabbit {
+     *      org.apache.jackrabbit.core.security.SimpleLoginModule required;
+     *    };
+     * </code>
+     * 
+     * All that is very boring and breaks compatibility. 
+     * So I added code to create this file in the repository homedir if not present, with
the default content 
+     * as described above and set the env property accordingly. 
+     * Of course, if the property is already set, nothing is done.
+     * 
      */
     public Session login(Credentials credentials, String workspaceName)
             throws LoginException, NoSuchWorkspaceException, RepositoryException {
@@ -664,6 +694,41 @@
             throw new NoSuchWorkspaceException(workspaceName);
         }
 
+		// Generating file + set the property to support the login module
+        if (System.getProperty(SYS_JAAS_CONFIG) == null ) {
+			// Create the file 
+			
+			String jaasConfigFilepath = repConfig.getHomeDir() + File.separator +"jaasgenerated.config"
;
+			File jaasConfigFile = new File( jaasConfigFilepath ) ;
+				BufferedWriter writer = null ;
+				try {
+					writer = new BufferedWriter( new FileWriter( jaasConfigFilepath )) ;
+					StringBuffer content = new StringBuffer() ;
+					content.append( "Jackrabbit { \n"  ) ;
+					content.append( "  org.apache.jackrabbit.core.security.SimpleLoginModule required; \n"
) ;
+					content.append( "    };\n" ) ;
+					writer.write( content.toString() ) ;
+					writer.flush() ;
+                    log.info( "The JAAS configuration file '" + jaasConfigFile.getAbsolutePath()
+ "' has been generated.") ;
+				} catch (IOException e) {
+					// Exception
+					log.debug("The file " + jaasConfigFilepath + "failed to be generated. Erreur : " + e.getMessage()
);
+				}
+				finally
+				{
+					if( writer != null )
+					{
+						try {
+							writer.close() ;
+						} catch (IOException e1) {
+							// ok
+						}
+					}
+				}
+			// Set the property
+            System.setProperty(SYS_JAAS_CONFIG, jaasConfigFile.getAbsolutePath() );
+        }
+
         CredentialsCallbackHandler cbHandler =
                 new CredentialsCallbackHandler(credentials);
         LoginContext lc;

Mime
View raw message