private function creatGroup($username, $password, $officialName, $groupType)
 {
     $stateGroup = new Group();
     $stateGroup->setUsername($username);
     $stateGroup->setManagerEmail('*****@*****.**');
     $stateGroup->setOfficialName($officialName);
     $stateGroup->setGroupType($groupType);
     $generator = new SecureRandom();
     $password = $generator->nextBytes(10);
     $stateGroup->setPassword($password);
     return $stateGroup;
 }
 private function creatGroup($username, $password, $officialName, $groupType, $parent = null)
 {
     $stateGroup = new Group();
     $stateGroup->setUsername($username);
     $stateGroup->setManagerEmail(self::COMMON_STATE_GROUP_EMAIL);
     $stateGroup->setOfficialName($officialName);
     $stateGroup->setGroupType($groupType);
     $stateGroup->setParent($parent);
     $stateGroup->setLocationName($username);
     $generator = new SecureRandom();
     $factory = $this->container->get('security.encoder_factory');
     $encoder = $factory->getEncoder($stateGroup);
     $password = $encoder->encodePassword(sha1($generator->nextBytes(10)), $stateGroup->getSalt());
     $stateGroup->setPassword($password);
     return $stateGroup;
 }
 public function setGroupType($type)
 {
     $this->__load();
     return parent::setGroupType($type);
 }
 public function getLocalGroup(AddressComponent $addressComponent, Group $stateGroup = null)
 {
     $group = $this->findLocalGroup($addressComponent->getShortName(), $stateGroup);
     if (!$group) {
         $group = new Group();
         $group->setGroupType(Group::GROUP_TYPE_LOCAL)->setUsername($addressComponent->getShortName() . uniqid())->setOfficialName($addressComponent->getLongName())->setLocationName($addressComponent->getShortName())->setParent($stateGroup);
         $generator = new SecureRandom();
         $group->setPassword(sha1($generator->nextBytes(10)));
         $this->getEntityManager()->persist($group);
         $this->getEntityManager()->flush($group);
     }
     return $group;
 }