Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  //
  //  ========================================================================
  //  Copyright (c) 1995-2013 Mort Bay Consulting Pty. Ltd.
  //  ------------------------------------------------------------------------
  //  All rights reserved. This program and the accompanying materials
  //  are made available under the terms of the Eclipse Public License v1.0
  //  and Apache License v2.0 which accompanies this distribution.
  //
  //      The Eclipse Public License is available at
 //      http://www.eclipse.org/legal/epl-v10.html
 //
 //      The Apache License v2.0 is available at
 //      http://www.opensource.org/licenses/apache2.0.php
 //
 //  You may elect to redistribute this code under either of these licenses.
 //  ========================================================================
 //
 
 package org.eclipse.jetty.jaas.spi;
 
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
 
PropertyFileLoginModule
 
 {
     public static final String DEFAULT_FILENAME = "realm.properties";
 
     private static final Logger LOG = Log.getLogger(PropertyFileLoginModule.class);
 
 
     private int _refreshInterval = 0;
     private String _filename = ;

    
Read contents of the configured property file.

 
     public void initialize(Subject subjectCallbackHandler callbackHandlerMap<String, ?> sharedStateMap<String, ?> options)
     {
         super.initialize(subject,callbackHandler,sharedState,options);
         setupPropertyUserStore(options);
     }
 
     private void setupPropertyUserStore(Map<String, ?> options)
     {
         parseConfig(options);
 
         if (.get() == null)
         {
             PropertyUserStore propertyUserStore = new PropertyUserStore();
             propertyUserStore.setConfig();
             propertyUserStore.setRefreshInterval();
 
             PropertyUserStore prev = .putIfAbsent(propertyUserStore);
             if (prev == null)
             {
                 .debug("setupPropertyUserStore: Starting new PropertyUserStore. PropertiesFile: " +  + " refreshInterval: " + );
 
                 try
                 {
                     propertyUserStore.start();
                 }
                 catch (Exception e)
                 {
                     .warn("Exception while starting propertyUserStore: ",e);
                 }
             }
         }
     }
 
     private void parseConfig(Map<String, ?> options)
     {
         String tmp = (String)options.get("file");
          = (tmp == null : tmp);
        tmp = (String)options.get("refreshInterval");
         = (tmp == null?:Integer.parseInt(tmp));
    }

    
Don't implement this as we want to pre-fetch all of the users.

Parameters:
userName
Throws:
java.lang.Exception
    public UserInfo getUserInfo(String userNamethrows Exception
    {
        PropertyUserStore propertyUserStore = .get();
        if (propertyUserStore == null)
            throw new IllegalStateException("PropertyUserStore should never be null here!");
        
        .debug("Checking PropertyUserStore "++" for "+userName);
        UserIdentity userIdentity = propertyUserStore.getUserIdentity(userName);
        if (userIdentity==null)
            return null;
        Set<Principalprincipals = userIdentity.getSubject().getPrincipals();
        List<Stringroles = new ArrayList<String>();
        for ( Principal principal : principals )
        {
            roles.addprincipal.getName() );
        }
        Credential credential = (Credential)userIdentity.getSubject().getPrivateCredentials().iterator().next();
        .debug("Found: " + userName + " in PropertyUserStore "+);
        return new UserInfo(userNamecredentialroles);
    }
New to GrepCode? Check out our FAQ X