File Source: defaultuserdetailsservice.java

     1  package net.sourceforge.pebble.security;
     2  
     3  import org.acegisecurity.userdetails.UserDetails;
     4  import org.acegisecurity.userdetails.UserDetailsService;
     5  import org.acegisecurity.userdetails.UsernameNotFoundException;
     6  import org.apache.commons.logging.Log;
     7  import org.apache.commons.logging.LogFactory;
     8  
     9  /**
    10   * Implementation of the UserDetailsService that gets authentication
    11   * credentials from a SecurityRealm implementation.
    12   *
    13   * @author    Simon Brown
    14   */
         /* 
    P/P   *  Method: void net.sourceforge.pebble.security.DefaultUserDetailsService()
          */
    15  public class DefaultUserDetailsService implements UserDetailsService {
    16  
           /* 
    P/P     *  Method: net.sourceforge.pebble.security.DefaultUserDetailsService__static_init
            * 
            *  Postconditions:
            *    init'ed(log)
            */
    17    private static final Log log = LogFactory.getLog(DefaultUserDetailsService.class);
    18  
    19    private SecurityRealm securityRealm;
    20  
    21    /**
    22     * Looks up and returns user details for the given username.
    23     *
    24     * @param username    the username to find details for
    25     * @return  a PebbleUserDetails instance
    26     * @throws org.acegisecurity.userdetails.UsernameNotFoundException
    27     */
    28    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
    29      try {
               /* 
    P/P         *  Method: UserDetails loadUserByUsername(String)
                * 
                *  Preconditions:
                *    this.securityRealm != null
                *    this.securityRealm.configuration != null
                * 
                *  Presumptions:
                *    java.io.File:exists(...)@103 == 1
                *    java.util.Iterator:hasNext(...)@126 == 0
                * 
                *  Postconditions:
                *    return_value == &new PebbleUserDetails(getUser#4)
                *    new HashMap(PebbleUserDetails#1) num objects == 1
                *    new HashMap(getUser#3) num objects == 1
                *    new PebbleUserDetails(getUser#4) num objects == 1
                *    init'ed(new PebbleUserDetails(getUser#4).detailsUpdateable)
                *    init'ed(new PebbleUserDetails(getUser#4).emailAddress)
                *    init'ed(new PebbleUserDetails(getUser#4).grantedAuthories)
                *    init'ed(new PebbleUserDetails(getUser#4).name)
                *    init'ed(new PebbleUserDetails(getUser#4).password)
                *    new PebbleUserDetails(getUser#4).preferences == &new HashMap(getUser#3)
                *    ...
                */
    30        PebbleUserDetails user = securityRealm.getUser(username);
    31        if (user == null) {
    32          throw new UsernameNotFoundException("A user with username " + username + " does not exist");
    33        } else {
    34          return user;
    35        }
    36      } catch (SecurityRealmException e) {
    37        throw new UsernameNotFoundException("User details not found", e);
    38      }
    39    }
    40  
    41    public SecurityRealm getSecurityRealm() {
             /* 
    P/P       *  Method: SecurityRealm getSecurityRealm()
              * 
              *  Preconditions:
              *    init'ed(this.securityRealm)
              * 
              *  Postconditions:
              *    return_value == this.securityRealm
              *    init'ed(return_value)
              */
    42      return securityRealm;
    43    }
    44  
    45    public void setSecurityRealm(SecurityRealm securityRealm) {
             /* 
    P/P       *  Method: void setSecurityRealm(SecurityRealm)
              * 
              *  Postconditions:
              *    this.securityRealm == securityRealm
              *    init'ed(this.securityRealm)
              */
    46      this.securityRealm = securityRealm;
    47    }
    48  
    49  }








SofCheck Inspector Build Version : 2.22510
defaultuserdetailsservice.java 2010-Jun-25 19:40:32
defaultuserdetailsservice.class 2010-Jul-19 20:23:38