KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > security > auth > login > AuthenticationInfo


1 /*
2  * JBoss, the OpenSource EJB server
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.security.auth.login;
8
9 import java.util.Iterator JavaDoc;
10 import java.util.Map JavaDoc;
11 import java.util.ArrayList JavaDoc;
12 import java.util.Arrays JavaDoc;
13 import java.util.Map.Entry;
14 import javax.security.auth.AuthPermission JavaDoc;
15 import javax.security.auth.callback.CallbackHandler JavaDoc;
16 import javax.security.auth.login.AppConfigurationEntry JavaDoc;
17
18 /** The login module configuration information.
19  
20  @author Scott.Stark@jboss.org
21  @version $Revision: 1.2.26.1 $
22  */

23 public class AuthenticationInfo
24 {
25    public static final AuthPermission JavaDoc GET_CONFIG_ENTRY_PERM = new AuthPermission JavaDoc("getLoginConfiguration");
26    public static final AuthPermission JavaDoc SET_CONFIG_ENTRY_PERM = new AuthPermission JavaDoc("setLoginConfiguration");
27    private String JavaDoc name;
28    private ArrayList JavaDoc loginModules = new ArrayList JavaDoc();
29    private CallbackHandler JavaDoc callbackHandler;
30
31    public AuthenticationInfo()
32    {
33       this(null);
34    }
35    public AuthenticationInfo(String JavaDoc name)
36    {
37       this.name = name;
38    }
39
40    public String JavaDoc getName()
41    {
42       return name;
43    }
44
45    /** Get a copy of the application authentication configuration. This requires
46     an AuthPermission("getLoginConfiguration") access.
47     */

48    public AppConfigurationEntry JavaDoc[] copyAppConfigurationEntry()
49    {
50       SecurityManager JavaDoc sm = System.getSecurityManager();
51       if( sm != null )
52          sm.checkPermission(GET_CONFIG_ENTRY_PERM);
53       AppConfigurationEntry JavaDoc[] copy = new AppConfigurationEntry JavaDoc[loginModules.size()];
54       for(int i = 0; i < copy.length; i ++)
55       {
56          AppConfigurationEntry JavaDoc entry = (AppConfigurationEntry JavaDoc) loginModules.get(i);
57          copy[i] = new AppConfigurationEntry JavaDoc(entry.getLoginModuleName(),
58                                 entry.getControlFlag(), entry.getOptions());
59       }
60       return copy;
61    }
62
63    public void addAppConfigurationEntry(AppConfigurationEntry JavaDoc entry)
64    {
65       loginModules.add(entry);
66    }
67    /** Get an application authentication configuration. This requires an
68     AuthPermission("getLoginConfiguration") access.
69     */

70    public AppConfigurationEntry JavaDoc[] getAppConfigurationEntry()
71    {
72       SecurityManager JavaDoc sm = System.getSecurityManager();
73       if( sm != null )
74          sm.checkPermission(GET_CONFIG_ENTRY_PERM);
75       AppConfigurationEntry JavaDoc[] entries = new AppConfigurationEntry JavaDoc[loginModules.size()];
76       loginModules.toArray(entries);
77       return entries;
78    }
79    /** Set an application authentication configuration. This requires an
80     AuthPermission("setLoginConfiguration") access.
81     */

82    public void setAppConfigurationEntry(AppConfigurationEntry JavaDoc[] loginModules)
83    {
84       SecurityManager JavaDoc sm = System.getSecurityManager();
85       if( sm != null )
86          sm.checkPermission(SET_CONFIG_ENTRY_PERM);
87       
88       this.loginModules.addAll(Arrays.asList(loginModules));
89    }
90
91    /**
92     */

93    public CallbackHandler JavaDoc getAppCallbackHandler()
94    {
95       return callbackHandler;
96    }
97    public void setAppCallbackHandler(CallbackHandler JavaDoc handler)
98    {
99       this.callbackHandler = handler;
100    }
101
102    public String JavaDoc toString()
103    {
104       StringBuffer JavaDoc buffer = new StringBuffer JavaDoc("AppConfigurationEntry[]:\n");
105       for(int i = 0; i < loginModules.size(); i ++)
106       {
107          AppConfigurationEntry JavaDoc entry = (AppConfigurationEntry JavaDoc) loginModules.get(i);
108          buffer.append("["+i+"]");
109          buffer.append("\nLoginModule Class: "+entry.getLoginModuleName());
110          buffer.append("\nControlFlag: "+entry.getControlFlag());
111          buffer.append("\nOptions:");
112          Map JavaDoc options = entry.getOptions();
113          Iterator JavaDoc iter = options.entrySet().iterator();
114          while( iter.hasNext() )
115          {
116             Entry e = (Entry) iter.next();
117             buffer.append("name="+e.getKey());
118             buffer.append(", value="+e.getValue());
119             buffer.append("\n");
120          }
121       }
122       return buffer.toString();
123    }
124
125 }
126
Popular Tags