View | Details | Raw Unified | Return to bug 53777
Collapse All | Expand All

(-)C:/Users/Utente/AppData/Local/Temp/JAASRealm.java-revBASE.svn000.tmp.java (-4 / +79 lines)
Lines 19-24 Link Here
19
package org.apache.catalina.realm;
19
package org.apache.catalina.realm;
20
20
21
21
22
import java.lang.reflect.Constructor;
23
import java.lang.reflect.InvocationTargetException;
24
import java.net.URI;
25
import java.net.URISyntaxException;
26
import java.net.URL;
22
import java.security.Principal;
27
import java.security.Principal;
23
import java.util.ArrayList;
28
import java.util.ArrayList;
24
import java.util.Iterator;
29
import java.util.Iterator;
Lines 27-32 Link Here
27
import javax.security.auth.Subject;
32
import javax.security.auth.Subject;
28
import javax.security.auth.callback.CallbackHandler;
33
import javax.security.auth.callback.CallbackHandler;
29
import javax.security.auth.login.AccountExpiredException;
34
import javax.security.auth.login.AccountExpiredException;
35
import javax.security.auth.login.Configuration;
30
import javax.security.auth.login.CredentialExpiredException;
36
import javax.security.auth.login.CredentialExpiredException;
31
import javax.security.auth.login.FailedLoginException;
37
import javax.security.auth.login.FailedLoginException;
32
import javax.security.auth.login.LoginContext;
38
import javax.security.auth.login.LoginContext;
Lines 172-181 Link Here
172
     */
178
     */
173
     protected boolean useContextClassLoader = true;
179
     protected boolean useContextClassLoader = true;
174
180
175
181
     /**
182
      * Path to find a JAAS configuration file, if not set global JVM JAAS configuraion will be used
183
      */
184
     protected String configfile;
185
     
176
    // ------------------------------------------------------------- Properties
186
    // ------------------------------------------------------------- Properties
177
187
178
    
188
     /**
189
     * getter for the <code>configfile</code> member variable
190
     */
191
     public String getConfigfile() {
192
        return configfile;
193
     }
194
195
     /**
196
      * setter for the <code>configfile</code> member variable
197
      */
198
     public void setConfigfile(String configfile) {
199
         this.configfile = configfile;
200
     }
201
     
202
     
179
    /**
203
    /**
180
     * setter for the <code>appName</code> member variable
204
     * setter for the <code>appName</code> member variable
181
     */
205
     */
Lines 278-284 Link Here
278
                               "java.security.Principal! Class not added.");
302
                               "java.security.Principal! Class not added.");
279
                 }
303
                 }
280
             } catch (ClassNotFoundException e) {
304
             } catch (ClassNotFoundException e) {
281
                 log.error("Class "+classNames[i]+" not found! Class not added.");
305
                 if (isUseContextClassLoader()) {
306
                     log.warn("Class "+classNames[i]+" could not be verified",e);
307
                     classNamesList.add(classNames[i]);
308
                 } else {
309
                    log.error("Class "+classNames[i]+" not found! Class not added.");
310
                 }
282
             }
311
             }
283
         }
312
         }
284
     }     
313
     }     
Lines 389-395 Link Here
389
        }
418
        }
390
419
391
        try {
420
        try {
392
            loginContext = new LoginContext(appName, callbackHandler);
421
            Configuration config = getConfig();                
422
            loginContext = new LoginContext(appName, null, callbackHandler, config);
393
        } catch (Throwable e) {
423
        } catch (Throwable e) {
394
            ExceptionUtils.handleThrowable(e);
424
            ExceptionUtils.handleThrowable(e);
395
            log.error(sm.getString("jaasRealm.unexpectedError"), e);
425
            log.error(sm.getString("jaasRealm.unexpectedError"), e);
Lines 605-608 Link Here
605
635
606
        super.startInternal();
636
        super.startInternal();
607
     }
637
     }
638
     
639
    protected Configuration jaasConfiguration;
640
    protected volatile boolean jaasConfigurationLoaded = false;
641
642
    /**
643
     * Load custom JAAS Configuration     
644
     */
645
    protected Configuration getConfig() {
646
        try {
647
            if (jaasConfigurationLoaded) {
648
                return jaasConfiguration;
649
            }
650
            synchronized (this) {
651
                if (configfile == null) {
652
                    jaasConfigurationLoaded = true;
653
                    return null;
654
                }
655
                URL resource = Thread.currentThread().getContextClassLoader().getResource(configfile);
656
                URI uri = resource.toURI();
657
                Class sunConfigFile = Class.forName("com.sun.security.auth.login.ConfigFile");
658
                Constructor<Configuration> constructor = sunConfigFile.getConstructor(URI.class);
659
                Configuration config = constructor.newInstance(uri);
660
                this.jaasConfiguration = config;
661
                this.jaasConfigurationLoaded = true;
662
                return this.jaasConfiguration;
663
            }
664
        } catch (URISyntaxException ex) {
665
            throw new RuntimeException(ex);
666
        } catch (NoSuchMethodException ex) {
667
            throw new RuntimeException(ex);
668
        } catch (SecurityException ex) {
669
            throw new RuntimeException(ex);
670
        } catch (InstantiationException ex) {
671
            throw new RuntimeException(ex);
672
        } catch (IllegalAccessException ex) {
673
            throw new RuntimeException(ex);
674
        } catch (IllegalArgumentException ex) {
675
            throw new RuntimeException(ex);
676
        } catch (InvocationTargetException ex) {
677
            throw new RuntimeException(ex.getCause());
678
        } catch (ClassNotFoundException ex) {
679
            throw new RuntimeException(ex);
680
        }
681
682
    }
608
}
683
}

Return to bug 53777