KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > security > ModulesDataSource


1 package com.sslexplorer.security;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.Collection JavaDoc;
5 import java.util.Iterator JavaDoc;
6 import java.util.List JavaDoc;
7
8 import org.apache.struts.util.LabelValueBean;
9 import org.apache.struts.util.MessageResources;
10
11 import com.sslexplorer.core.CoreUtil;
12 import com.sslexplorer.input.MultiSelectDataSource;
13
14 public class ModulesDataSource implements MultiSelectDataSource {
15
16     String JavaDoc key;
17
18     public ModulesDataSource(String JavaDoc key) {
19         this.key = key;
20     }
21
22     public Collection JavaDoc<LabelValueBean> getValues(SessionInfo session) {
23         List JavaDoc l = new ArrayList JavaDoc();
24         for (Iterator JavaDoc i = AuthenticationModuleManager.getInstance().authenticationModuleDefinitions(); i.hasNext();) {
25             AuthenticationModuleDefinition def = (AuthenticationModuleDefinition) i.next();
26             /*
27              * NOTE As from 0.1.12, HTTP Basic Authentication is still
28              * registered (it is needed by WebDAV and Web Forwards) but it is
29              * not a valid module to use for authentication.
30              */

31             if (!def.getSystem()
32                             && !def.getName().equals(HTTPAuthenticationModule.MODULE_NAME)
33                             || (def.getName().equals(HTTPAuthenticationModule.MODULE_NAME) && "true".equals(System.getProperty(
34                                             "sslexplorer.httpBasicAuthenticationModule.enabled", "false")))) {
35                 StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
36                 if (def.getPrimary()) {
37                     buf.append(" (");
38                     buf.append(CoreUtil.getMessageResources(session.getHttpSession(), key).getMessage("authenticationModule.primary"));
39                 } else if(def.getPrimaryIfSecondardExists()) {
40                     buf.append(" (");
41                     buf.append(CoreUtil.getMessageResources(session.getHttpSession(), key).getMessage("authenticationModule.primaryIfSecondaryExists"));
42                 } else if (def.getSecondary()) {
43                     buf.append(" (");
44                     buf.append(CoreUtil.getMessageResources(session.getHttpSession(), key).getMessage("authenticationModule.secondary"));
45                 }
46                 
47                 if (buf.length() != 0) {
48                     buf.append(")");
49                 }
50                 MessageResources mr = CoreUtil.getMessageResources(session.getHttpSession(), def.getMessageResourcesKey());
51                 l
52                                 .add(new LabelValueBean(
53                                                 mr == null ? ("!unknown bundle " + def.getMessageResourcesKey() + " in module definition")
54                                                                 : mr.getMessage("authenticationModule." + def.getName() + ".name")
55                                                                                 + buf.toString(), def.getName()));
56             }
57         }
58         return l;
59     }
60
61 }
62
Popular Tags