Search in sources :

Example 1 with UserRoleService

use of org.finos.waltz.service.user.UserRoleService in project waltz by khartec.

the class BulkRoleAssign method main.

public static void main(String[] args) {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    DSLContext dsl = ctx.getBean(DSLContext.class);
    UserRoleService userRoleService = ctx.getBean(UserRoleService.class);
    Set<String> defaultRoles = SetUtilities.asSet(SystemRole.BOOKMARK_EDITOR.name(), SystemRole.LOGICAL_DATA_FLOW_EDITOR.name(), SystemRole.LINEAGE_EDITOR.name());
    Set<String> mustHaveRoles = SetUtilities.asSet(SystemRole.TAXONOMY_EDITOR.name(), SystemRole.CAPABILITY_EDITOR.name(), SystemRole.RATING_EDITOR.name());
    InputStream inputStream = BulkRoleAssign.class.getClassLoader().getResourceAsStream("bulk-role-assign-example.txt");
    Set<Tuple2<String, Set<String>>> updates = IOUtilities.streamLines(inputStream).map(d -> d.toLowerCase().trim()).map(d -> Tuple.tuple(d, userRoleService.getUserRoles(d))).map(t -> t.map2(existingRoles -> union(existingRoles, defaultRoles, mustHaveRoles))).collect(Collectors.toSet());
    System.out.printf("About to update: %d user-role mappings\n", updates.size());
    updates.forEach(t -> userRoleService.updateRoles("admin", t.v1, ImmutableUpdateRolesCommand.builder().roles(t.v2).comment("Updated via the Bulk Role Assign tool").build()));
    System.out.println("Finished updating mappings");
}
Also used : UserRoleService(org.finos.waltz.service.user.UserRoleService) Set(java.util.Set) DIConfiguration(org.finos.waltz.service.DIConfiguration) Collectors(java.util.stream.Collectors) IOUtilities(org.finos.waltz.common.IOUtilities) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) SetUtilities.union(org.finos.waltz.common.SetUtilities.union) ImmutableUpdateRolesCommand(org.finos.waltz.model.user.ImmutableUpdateRolesCommand) Tuple2(org.jooq.lambda.tuple.Tuple2) Tuple(org.jooq.lambda.tuple.Tuple) UserRoleService(org.finos.waltz.service.user.UserRoleService) SetUtilities(org.finos.waltz.common.SetUtilities) SystemRole(org.finos.waltz.model.user.SystemRole) DSLContext(org.jooq.DSLContext) InputStream(java.io.InputStream) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) InputStream(java.io.InputStream) Tuple2(org.jooq.lambda.tuple.Tuple2) DSLContext(org.jooq.DSLContext)

Example 2 with UserRoleService

use of org.finos.waltz.service.user.UserRoleService in project waltz by khartec.

the class PhysicalSpecDefinitionEndpoint method register.

@Override
public void register() {
    String findForSpecificationPath = WebUtilities.mkPath(BASE_URL, "specification", ":id");
    String findBySelectorPath = WebUtilities.mkPath(BASE_URL, "selector");
    String createPath = WebUtilities.mkPath(BASE_URL, "specification", ":id");
    String updateStatusPath = WebUtilities.mkPath(BASE_URL, "specification", ":id", "status");
    String deletePath = WebUtilities.mkPath(BASE_URL, "specification", ":id");
    ListRoute<PhysicalSpecDefinition> findForSpecificationRoute = (req, res) -> specDefinitionService.findForSpecification(WebUtilities.getId(req));
    ListRoute<PhysicalSpecDefinition> findBySelectorRoute = (req, res) -> specDefinitionService.findBySelector(WebUtilities.readIdSelectionOptionsFromBody(req));
    DatumRoute<Long> createRoute = (req, res) -> {
        WebUtilities.requireRole(userRoleService, req, SystemRole.LOGICAL_DATA_FLOW_EDITOR);
        PhysicalSpecDefinitionChangeCommand physicalSpecDefinitionChangeCommand = WebUtilities.readBody(req, PhysicalSpecDefinitionChangeCommand.class);
        long physicalSpecificationId = WebUtilities.getId(req);
        Set<String> existingVersions = map(specDefinitionService.findForSpecification(physicalSpecificationId), d -> d.version());
        if (existingVersions.contains(physicalSpecDefinitionChangeCommand.version())) {
            throw new DuplicateKeyException("Cannot create physical specification definition with version that already exists");
        }
        return specDefinitionService.create(WebUtilities.getUsername(req), physicalSpecificationId, physicalSpecDefinitionChangeCommand);
    };
    DatumRoute<Boolean> updateStatusRoute = (req, res) -> {
        WebUtilities.requireRole(userRoleService, req, SystemRole.LOGICAL_DATA_FLOW_EDITOR);
        return specDefinitionService.updateStatus(WebUtilities.getUsername(req), WebUtilities.getId(req), WebUtilities.readBody(req, ReleaseLifecycleStatusChangeCommand.class));
    };
    DatumRoute<Integer> deleteRoute = (req, res) -> {
        WebUtilities.requireRole(userRoleService, req, SystemRole.LOGICAL_DATA_FLOW_EDITOR);
        return specDefinitionService.delete(WebUtilities.getUsername(req), WebUtilities.getId(req));
    };
    EndpointUtilities.getForList(findForSpecificationPath, findForSpecificationRoute);
    EndpointUtilities.postForList(findBySelectorPath, findBySelectorRoute);
    EndpointUtilities.postForDatum(createPath, createRoute);
    EndpointUtilities.putForDatum(updateStatusPath, updateStatusRoute);
    EndpointUtilities.deleteForDatum(deletePath, deleteRoute);
}
Also used : ListRoute(org.finos.waltz.web.ListRoute) Endpoint(org.finos.waltz.web.endpoints.Endpoint) DatumRoute(org.finos.waltz.web.DatumRoute) Autowired(org.springframework.beans.factory.annotation.Autowired) Set(java.util.Set) PhysicalSpecDefinition(org.finos.waltz.model.physical_specification_definition.PhysicalSpecDefinition) ReleaseLifecycleStatusChangeCommand(org.finos.waltz.model.ReleaseLifecycleStatusChangeCommand) SetUtilities.map(org.finos.waltz.common.SetUtilities.map) Checks.checkNotNull(org.finos.waltz.common.Checks.checkNotNull) UserRoleService(org.finos.waltz.service.user.UserRoleService) PhysicalSpecDefinitionService(org.finos.waltz.service.physical_specification_definition.PhysicalSpecDefinitionService) Service(org.springframework.stereotype.Service) WebUtilities(org.finos.waltz.web.WebUtilities) SystemRole(org.finos.waltz.model.user.SystemRole) DuplicateKeyException(org.finos.waltz.common.exception.DuplicateKeyException) PhysicalSpecDefinitionChangeCommand(org.finos.waltz.model.physical_specification_definition.PhysicalSpecDefinitionChangeCommand) EndpointUtilities(org.finos.waltz.web.endpoints.EndpointUtilities) PhysicalSpecDefinitionChangeCommand(org.finos.waltz.model.physical_specification_definition.PhysicalSpecDefinitionChangeCommand) Set(java.util.Set) DuplicateKeyException(org.finos.waltz.common.exception.DuplicateKeyException) PhysicalSpecDefinition(org.finos.waltz.model.physical_specification_definition.PhysicalSpecDefinition)

Example 3 with UserRoleService

use of org.finos.waltz.service.user.UserRoleService in project waltz by khartec.

the class UserHarness method main.

public static void main(String[] args) {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    UserRoleService userRoleService = ctx.getBean(UserRoleService.class);
    DSLContext dsl = ctx.getBean(DSLContext.class);
    int rc = dsl.insertInto(USER).set(USER.USER_NAME, "kamran").set(USER.PASSWORD, "1234").onDuplicateKeyIgnore().execute();
    System.out.println(rc);
// 
// ImmutableLoginRequest loginRequest = ImmutableLoginRequest.builder()
// .userName("dwatkins")
// .password("wrong")
// .build();
// 
// boolean authenticated = userService.authenticate(loginRequest);
// System.out.println(authenticated);
// 
// userRoleService.findAllUsers().forEach(System.out::println);
}
Also used : UserRoleService(org.finos.waltz.service.user.UserRoleService) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) DSLContext(org.jooq.DSLContext)

Aggregations

UserRoleService (org.finos.waltz.service.user.UserRoleService)3 Set (java.util.Set)2 SystemRole (org.finos.waltz.model.user.SystemRole)2 DSLContext (org.jooq.DSLContext)2 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)2 InputStream (java.io.InputStream)1 Collectors (java.util.stream.Collectors)1 Checks.checkNotNull (org.finos.waltz.common.Checks.checkNotNull)1 IOUtilities (org.finos.waltz.common.IOUtilities)1 SetUtilities (org.finos.waltz.common.SetUtilities)1 SetUtilities.map (org.finos.waltz.common.SetUtilities.map)1 SetUtilities.union (org.finos.waltz.common.SetUtilities.union)1 DuplicateKeyException (org.finos.waltz.common.exception.DuplicateKeyException)1 ReleaseLifecycleStatusChangeCommand (org.finos.waltz.model.ReleaseLifecycleStatusChangeCommand)1 PhysicalSpecDefinition (org.finos.waltz.model.physical_specification_definition.PhysicalSpecDefinition)1 PhysicalSpecDefinitionChangeCommand (org.finos.waltz.model.physical_specification_definition.PhysicalSpecDefinitionChangeCommand)1 ImmutableUpdateRolesCommand (org.finos.waltz.model.user.ImmutableUpdateRolesCommand)1 DIConfiguration (org.finos.waltz.service.DIConfiguration)1 PhysicalSpecDefinitionService (org.finos.waltz.service.physical_specification_definition.PhysicalSpecDefinitionService)1 DatumRoute (org.finos.waltz.web.DatumRoute)1