Package org.graylog2.restclient.models.api.requests

Examples of org.graylog2.restclient.models.api.requests.ChangeUserRequestForm


            case EMAIL_TRANSPORT_FAILED:
                return new EmailTransportFailedNotification(notification);
            case STREAM_PROCESSING_DISABLED:
                String streamTitle;
                try {
                    final Stream stream = streamService.get(notification.getDetail("stream_id").toString());
                    streamTitle = stream.getTitle();
                } catch (APIException | IOException e) {
                    streamTitle = "(Stream title unavailable)";
                }
                int faultCount = (int) notification.getDetail("fault_count");
                return new StreamProcessingDisabledNotification(notification, streamTitle, faultCount);
View Full Code Here


    public static SessionService sessionService;

    @Override
    public String getUsername(Context ctx) {
        try {
            final User sessionUser = pipelineAuths(authenticateSessionUser(), authenticateBasicAuthUser());
            if (sessionUser == null) {
                return null;
            }
            return sessionUser.getName();
        } catch (Graylog2ServerUnavailableException e) {
            ctx.args.put(GRAYLOG_2_SERVER_MISSING_KEY, e);
            return null;
        }
    }
View Full Code Here

    }

    @Override
    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
        // the current user has been previously loaded via doGetAuthenticationInfo before, use those permissions
        User user = UserService.current();
        if (!principals.getPrimaryPrincipal().equals(user.getName())) {
            log.info("retrieving loaded user {} from per-request user cache", principals.getPrimaryPrincipal());
            user = (User) Http.Context.current().args.get("perRequestUsersCache:" + principals.getPrimaryPrincipal().toString());
            if (user == null) {
                log.error("Cannot find previously loaded user, need to load it explicitely. This is unimplemented.");
                return null;
            }
        }
        final List<String> permissions = user.getPermissions();
        final SimpleAuthorizationInfo authzInfo = new SimpleAuthorizationInfo();
        if (log.isTraceEnabled()) {
            log.trace("Permissions for {} are {}", user.getName(), Ordering.natural().sortedCopy(user.getPermissions()));
        }
        authzInfo.setStringPermissions(Sets.newHashSet(permissions));
        return authzInfo;
    }
View Full Code Here

            final String sessionId = token.getPrincipal().toString();
            response = api.get(UserResponse.class)
                    .path("/users/{0}", token.getUsername())
                    .session(sessionId)
                    .execute();
            final User user = userFactory.fromResponse(response, sessionId);

            UserService.setCurrent(user);
            user.setSubject(new Subject.Builder(SecurityUtils.getSecurityManager())
                    .principals(new SimplePrincipalCollection(user.getName(), "REST realm"))
                    .authenticated(true)
                    .buildSubject());
        } catch (IOException e) {
            throw new Graylog2ServerUnavailableException("Could not connect to Graylog2 Server.", e);
        } catch (APIException e) {
View Full Code Here

    public List<Alert> getAlertsSince(int since) throws APIException, IOException {
        List<Alert> alerts = Lists.newArrayList();

        for (AlertSummaryResponse alert : getAlertsInformation(since).alerts) {
            alerts.add(new Alert(alert));
        }

        return alerts;
    }
View Full Code Here

        }
        return subject;
    }

    public boolean setStartpage(Startpage startpage) {
        ChangeUserRequest cur = new ChangeUserRequest(this);

        if (startpage == null) {
            cur.startpage.type = null;
            cur.startpage.id = null;
        } else {
View Full Code Here

    public Result editUserForm(String username) {
        BreadcrumbList bc = breadcrumbs();
        bc.addCrumb("Edit " + username, routes.UsersController.editUserForm(username));

        User user = userService.load(username);
        final Form<ChangeUserRequestForm> form = changeUserForm.fill(new ChangeUserRequestForm(user));
        boolean requiresOldPassword = checkRequireOldPassword(username);
        try {
            return ok(edit.render(
                            form,
                            username,
View Full Code Here

                String message = "Could not fetch streams. We expected HTTP 200, but got a HTTP " + e.getHttpCode() + ".";
                return status(504, views.html.errors.error.render(message, e, request()));
            }
        }

        final ChangeUserRequestForm formData = requestForm.get();
        // translate session timeout value from form fields to millis
        if (!formData.session_timeout_never) {
            TimeUnit timeoutUnit;
            if (formData.timeout_unit != null) {
                try {
                    timeoutUnit = TimeUnit.valueOf(formData.timeout_unit.toUpperCase());
                    formData.sessionTimeoutMs = timeoutUnit.toMillis(formData.timeout);
                } catch (IllegalArgumentException e) {
                    log.warn("Unknown value for session timeout unit. Cannot set session timeout value.", e);
                }
            }
        } else {
            formData.sessionTimeoutMs = -1; // which translates to "never".
        }
        Set<String> permissions = Sets.newHashSet(user.getPermissions());
        // TODO this does not handle combined permissions like streams:edit,read:1,2 !
        // remove all streams:edit, streams:read permissions and add the ones from the form back.

        permissions = Sets.newHashSet(Sets.filter(permissions, new Predicate<String>() {
            @Override
            public boolean apply(@Nullable String input) {
                return (input != null) &&
                        !(input.startsWith(STREAMS_READ) || input.startsWith(STREAMS_EDIT) ||
                                input.startsWith(DASHBOARDS_READ) || input.startsWith(DASHBOARDS_EDIT));
            }
        }));
        for (String streampermission : formData.streampermissions) {
            permissions.add(RestPermissions.STREAMS_READ + ":" + streampermission);
        }
        for (String streameditpermission : formData.streameditpermissions) {
            permissions.add(RestPermissions.STREAMS_EDIT + ":" + streameditpermission);
        }
        for (String dashboardpermission : formData.dashboardpermissions) {
            permissions.add(RestPermissions.DASHBOARDS_READ + ":" + dashboardpermission);
        }
        for (String dashboardeditpermissions : formData.dashboardeditpermissions) {
            permissions.add(RestPermissions.DASHBOARDS_EDIT + ":" + dashboardeditpermissions);
        }
        final ChangeUserRequest changeRequest = formData.toApiRequest();
        changeRequest.permissions = Lists.newArrayList(permissions);
        user.update(changeRequest);

        return redirect(routes.UsersController.index());
    }
View Full Code Here

        addOutputs(streamId, outputs);
    }

    public void addOutputs(String streamId, Set<String> outputIds) throws APIException, IOException {
        AddOutputRequest request = new AddOutputRequest();
        request.outputs = outputIds;
        api.path(routes.StreamOutputResource().add(streamId)).expect(Http.Status.CREATED).body(request).execute();
    }
View Full Code Here

                        .path("/some/resource")
                        .unauthenticated()
                        .node(node)
                        .timeout(1, TimeUnit.SECONDS);
        stubHttpProvider.expectResponse(requestBuilder.prepareUrl(node), 200, "{}");
        final EmptyResponse response = requestBuilder.execute();

        Assert.assertNotNull(response);
        Assert.assertTrue(stubHttpProvider.isExpectationsFulfilled());
    }
View Full Code Here

TOP

Related Classes of org.graylog2.restclient.models.api.requests.ChangeUserRequestForm

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.