Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source.
   * Copyright 2012, Red Hat, Inc., and individual contributors
   * as indicated by the @author tags. See the copyright.txt file 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.picketbox.http;
 
 import java.util.List;
 
 

org.picketbox.core.PicketBoxManager implementation to be used by web applications.

Author(s):
Pedro Silva
 
 public final class PicketBoxHTTPManager extends AbstractPicketBoxManager {
 
     @SuppressWarnings("rawtypes")
 
     public PicketBoxHTTPManager(PicketBoxHTTPConfiguration configuration) {
         super(configuration);
         this. = configuration;
     }
 
     /*
      * (non-Javadoc)
      *
      * @see org.picketbox.core.AbstractPicketBoxManager#doPreAuthentication(org.picketbox.core.PicketBoxSecurityContext,
      * org.picketbox.core.authentication.AuthenticationCallbackHandler)
      */
     @SuppressWarnings("unchecked")
     @Override
     protected boolean doPreAuthentication(PicketBoxSubject subject) {
         if (this. == null) {
             return true;
         }
 
         PicketBoxHTTPSubject httpSubject = (PicketBoxHTTPSubjectsubject;
 
                 httpSubject.getRequest(), httpSubject.getResponse()));
 
         return protectedResource.requiresAuthentication();
     }
 
     @SuppressWarnings("unchecked")
     @Override
     public boolean authorize(PicketBoxSubject subjectResource resource) {
         if (this. != null && subject != null) {
             ProtectedResource protectedResource = this..getProtectedResource(resource);
 
             if (protectedResource.requiresAuthorization() && subject.isAuthenticated()) {
                 if (!protectedResource.isAllowed(subject)) {
                     return false;
                 }
             }
         }
 
         return super.authorize(subjectresource);
     }
 
     private WebResource createWebResource(HttpServletRequest requestHttpServletResponse response) {
         WebResource resource = new WebResource();
 
         resource.setContext(request.getServletContext());
        resource.setRequest(request);
        resource.setResponse(response);
        return resource;
    }
    /*
     * (non-Javadoc)
     *
     * @see org.picketbox.core.AbstractPicketBoxManager#doConfigure()
     */
    @Override
    protected void doConfigure() {
        List<ProtectedResourceresources = this..getProtectedResource().getResources();
        for (ProtectedResource protectedResource : resources) {
            this..addProtectedResource(protectedResource);
        }
        this..start();
        super. = new HTTPSessionManager(this.);
        super..start();
    }
    public PicketBoxSubject getSubject(HttpServletRequest request) {
        HttpSession session = request.getSession(false);
        if (session == null) {
            return null;
        }
        return (PicketBoxSubjectsession.getAttribute(getUserAttributeName());
    }

    

Returns the attribute name that should be used to store the org.picketbox.core.PicketBoxSubject.

Returns:
    private String getUserAttributeName() {
        if (name == null) {
            name = .;
        }
        return name;
    }
    @SuppressWarnings("unchecked")
    public boolean requiresAuthentication(HttpServletRequest requestHttpServletResponse response) {
        return this. != null
                && this..getProtectedResource(createWebResource(requestresponse))
                        .requiresAuthentication();
    }
New to GrepCode? Check out our FAQ X