Java源码示例:org.wso2.carbon.integration.common.admin.client.UserManagementClient
示例1
/**
* Setting up Server and Apply new Configuration Files.
*
* @throws Exception
*/
@BeforeTest(alwaysRun = true)
public void setupTest() throws Exception {
log.info("Initializing HumanTaskCoordination Test Case");
init();
requestSender = new RequestSender();
userManagementClient = new UserManagementClient(backEndUrl, sessionCookie);
log.info("Deploy ClaimsApprovalProcess and ClaimsApprovalTask artifacts");
deployArtifact();
log.info("Adding Users and Roles");
addRoles();
log.info("Enable HumanTask coordination and restarting server.");
serverConfigurationManager = new ServerConfigurationManager(bpsServer);
applyCoordinationConfig();
setupTestClients();
}
示例2
/**
* Initializes before a test method. Removes users of admin group if exists. Adds new roles with
* permissions.
*
* @throws Exception
*/
@BeforeMethod(alwaysRun = true)
public void initialize() throws Exception {
super.init(TestUserMode.SUPER_TENANT_ADMIN);
String[] createPubSubUsers = new String[]{"authUser1", "authUser2"};
String[] pubSubUsers = new String[]{"authUser3", "authUser4"};
String[] noPermissionUsers = new String[]{"authUser5"};
String[] allUsers =
new String[]{"authUser1", "authUser2", "authUser3", "authUser4", "authUser5"};
// Logging into user management as admin
userManagementClient = new UserManagementClient(backendURL, "admin", "admin");
// Removing admin permission for all users
userManagementClient.updateUserListOfRole(FrameworkConstants.ADMIN_ROLE, null, allUsers);
// Adding roles along with users if roles does not exist.
userManagementClient
.addRole(CREATE_PUB_SUB_TOPIC_ROLE, createPubSubUsers, new String[]{ADD_TOPIC_PERMISSION});
userManagementClient.addRole(PUB_SUB_TOPIC_ROLE, pubSubUsers, new String[]{});
userManagementClient.addRole(NO_PERMISSION_TOPIC_ROLE, noPermissionUsers, new String[]{});
}
示例3
/**
* Initializes before a test method. Removes users of admin group if exists. Adds new roles with
* permissions.
*
* @throws Exception
*/
@BeforeMethod(alwaysRun = true)
public void initialize() throws Exception {
super.init(TestUserMode.SUPER_TENANT_ADMIN);
String[] createPubSubUsers = new String[]{"authUser1", "authUser2"};
String[] pubSubUsers = new String[]{"authUser3", "authUser4"};
String[] noPermissionUsers = new String[]{"authUser5"};
String[] allUsers =
new String[]{"authUser1", "authUser2", "authUser3", "authUser4", "authUser5"};
// Logging into user management as admin
userManagementClient = new UserManagementClient(backendURL, "admin", "admin");
// Removing admin permission for all users
userManagementClient.updateUserListOfRole(FrameworkConstants.ADMIN_ROLE, null, allUsers);
// Adding roles along with users if roles does not exist.
userManagementClient
.addRole(CREATE_PUB_SUB_TOPIC_ROLE, createPubSubUsers, new String[]{ADD_TOPIC_PERMISSION});
userManagementClient.addRole(PUB_SUB_TOPIC_ROLE, pubSubUsers, new String[]{});
userManagementClient.addRole(NO_PERMISSION_TOPIC_ROLE, noPermissionUsers, new String[]{});
}
示例4
/**
* Initializes before a test method. Removes users of admin group if exists. Adds new roles
* with permissions.
*
* @throws Exception
*/
@BeforeMethod(alwaysRun = true)
public void initialize() throws Exception {
super.init(TestUserMode.SUPER_TENANT_ADMIN);
String[] createPubSubUsers = new String[]{"authUser1", "authUser2"};
String[] pubSubUsers = new String[]{"authUser3", "authUser4"};
String[] noPermissionUsers = new String[]{"authUser5"};
String[] allUsers =
new String[]{"authUser1", "authUser2", "authUser3", "authUser4", "authUser5"};
// Logging into user management as admin
userManagementClient = new UserManagementClient(backendURL, "admin", "admin");
// Removing admin permission for all users
userManagementClient.updateUserListOfRole(FrameworkConstants.ADMIN_ROLE, null, allUsers);
// Adding roles along with users
userManagementClient
.addRole(CREATE_PUB_SUB_QUEUE_ROLE, createPubSubUsers, new String[]{ADD_QUEUE_PERMISSION});
userManagementClient.addRole(PUB_SUB_QUEUE_ROLE, pubSubUsers, new String[]{});
userManagementClient.addRole(NO_PERMISSION_QUEUE_ROLE, noPermissionUsers, new String[]{});
}
示例5
@BeforeClass(alwaysRun = true)
public void serviceDeployment() throws Exception {
super.init();
List<File> sqlFileLis = new ArrayList<File>();
sqlFileLis.add(selectSqlFile("CreateEmailUsersTable.sql"));
deployService(serviceName, createArtifact(
getResourceLocation() + File.separator + "samples" + File.separator + "dbs" + File.separator + "rdbms"
+ File.separator + serviceName + ".dbs", sqlFileLis));
backendUrl = dssContext.getContextUrls().getBackEndUrl();
/* login to the server as super user and add user with email user name for the test case */
userManagementClient = new UserManagementClient(backendUrl, sessionCookie);
userManagementClient.addRole("sampleRole", new String[] {}, new String[] { "admin" });
userManagementClient
.addUser("[email protected]", "test123", new String[] { "sampleRole" }, "emailUserProfile");
serverConfigurationManager = new ServerConfigurationManager(dssContext);
serverConfigurationManager.copyToComponentLib(new File(
getResourceLocation() + File.separator + "jar" + File.separator + "msgContextHandler-1.0.0.jar"));
String carbonHome = System.getProperty("carbon.home");
File sourceFile = new File(
getResourceLocation() + File.separator + "serverConfigs" + File.separator + "axis2.xml");
File destinationFile = new File(
carbonHome + File.separator + "conf" + File.separator + "axis2" + File.separator + "axis2.xml");
serverConfigurationManager
.applyConfiguration(sourceFile, destinationFile);//this will restart the server as well
LoginLogoutClient loginLogoutClient = new LoginLogoutClient(dssContext);
sessionCookie = loginLogoutClient.login();
serviceEndPoint = getServiceUrlHttp(serviceName);
}
示例6
@BeforeTest(alwaysRun = true)
public void addNonAdminUser() throws Exception {
AutomationContext esbContext = new AutomationContext("ESB", TestUserMode.SUPER_TENANT_ADMIN);
String sessionCookie = new LoginLogoutClient(esbContext).login();
ResourceAdminServiceClient resourceAdmin = new ResourceAdminServiceClient(
esbContext.getContextUrls().getBackEndUrl(), sessionCookie);
UserManagementClient userManagementClient = new UserManagementClient(
esbContext.getContextUrls().getBackEndUrl(), sessionCookie);
//done this change due to a bug in UM - please refer to carbon dev mail
// "G-Reg integration test failures due to user mgt issue."
String[] permissions = { "/permission/admin/configure/", "/permission/admin/login", "/permission/admin/manage/",
"/permission/admin/monitor", "/permission/protected" };
if (!userManagementClient.roleNameExists(ROLE_NAME)) {
userManagementClient.addRole(ROLE_NAME, null, permissions);
resourceAdmin.addResourcePermission("/", ROLE_NAME, "3", "1");
resourceAdmin.addResourcePermission("/", ROLE_NAME, "2", "1");
resourceAdmin.addResourcePermission("/", ROLE_NAME, "4", "1");
resourceAdmin.addResourcePermission("/", ROLE_NAME, "5", "1");
}
userManagementClient.addUser("nonadminuser", "password", new String[] { ROLE_NAME }, null);
//check user creation
nonAdminUser = new User();
nonAdminUser.setUserName("nonadminuser");
nonAdminUser.setPassword("password");
}
示例7
/**
* Initialize the test by deploying required artifacts.
* @throws Exception
*/
@BeforeGroups(groups = { "wso2.bps.task.people.assignment" })
protected void initialize() throws Exception {
log.info("Initializing HumanTask task creation Test...");
userManagementClient = new UserManagementClient(backEndUrl, sessionCookie);
addRoles();
humanTaskPackageManagementClient = new HumanTaskPackageManagementClient(backEndUrl, sessionCookie);
log.info("Add users success !");
humanTaskPackageManagementClient
.unDeployHumanTask(HumanTaskTestConstants.CLAIMS_APPROVAL_PACKAGE_ORG_ENTITY_NAME, "ApproveClaim");
deployArtifact();
requestSender.waitForProcessDeployment(backEndUrl + "ClaimService");
}
示例8
@BeforeGroups(groups = {"wso2.bps.task.people.assignment"})
protected void initialize() throws Exception {
log.info("Initializing HumanTask task creation Test...");
userManagementClient = new UserManagementClient(backEndUrl, sessionCookie);
addRoles();
humanTaskPackageManagementClient = new HumanTaskPackageManagementClient(backEndUrl, sessionCookie);
log.info("Add users success !");
deployArtifact();
requestSender.waitForProcessDeployment(backEndUrl + HumanTaskTestConstants.CLAIM_SERVICE);
}
示例9
protected void initialize() throws Exception {
log.info("Initializing HumanTask task creation Test...");
userManagementClient = new UserManagementClient(backEndUrl, sessionCookie);
addRoles();
instanceManagementClient = new BpelInstanceManagementClient(backEndUrl, sessionCookie);
humanTaskPackageManagementClient = new HumanTaskPackageManagementClient(backEndUrl, sessionCookie);
log.info("Add users success !");
deployArtifact();
requestSender.waitForProcessDeployment(backEndUrl + HumanTaskTestConstants.CLAIM_APPROVAL_PROCESS_SERVICE);
requestSender.waitForProcessDeployment(backEndUrl + HumanTaskTestConstants.CLAIM_SERVICE);
}
示例10
/**
* Creates a topic by giving topic creation rights to the user.
* 1. User is in a role with no permissions.
* 2. Admin gives permissions to the role to create topics and for logging in.
* 3. User creates a topic.
* 4. Validates whether topic is created.
*
* @throws XPathExpressionException
* @throws IOException
* @throws UserAdminUserAdminException
*/
@Test(groups = {"wso2.mb", "topic"})
public void createTopicPermissionTestCase() throws XPathExpressionException, IOException, UserAdminUserAdminException {
String topicName = "topicCreationPermission";
AutomationContext authAutomationContext =
new AutomationContext("MB", "mb001", FrameworkConstants.SUPER_TENANT_KEY,
"topicAuthUser");
User contextUser = authAutomationContext.getContextTenant().getContextUser();
String[] createPermissionUser = new String[]{contextUser.getUserNameWithoutDomain()};
// Logging into user management as admin
UserManagementClient userManagementClient =
new UserManagementClient(super.backendURL, "admin", "admin");
// Removing admin permission for user
userManagementClient.updateUserListOfRole(FrameworkConstants.ADMIN_ROLE, null, createPermissionUser);
// Adding roles along with users
userManagementClient
.addRole(CREATE_TOPIC_PERMISSION_ROLE, createPermissionUser, new String[]{ADD_TOPIC_PERMISSION, LOGIN_PERMISSION});
driver.get(getLoginURL());
LoginPage loginPage = new LoginPage(driver);
// Logging in to the the management console
HomePage homePage = loginPage.loginAs(contextUser.getUserNameWithoutDomain(), contextUser.getPassword());
TopicAddPage topicAddPage =
homePage.getTopicAddPage("home.mb.topics.add.without.queue.xpath");
// Creating a topic by the user and check whether valid dialog pop up is shown
Assert.assertEquals(topicAddPage.addTopic(topicName), true);
TopicsBrowsePage topicsBrowsePage = homePage.getTopicsBrowsePage("home.mb.topics.browse.without.queue.xpath");
// Checks whether topic is created in the browsing page
Assert.assertEquals(topicsBrowsePage.isTopicPresent(topicName), true);
}
示例11
/**
* Initializes the test case.
*
* @throws XPathExpressionException
* @throws RemoteException
* @throws UserAdminUserAdminException
*/
@BeforeClass(alwaysRun = true)
public void init() throws XPathExpressionException, RemoteException, UserAdminUserAdminException {
super.init(TestUserMode.SUPER_TENANT_USER);
// Logging into user management as admin and adding a new role to give permission for publishing/subscribe
userManagementClient = new UserManagementClient(backendURL, "[email protected]",
"admin");
String[] publishers = {"topictenantuser1"};
userManagementClient.addRole(PUBLISHER_ROLE, publishers, new String[]{});
}
示例12
/**
* Initializing test
*
* @throws XPathExpressionException
* @throws RemoteException
* @throws UserAdminUserAdminException
*/
@BeforeClass(alwaysRun = true)
public void init() throws XPathExpressionException, RemoteException, UserAdminUserAdminException {
super.init(TestUserMode.SUPER_TENANT_USER);
// Logging into user management as admin and adding a new role to give permission for publishing/subscribe
userManagementClient = new UserManagementClient(backendURL, "[email protected]",
"admin");
String[] publishers = {"topictenantuser1"};
userManagementClient.addRole(PUBLISHER_ROLE, publishers, new String[]{});
}
示例13
@BeforeClass(alwaysRun = true)
public void serviceDeployment() throws Exception {
super.init();
List<File> sqlFileLis = new ArrayList<File>();
sqlFileLis.add(selectSqlFile("CreateEmailUsersTable.sql"));
deployService(serviceName,
createArtifact(getResourceLocation() + File.separator + "samples" + File.separator
+ "dbs" + File.separator + "rdbms" + File.separator
+ serviceName + ".dbs", sqlFileLis));
backendUrl = dssContext.getContextUrls().getBackEndUrl();
/* login to the server as super user and add user with email user name for the test case */
userManagementClient = new UserManagementClient(backendUrl,sessionCookie);
userManagementClient.addRole("sampleRole", new String[]{},new String[]{"admin"});
userManagementClient.addUser("[email protected]","test123",new String[]{"sampleRole"},"emailUserProfile");
serverConfigurationManager = new ServerConfigurationManager(dssContext);
serverConfigurationManager.copyToComponentLib(new File(getResourceLocation()
+ File.separator + "jar" + File.separator
+ "msgContextHandler-1.0.0.jar"));
String carbonHome = System.getProperty("carbon.home");
File sourceFile = new File(getResourceLocation()
+ File.separator + "serverConfigs" + File.separator
+ "axis2.xml");
File destinationFile = new File(carbonHome + File.separator + "conf" + File.separator + "axis2"+ File.separator + "axis2.xml");
serverConfigurationManager.applyConfiguration(sourceFile, destinationFile);//this will restart the server as well
LoginLogoutClient loginLogoutClient = new LoginLogoutClient(dssContext);
sessionCookie = loginLogoutClient.login();
serviceEndPoint = getServiceUrlHttp(serviceName);
}
示例14
@BeforeTest(alwaysRun = true)
public void addNonAdminUser() throws Exception {
AutomationContext esbContext = new AutomationContext("ESB", TestUserMode.SUPER_TENANT_ADMIN);
String sessionCookie = new LoginLogoutClient(esbContext).login();
ResourceAdminServiceClient resourceAdmin = new ResourceAdminServiceClient(esbContext.getContextUrls().getBackEndUrl(), sessionCookie);
UserManagementClient userManagementClient = new UserManagementClient(esbContext.getContextUrls().getBackEndUrl(), sessionCookie);
//done this change due to a bug in UM - please refer to carbon dev mail
// "G-Reg integration test failures due to user mgt issue."
String[] permissions = {"/permission/admin/configure/",
"/permission/admin/login",
"/permission/admin/manage/",
"/permission/admin/monitor",
"/permission/protected"};
if (!userManagementClient.roleNameExists(ROLE_NAME)) {
userManagementClient.addRole(ROLE_NAME, null, permissions);
resourceAdmin.addResourcePermission("/", ROLE_NAME, "3", "1");
resourceAdmin.addResourcePermission("/", ROLE_NAME, "2", "1");
resourceAdmin.addResourcePermission("/", ROLE_NAME, "4", "1");
resourceAdmin.addResourcePermission("/", ROLE_NAME, "5", "1");
}
userManagementClient.addUser("nonadminuser", "password", new String[]{ROLE_NAME}, null);
//check user creation
nonAdminUser = new User();
nonAdminUser.setUserName("nonadminuser");
nonAdminUser.setPassword("password");
}
示例15
@BeforeClass(alwaysRun = true)
public void setUp() throws Exception {
super.init();
driver = new ESWebDriver(BrowserManager.getWebDriver());
baseUrl = getWebAppURL();
AutomationContext automationContext = new AutomationContext(PRODUCT_GROUP_NAME, TestUserMode.SUPER_TENANT_ADMIN);
backendURL = automationContext.getContextUrls().getBackEndUrl();
userManagementClient = new UserManagementClient(backendURL, userInfo.getUserName(), userInfo.getPassword());
adminUserName = automationContext.getSuperTenant().getTenantAdmin().getUserName();
adminUserPwd = automationContext.getSuperTenant().getTenantAdmin().getPassword();
}
示例16
/**
* add a role
*
* @return true if the created role exist
* @throws Exception
*/
private static boolean addRole() throws Exception {
UserManagementClient userManagementClient =
new UserManagementClient(backEndUrl, sessionCookie);
if (userManagementClient.roleNameExists("RoleSubscriptionTest")) {
return true;
}
userManagementClient.addRole("RoleSubscriptionTest",
new String[]{userNameWithoutDomain}, new String[]{""});
return userManagementClient.roleNameExists("RoleSubscriptionTest");
}
示例17
/**
* delete the added role and remove the added property of the collection or
* reource
*
* @param path path of the collection or resource
* @throws Exception
*/
private static void clean(String path) throws Exception {
UserManagementClient userManagementClient =
new UserManagementClient(backEndUrl, sessionCookie);
if (userManagementClient.roleNameExists("RoleSubscriptionTest")) {
// userManagementClient.deleteRole("RoleSubscriptionTest");
}
PropertiesAdminServiceClient propertiesAdminServiceClient =
new PropertiesAdminServiceClient(backEndUrl, sessionCookie);
propertiesAdminServiceClient.removeProperty(path, "TestProperty");
}
示例18
public void setInfoRolesAndUsers(String adminUserKey)
throws LoginAuthenticationExceptionException, RemoteException,
XPathExpressionException {
//todo -
// FrameworkProperties isProperties = FrameworkFactory.getFrameworkProperties(ProductConstant.IS_SERVER_NAME);
AutomationContext isContext = new AutomationContext("IS", "is", "carbon.supper", adminUserKey);
Tenant userAdminDetails = isContext.getContextTenant();
sessionCookie = login(userAdminDetails.getContextUser().getUserName(), userAdminDetails.getContextUser().getPassword(),
isContext.getContextUrls().getBackEndUrl());
userAdminStub = new UserManagementClient(isContext.getContextUrls().getBackEndUrl(), sessionCookie);
}
示例19
/**
* Creates a queue by giving queue creation rights to the user.
* 1. User is in a role with no permissions.
* 2. Admin gives permissions to the role to create queues and for logging in.
* 3. User creates a queue.
* 4. Validates whether queue is created.
*
* @throws IOException
* @throws UserAdminUserAdminException
* @throws XPathExpressionException
*/
@Test(groups = {"wso2.mb", "queue"})
public void createQueuePermissionTestCase() throws IOException, UserAdminUserAdminException,
XPathExpressionException {
String queueName = "queueCreationPermission";
AutomationContext authAutomationContext =
new AutomationContext("MB", "mb001", FrameworkConstants.SUPER_TENANT_KEY,
"queueAuthUser");
User contextUser = authAutomationContext.getContextTenant().getContextUser();
String[] createPermissionUsers = new String[]{contextUser.getUserNameWithoutDomain()};
// Logging into user management as admin
UserManagementClient userManagementClient =
new UserManagementClient(backendURL, "admin", "admin");
// Removing admin permission for user
userManagementClient
.updateUserListOfRole(FrameworkConstants.ADMIN_ROLE, null, createPermissionUsers);
// Adding roles along with user
userManagementClient.addRole(CREATE_QUEUE_PERMISSION_ROLE, createPermissionUsers,
new String[]{ADD_QUEUE_PERMISSION, LOGIN_PERMISSION});
driver.get(getLoginURL());
LoginPage loginPage = new LoginPage(driver);
// Logging in to the the management console
HomePage homePage = loginPage.loginAs(contextUser.getUserNameWithoutDomain(), contextUser.getPassword());
QueueAddPage queueAddPage = homePage.getQueueAddPage();
// Creating a queue by the user and check whether valid dialog pop up is shown
Assert.assertEquals(queueAddPage.addQueue(queueName), true);
QueuesBrowsePage queuesBrowsePage = homePage.getQueuesBrowsePage();
// Checks whether queue is created in the browsing page
Assert.assertEquals(queuesBrowsePage.isQueuePresent(queueName), true);
}
示例20
/**
* @param path path of the collection or resource to be subscribed
* @param type type of the element
* @return true if subscriptions are created for all events and required
* notifications are captured, false otherwise
* @throws Exception
*/
public boolean init(String path, AutomationContext automationContext, String type)
throws Exception {
this.automationContext = automationContext;
backEndUrl = this.automationContext.getContextUrls().getBackEndUrl();
LoginLogoutClient loginLogoutClient = new LoginLogoutClient(this.automationContext);
sessionCookie = loginLogoutClient.login();
userName = this.automationContext.getContextTenant().getContextUser().getUserName();
if (userName.contains("@"))
userNameWithoutDomain = userName.substring(0, userName.indexOf('@'));
else
userNameWithoutDomain = userName;
wsRegistryServiceClient =
registryProviderUtil.getWSRegistry(this.automationContext);
lifeCycleAdminServiceClient =
new LifeCycleAdminServiceClient(backEndUrl, sessionCookie);
userManagementClient =
new UserManagementClient(backEndUrl, sessionCookie);
infoServiceAdminClient =
new InfoServiceAdminClient(backEndUrl, sessionCookie);
humanTaskAdminClient =
new HumanTaskAdminClient(backEndUrl, sessionCookie);
resourceAdminServiceClient =
new ResourceAdminServiceClient(backEndUrl, sessionCookie);
addRole();
boolean result1 = true;
boolean result2 = true;
boolean result3 = true;
boolean result4 = true;
boolean result5;
boolean result6 = true;
boolean result7 = true;
boolean result8 = true;
if (!path.equals("/")) {
result1 =
consoleSubscribe(path, "LifeCycleCreated") && addLifeCycle(path) &&
getNotification("The LifeCycle was created") &&
managementUnsubscribe(path);
result2 =
consoleSubscribe(path, "CheckListItemChecked") &&
checkItem(path) &&
getNotification("The CheckList item 'Effective Inspection Completed' of LifeCycle State 'Tested' was Checked" +
" for resource at " + path + ".") &&
managementUnsubscribe(path);
result3 =
consoleSubscribe(path, "CheckListItemUnchecked") &&
unCheckItem(path) &&
getNotification("The CheckList item 'Effective Inspection Completed' of LifeCycle State 'Tested' was Unchecked" +
" for resource at " + path + ".") &&
managementUnsubscribe(path);
result4 =
consoleSubscribe(path, "LifeCycleStateChanged") &&
changeState(path) &&
getNotification("The LifeCycle State Changed from 'Tested' to 'Development'" +
" for resource at " + path + ".") &&
managementUnsubscribe(path);
}
result5 =
consoleSubscribe(path, type + "Updated") && update(path) &&
getNotification("at path " + path + " was updated.") &&
managementUnsubscribe(path);
if (type.equals("Collection")) {
result6 =
consoleSubscribe(path, "ChildCreated") &&
addChild(path) &&
getNotification("A resource was added to the collection " + path +
" at Path: " + path + "/" + CHILD) &&
managementUnsubscribe(path);
result7 =
consoleSubscribe(path, "ChildDeleted") &&
deleteChild(path) &&
getNotification("A resource was removed from the collection " + path +
" at Path: " + path + "/" + CHILD) &&
managementUnsubscribe(path);
}
if (!path.equals("/")) {
result8 =
consoleSubscribe(path, type + "Deleted") && delete(path) &&
getNotification("at path " + path + " was deleted.");
}
clean();
return result1 && result2 && result3 && result4 && result5 && result6 && result7 && result8;
}