Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
* Licensed to The OpenNMS Group, Inc (TOG) under one or more
* contributor license agreements. See the LICENSE.md file
* distributed with this work for additional information
* regarding copyright ownership.
*
* TOG licenses this file to You under the GNU Affero General
* Public License Version 3 (the "License") or (at your option)
* any later version. You may not use this file except in
* compliance with the License. You may obtain a copy of the
* License at:
*
* https://www.gnu.org/licenses/agpl-3.0.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
package org.opennms.web.rest.v2.api;

import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.SecurityContext;

import org.opennms.web.rest.v2.model.UserDto;
import org.opennms.web.rest.v2.model.UserPasswordRequest;
import org.opennms.web.rest.v2.model.UserRenameRequest;
import org.opennms.web.rest.v2.model.UserWriteRequest;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;

/**
* Versioned user management API backed by users.xml. Password hashes are
* never returned; admin-only (enforced by Spring Security and in-code).
*/
@Path("users")
@Tag(name = "Users", description = "User Management API")
public interface UsersRestApi {

@GET
@Produces(MediaType.APPLICATION_JSON)
@Operation(summary = "List all users", operationId = "listUsers")
Response listUsers(@Context SecurityContext securityContext);

@GET
@Path("{userId}")
@Produces(MediaType.APPLICATION_JSON)
@Operation(summary = "Get one user", operationId = "getUser")
Response getUser(@Context SecurityContext securityContext, @PathParam("userId") String userId);

@GET
@Path("available-roles")
@Produces(MediaType.APPLICATION_JSON)
@Operation(summary = "List the assignable security roles", operationId = "listAvailableRoles")
Response listAvailableRoles(@Context SecurityContext securityContext);

@POST
@Consumes(MediaType.APPLICATION_JSON)
@Operation(summary = "Create a user", operationId = "createUser")
Response createUser(@Context SecurityContext securityContext, UserWriteRequest request);

@PUT
@Path("{userId}")
@Consumes(MediaType.APPLICATION_JSON)
@Operation(summary = "Update a user's details (contact types and password not covered here are preserved)", operationId = "updateUser")
Response updateUser(@Context SecurityContext securityContext, @PathParam("userId") String userId, UserDto user);

@PUT
@Path("{userId}/password")
@Consumes(MediaType.APPLICATION_JSON)
@Operation(summary = "Set a user's password (stored salted)", operationId = "setUserPassword")
Response setPassword(@Context SecurityContext securityContext, @PathParam("userId") String userId, UserPasswordRequest request);

@POST
@Path("{userId}/rename")
@Consumes(MediaType.APPLICATION_JSON)
@Operation(summary = "Rename a user (also updates group memberships)", operationId = "renameUser")
Response renameUser(@Context SecurityContext securityContext, @PathParam("userId") String userId, UserRenameRequest request);

@DELETE
@Path("{userId}")
@Operation(summary = "Delete a user (also removes group memberships; admin and rtc are protected)", operationId = "deleteUser")
Response deleteUser(@Context SecurityContext securityContext, @PathParam("userId") String userId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
/*
* Licensed to The OpenNMS Group, Inc (TOG) under one or more
* contributor license agreements. See the LICENSE.md file
* distributed with this work for additional information
* regarding copyright ownership.
*
* TOG licenses this file to You under the GNU Affero General
* Public License Version 3 (the "License") or (at your option)
* any later version. You may not use this file except in
* compliance with the License. You may obtain a copy of the
* License at:
*
* https://www.gnu.org/licenses/agpl-3.0.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
package org.opennms.web.rest.v2.model;

import java.util.List;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

/**
* A user as exposed by the v2 user management API. Field names mirror
* users.xml where they overlap; the password hash is deliberately never part
* of this representation, and contact types the API does not expose (XMPP,
* microblog, phones, pager PINs) are preserved server-side on update.
*/
@XmlRootElement(name = "user")
@XmlAccessorType(XmlAccessType.FIELD)
public class UserDto {

@XmlElement(name = "user-id")
private String userId;

@XmlElement(name = "full-name")
private String fullName;

@XmlElement(name = "user-comments")
private String userComments;

@XmlElement(name = "email")
private String email;

@XmlElement(name = "pager-email")
private String pagerEmail;

@XmlElement(name = "tui-pin")
private String tuiPin;

@XmlElement(name = "time-zone-id")
private String timeZoneId;

// null (not empty) defaults: a request body that omits these keys
// deserializes to null, which update semantics treat as "preserve"
@XmlElement(name = "duty-schedule")
private List<String> dutySchedules;

@XmlElement(name = "role")
private List<String> roles;

@XmlElement(name = "read-only")
private Boolean readOnly;

public String getUserId() {
return userId;
}

public void setUserId(final String userId) {
this.userId = userId;
}

public String getFullName() {
return fullName;
}

public void setFullName(final String fullName) {
this.fullName = fullName;
}

public String getUserComments() {
return userComments;
}

public void setUserComments(final String userComments) {
this.userComments = userComments;
}

public String getEmail() {
return email;
}

public void setEmail(final String email) {
this.email = email;
}

public String getPagerEmail() {
return pagerEmail;
}

public void setPagerEmail(final String pagerEmail) {
this.pagerEmail = pagerEmail;
}

public String getTuiPin() {
return tuiPin;
}

public void setTuiPin(final String tuiPin) {
this.tuiPin = tuiPin;
}

public String getTimeZoneId() {
return timeZoneId;
}

public void setTimeZoneId(final String timeZoneId) {
this.timeZoneId = timeZoneId;
}

public List<String> getDutySchedules() {
return dutySchedules;
}

public void setDutySchedules(final List<String> dutySchedules) {
this.dutySchedules = dutySchedules;
}

public List<String> getRoles() {
return roles;
}

public void setRoles(final List<String> roles) {
this.roles = roles;
}

public Boolean getReadOnly() {
return readOnly;
}

public void setReadOnly(final Boolean readOnly) {
this.readOnly = readOnly;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Licensed to The OpenNMS Group, Inc (TOG) under one or more
* contributor license agreements. See the LICENSE.md file
* distributed with this work for additional information
* regarding copyright ownership.
*
* TOG licenses this file to You under the GNU Affero General
* Public License Version 3 (the "License") or (at your option)
* any later version. You may not use this file except in
* compliance with the License. You may obtain a copy of the
* License at:
*
* https://www.gnu.org/licenses/agpl-3.0.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
package org.opennms.web.rest.v2.model;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name = "user-password-request")
@XmlAccessorType(XmlAccessType.FIELD)
public class UserPasswordRequest {

@XmlElement(name = "password")
private String password;

public String getPassword() {
return password;
}

public void setPassword(final String password) {
this.password = password;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Licensed to The OpenNMS Group, Inc (TOG) under one or more
* contributor license agreements. See the LICENSE.md file
* distributed with this work for additional information
* regarding copyright ownership.
*
* TOG licenses this file to You under the GNU Affero General
* Public License Version 3 (the "License") or (at your option)
* any later version. You may not use this file except in
* compliance with the License. You may obtain a copy of the
* License at:
*
* https://www.gnu.org/licenses/agpl-3.0.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
package org.opennms.web.rest.v2.model;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name = "user-rename-request")
@XmlAccessorType(XmlAccessType.FIELD)
public class UserRenameRequest {

@XmlElement(name = "new-user-id")
private String newUserId;

public String getNewUserId() {
return newUserId;
}

public void setNewUserId(final String newUserId) {
this.newUserId = newUserId;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Licensed to The OpenNMS Group, Inc (TOG) under one or more
* contributor license agreements. See the LICENSE.md file
* distributed with this work for additional information
* regarding copyright ownership.
*
* TOG licenses this file to You under the GNU Affero General
* Public License Version 3 (the "License") or (at your option)
* any later version. You may not use this file except in
* compliance with the License. You may obtain a copy of the
* License at:
*
* https://www.gnu.org/licenses/agpl-3.0.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
package org.opennms.web.rest.v2.model;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

/**
* Create request for the v2 user management API: the UserDto fields plus the
* initial password, which is hashed (salted) before it reaches users.xml.
* Password changes on existing users go through the dedicated password
* endpoint instead.
*/
@XmlRootElement(name = "user-create-request")
@XmlAccessorType(XmlAccessType.FIELD)
public class UserWriteRequest extends UserDto {

@XmlElement(name = "password")
private String password;

public String getPassword() {
return password;
}

public void setPassword(final String password) {
this.password = password;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@
{
"id": "manageUsers",
"name": "Manage Users",
"url": "admin/userGroupView/users/list.jsp",
"url": "ui/index.html#/admin/users",
"locationMatch": "",
"roles": null
},
Expand Down
Loading
Loading