Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Is there any API to get spaces which has anonymous access

Deleted user June 12, 2019

Is there API to get spaces which has anonymous access ?

1 answer

0 votes
SunRiser
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 12, 2019

Hi Himanshu,

You can run the below SQL query to get a list of all spaces that can be accessed by anonymous users:

SELECT SPACENAME FROM SPACES WHERE SPACEID IN (SELECT SPACEID FROM SPACEPERMISSIONS WHERE PERMTYPE = 'VIEWSPACE' AND PERMGROUPNAME IS NULL AND PERMUSERNAME IS NULL AND PERMALLUSERSSUBJECT IS NULL);

Regards,

Mahesh

Deleted user June 12, 2019

Hi Mahesh ,

 

I have same SQL query but we need to get information through API or Curl command

 

Thanks 

 

Regards ,

Himanshu

Deleted user June 12, 2019

We have created SQL query to get spaces which as anonymous access , but our client don't want to run SQL queries directly in prod system.

So , We are looking for other alternative may be API.could you please suggest a feasible alternative here?

SunRiser
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 13, 2019

Can you please let us know how you are planning to share the data with your client?  Are you are planning to show the results on a Confluence page or some other way?

Deleted user June 13, 2019

We are planing to share data in excel through email.

The intention here is to trigger a email notification to get spaces which has anonymous access for that we are planing to create Jenkins job to achieve this .

 

Could you please suggest some feasible way.

 

Note : SQL query is not a feasible solution as per client requirement

SunRiser
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 13, 2019

Hi Himanshu,

Did some research and found the following example which should retrieve the Anonymous user permissions for Space

curl -v --data '["SpaceKey", ""]' -u admin:admin -H "Content-Type: application/json" http://localhost:8090/confluence/rpc/json-rpc/confluenceservice-v2/getPermissionsForUser?os_authType=basic\\

When I tried it in my local test instance, it returned empty even though I have anonymous access enabled for few spaces. This seems to be because anonymous does not have an actual user name, but the method requires two parameters, which are:

  1. Space key
  2. User Name

I tested the following three possibilities for the user name parameter, but all returned empty results:

  1.  "" - Empty value (as shown in the example above)
  2.  "null"
  3.  "anonymous"

With that in mind, we need to find an alternative way of gathering that information. I was able to find the following method that may be useful:

/rpc/json-rpc/confluenceservice-v2/getSpacePermissionSets
  • SpacePermissionSet\[\] getSpacePermissionSets(String token, String spaceKey) - retrieves all permission sets specified for space with given spaceKey.

This method returns all permissions for a specific space key. Once you get the response, you can review it to find out if anonymous access is enabled. Here is how we can do that:

  1. In my test, I enabled only the VIEW permission for anonymous
  2.  Inspecting the output of the method above, we can see this:
    "type": "VIEWSPACE",

    "spacePermissions": [

    {

    "type": "VIEWSPACE",

    "userName": null,

    "groupName": null

    },

    3. When you see *userName* and *groupName* set to *NULL*, this means that Anonymous access has that permission

Let us know if this option is useful in your use case.

REST API

I did some research on the REST API methods and could see that we still don't have the ability to search for space permissions through the API. Here are the feature requests which are under consideration for future implementation:

Hope this information helps you.

Best Regards,

Mahesh

Deleted user June 13, 2019

Hi Mahesh ,

 

getSpacePermissionSets(String token, String spaceKey) 

 

What we need to pass in "String Token"

 

Could you please provide some example

 

Thanks in advance

 

Regards ,

Himanshu

SunRiser
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 14, 2019

Hi Himanshu,

The token is used for authentication: creating a token

It is only valid if your Confluence is running on Cloud. For self-hosted or server versions, you can try the below (please tweak the values)

USRNAME="admin"
USRPWD="admin"
SPACEKEY="S1"
CONFBASEURL="http://localhost:8090"
curl --user $USRNAME:$USRPWD -H "Content-Type: application/json" -H "Accept: application/json" -X POST -d '{ "jsonrpc" : "2.0", "method" : "getSpacePermissionSets", "params" : [ "S1" ] , "id": 7 }' $CONFBASEURL/rpc/json-rpc/confluenceservice-v2?os_authType=basic 2>/dev/null | python -mjson.tool

Good luck!

Mahesh

Deleted user June 14, 2019

Hi Mahesh ,

 

we are running confluence on cloud  and we are struggling , Because we don't know how to use above provided URL  and after that how to use below provided response 

"type": "VIEWSPACE",

"spacePermissions": [

{

"type": "VIEWSPACE",

"userName": null,

"groupName": null

},

 Do you have any sample code ?

SunRiser
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 18, 2019

Please refer to link on how to create and use tokens: Confluence Tokens

In the response, if you see the below then it means that space has anonymous access. You may need to write additional logic to extract the space names from the response.

"userName": null,

"groupName": null

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events