/AuthenticRoast/AuthenticRoast-Impl/src/main/java/name/aikesommer/authenticator/CrossContextPrincipalStore.java
http://authenticroast.googlecode.com/ · Java · 69 lines · 32 code · 10 blank · 27 comment · 6 complexity · a8bd16f95fef0c6944bb9a6c909479b9 MD5 · raw file
- /**
- * Copyright (C) 2007-2010 Aike J Sommer (http://aikesommer.name/)
- *
- * This file is part of AuthenticRoast.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General
- * Public License along with this library; if not, write to the
- * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301 USA
- *
- * You can reach the author and get more information about this
- * project at: http://aikesommer.name/
- */
- package name.aikesommer.authenticator;
- import java.lang.ref.WeakReference;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- /**
- *
- * @author Aike J Sommer
- */
- public class CrossContextPrincipalStore implements PrincipalStore {
- private static final String PRINCIPAL_NOTE = CrossContextPrincipalStore.class.getName()
- + ".PRINCIPAL";
- private final WeakReference<SuperSession> session;
- public CrossContextPrincipalStore(HttpServletRequest request, HttpServletResponse response) {
- session = new WeakReference<SuperSession>(SuperSession.self(request,
- response, true));
- }
- public void store(SimplePrincipal principal) {
- SuperSession s = session.get();
- if (s != null) {
- s.attributes().put(PRINCIPAL_NOTE, principal);
- }
- }
- public SimplePrincipal fetch() {
- SuperSession s = session.get();
- if (s != null) {
- return (SimplePrincipal) s.attributes().get(PRINCIPAL_NOTE);
- }
- return null;
- }
- public void invalidate() {
- SuperSession s = session.get();
- if (s != null) {
- s.attributes().remove(PRINCIPAL_NOTE);
- }
- }
- }