Exemplo n.º 1
0
  protected void initContext(String customerName, String user, String login) {
    customer = new Customer(customerName);
    AppContext rootctx = ServiceUtils.getInstance().getRootUserContext(customer.getCustomerId());
    customer = customerService.store(rootctx, customer);
    String customerId = customer.getCustomerId();

    // add a owner
    User owner = new User(new UserPK(customer.getCustomerId()), "super", "squ1d4you");
    owner.setEmail("*****@*****.**");
    userService.store(rootctx, owner);
    AccessRight ownerRight = new AccessRight(Role.OWNER, owner.getId().getUserId(), null);
    customer.getAccessRights().add(ownerRight);
    customerService.store(rootctx, customer);
    AppContext ownerCtx = new AppContext.Builder(customerId, owner).build();

    // add a write user which will be our project owner
    User writeUser = new User(new UserPK(customer.getCustomerId()), "user1", "user14you");
    writeUser.setEmail("*****@*****.**");
    userService.store(ownerCtx, writeUser);
    customer
        .getAccessRights()
        .add(new AccessRight(Role.WRITE, writeUser.getId().getUserId(), null));

    // add a write user which will be allowed to create its own project (but read others)
    User writeUser2 = new User(new UserPK(customer.getCustomerId()), "user", "user4you");
    writeUser2.setEmail("*****@*****.**");
    userService.store(ownerCtx, writeUser2);
    customer
        .getAccessRights()
        .add(new AccessRight(Role.READ, writeUser2.getId().getUserId(), null));

    // add a read user
    User readUser = new User(new UserPK(customer.getCustomerId()), "guest", "guest4you");
    readUser.setEmail("*****@*****.**");
    userService.store(ownerCtx, readUser);
    customer.getAccessRights().add(new AccessRight(Role.READ, readUser.getId().getUserId(), null));

    ClientPK clientPK = new ClientPK(customer.getCustomerId(), "admin_console");
    Client client = new Client(clientPK, "squid", "secret", new ArrayList<String>());
    client = ClientServiceBaseImpl.getInstance().store(ownerCtx, client);

    customerService.store(ownerCtx, customer);

    System.out.println(
        "customerId : " + customerId + " clientId : " + client.getId().getClientId());

    ctx = new AppContext.Builder(customerId, writeUser).build();
  }
Exemplo n.º 2
0
 /**
  * create an user as owner of the givent project
  *
  * @param project
  * @param string
  * @param string2
  * @return
  */
 public User User(Project project, String name, String login) {
   // add a owner
   User owner = new User(new UserPK(ctx.getCustomerId()), name, login);
   UserServiceBaseImpl.getInstance().store(ctx, owner);
   AccessRight ownerRight = new AccessRight(Role.OWNER, owner.getId().getUserId(), null);
   customer.getAccessRights().add(ownerRight);
   AppContext ownerCtx = new AppContext.Builder(ctx.getCustomerId(), owner).build();
   CustomerServiceBaseImpl.getInstance().store(ownerCtx, customer);
   return owner;
 }