//# 0 errors, 31 messages
//#
/*
    //#RollerCasPopulator.java:1:1: class: org.apache.roller.weblogger.ui.core.security.RollerCasPopulator
* Licensed to the Apache Software Foundation (ASF) under one or more
*  contributor license agreements.  The ASF licenses this file to You
* under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.  For additional information regarding
* copyright in this work, please see the NOTICE file in the top level
* directory of this distribution.
*/
package org.apache.roller.weblogger.ui.core.security;

import org.acegisecurity.AuthenticationException;
import org.acegisecurity.GrantedAuthority;
import org.acegisecurity.GrantedAuthorityImpl;
import org.acegisecurity.providers.cas.CasAuthoritiesPopulator;
import org.acegisecurity.userdetails.User;
import org.acegisecurity.userdetails.UserDetails;
import org.acegisecurity.userdetails.UserDetailsService;
import org.apache.log4j.Logger;

/**
 * An implementation of CasAuthoritiesPopulator that uses a UserDetailsService to retrieve
 * User object from RollerDB. 
 * 
 * @author Phillip Rhodes (<a href="mailto:mindcrime@cpphacker.co.uk">mindcrime@cpphacker.co.uk</a>)
 */
public class RollerCasPopulator implements CasAuthoritiesPopulator {
    //#RollerCasPopulator.java:35: method: void org.apache.roller.weblogger.ui.core.security.RollerCasPopulator.org.apache.roller.weblogger.ui.core.security.RollerCasPopulator()
    //#RollerCasPopulator.java:35: end of method: void org.apache.roller.weblogger.ui.core.security.RollerCasPopulator.org.apache.roller.weblogger.ui.core.security.RollerCasPopulator()
    private static final Logger logger = Logger.getLogger(RollerCasPopulator.class);
    //#RollerCasPopulator.java:36: method: org.apache.roller.weblogger.ui.core.security.RollerCasPopulator.org.apache.roller.weblogger.ui.core.security.RollerCasPopulator__static_init
    //#RollerCasPopulator.java:36: Warning: method not available
    //#    -- call on Logger org.apache.log4j.Logger:getLogger(Class)
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.core.security.RollerCasPopulator
    //#    method: org.apache.roller.weblogger.ui.core.security.RollerCasPopulator__static_init
    //#    unanalyzed callee: Logger org.apache.log4j.Logger:getLogger(Class)
    //#output(org.apache.roller.weblogger.ui.core.security.RollerCasPopulator__static_init): __Descendant_Table[org/apache/roller/weblogger/ui/core/security/RollerCasPopulator]
    //#output(org.apache.roller.weblogger.ui.core.security.RollerCasPopulator__static_init): __Dispatch_Table.getUserDetails(Ljava/lang/String;)Lorg/acegisecurity/userdetails/UserDetails;
    //#output(org.apache.roller.weblogger.ui.core.security.RollerCasPopulator__static_init): __Dispatch_Table.setUserDetailsService(Lorg/acegisecurity/userdetails/UserDetailsService;)V
    //#output(org.apache.roller.weblogger.ui.core.security.RollerCasPopulator__static_init): logger
    //#post(org.apache.roller.weblogger.ui.core.security.RollerCasPopulator__static_init): __Descendant_Table[org/apache/roller/weblogger/ui/core/security/RollerCasPopulator] == &__Dispatch_Table
    //#post(org.apache.roller.weblogger.ui.core.security.RollerCasPopulator__static_init): __Dispatch_Table.getUserDetails(Ljava/lang/String;)Lorg/acegisecurity/userdetails/UserDetails; == &getUserDetails
    //#post(org.apache.roller.weblogger.ui.core.security.RollerCasPopulator__static_init): __Dispatch_Table.setUserDetailsService(Lorg/acegisecurity/userdetails/UserDetailsService;)V == &setUserDetailsService
    //#post(org.apache.roller.weblogger.ui.core.security.RollerCasPopulator__static_init): init'ed(logger)
    //#RollerCasPopulator.java:36: end of method: org.apache.roller.weblogger.ui.core.security.RollerCasPopulator.org.apache.roller.weblogger.ui.core.security.RollerCasPopulator__static_init
    private UserDetailsService userDetailsService;

    public void setUserDetailsService(UserDetailsService userDetailsService) {
        this.userDetailsService = userDetailsService;
    //#RollerCasPopulator.java:40: method: void org.apache.roller.weblogger.ui.core.security.RollerCasPopulator.setUserDetailsService(UserDetailsService)
    //#input(void setUserDetailsService(UserDetailsService)): this
    //#input(void setUserDetailsService(UserDetailsService)): userDetailsService
    //#output(void setUserDetailsService(UserDetailsService)): this.userDetailsService
    //#post(void setUserDetailsService(UserDetailsService)): this.userDetailsService == userDetailsService
    //#post(void setUserDetailsService(UserDetailsService)): init'ed(this.userDetailsService)
    }
    //#RollerCasPopulator.java:41: end of method: void org.apache.roller.weblogger.ui.core.security.RollerCasPopulator.setUserDetailsService(UserDetailsService)

    public UserDetails getUserDetails(String userName) throws AuthenticationException {
        User userObject = (User) userDetailsService.loadUserByUsername(userName);
    //#RollerCasPopulator.java:44: method: UserDetails org.apache.roller.weblogger.ui.core.security.RollerCasPopulator.getUserDetails(String)
    //#RollerCasPopulator.java:44: Warning: method not available
    //#    -- call on UserDetails org.acegisecurity.userdetails.UserDetailsService:loadUserByUsername(String)
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.core.security.RollerCasPopulator
    //#    method: UserDetails getUserDetails(String)
    //#    unanalyzed callee: UserDetails org.acegisecurity.userdetails.UserDetailsService:loadUserByUsername(String)
    //#input(UserDetails getUserDetails(String)): this
    //#input(UserDetails getUserDetails(String)): this.userDetailsService
    //#input(UserDetails getUserDetails(String)): userName
    //#output(UserDetails getUserDetails(String)): return_value
    //#pre[2] (UserDetails getUserDetails(String)): this.userDetailsService != null
    //#post(UserDetails getUserDetails(String)): init'ed(return_value)

        // in  a more sophisticated implementation we would look up and insert
        // GrantedAuthoritys here.

        return userObject;
    //#RollerCasPopulator.java:49: end of method: UserDetails org.apache.roller.weblogger.ui.core.security.RollerCasPopulator.getUserDetails(String)
    }
}    //#RollerCasPopulator.java:: end of class: org.apache.roller.weblogger.ui.core.security.RollerCasPopulator
