use of org.graylog2.shared.security.Permissions in project graylog2-server by Graylog2.
the class UserImplTest method permissionsArentModified.
@Test
public void permissionsArentModified() {
final Permissions permissions = new Permissions(Collections.emptySet());
final Map<String, Object> fields = Collections.singletonMap(UserImpl.USERNAME, "foobar");
user = new UserImpl(passwordAlgorithmFactory, permissions, fields);
final List<String> newPermissions = ImmutableList.<String>builder().addAll(user.getPermissions()).add("perm:1").build();
user.setPermissions(newPermissions);
}
use of org.graylog2.shared.security.Permissions in project graylog2-server by Graylog2.
the class UserImplTest method getPermissionsWorksWithEmptyPermissions.
@Test
public void getPermissionsWorksWithEmptyPermissions() throws Exception {
final Permissions permissions = new Permissions(Collections.emptySet());
final Map<String, Object> fields = Collections.singletonMap(UserImpl.USERNAME, "foobar");
user = new UserImpl(passwordAlgorithmFactory, permissions, fields);
assertThat(user.getPermissions()).containsAll(permissions.userSelfEditPermissions("foobar"));
}
use of org.graylog2.shared.security.Permissions in project graylog2-server by Graylog2.
the class UserServiceImplTest method setUp.
@Before
public void setUp() throws Exception {
this.mongoConnection = mongoRule.getMongoConnection();
this.configuration = new Configuration();
this.userFactory = new UserImplFactory(configuration);
this.permissions = new Permissions(ImmutableSet.of(new RestPermissions()));
this.userService = new UserServiceImpl(mongoConnection, configuration, roleService, userFactory, permissionsResolver);
when(roleService.getAdminRoleObjectId()).thenReturn("deadbeef");
}
use of org.graylog2.shared.security.Permissions in project graylog2-server by Graylog2.
the class UsersResource method create.
@POST
@RequiresPermissions(RestPermissions.USERS_CREATE)
@ApiOperation("Create a new user account.")
@ApiResponses({ @ApiResponse(code = 400, message = "Missing or invalid user details.") })
@AuditEvent(type = AuditEventTypes.USER_CREATE)
public Response create(@ApiParam(name = "JSON body", value = "Must contain username, full_name, email, password and a list of permissions.", required = true) @Valid @NotNull CreateUserRequest cr) throws ValidationException {
if (userService.load(cr.username()) != null) {
final String msg = "Cannot create user " + cr.username() + ". Username is already taken.";
LOG.error(msg);
throw new BadRequestException(msg);
}
// Create user.
User user = userService.create();
user.setName(cr.username());
user.setPassword(cr.password());
user.setFullName(cr.fullName());
user.setEmail(cr.email());
user.setPermissions(cr.permissions());
setUserRoles(cr.roles(), user);
if (cr.timezone() != null) {
user.setTimeZone(cr.timezone());
}
final Long sessionTimeoutMs = cr.sessionTimeoutMs();
if (sessionTimeoutMs != null) {
user.setSessionTimeoutMs(sessionTimeoutMs);
}
final Startpage startpage = cr.startpage();
if (startpage != null) {
user.setStartpage(startpage.type(), startpage.id());
}
final String id = userService.save(user);
LOG.debug("Saved user {} with id {}", user.getName(), id);
final URI userUri = getUriBuilderToSelf().path(UsersResource.class).path("{username}").build(user.getName());
return Response.created(userUri).build();
}
use of org.graylog2.shared.security.Permissions in project graylog2-server by Graylog2.
the class UsersResource method editPermissions.
@PUT
@Path("{username}/permissions")
@RequiresPermissions(RestPermissions.USERS_PERMISSIONSEDIT)
@ApiOperation("Update a user's permission set.")
@ApiResponses({ @ApiResponse(code = 400, message = "Missing or invalid permission data.") })
@AuditEvent(type = AuditEventTypes.USER_PERMISSIONS_UPDATE)
public void editPermissions(@ApiParam(name = "username", value = "The name of the user to modify.", required = true) @PathParam("username") String username, @ApiParam(name = "JSON body", value = "The list of permissions to assign to the user.", required = true) @Valid @NotNull PermissionEditRequest permissionRequest) throws ValidationException {
final User user = userService.load(username);
if (user == null) {
throw new NotFoundException("Couldn't find user " + username);
}
user.setPermissions(getEffectiveUserPermissions(user, permissionRequest.permissions()));
userService.save(user);
}
Aggregations