1 28 29 package com.caucho.server.security; 30 31 import com.caucho.config.Config; 32 import com.caucho.config.ConfigException; 33 import com.caucho.config.types.InitProgram; 34 import com.caucho.log.Log; 35 import com.caucho.util.L10N; 36 37 import javax.servlet.ServletException ; 38 import java.util.logging.Logger ; 39 40 43 public class LoginConfig { 44 static final Logger log = Log.open(LoginConfig.class); 45 static final L10N L = new L10N(LoginConfig.class); 46 47 private String _authMethod = "basic"; 48 private String _realmName; 49 private Class _customType; 50 private InitProgram _formLoginConfig; 51 private InitProgram _init; 52 53 private ServletAuthenticator _authenticator; 54 55 58 public LoginConfig() 59 { 60 } 61 62 65 public void setAuthMethod(String method) 66 { 67 _authMethod = method; 68 } 69 70 73 public String getAuthMethod() 74 { 75 return _authMethod; 76 } 77 78 81 public void setAuthenticator(ServletAuthenticator auth) 82 { 83 _authenticator = auth; 84 } 85 86 89 public void setType(Class type) 90 throws ConfigException 91 { 92 _customType = type; 93 94 Config.validate(type, AbstractLogin.class); 95 } 96 97 100 public void setRealmName(String realmName) 101 { 102 _realmName = realmName; 103 } 104 105 108 public String getRealmName() 109 { 110 return _realmName; 111 } 112 113 116 public InitProgram createFormLoginConfig() 117 { 118 if (_formLoginConfig == null) 119 _formLoginConfig = new InitProgram(); 120 121 return _formLoginConfig; 122 } 123 124 127 public InitProgram createInit() 128 { 129 if (_init == null) 130 _init = new InitProgram(); 131 132 return _init; 133 } 134 135 138 public AbstractLogin getLogin() 139 throws Throwable 140 { 141 145 146 AbstractLogin login; 147 148 if (_customType != null) { 149 login = (AbstractLogin) _customType.newInstance(); 150 151 if (_init != null) 152 _init.getBuilderProgram().configure(login); 153 } 154 else if (_authMethod.equalsIgnoreCase("basic")) { 155 BasicLogin basicLogin = new BasicLogin(); 156 basicLogin.setRealmName(_realmName); 157 login = basicLogin; 158 } 159 else if (_authMethod.equalsIgnoreCase("digest")) { 160 DigestLogin digestLogin = new DigestLogin(); 161 digestLogin.setRealmName(_realmName); 162 login = digestLogin; 163 } 164 else if (_authMethod.equalsIgnoreCase("client-cert")) { 165 ClientCertLogin certLogin = new ClientCertLogin(); 166 login = certLogin; 167 } 168 else if (_authMethod.equalsIgnoreCase("form")) { 169 login = new FormLogin(); 170 if (_formLoginConfig != null) 171 _formLoginConfig.init(login); 172 } 173 else 174 throw new ServletException (L.l("`{0}' is an unknown auth-type.", 175 _authMethod)); 176 177 if (_authenticator != null) 178 login.setAuthenticator(_authenticator); 179 180 login.init(); 181 182 return login; 183 } 184 } 185 | Popular Tags |