创建用户并为其分配预定义角色

使用本节中的脚本可创建用户并为其分配身份域中的预定义角色。

这些脚本使用 EPM Automate 命令完成以下活动:
  • 以具有身份域管理员角色的服务管理员身份登录环境。

  • 从环境导出组和成员身份信息以重新生成您指定的快照,例如 example_snapshot.zip。假设您先前使用迁移导出组和成员身份对象创建了此快照。

  • 将快照 (example_snapshot.zip) 下载到本地目录。

  • 从环境中删除快照 (example_snapshot.zip)。

  • 从环境中注销。

  • 执行为其添加了自定义代码的操作。此类操作可以包括:

    • 提取 example_snapshot.zip 的内容
    • 以“名字,姓氏,电子邮件,用户登录名”格式将新用户信息附加到 HSS-Shared Services\resource\External Directory\Users.csv。有关详细信息,请参阅《Getting Started with Oracle Cloud》中的 "Importing a Batch of User Accounts"。
    • 将新用户的角色分配信息(以“名字,姓氏,电子邮件,用户登录名”格式)附加到 HSS-Shared Services\resource\External Directory\Roles\ 中的适当角色文件。例如,服务管理员角色分配应附加到 <service_name> Service Administrator.csv,而查看者角色分配应附加到 HSS-Shared Services\resource\External Directory\Roles\<service_name> Viewer.csv。有关详细信息,请参阅《Getting Started with Oracle Cloud》中的 "Assigning One Role to Many Users"。
    • 通过压缩 HSS-Shared Services 目录及其内容,使用更新的文件重新创建快照。
  • 以同时具有身份域管理员角色的服务管理员身份登录到环境。

  • 将修改后的 example_snapshot.zip 上传到环境。

  • example_snapshot.zip 导入环境中。

  • 从环境中删除上传的 example_snapshot.zip

  • 注销。

Windows 示例脚本

通过复制以下脚本来创建一个名为 createUsersAndAssignRoles.ps1 的文件。将其存储在本地目录中。
$inputproperties = ConvertFrom-StringData(Get-Content ./input.properties -raw)
$username="$($inputproperties.username)"
$passwordfile="$($inputproperties.passwordfile)"
$serviceURL="$($inputproperties.serviceURL)"
$snapshotName="$($inputproperties.snapshotName)"
$userspassword="$($inputproperties.userspassword)"
$resetPassword="$($inputproperties.resetPassword)"

epmautomate login ${username} ${passwordfile} ${serviceURL}
epmautomate exportsnapshot ${snapshotName}
epmautomate downloadfile ${snapshotName}.zip
epmautomate deletefile ${snapshotName}.zip
epmautomate logout

# Add custom code to extract the contents of example_snapshot.zip
# Add custom code to append new user information to HSS-Shared Services\resource\External Directory\Users.csv
# Optional: Add custom code to append role information to the appropriate role file(s) in HSS-Shared Services\resource\External Directory\Roles\
# Add custom code to zip HSS-Shared Services and its contents as example_snapshot.zip

epmautomate login ${username} ${passwordfile} ${serviceURL}
epmautomate uploadfile ${snapshotName}.zip
epmautomate importsnapshot ${snapshotName} userPassword=${userspassword} resetPassword=${resetPassword}
epmautomate deletefile ${snapshotName}.zip
epmautomate logout

Linux/UNIX 示例脚本

通过复制以下脚本来创建一个名为 createUsersAndAssignRoles.sh 的文件。将其存储在本地目录中。
#!/bin/bash

. ./input.properties
export JAVA_HOME=${javahome}
${epmautomatescript} login "${username}" "${passwordfile}" "${serviceURL}"
${epmautomatescript} exportsnapshot "${snapshotName}"
${epmautomatescript} downloadfile "${snapshotName}.zip"
${epmautomatescript} deletefile "${snapshotName}.zip"
${epmautomatescript} logout

# Add custom code to extract the contents of example_snapshot.zip
# Add custom code to append new user information to HSS-Shared Services\resource\External Directory\Users.csv
# Optional: Add custom code to append role information to the appropriate role file(s) in HSS-Shared Services\resource\External Directory\Roles\
# Add custom code to zip HSS-Shared Services and its contents as example_snapshot.zip

${epmautomatescript} login "${username}" "${passwordfile}" "${serviceURL}"
${epmautomatescript} uploadfile "${snapshotName}.zip"
${epmautomatescript} importsnapshot "${snapshotName}" "userPassword=${userspassword}" "resetPassword=${resetPassword}"
${epmautomatescript} deletefile "${snapshotName}.zip"
${epmautomatescript} logout

示例 input.properties 文件

要运行 createUsersAndAssignRoles 脚本,请创建 input.properties 文件并使用环境信息进行相应的更新。将文件保存在存储 createUsersAndAssignRoles.ps1createUsersAndAssignRoles.sh 的目录中。

Windows

uusername=exampleAdmin
passwordfile=examplePassword.epw
serviceURL=exampleURL
snapshotName=SNAPSHOT_NAME
userspassword=TEMP_IDM_PASSWORD
resetPassword=true

Linux/UNIX

javahome=JAVA_HOME
epmautomatescript=EPM_AUTOMATE_LOCATION
username=exampleAdmin
passwordfile=examplePassword.epw
serviceURL=exampleURL
snapshotName=SNAPSHOT_NAME
userspassword=TEMP_IDM_PASSWORD
resetPassword=true

表 3-2 input.properties 参数

参数 说明
javahome JAVA_HOME 位置。仅限 Linux/UNIX。
epmautomatescript EPM Automate 可执行文件 (epmautomate.sh) 的绝对路径。仅限 Linux/UNIX。
username 同时具有身份域管理员角色的服务管理员的用户名。
password 服务管理员的密码或加密密码文件的名称和位置。
serviceURL 要从其生成快照的环境的 URL。
snapshotName 要生成的快照的名称。假设您先前使用迁移导出组和成员身份对象创建了此快照。
userspassword 新用户的初始密码。
resetPassword 新用户初次登录时是否必须重置密码。将此值设置为 true 将强制新用户在首次登录时更改其密码。

重新运行该脚本

  1. 通过复制上一节的脚本来创建 createUsersAndAssignRoles.ps1createUsersAndAssignRoles.sh
  2. 添加自定义代码以执行以下操作:
    • 提取快照的内容
    • 将新用户信息附加到 HSS-Shared Services\resource\External Directory\Users.csv
    • (可选)将新用户的角色分配信息(以“名字,姓氏,电子邮件,用户登录名”格式)附加到 HSS-Shared Services\resource\External Directory\Roles\ 中的适当角色文件。
    • 使用更新的文件重新创建快照。
  3. 创建 input.properties 文件,并将其保存在 createUsersAndAssignRoles 脚本所在的目录中。此文件的内容因操作系统的不同而异。请参阅“示例 input.properties 文件”。

    请确保您对此目录具有写权限。对于 Windows,您可能需要使用以管理员身份运行选项启动 PowerShell,以便能够运行脚本。

  4. 启动脚本。
    • Windows PowerShell:运行 createUsersAndAssignRoles.ps1
    • Linux/UNIX:运行 ./createUsersAndAssignRoles.sh