Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   *
   *  JBoss, a division of Red Hat
   *  Copyright 2012, Red Hat Middleware, LLC, and individual contributors as indicated
   *  by the @authors tag. See the copyright.txt in the distribution for a
   *  full listing of individual contributors.
   *
   *  This 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 2.1 of
  *  the License, or (at your option) any later version.
  *
  *  This software 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 software; if not, write to the Free
  *  Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  *  02110-1301 USA, or see the FSF site: http://www.fsf.org.
  *
  */
 
 package org.exoplatform.web.security;
 
 import java.util.Map;
 
 
Temporary registry for hold credentials (and potentially other attributes) during login process to avoid store them in session. Registry is used only during authentication process and attributes of target client are cleared usually after successful authentication,

Author(s):
Marek Posolda
 
 public class AuthenticationRegistryImpl implements AuthenticationRegistry {
     private static final Logger log = LoggerFactory.getLogger(AuthenticationRegistryImpl.class);
 
     // Key is ID of HTTP Session. Value is map with various attributes of single client (session),
     // which will be used during authentication process.
     private final ConcurrentMap<StringMap<StringObject>> registry = new ConcurrentHashMap<StringMap<StringObject>>();
 
     @Override
     public Credentials getCredentials(HttpServletRequest request) {
         return (CredentialsgetAttributeOfClient(request.);
     }
 
     @Override
     public void setCredentials(HttpServletRequest requestCredentials credentials) {
         setAttributeOfClient(request.credentials);
     }
 
     @Override
     public Credentials removeCredentials(HttpServletRequest request) {
         return (Credentials)removeAttributeOfClient(request.);
     }
 
     @Override
     public void removeClient(String sessionId) {
         .remove(sessionId);
 
         if (.isTraceEnabled()) {
             .trace("Entry cleared for session " + sessionId);
         }
     }
 
     @Override
     public void setAttributeOfClient(HttpServletRequest requestString attributeNameObject attributeValue) {
         String sessionId = getSessionId(request);
 
         Map<StringObjectattributesOfClient = getAllAttributesOfClient(sessionId);
         attributesOfClient.put(attributeNameattributeValue);
     }
 
     @Override
     public Object getAttributeOfClient(HttpServletRequest requestString attributeName) {
         String sessionId = getSessionId(request);
         Map<StringObjectattributesOfClient = .get(sessionId);
 
         if (attributesOfClient == null) {
             return null;
         }
 
         return attributesOfClient.get(attributeName);
     }
 
     @Override
     public Object removeAttributeOfClient(HttpServletRequest requestString attributeName) {
         String sessionId = getSessionId(request);
 
         Map<StringObjectattributesOfClient = getAllAttributesOfClient(sessionId);
        Object removedAttribute = attributesOfClient.remove(attributeName);
        // Clear map if no more attributes are here.
        if (attributesOfClient.size() == 0) {
            removeClient(sessionId);
        }
        return removedAttribute;
    }
    private Map<StringObjectgetAllAttributesOfClient(String sessionId) {
        Map<StringObjectattributes = .get(sessionId);
        if (attributes == null) {
            attributes = new ConcurrentHashMap<StringObject>();
            .putIfAbsent(sessionIdattributes);
            if (.isTraceEnabled()) {
                .trace("New entry created in AuthenticationRegistry for session " + sessionId);
            }
        }
        return .get(sessionId);
    }
    private String getSessionId(HttpServletRequest req) {
        return req.getSession().getId();
    }
New to GrepCode? Check out our FAQ X