All Downloads are FREE. Search and download functionalities are using the official Maven repository.

hudson.plugins.sfee.SFEEUserDetailsService Maven / Gradle / Ivy

Go to download

This plugin integrates Hudson with a Source Forge Enterprise Edition (SFEE) Server

There is a newer version: 1.0.4
Show newest version
package hudson.plugins.sfee;

import hudson.plugins.sfee.webservice.ProjectSoapRow;
import hudson.plugins.sfee.webservice.UserSoapDO;

import java.util.HashSet;
import java.util.Set;

import org.acegisecurity.BadCredentialsException;
import org.acegisecurity.GrantedAuthority;
import org.acegisecurity.GrantedAuthorityImpl;
import org.acegisecurity.userdetails.User;
import org.acegisecurity.userdetails.UserDetails;
import org.acegisecurity.userdetails.UserDetailsService;
import org.acegisecurity.userdetails.UsernameNotFoundException;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.DataRetrievalFailureException;

public class SFEEUserDetailsService implements UserDetailsService {

	public UserDetails loadUserByUsername(String username)
			throws UsernameNotFoundException, DataAccessException {
		SourceForgeSite site = SourceForgeSite.DESCRIPTOR.getSite();
		Set authorities = new HashSet();
		authorities.add(new GrantedAuthorityImpl("authenticated"));

		String password = SFEESecurityRealm.DESCRIPTOR.getPassword(username);
		if (password == null) {
			throw new UsernameNotFoundException(
					"Password not known for this user - please login");
		}

		try {
			String sessionId = site.createSession(username, password);

			UserSoapDO userDetails = site.getUserDetails(username);
			if (userDetails.isSuperUser()) {
				authorities.add(new GrantedAuthorityImpl("admin"));
			}
			ProjectSoapRow[] projects = site.getProjects(sessionId);
			for (ProjectSoapRow project : projects) {
				authorities.add(new GrantedAuthorityImpl(project.getId()));
			}

			GrantedAuthority[] authoritiesArray = (GrantedAuthority[]) authorities
					.toArray(new GrantedAuthority[authorities.size()]);

			return new User(username, password, true, true, true, true,
					authoritiesArray);
		} catch (BadCredentialsException e) {
			throw e;
		} catch (Exception e) {
			throw new DataRetrievalFailureException("SFEE error", e);
		}
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy