本文整理汇总了C++中Owned::createUser方法的典型用法代码示例。如果您正苦于以下问题:C++ Owned::createUser方法的具体用法?C++ Owned::createUser怎么用?C++ Owned::createUser使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Owned
的用法示例。
在下文中一共展示了Owned::createUser方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: initLDAP
//-----------------------------------------------------
//
//-----------------------------------------------------
bool initLDAP(IPropertyTree * ldapProps)
{
StringAttr serverType( ldapProps->queryProp("@serverType") );
if (!serverType.length())
{
fprintf(stderr, "\nERROR: serverType not set in LDAPServer component");
return false;
}
StringBuffer hpccUser;
StringBuffer hpccPwd;
ldapProps->getProp("@systemUser", hpccUser);
ldapProps->getProp("@systemPassword", hpccPwd);
if (0==hpccUser.length() || 0==hpccPwd.length())
{
fprintf(stderr, "\nERROR: HPCC systemUser credentials not found in configuration");
return false;
}
StringBuffer ldapAddress;
ldapProps->getProp("@ldapAddress", ldapAddress);
//Get LDAP admin creds from user
char buff[100];
fprintf(stdout, "\nEnter the '%s' LDAP Admin User name on '%s'...",serverType.get(),ldapAddress.str());
do
{
char * line = fgets(buff, sizeof(buff), stdin);
if (!line)
return false;
}
while (buff[0] == (char)'\n');
if (buff[strlen(buff)-1] == '\n')
buff[strlen(buff)-1] = (char)NULL;
StringAttr ldapUser(buff);
fprintf(stdout, "Enter the LDAP Admin user '%s' password...",ldapUser.get());
char * line = fgets(buff, sizeof(buff), stdin);
if (!line)
return false;
if (buff[strlen(buff)-1] == '\n')
buff[strlen(buff)-1] = (char)NULL;
StringAttr ldapPwd(buff);
if (0==ldapUser.length() || 0==ldapPwd.length())
{
fprintf(stderr, "\nERROR: Invalid LDAP Admin account credentials entered");
return false;
}
fprintf(stdout, "\nReady to initialize HPCC LDAP Environment, using the following settings");
fprintf(stdout, "\n\tLDAP Server : %s", ldapAddress.str());
fprintf(stdout, "\n\tLDAP Type : %s", serverType.get());
fprintf(stdout, "\n\tHPCC Admin User : %s", hpccUser.str());
fprintf(stdout, "\nProceed? y/n ");
for (;;)
{
int c = getchar();
if (c == 'y' || c == 'Y')
break;
else if (c == 'n' || c == 'N')
return true;
}
if (stricmp(serverType.get(),"ActiveDirectory"))
ldapProps->setProp("@systemBasedn", "");
//Replace system user with LDAP Admin credentials
ldapProps->setProp("@systemUser", ldapUser);
ldapProps->setProp("@systemCommonName", ldapUser);
StringBuffer sb;
encrypt(sb,ldapPwd);
ldapProps->setProp("@systemPassword", sb.str());
//Create security manager. This creates the required OUs
Owned<ISecManager> secMgr;
try
{
secMgr.setown(newLdapSecManager("initldap", *LINK(ldapProps)));
}
catch(IException *e)
{
StringBuffer buff;
e->errorMessage(buff);
e->Release();
fprintf(stderr, "\nERROR: Unable to create security manager : %s", buff.str());
return false;
}
//Create HPCC Admin user
Owned<ISecUser> user = secMgr->createUser(hpccUser.str());
StringBuffer pwd;
decrypt(pwd, hpccPwd.str());
user->credentials().setPassword(pwd.str());
try { secMgr->addUser(*user.get()); }
catch(...) {}//user may already exist, so just move on
//.........这里部分代码省略.........
示例2: main
//.........这里部分代码省略.........
{
printf("security manager can't be created\n");
return -1;
}
if(action == NULL || stricmp(action, "-ac") == 0)
{
if(username == NULL || *username == '\0')
{
printf("missing username\n");
return -1;
}
if(resource == NULL || *resource == '\0')
{
printf("missing resource\n");
return -1;
}
SecResourceType rtype = RT_DEFAULT;
if((resourcetype != NULL) && (stricmp(resourcetype, "filescope") == 0))
rtype = RT_FILE_SCOPE;
else if((resourcetype != NULL) && (stricmp(resourcetype, "workunit") == 0))
rtype = RT_WORKUNIT_SCOPE;
StringBuffer passbuf;
if(passwd == NULL || *passwd == '\0')
{
getpassword("Enter password: ", passbuf, false);
passwd = passbuf.str();
}
if(!stress)
{
Owned<ISecUser> usr = secmgr->createUser(username);
usr->credentials().setPassword(passwd);
int access = secmgr->authorizeEx(rtype, *usr, resource);
printf("%s's permission = %d \n", resource, access);
}
else
{
CPermissionCheckThread** thrds = new CPermissionCheckThread*[numthrds];
for(int i = 0; i < numthrds; i++)
thrds[i] = new CPermissionCheckThread(secmgr, username, passwd, resource, rtype, numrounds);
for(int j = 0; j < numthrds; j++)
thrds[j]->start();
for(int k = 0; k < numthrds; k++)
thrds[k]->join();
}
}
else if(stricmp(action, "-au") == 0)
{
if(username == NULL || *username == '\0')
{
printf("missing username\n");
return -1;
}
Owned<ISecUser> usr = secmgr->createUser(username);
if(firstname != NULL)
usr->setFirstName(firstname);
if(lastname != NULL)
usr->setLastName(lastname);
usr->credentials().setPassword(passwd);
bool ok = usr?secmgr->addUser(*usr):false;
if(ok)
printf("user %s added\n", username);