Merge branch 'user-store' into 'master'

Add new API to fetch userstores

See merge request entgra/carbon-device-mgt!884
temp
Pahansith Gunathilake 3 years ago
commit 4d76be36de

@ -0,0 +1,53 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.wso2.carbon.device.mgt.jaxrs.beans;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.util.List;
@ApiModel(value = "User Store List")
public class UserStoreList extends BasePaginatedResult {
private List<String> userStores;
@ApiModelProperty(value = "Returns the list of user stores available for a tenant.")
@JsonProperty("userStores")
public List<String> getList() {
return userStores;
}
public void setList(List<String> userStores) {
this.userStores = userStores;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("{\n");
sb.append(" count: ").append(getCount()).append(",\n");
sb.append(" userStores: [").append(userStores).append("\n");
sb.append("]}\n");
return sb.toString();
}
}

@ -60,6 +60,7 @@ import org.wso2.carbon.device.mgt.jaxrs.beans.OldPasswordResetWrapper;
import org.wso2.carbon.device.mgt.jaxrs.beans.PermissionList; import org.wso2.carbon.device.mgt.jaxrs.beans.PermissionList;
import org.wso2.carbon.device.mgt.jaxrs.beans.RoleList; import org.wso2.carbon.device.mgt.jaxrs.beans.RoleList;
import org.wso2.carbon.device.mgt.jaxrs.beans.UserInfo; import org.wso2.carbon.device.mgt.jaxrs.beans.UserInfo;
import org.wso2.carbon.device.mgt.jaxrs.beans.UserStoreList;
import org.wso2.carbon.device.mgt.jaxrs.util.Constants; import org.wso2.carbon.device.mgt.jaxrs.util.Constants;
import javax.validation.Valid; import javax.validation.Valid;
@ -1234,4 +1235,54 @@ public interface UserManagementService {
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
Response getPermissionsOfUser(); Response getPermissionsOfUser();
@GET
@Path("/user-stores")
@ApiOperation(
produces = MediaType.APPLICATION_JSON,
httpMethod = "GET",
value = "Getting list of userstores",
notes = "You are able to manage users in WSO2 IoTS by adding, updating and removing users. If you wish to" +
" get the list of users registered with WSO2 IoTS, you can do so "
+ "using this REST API",
tags = "User Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = Constants.SCOPE, value = "perm:users:user-details")
})
}
)
@ApiResponses(value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully fetched the list of user stores registered with WSO2 IoTS.",
response = UserStoreList.class,
responseHeaders = {
@ResponseHeader(
name = "Content-Type",
description = "The content type of the body"),
@ResponseHeader(
name = "ETag",
description = "Entity Tag of the response resource.\n" +
"Used by caches, or in conditional requests."),
@ResponseHeader(
name = "Last-Modified",
description = "Date and time the resource was last modified.\n" +
"Used by caches, or in conditional requests."),
}),
@ApiResponse(
code = 304,
message = "Not Modified. \n Empty body because the client already has the latest version of " +
"the requested resource.\n"),
@ApiResponse(
code = 406,
message = "Not Acceptable.\n The requested media type is not supported",
response = ErrorResponse.class),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Server error occurred while fetching the list of WSO2 IoTS " +
"user stores.",
response = ErrorResponse.class)
})
Response getUserStores();
} }

@ -64,6 +64,7 @@ import org.wso2.carbon.device.mgt.jaxrs.beans.OldPasswordResetWrapper;
import org.wso2.carbon.device.mgt.jaxrs.beans.PermissionList; import org.wso2.carbon.device.mgt.jaxrs.beans.PermissionList;
import org.wso2.carbon.device.mgt.jaxrs.beans.RoleList; import org.wso2.carbon.device.mgt.jaxrs.beans.RoleList;
import org.wso2.carbon.device.mgt.jaxrs.beans.UserInfo; import org.wso2.carbon.device.mgt.jaxrs.beans.UserInfo;
import org.wso2.carbon.device.mgt.jaxrs.beans.UserStoreList;
import org.wso2.carbon.device.mgt.jaxrs.exception.BadRequestException; import org.wso2.carbon.device.mgt.jaxrs.exception.BadRequestException;
import org.wso2.carbon.device.mgt.jaxrs.service.api.UserManagementService; import org.wso2.carbon.device.mgt.jaxrs.service.api.UserManagementService;
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil; import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil;
@ -1270,4 +1271,39 @@ public class UserManagementServiceImpl implements UserManagementService {
return permissionsList; return permissionsList;
} }
/**
* Returns a Response with the list of user stores available for a tenant
* @return list of user stores
* @throws UserStoreException If unable to search for user stores
*/
@GET
@Path("/user-stores")
@Override
public Response getUserStores() {
String domain;
List<String> userStores = new ArrayList<>();
UserStoreList userStoreList = new UserStoreList();
try {
RealmConfiguration realmConfiguration = DeviceMgtAPIUtils.getUserRealm().getRealmConfiguration();
userStores.add(realmConfiguration
.getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_DOMAIN_NAME));
while (realmConfiguration != null) {
realmConfiguration = realmConfiguration.getSecondaryRealmConfig();
if (realmConfiguration != null) {
domain = realmConfiguration
.getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_DOMAIN_NAME);
userStores.add(domain);
} else {
break;
}
}
} catch (UserStoreException e) {
String msg = "Error occurred while retrieving user stores.";
log.error(msg, e);
}
userStoreList.setList(userStores);
userStoreList.setCount(userStores.size());
return Response.status(Response.Status.OK).entity(userStoreList).build();
}
} }

Loading…
Cancel
Save