| 1 10 package org.mmbase.security; 11 12 import java.util.Map ; 13 14 import org.mmbase.util.functions.*; 15 16 import org.mmbase.util.logging.Logger; 17 import org.mmbase.util.logging.Logging; 18 19 28 public abstract class Authentication extends Configurable implements AuthenticationData { 29 private static final Logger log = Logging.getLoggerInstance(Authentication.class); 30 31 static { 32 try { 33 PARAMETER_USERNAME.getLocalizedDescription().setBundle(STRINGS); 34 PARAMETER_PASSWORD.getLocalizedDescription().setBundle(STRINGS); 35 PARAMETER_USERNAMES.getLocalizedDescription().setBundle(STRINGS); 36 PARAMETER_RANK.getLocalizedDescription().setBundle(STRINGS); 37 PARAMETER_SESSIONNAME.getLocalizedDescription().setBundle(STRINGS); 38 PARAMETER_LOGOUT.getLocalizedDescription().setBundle(STRINGS); 39 PARAMETER_AUTHENTICATE.getLocalizedDescription().setBundle(STRINGS); 40 } catch (Exception e) { 41 log.error(e); 42 } 43 } 44 45 46 61 public abstract UserContext login(String application, Map loginInfo, Object [] parameters) throws SecurityException ; 62 63 66 public int getMethod(String m) { 67 if (m == null || m.equals("")) { 68 return METHOD_UNSET; 69 } 70 m = m.toLowerCase(); 71 if ("http".equals(m)) { 72 return METHOD_HTTP; 73 } else if ("asis".equals(m)) { 74 return METHOD_ASIS; 75 } else if ("anonymous".equals(m)) { 76 return METHOD_ANONYMOUS; 77 } else if ("logout".equals(m)) { 78 return METHOD_LOGOUT; 79 } else if ("loginpage".equals(m)) { 80 return METHOD_LOGINPAGE; 81 } else if ("delegate".equals(m)) { 82 return METHOD_DELEGATE; 83 } else if ("sessiondelegate".equals(m)) { 84 return METHOD_SESSIONDELEGATE; 85 } else if ("pagelogon".equals(m)) { 86 return METHOD_PAGELOGON; 87 } else if ("sessionlogon".equals(m)) { 88 return METHOD_SESSIONLOGON; 89 } else if ("default".equals(m)) { 90 return METHOD_DEFAULT; 91 } else { 94 throw new RuntimeException ("Unknown value for 'method' attribute (" + m + ")"); 95 } 96 } 97 98 102 public int getDefaultMethod(String protocol) { 103 if (protocol == null || protocol.substring(0, 4).equalsIgnoreCase("HTTP")) { 104 return METHOD_HTTP; 105 } else { 106 return METHOD_DELEGATE; } 108 } 109 110 114 public String [] getTypes() { 115 return getTypes(METHOD_UNSET); 116 } 117 121 public String [] getTypes(int method) { 122 if (method == METHOD_ASIS) { 123 return new String [] {"anonymous", "name/password", "class"}; 124 } else { 125 return new String [] {"name/password", "class"}; 126 } 127 } 128 129 protected static final Parameter[] PARAMETERS_USERS = new Parameter[] { PARAMETER_USERNAMES, PARAMETER_RANK }; 130 protected static final Parameter[] PARAMETERS_ANONYMOUS = new Parameter[] { PARAMETER_LOGOUT, PARAMETER_AUTHENTICATE}; 131 protected static final Parameter[] PARAMETERS_NAME_PASSWORD = new Parameter[] { PARAMETER_USERNAME, PARAMETER_PASSWORD, new Parameter.Wrapper(PARAMETERS_USERS) }; 132 133 public Parameters createParameters(String application) { 134 application = application.toLowerCase(); 135 if ("anonymous".equals(application)) { 136 return new Parameters(PARAMETERS_ANONYMOUS); 137 } else if ("class".equals(application)) { 138 return Parameters.VOID; 139 } else if ("name/password".equals(application)) { 140 return new Parameters(PARAMETERS_NAME_PASSWORD); 141 } else { 142 return new AutodefiningParameters(); 143 } 144 } 145 146 long key = System.currentTimeMillis(); 147 148 155 public long getKey() { 156 return key; 157 } 158 } 159 | Popular Tags |