//# 2 errors, 43 messages
//#
package org.apache.roller.weblogger.ui.core.security;
    //#RollerUserDetailsService.java:1:1: class: org.apache.roller.weblogger.ui.core.security.RollerUserDetailsService
    //#RollerUserDetailsService.java:1:1: method: org.apache.roller.weblogger.ui.core.security.RollerUserDetailsService.org.apache.roller.weblogger.ui.core.security.RollerUserDetailsService__static_init

import java.util.Iterator;
import org.acegisecurity.GrantedAuthority;
import org.acegisecurity.GrantedAuthorityImpl;
import org.acegisecurity.userdetails.UserDetails;
import org.acegisecurity.userdetails.UserDetailsService;
import org.acegisecurity.userdetails.UsernameNotFoundException;
import org.apache.roller.weblogger.WebloggerException;
import org.apache.roller.weblogger.business.Weblogger;
import org.apache.roller.weblogger.business.WebloggerFactory;
import org.apache.roller.weblogger.business.UserManager;
import org.apache.roller.weblogger.pojos.UserRole;
import org.apache.roller.weblogger.pojos.User;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.DataRetrievalFailureException;

/**
 * Acegi user details service implemented using Weblogger API.
 */
public class RollerUserDetailsService implements UserDetailsService {
    //#RollerUserDetailsService.java:21: method: void org.apache.roller.weblogger.ui.core.security.RollerUserDetailsService.org.apache.roller.weblogger.ui.core.security.RollerUserDetailsService()
    //#RollerUserDetailsService.java:21: end of method: void org.apache.roller.weblogger.ui.core.security.RollerUserDetailsService.org.apache.roller.weblogger.ui.core.security.RollerUserDetailsService()

    public UserDetails loadUserByUsername(String userName) 
        throws UsernameNotFoundException, DataAccessException {
        
        User userData = null;
    //#RollerUserDetailsService.java:26: method: UserDetails org.apache.roller.weblogger.ui.core.security.RollerUserDetailsService.loadUserByUsername(String)
    //#RollerUserDetailsService.java:26: Warning: unused assignment
    //#    unused assignment into userData
    //#    severity: SUPPRESSED
    //#    class: org.apache.roller.weblogger.ui.core.security.RollerUserDetailsService
    //#    method: UserDetails loadUserByUsername(String)
    //#    Attribs:  Uncertain
    //#input(UserDetails loadUserByUsername(String)): "ERROR no user: "._tainted
    //#input(UserDetails loadUserByUsername(String)): java.lang.Boolean.TRUE
    //#input(UserDetails loadUserByUsername(String)): userName
    //#input(UserDetails loadUserByUsername(String)): userName._tainted
    //#output(UserDetails loadUserByUsername(String)): new User(loadUserByUsername#6) num objects
    //#output(UserDetails loadUserByUsername(String)): return_value
    //#new obj(UserDetails loadUserByUsername(String)): new User(loadUserByUsername#6)
    //#presumption(UserDetails loadUserByUsername(String)): init'ed(java.lang.Boolean.TRUE)
    //#presumption(UserDetails loadUserByUsername(String)): java.util.Iterator:next(...)@43 != null
    //#presumption(UserDetails loadUserByUsername(String)): java.util.Set:size(...)@39 >= 1
    //#presumption(UserDetails loadUserByUsername(String)): org.apache.roller.weblogger.business.UserManager:getUserByUserName(...)@30 != null
    //#presumption(UserDetails loadUserByUsername(String)): org.apache.roller.weblogger.business.Weblogger:getUserManager(...)@29 != null
    //#presumption(UserDetails loadUserByUsername(String)): org.apache.roller.weblogger.business.WebloggerFactory:getWeblogger(...)@28 != null
    //#presumption(UserDetails loadUserByUsername(String)): org.apache.roller.weblogger.pojos.User:getRoles(...)@39 != null
    //#presumption(UserDetails loadUserByUsername(String)): org.apache.roller.weblogger.pojos.User:getRoles(...)@42 != null
    //#post(UserDetails loadUserByUsername(String)): return_value == &new User(loadUserByUsername#6)
    //#post(UserDetails loadUserByUsername(String)): new User(loadUserByUsername#6) num objects == 1
    //#test_vector(UserDetails loadUserByUsername(String)): java.util.Iterator:hasNext(...)@42: {0}, {1}
        try {
            Weblogger roller = WebloggerFactory.getWeblogger();
    //#RollerUserDetailsService.java:28: Warning: method not available
    //#    -- call on Weblogger org.apache.roller.weblogger.business.WebloggerFactory:getWeblogger()
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.core.security.RollerUserDetailsService
    //#    method: UserDetails loadUserByUsername(String)
    //#    unanalyzed callee: Weblogger org.apache.roller.weblogger.business.WebloggerFactory:getWeblogger()
            UserManager umgr = roller.getUserManager();
    //#RollerUserDetailsService.java:29: Warning: method not available
    //#    -- call on UserManager org.apache.roller.weblogger.business.Weblogger:getUserManager()
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.core.security.RollerUserDetailsService
    //#    method: UserDetails loadUserByUsername(String)
    //#    unanalyzed callee: UserManager org.apache.roller.weblogger.business.Weblogger:getUserManager()
            userData = umgr.getUserByUserName(userName, Boolean.TRUE); 
    //#RollerUserDetailsService.java:30: Warning: method not available
    //#    -- call on User org.apache.roller.weblogger.business.UserManager:getUserByUserName(String, Boolean)
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.core.security.RollerUserDetailsService
    //#    method: UserDetails loadUserByUsername(String)
    //#    unanalyzed callee: User org.apache.roller.weblogger.business.UserManager:getUserByUserName(String, Boolean)
        } catch (WebloggerException ex) {
            throw new DataRetrievalFailureException("ERROR in user lookup", ex);
        } 
        
        if (userData == null) {
            throw new UsernameNotFoundException("ERROR no user: " + userName);
        }
        
        GrantedAuthority[] authorities = 
    //#RollerUserDetailsService.java:39: Warning: method not available
    //#    -- call on Set org.apache.roller.weblogger.pojos.User:getRoles()
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.core.security.RollerUserDetailsService
    //#    method: UserDetails loadUserByUsername(String)
    //#    unanalyzed callee: Set org.apache.roller.weblogger.pojos.User:getRoles()
            new GrantedAuthorityImpl[userData.getRoles().size()];
        int i = 0;
        for (Iterator it = userData.getRoles().iterator(); it.hasNext();) {
    //#RollerUserDetailsService.java:42: Warning: method not available
    //#    -- call on Set org.apache.roller.weblogger.pojos.User:getRoles()
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.core.security.RollerUserDetailsService
    //#    method: UserDetails loadUserByUsername(String)
    //#    unanalyzed callee: Set org.apache.roller.weblogger.pojos.User:getRoles()
            UserRole role = (UserRole)it.next();
            authorities[i++] = new GrantedAuthorityImpl(role.getRole());
    //#RollerUserDetailsService.java:44: ?overflow
    //#    i in -2_147_483_649..4_294_967_294
    //#    severity: LOW
    //#    class: org.apache.roller.weblogger.ui.core.security.RollerUserDetailsService
    //#    method: UserDetails loadUserByUsername(String)
    //#    basic block: bb_8
    //#    assertion: i in -2_147_483_649..4_294_967_294
    //#    VN: i + 1
    //#    Expected: {-2_147_483_648..4_294_967_295, Invalid}
    //#    Bad: {4_294_967_296}
    //#    Attribs:  Int  Bad singleton  Bad > Exp
    //#RollerUserDetailsService.java:44: Warning: method not available
    //#    -- call on String org.apache.roller.weblogger.pojos.UserRole:getRole()
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.core.security.RollerUserDetailsService
    //#    method: UserDetails loadUserByUsername(String)
    //#    unanalyzed callee: String org.apache.roller.weblogger.pojos.UserRole:getRole()
    //#RollerUserDetailsService.java:44: Warning: method not available
    //#    -- call on void org.acegisecurity.GrantedAuthorityImpl(String)
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.core.security.RollerUserDetailsService
    //#    method: UserDetails loadUserByUsername(String)
    //#    unanalyzed callee: void org.acegisecurity.GrantedAuthorityImpl(String)
    //#RollerUserDetailsService.java:44: ?array index out of bounds
    //#    i < authorities.length
    //#    severity: MEDIUM
    //#    class: org.apache.roller.weblogger.ui.core.security.RollerUserDetailsService
    //#    method: UserDetails loadUserByUsername(String)
    //#    basic block: bb_8
    //#    assertion: i < authorities.length
    //#    VN: -(i - java.util.Set:size(...)@39)
    //#    Expected: {1..+Inf}
    //#    Bad: {0}
    //#    Attribs:  Int  Bad singleton  Bad overlaps +/-1000  Bad < Exp
        }
        
        return new org.acegisecurity.userdetails.User(
    //#RollerUserDetailsService.java:47: Warning: method not available
    //#    -- call on String org.apache.roller.weblogger.pojos.User:getUserName()
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.core.security.RollerUserDetailsService
    //#    method: UserDetails loadUserByUsername(String)
    //#    unanalyzed callee: String org.apache.roller.weblogger.pojos.User:getUserName()
    //#RollerUserDetailsService.java:47: Warning: method not available
    //#    -- call on String org.apache.roller.weblogger.pojos.User:getPassword()
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.core.security.RollerUserDetailsService
    //#    method: UserDetails loadUserByUsername(String)
    //#    unanalyzed callee: String org.apache.roller.weblogger.pojos.User:getPassword()
    //#RollerUserDetailsService.java:47: Warning: method not available
    //#    -- call on void org.acegisecurity.userdetails.User(String, String, bool, GrantedAuthority[])
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.core.security.RollerUserDetailsService
    //#    method: UserDetails loadUserByUsername(String)
    //#    unanalyzed callee: void org.acegisecurity.userdetails.User(String, String, bool, GrantedAuthority[])
    //#RollerUserDetailsService.java:47: end of method: UserDetails org.apache.roller.weblogger.ui.core.security.RollerUserDetailsService.loadUserByUsername(String)
            userData.getUserName(), userData.getPassword(), true, authorities);
    }
    
}
    //#output(org.apache.roller.weblogger.ui.core.security.RollerUserDetailsService__static_init): __Descendant_Table[org/apache/roller/weblogger/ui/core/security/RollerUserDetailsService]
    //#output(org.apache.roller.weblogger.ui.core.security.RollerUserDetailsService__static_init): __Dispatch_Table.loadUserByUsername(Ljava/lang/String;)Lorg/acegisecurity/userdetails/UserDetails;
    //#post(org.apache.roller.weblogger.ui.core.security.RollerUserDetailsService__static_init): __Descendant_Table[org/apache/roller/weblogger/ui/core/security/RollerUserDetailsService] == &__Dispatch_Table
    //#post(org.apache.roller.weblogger.ui.core.security.RollerUserDetailsService__static_init): __Dispatch_Table.loadUserByUsername(Ljava/lang/String;)Lorg/acegisecurity/userdetails/UserDetails; == &loadUserByUsername
    //#RollerUserDetailsService.java:: end of method: org.apache.roller.weblogger.ui.core.security.RollerUserDetailsService.org.apache.roller.weblogger.ui.core.security.RollerUserDetailsService__static_init
    //#RollerUserDetailsService.java:: end of class: org.apache.roller.weblogger.ui.core.security.RollerUserDetailsService
