Skip to content

Commit

Permalink
Fix unauthorized routes in ApiHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
cbbayburt committed Feb 21, 2025
1 parent 0c5cf64 commit 17d5403
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
15 changes: 4 additions & 11 deletions java/code/src/com/redhat/rhn/frontend/xmlrpc/api/ApiHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import com.redhat.rhn.common.conf.Config;
import com.redhat.rhn.common.conf.ConfigDefaults;
import com.redhat.rhn.common.util.StringUtil;
import com.redhat.rhn.domain.user.User;
import com.redhat.rhn.frontend.xmlrpc.BaseHandler;
import com.redhat.rhn.frontend.xmlrpc.HandlerFactory;

Expand Down Expand Up @@ -92,19 +91,17 @@ public String getVersion() {
}

/** Lists available API namespaces
* @param loggedInUser The current user
* @return map of API namespaces
*
* @apidoc.doc Lists available API namespaces
* @apidoc.param #session_key()
* @apidoc.returntype
* #struct_begin("namespace")
* #prop_desc("string", "namespace", "API namespace")
* #prop_desc("string", "handler", "API Handler")
* #struct_end()
*/
@ReadOnly
public Map<String, String> getApiNamespaces(User loggedInUser) {
public Map<String, String> getApiNamespaces() {
return handlers.getKeys().stream().collect(Collectors.toMap(
namespace -> namespace,
namespace -> StringUtil.getClassNameNoPackage(
Expand All @@ -114,11 +111,9 @@ public Map<String, String> getApiNamespaces(User loggedInUser) {

/**
* Lists all available api calls grouped by namespace
* @param loggedInUser The current user
* @return a map containing list of api calls for every namespace
*
* @apidoc.doc Lists all available api calls grouped by namespace
* @apidoc.param #session_key()
* @apidoc.returntype
* #struct_begin("method_info")
* #prop_desc("string", "name", "method name")
Expand All @@ -128,21 +123,19 @@ public Map<String, String> getApiNamespaces(User loggedInUser) {
* #struct_end()
*/
@ReadOnly
public Map<String, Object> getApiCallList(User loggedInUser) {
public Map<String, Object> getApiCallList() {
return handlers.getKeys().stream().collect(Collectors.toMap(
namespace -> namespace,
namespace -> getApiNamespaceCallList(loggedInUser, namespace)
this::getApiNamespaceCallList
));
}

/**
* Lists all available api calls for the specified namespace
* @param loggedInUser The current user
* @param namespace namespace of interest
* @return a map containing list of api calls for every namespace
*
* @apidoc.doc Lists all available api calls for the specified namespace
* @apidoc.param #session_key()
* @apidoc.param #param("string", "namespace")
* @apidoc.returntype
* #struct_begin("method_info")
Expand All @@ -153,7 +146,7 @@ public Map<String, Object> getApiCallList(User loggedInUser) {
* #struct_end()
*/
@ReadOnly
public Map getApiNamespaceCallList(User loggedInUser, String namespace) {
public Map getApiNamespaceCallList(String namespace) {
Class<? extends BaseHandler> handlerClass =
handlers.getHandler(namespace)
.orElseThrow(() -> new RuntimeException("Handler " + namespace + " not found."))
Expand Down
5 changes: 4 additions & 1 deletion java/code/src/com/suse/manager/api/HttpApiRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,13 @@ public void initRoutes() {
* Contains the endpoints that should be exposed without requiring any authentication.
* @return a Set containing the URL to the public endpoints
*/
// TODO: Revisit (unnecessary now)
public static Set<String> getUnautenticatedRoutes() {
return Set.of(
"/rhn/manager/api/api/getVersion",
"/rhn/manager/api/api/getApiCallList",
"/rhn/manager/api/api/systemVersion",
"/rhn/manager/api/api/getApiNamespaces",
"/rhn/manager/api/api/productName",
"/rhn/manager/api/org/createFirst"
);
Expand All @@ -136,7 +139,7 @@ public static Set<String> getUnautenticatedRoutes() {
*/
private void registerAuthEndpoints() {
registrationHelper.addPostRoute(HTTP_API_ROOT + "auth/login", LoginController::apiLogin);
registrationHelper.addPostRoute(HTTP_API_ROOT + "auth/logout", withUser(LoginController::logout));
registrationHelper.addGetRoute(HTTP_API_ROOT + "auth/logout", withUser(LoginController::logout));
}

/**
Expand Down

0 comments on commit 17d5403

Please sign in to comment.