1 7 package org.jboss.security.auth.login; 8 9 import java.util.Iterator ; 10 import java.util.Map ; 11 import java.util.ArrayList ; 12 import java.util.Arrays ; 13 import java.util.Map.Entry; 14 import javax.security.auth.AuthPermission ; 15 import javax.security.auth.callback.CallbackHandler ; 16 import javax.security.auth.login.AppConfigurationEntry ; 17 18 23 public class AuthenticationInfo 24 { 25 public static final AuthPermission GET_CONFIG_ENTRY_PERM = new AuthPermission ("getLoginConfiguration"); 26 public static final AuthPermission SET_CONFIG_ENTRY_PERM = new AuthPermission ("setLoginConfiguration"); 27 private String name; 28 private ArrayList loginModules = new ArrayList (); 29 private CallbackHandler callbackHandler; 30 31 public AuthenticationInfo() 32 { 33 this(null); 34 } 35 public AuthenticationInfo(String name) 36 { 37 this.name = name; 38 } 39 40 public String getName() 41 { 42 return name; 43 } 44 45 48 public AppConfigurationEntry [] copyAppConfigurationEntry() 49 { 50 SecurityManager sm = System.getSecurityManager(); 51 if( sm != null ) 52 sm.checkPermission(GET_CONFIG_ENTRY_PERM); 53 AppConfigurationEntry [] copy = new AppConfigurationEntry [loginModules.size()]; 54 for(int i = 0; i < copy.length; i ++) 55 { 56 AppConfigurationEntry entry = (AppConfigurationEntry ) loginModules.get(i); 57 copy[i] = new AppConfigurationEntry (entry.getLoginModuleName(), 58 entry.getControlFlag(), entry.getOptions()); 59 } 60 return copy; 61 } 62 63 public void addAppConfigurationEntry(AppConfigurationEntry entry) 64 { 65 loginModules.add(entry); 66 } 67 70 public AppConfigurationEntry [] getAppConfigurationEntry() 71 { 72 SecurityManager sm = System.getSecurityManager(); 73 if( sm != null ) 74 sm.checkPermission(GET_CONFIG_ENTRY_PERM); 75 AppConfigurationEntry [] entries = new AppConfigurationEntry [loginModules.size()]; 76 loginModules.toArray(entries); 77 return entries; 78 } 79 82 public void setAppConfigurationEntry(AppConfigurationEntry [] loginModules) 83 { 84 SecurityManager 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 93 public CallbackHandler getAppCallbackHandler() 94 { 95 return callbackHandler; 96 } 97 public void setAppCallbackHandler(CallbackHandler handler) 98 { 99 this.callbackHandler = handler; 100 } 101 102 public String toString() 103 { 104 StringBuffer buffer = new StringBuffer ("AppConfigurationEntry[]:\n"); 105 for(int i = 0; i < loginModules.size(); i ++) 106 { 107 AppConfigurationEntry entry = (AppConfigurationEntry ) 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 options = entry.getOptions(); 113 Iterator 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 |