/AuthenticRoast/AuthenticRoast-Impl/src/main/java/name/aikesommer/authenticator/DelegatingAuthenticator.java

http://authenticroast.googlecode.com/ · Java · 60 lines · 26 code · 11 blank · 23 comment · 0 complexity · 047107f35efd8aee09a4dbaf044b57e6 MD5 · raw file

  1. /**
  2. * Copyright (C) 2007-2010 Aike J Sommer (http://aikesommer.name/)
  3. *
  4. * This file is part of AuthenticRoast.
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General
  17. * Public License along with this library; if not, write to the
  18. * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  19. * Boston, MA 02110-1301 USA
  20. *
  21. * You can reach the author and get more information about this
  22. * project at: http://aikesommer.name/
  23. */
  24. package name.aikesommer.authenticator;
  25. import javax.servlet.ServletContext;
  26. public class DelegatingAuthenticator extends PluggableAuthenticator {
  27. private PluggableAuthenticator delegateAuthenticator;
  28. private ServletContext delegateContext;
  29. public DelegatingAuthenticator(PluggableAuthenticator delegateAuthenticator,
  30. ServletContext delegateContext) {
  31. this.delegateAuthenticator = delegateAuthenticator;
  32. this.delegateContext = delegateContext;
  33. }
  34. private AuthenticationRequest wrapRequest(AuthenticationRequest request) {
  35. return ((AuthenticationRequestImpl) request).delegate(delegateContext);
  36. }
  37. @Override
  38. public AuthenticationRequest.Status tryAuthenticate(AuthenticationManager manager, AuthenticationRequest request) {
  39. return delegateAuthenticator.tryAuthenticate(manager, wrapRequest(request));
  40. }
  41. @Override
  42. public AuthenticationRequest.Status authenticate(AuthenticationManager manager, AuthenticationRequest request) {
  43. return delegateAuthenticator.authenticate(manager, wrapRequest(request));
  44. }
  45. @Override
  46. public AuthenticationRequest.ManageAction manage(AuthenticationManager manager, AuthenticationRequest request) {
  47. return delegateAuthenticator.manage(manager, wrapRequest(request));
  48. }
  49. }