-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow Service Group level roles to be created
- creates new file to allow the creation of service group level roles - adds new file to DeploySampleDataRunner
- Loading branch information
Showing
2 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?php | ||
|
||
require_once __DIR__."/../bootstrap.php"; | ||
require_once __DIR__."/AddUtils.php"; | ||
|
||
$usersRolesFileName = __DIR__ . "/" . $GLOBALS['dataDir'] . "/UsersAndRoles.xml"; | ||
$usersRoles = simplexml_load_file($usersRolesFileName); | ||
|
||
foreach($usersRoles as $user) { | ||
foreach($user->USER_ROLE as $role) { | ||
// Check for blank role, skip if it's blank | ||
if((string) $role->USER_ROLE == "") { | ||
continue; | ||
} | ||
|
||
// Skip all non-serviceGroup roles | ||
if ((string) $role->ENTITY_TYPE !== "serviceGroup") { | ||
continue; | ||
} | ||
|
||
// get roletype entity | ||
$userRole = (string) $role->USER_ROLE; | ||
$dql = "SELECT rt FROM RoleType rt WHERE rt.name = :roleType"; | ||
$roleTypes = $entityManager->createQuery($dql) | ||
->setParameter(':roleType', $userRole) | ||
->getResult(); | ||
|
||
/* | ||
* Error checking: ensure each role type refers to exactly | ||
* one role type | ||
*/ | ||
if(count($roleTypes) !== 1) { | ||
throw new Exception(count($roleTypes) . " role types found with name: " . | ||
$userRole); | ||
} | ||
|
||
foreach($roleTypes as $result) { | ||
$roleType = $result; | ||
} | ||
|
||
// Get user entity | ||
$userDN = (string) $user->CERTDN; | ||
$dql = "SELECT u FROM User u JOIN u.userIdentifiers up WHERE up.keyValue = :keyValue"; | ||
$users = $entityManager->createQuery($dql) | ||
->setParameter('keyValue', trim($userDN)) | ||
->getResult(); | ||
|
||
/* | ||
* Error checking: ensure each "user" refers to exactly | ||
* one user | ||
*/ | ||
if(count($users) !== 1) { | ||
throw new Exception(count($users) . " users found with DN: " . | ||
$userDN); | ||
} | ||
|
||
foreach($users as $doctrineUser) { | ||
$doctrineUser = $doctrineUser; | ||
} | ||
|
||
// get serviceGroup entity | ||
$sgName = (string) $role->ON_ENTITY; | ||
$dql = "SELECT sg FROM ServiceGroup sg WHERE sg.name = :service_group"; | ||
$serviceGroups = $entityManager->createQuery($dql) | ||
->setParameter('service_group', $sgName) | ||
->getResult(); | ||
|
||
/* | ||
* Error checking: ensure each "service group" refers to exactly | ||
* one service group | ||
*/ | ||
if(count($serviceGroups) !== 1) { | ||
throw new Exception(count($serviceGroups) . " Service Groups found name: " . | ||
$sgName); | ||
} | ||
|
||
foreach($serviceGroups as $serviceGroup) { | ||
$serviceGroup = $serviceGroup; | ||
} | ||
|
||
$doctrineRole = new Role($roleType, $doctrineUser, $serviceGroup, 'STATUS_GRANTED'); | ||
$entityManager->persist($doctrineRole); | ||
} | ||
} | ||
|
||
$entityManager->flush(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters