Search in sources :

Example 6 with UserDetails

use of org.acegisecurity.userdetails.UserDetails in project blueocean-plugin by jenkinsci.

the class PipelineBaseTest method login.

protected User login(String userId, String fullName, String email) throws IOException {
    j.jenkins.setSecurityRealm(j.createDummySecurityRealm());
    hudson.model.User bob = User.get(userId);
    bob.setFullName(fullName);
    if (email != null) {
        bob.addProperty(new Mailer.UserProperty(email));
    }
    UserDetails d = Jenkins.getInstance().getSecurityRealm().loadUserByUsername(bob.getId());
    SecurityContextHolder.getContext().setAuthentication(new PrincipalAcegiUserToken(bob.getId(), bob.getId(), bob.getId(), d.getAuthorities(), bob.getId()));
    return bob;
}
Also used : UserDetails(org.acegisecurity.userdetails.UserDetails) Mailer(hudson.tasks.Mailer) User(hudson.model.User) PrincipalAcegiUserToken(org.acegisecurity.adapters.PrincipalAcegiUserToken)

Example 7 with UserDetails

use of org.acegisecurity.userdetails.UserDetails in project blueocean-plugin by jenkinsci.

the class BaseTest method login.

protected User login(String userId, String fullName, String email) throws IOException {
    j.jenkins.setSecurityRealm(j.createDummySecurityRealm());
    hudson.model.User bob = User.get(userId);
    bob.setFullName(fullName);
    bob.addProperty(new Mailer.UserProperty(email));
    UserDetails d = Jenkins.getInstance().getSecurityRealm().loadUserByUsername(bob.getId());
    SecurityContextHolder.getContext().setAuthentication(new PrincipalAcegiUserToken(bob.getId(), bob.getId(), bob.getId(), d.getAuthorities(), bob.getId()));
    return bob;
}
Also used : UserDetails(org.acegisecurity.userdetails.UserDetails) Mailer(hudson.tasks.Mailer) User(hudson.model.User) PrincipalAcegiUserToken(org.acegisecurity.adapters.PrincipalAcegiUserToken)

Example 8 with UserDetails

use of org.acegisecurity.userdetails.UserDetails in project blueocean-plugin by jenkinsci.

the class ProfileApiTest method testPermissionOfOtherUser.

@Test
public void testPermissionOfOtherUser() throws IOException {
    j.jenkins.setSecurityRealm(j.createDummySecurityRealm());
    hudson.model.User alice = User.get("alice");
    alice.setFullName("Alice Cooper");
    alice.addProperty(new Mailer.UserProperty("alice@jenkins-ci.org"));
    hudson.model.User bob = User.get("bob");
    bob.setFullName("Bob Cooper");
    bob.addProperty(new Mailer.UserProperty("bob@jenkins-ci.org"));
    UserDetails d = Jenkins.getInstance().getSecurityRealm().loadUserByUsername(bob.getId());
    SecurityContextHolder.getContext().setAuthentication(new PrincipalAcegiUserToken(bob.getId(), bob.getId(), bob.getId(), d.getAuthorities(), bob.getId()));
    Assert.assertNull(new UserImpl(Iterables.getFirst(OrganizationFactory.getInstance().list(), null), alice).getPermission());
}
Also used : UserDetails(org.acegisecurity.userdetails.UserDetails) UserImpl(io.jenkins.blueocean.service.embedded.rest.UserImpl) Mailer(hudson.tasks.Mailer) User(hudson.model.User) PrincipalAcegiUserToken(org.acegisecurity.adapters.PrincipalAcegiUserToken) Test(org.junit.Test)

Aggregations

UserDetails (org.acegisecurity.userdetails.UserDetails)8 User (hudson.model.User)4 Mailer (hudson.tasks.Mailer)4 PrincipalAcegiUserToken (org.acegisecurity.adapters.PrincipalAcegiUserToken)4 Hudson (hudson.model.Hudson)2 DataAccessException (org.springframework.dao.DataAccessException)2 Binding (groovy.lang.Binding)1 Secret (hudson.util.Secret)1 BeanBuilder (hudson.util.spring.BeanBuilder)1 UserImpl (io.jenkins.blueocean.service.embedded.rest.UserImpl)1 AuthenticationException (org.acegisecurity.AuthenticationException)1 AuthenticationManager (org.acegisecurity.AuthenticationManager)1 GrantedAuthority (org.acegisecurity.GrantedAuthority)1 UsernamePasswordAuthenticationToken (org.acegisecurity.providers.UsernamePasswordAuthenticationToken)1 User (org.acegisecurity.userdetails.User)1 UserDetailsService (org.acegisecurity.userdetails.UserDetailsService)1 UsernameNotFoundException (org.acegisecurity.userdetails.UsernameNotFoundException)1 Test (org.junit.Test)1 UnixUser (org.jvnet.libpam.UnixUser)1 WebApplicationContext (org.springframework.web.context.WebApplicationContext)1