Search in sources :

Example 26 with User

use of org.candlepin.model.User in project candlepin by candlepin.

the class AdminResource method initialize.

@GET
@Produces({ MediaType.TEXT_PLAIN })
@Path("init")
@SecurityHole(noAuth = true)
@ApiOperation(notes = "Initializes the Candlepin database. Currently this just" + " creates the admin user for standalone deployments using the" + " default user service adapter. It must be called once after" + " candlepin is installed, repeat calls are not required, but" + " will be harmless. The String returned is the description if" + " the db was or already is initialized.", value = "initialize")
public String initialize() {
    log.debug("Called initialize()");
    log.info("Initializing Candlepin database.");
    // the default user service adapter, and no other users exist already:
    if (userService instanceof DefaultUserServiceAdapter && userCurator.getUserCount() == 0) {
        // Push the system principal so we can create all these entries as a
        // superuser:
        ResteasyProviderFactory.pushContext(Principal.class, new SystemPrincipal());
        log.info("Creating default super admin.");
        User defaultAdmin = new User("admin", "admin", true);
        userService.createUser(defaultAdmin);
        return "Initialized!";
    } else {
        // Any other user service adapter and we really have nothing to do:
        return "Already initialized.";
    }
}
Also used : DefaultUserServiceAdapter(org.candlepin.service.impl.DefaultUserServiceAdapter) User(org.candlepin.model.User) SystemPrincipal(org.candlepin.auth.SystemPrincipal) Path(javax.ws.rs.Path) SecurityHole(org.candlepin.common.auth.SecurityHole) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation)

Example 27 with User

use of org.candlepin.model.User in project candlepin by candlepin.

the class KatelloUserServiceAdapterTest method addUserToRole.

@Test(expected = UnsupportedOperationException.class)
public void addUserToRole() throws Exception {
    Role r = mock(Role.class);
    User user = mock(User.class);
    kusa.addUserToRole(r, user);
}
Also used : Role(org.candlepin.model.Role) User(org.candlepin.model.User) Test(org.junit.Test)

Example 28 with User

use of org.candlepin.model.User in project candlepin by candlepin.

the class KatelloUserServiceAdapterTest method removeUserFromRole.

@Test(expected = UnsupportedOperationException.class)
public void removeUserFromRole() throws Exception {
    Role r = mock(Role.class);
    User user = mock(User.class);
    kusa.removeUserFromRole(r, user);
}
Also used : Role(org.candlepin.model.Role) User(org.candlepin.model.User) Test(org.junit.Test)

Example 29 with User

use of org.candlepin.model.User in project candlepin by candlepin.

the class KatelloUserServiceAdapterTest method createUser.

@Test(expected = UnsupportedOperationException.class)
public void createUser() throws Exception {
    User user = mock(User.class);
    kusa.createUser(user);
}
Also used : User(org.candlepin.model.User) Test(org.junit.Test)

Example 30 with User

use of org.candlepin.model.User in project candlepin by candlepin.

the class UserResourceTest method testLookupUser.

@Test
public void testLookupUser() {
    User user = new User();
    user.setUsername("henri");
    user.setPassword("password");
    userResource.createUser(user);
    User u = userResource.getUserInfo("henri");
    assertEquals(user.getId(), u.getId());
}
Also used : User(org.candlepin.model.User) Test(org.junit.Test)

Aggregations

User (org.candlepin.model.User)49 Test (org.junit.Test)33 Role (org.candlepin.model.Role)14 Owner (org.candlepin.model.Owner)13 HashSet (java.util.HashSet)11 UserPrincipal (org.candlepin.auth.UserPrincipal)10 Principal (org.candlepin.auth.Principal)7 OwnerPermission (org.candlepin.auth.permissions.OwnerPermission)6 PermissionBlueprint (org.candlepin.model.PermissionBlueprint)6 Consumer (org.candlepin.model.Consumer)5 Before (org.junit.Before)5 ApiOperation (io.swagger.annotations.ApiOperation)4 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4 LinkedList (java.util.LinkedList)3 Permission (org.candlepin.auth.permissions.Permission)3 ConsumerType (org.candlepin.model.ConsumerType)3 Ignore (org.junit.Ignore)3 ApiResponses (io.swagger.annotations.ApiResponses)2 Method (java.lang.reflect.Method)2