1 28 29 package com.caucho.server.security; 30 31 import javax.annotation.PostConstruct; 32 import javax.servlet.ServletContext ; 33 import javax.servlet.ServletException ; 34 import javax.servlet.http.HttpServletRequest ; 35 import javax.servlet.http.HttpServletResponse ; 36 import javax.servlet.http.HttpSession ; 37 import java.security.Principal ; 38 import java.util.ArrayList ; 39 40 77 public class AuthenticatorList implements ServletAuthenticator { 78 private ArrayList <ServletAuthenticator> _authenticators 79 = new ArrayList <ServletAuthenticator>(); 80 81 84 public void addAuthenticator(ServletAuthenticator authenticator) 85 { 86 _authenticators.add(authenticator); 87 } 88 89 @PostConstruct 90 public void init() 91 throws ServletException 92 { 93 } 94 95 public Principal login(HttpServletRequest request, 96 HttpServletResponse response, 97 ServletContext application, 98 String user, String password) 99 throws ServletException 100 { 101 Principal result = null; 102 103 for (ServletAuthenticator authenticator : _authenticators) { 104 result = authenticator.login( request, 105 response, 106 application, 107 user, 108 password ); 109 110 if (result != null) 111 break; 112 } 113 114 return result; 115 } 116 117 public Principal getUserPrincipal(HttpServletRequest request, 118 HttpServletResponse response, 119 ServletContext application) 120 throws ServletException 121 { 122 Principal result = null; 123 124 for (ServletAuthenticator authenticator : _authenticators) { 125 result = authenticator.getUserPrincipal( request, 126 response, 127 application ); 128 129 if (result != null) 130 break; 131 } 132 133 return result; 134 } 135 136 public Principal loginDigest(HttpServletRequest request, 137 HttpServletResponse response, 138 ServletContext app, 139 String user, String realm, 140 String nonce, String uri, 141 String qop, String nc, String cnonce, 142 byte []clientDigset) 143 throws ServletException 144 { 145 Principal result = null; 146 147 for (ServletAuthenticator authenticator : _authenticators) { 148 result = authenticator.loginDigest( request, 149 response, 150 app, 151 user, 152 realm, 153 nonce, 154 uri, 155 qop, 156 nc, 157 cnonce, 158 clientDigset ); 159 160 if (result != null) 161 break; 162 } 163 164 return result; 165 } 166 167 public boolean isUserInRole(HttpServletRequest request, 168 HttpServletResponse response, 169 ServletContext application, 170 Principal user, String role) 171 throws ServletException 172 { 173 boolean result = false; 174 175 for (ServletAuthenticator authenticator : _authenticators) { 176 result = authenticator.isUserInRole( request, 177 response, 178 application, 179 user, 180 role ); 181 182 if (result) 183 break; 184 } 185 186 return result; 187 } 188 189 public void logout(ServletContext application, 190 HttpSession timeoutSession, 191 String sessionId, 192 Principal user) 193 throws ServletException 194 { 195 for (ServletAuthenticator authenticator : _authenticators) { 196 authenticator.logout(application, 197 timeoutSession, 198 sessionId, 199 user ); 200 } 201 } 202 } 203 | Popular Tags |