Search in sources :

Example 6 with Account

use of net.nemerosa.ontrack.model.security.Account in project ontrack by nemerosa.

the class BuildFilterServiceIT method delete_shared_filter.

@Test
public void delete_shared_filter() throws Exception {
    // Branch
    Branch branch = doCreateBranch();
    // Account for the tests
    Account account = doCreateAccount();
    // Creates a shared filter for this account
    Ack ack = asAccount(account).with(branch, BranchFilterMgt.class).call(() -> buildFilterService.saveFilter(branch.getId(), // Shared
    true, "MyFilter", NamedBuildFilterProvider.class.getName(), objectMapper.valueToTree(NamedBuildFilterData.of("1"))));
    assertTrue("Account filter saved", ack.isSuccess());
    // The filter is present for this account
    Collection<BuildFilterResource<?>> filters = asAccount(account).withView(branch).call(() -> buildFilterService.getBuildFilters(branch.getId()));
    assertEquals(1, filters.size());
    BuildFilterResource<?> filter = filters.iterator().next();
    assertEquals("MyFilter", filter.getName());
    assertTrue(filter.isShared());
    // ... and that it is available also for not logged users
    filters = asUser().withId(10).withView(branch).call(() -> buildFilterService.getBuildFilters(branch.getId()));
    assertEquals("Account filter available for everybody else", 1, filters.size());
    filter = filters.iterator().next();
    assertEquals("MyFilter", filter.getName());
    assertTrue(filter.isShared());
    // Deletes the filter
    asAccount(account).call(() -> buildFilterService.deleteFilter(branch.getId(), "MyFilter"));
    // The filter is no longer there for the account
    filters = asAccount(account).withView(branch).call(() -> buildFilterService.getBuildFilters(branch.getId()));
    assertEquals(0, filters.size());
    // ... not for unlogged users
    filters = asUser().withId(10).withView(branch).call(() -> buildFilterService.getBuildFilters(branch.getId()));
    assertEquals("Account filter not available for everybody else", 0, filters.size());
}
Also used : Account(net.nemerosa.ontrack.model.security.Account) Branch(net.nemerosa.ontrack.model.structure.Branch) BuildFilterResource(net.nemerosa.ontrack.model.buildfilter.BuildFilterResource) Ack(net.nemerosa.ontrack.model.Ack) BranchFilterMgt(net.nemerosa.ontrack.model.security.BranchFilterMgt) Test(org.junit.Test)

Example 7 with Account

use of net.nemerosa.ontrack.model.security.Account in project ontrack by nemerosa.

the class BuildFilterServiceIT method saveFilter_shared_after_account_one.

/**
 * Checks that sharing a saved filter overrides the account specific one.
 */
@Test
public void saveFilter_shared_after_account_one() throws Exception {
    // Branch
    Branch branch = doCreateBranch();
    // Account for the tests
    Account account = doCreateAccount();
    Account otherAccount = doCreateAccount();
    // Creates a filter for this account
    Ack ack = asAccount(account).call(() -> buildFilterService.saveFilter(branch.getId(), false, "MyFilter", NamedBuildFilterProvider.class.getName(), objectMapper.valueToTree(NamedBuildFilterData.of("1"))));
    assertTrue("Account filter saved", ack.isSuccess());
    // Makes sure we find this filter back when logged
    Collection<BuildFilterResource<?>> filters = asAccount(account).withView(branch).call(() -> buildFilterService.getBuildFilters(branch.getId()));
    assertEquals(1, filters.size());
    BuildFilterResource<?> filter = filters.iterator().next();
    assertEquals("MyFilter", filter.getName());
    assertFalse(filter.isShared());
    // ... but it is not available for anybody else
    assertTrue("Account filter not available for everybody else", asAccount(otherAccount).withView(branch).call(() -> buildFilterService.getBuildFilters(branch.getId()).isEmpty()));
    // Now, shares a filter with the same name
    ack = asAccount(account).with(branch.projectId(), ProjectView.class).with(branch.projectId(), BranchFilterMgt.class).call(() -> buildFilterService.saveFilter(branch.getId(), // Sharing
    true, "MyFilter", NamedBuildFilterProvider.class.getName(), objectMapper.valueToTree(NamedBuildFilterData.of("1"))));
    assertTrue("Account filter shared", ack.isSuccess());
    // Makes sure we find this filter back when logged
    filters = asAccount(account).call(() -> buildFilterService.getBuildFilters(branch.getId()));
    assertEquals(1, filters.size());
    filter = filters.iterator().next();
    assertEquals("MyFilter", filter.getName());
    assertTrue(filter.isShared());
    // ... and that it is available also for not logged users
    filters = asUser().withId(10).withView(branch).call(() -> buildFilterService.getBuildFilters(branch.getId()));
    assertEquals("Account filter available for everybody else", 1, filters.size());
    filter = filters.iterator().next();
    assertEquals("MyFilter", filter.getName());
    assertTrue(filter.isShared());
}
Also used : Account(net.nemerosa.ontrack.model.security.Account) Branch(net.nemerosa.ontrack.model.structure.Branch) BuildFilterResource(net.nemerosa.ontrack.model.buildfilter.BuildFilterResource) Ack(net.nemerosa.ontrack.model.Ack) ProjectView(net.nemerosa.ontrack.model.security.ProjectView) Test(org.junit.Test)

Example 8 with Account

use of net.nemerosa.ontrack.model.security.Account in project ontrack by nemerosa.

the class ApplicationLogServiceImpl method log.

@Override
@Transactional(propagation = Propagation.NESTED)
public void log(ApplicationLogEntry entry) {
    ApplicationLogEntry signedEntry = entry.withAuthentication(securityService.getAccount().map(Account::getName).orElse("anonymous"));
    doLog(signedEntry);
}
Also used : Account(net.nemerosa.ontrack.model.security.Account) ApplicationLogEntry(net.nemerosa.ontrack.model.support.ApplicationLogEntry) Transactional(org.springframework.transaction.annotation.Transactional)

Example 9 with Account

use of net.nemerosa.ontrack.model.security.Account in project ontrack by nemerosa.

the class AccountController method getUpdateForm.

/**
 * Update form for an account
 */
@RequestMapping(value = "{accountId}/update", method = RequestMethod.GET)
public Form getUpdateForm(@PathVariable ID accountId) {
    Account account = accountService.getAccount(accountId);
    Form form = getCreationForm();
    // Name in read-only mode for the default admin
    if (account.isDefaultAdmin()) {
        form = form.with(Form.defaultNameField().readOnly());
    }
    // Password not filled in, and not required on update
    form = form.with(Password.of("password").label("Password").length(40).help("Password for the account. Leave blank to keep it unchanged.").optional());
    // Groups
    form = form.with(MultiSelection.of("groups").label("Groups").items(accountService.getAccountGroupsForSelection(accountId)));
    // OK
    return form.fill("name", account.getName()).fill("fullName", account.getFullName()).fill("email", account.getEmail());
}
Also used : Account(net.nemerosa.ontrack.model.security.Account)

Example 10 with Account

use of net.nemerosa.ontrack.model.security.Account in project ontrack by nemerosa.

the class PasswordAuthenticationProviderIT method admin.

@Test
public void admin() {
    UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken("admin", "admin");
    // Retrieval
    UserDetails userDetails = provider.retrieveUser("admin", token);
    // Password check
    provider.additionalAuthenticationChecks(userDetails, token);
    // Checks
    assertNotNull(userDetails);
    assertNull(userDetails.getPassword());
    assertEquals("admin", userDetails.getUsername());
    assertTrue(userDetails instanceof AccountUserDetails);
    AccountUserDetails accountUserDetails = (AccountUserDetails) userDetails;
    Account account = accountUserDetails.getAccount();
    Entity.isEntityDefined(account, "Account must be defined");
    assertEquals("admin", account.getName());
    assertEquals(SecurityRole.ADMINISTRATOR, account.getRole());
}
Also used : Account(net.nemerosa.ontrack.model.security.Account) AccountUserDetails(net.nemerosa.ontrack.model.security.AccountUserDetails) UserDetails(org.springframework.security.core.userdetails.UserDetails) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) AccountUserDetails(net.nemerosa.ontrack.model.security.AccountUserDetails) Test(org.junit.Test)

Aggregations

Account (net.nemerosa.ontrack.model.security.Account)14 Test (org.junit.Test)10 Branch (net.nemerosa.ontrack.model.structure.Branch)7 Ack (net.nemerosa.ontrack.model.Ack)6 BuildFilterResource (net.nemerosa.ontrack.model.buildfilter.BuildFilterResource)4 Function (java.util.function.Function)2 BranchFilterMgt (net.nemerosa.ontrack.model.security.BranchFilterMgt)2 ProjectView (net.nemerosa.ontrack.model.security.ProjectView)2 SecurityService (net.nemerosa.ontrack.model.security.SecurityService)2 Project (net.nemerosa.ontrack.model.structure.Project)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 AccessDeniedException (org.springframework.security.access.AccessDeniedException)2 Transactional (org.springframework.transaction.annotation.Transactional)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 LocalDate (java.time.LocalDate)1 Collection (java.util.Collection)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 OptionalInt (java.util.OptionalInt)1