< 이전 | 다음 >

사용자 데이터베이스에 로그온

Session을 작성하고 나면, 액세스 가능한 데이터베이스 목록을 가져올 수 있으며 사용자 데이터베이스에 로그온하려면 로그온 신임을 제공해야 합니다.
권한이 없는 사용자로부터 데이터베이스를 보호하기 위해, 레코드에 액세스하기 전에 데이터베이스에 로그온해야 합니다. 후크의 경우, 이 사용자 인증은 Rational ClearQuest 클라이언트 애플리케이션에 의해 자동으로 처리됩니다. 그러나 외부 애플리케이션은 Session 오브젝트를 사용하여 프로그램적으로 로그온해야 합니다.
로그온할 데이터베이스를 판별하고 로그온을 수행하려면 다음 단계를 따르십시오.
  1. Session 오브젝트의 GetAccessibleDatabases 메소드를 호출하여 스키마 저장소와 연관된 데이터베이스 목록을 가져오십시오. 이 메소드는 각각 단일 사용자 데이터베이스에 대한 정보를 포함하는 DatabaseDesc 오브젝트 콜렉션을 리턴합니다.
  2. DatabaseDesc 오브젝트의 메소드를 사용하여 데이터베이스의 이름 또는 데이터베이스가 속한 데이터베이스 세트(스키마 저장소 및 연관된 데이터베이스)와 같은 특정 데이터베이스 정보를 가져오십시오.
  3. Session 오브젝트의 UserLogon 메소드를 호출하여 데이터베이스에 로그온하십시오.
UserLogon 메소드에는 네 개의 인수가 사용됩니다.
$CQsession->UserLogon(login_name, password, database_name, database_set_name); 
모든 인수는 문자열입니다. 예를 들어, 다음과 같습니다.
$CQSession->UserLogon("admin", "", "SAMPL", ""); 

다음 코드 예제에서, 사용자(admin)는 액세스 가능한 데이터베이스를 가져와서 데이터베이스 perl2에 로그인합니다.
require CQPerlExt; 
$CQsession = CQSession::Build();

#Start a Rational ClearQuest session
$sessionObj = CQSession::Build();

#Get a list of accessible databases
$databases = $sessionObj->GetAccessibleDatabases("MASTR", "admin", "");
$count = $databases->Count();

$sessionObj->UserLogon("admin", "", "perl2", "");  

#For each accessible database, 
# get database name and login as joe with password gh36ak3: 
for($x=0;$x<$count;$x++)
   { 
     $db = $databases->Item($x);
     $dbName = $db->GetDatabaseName();
     # Logon to the database 
     $sessionObj->UserLogon( "joe", "gh36ak3", $dbName, "" );
     #... 
   } 

# You can also ise the GetSessionDatabase method rather than the GetAccessibleDatabases method
$dbDesc = $sessionObj->GetSessionDatabase();  

# The GetSessionDatabase method returns information about the database that is being accessed 
# in the current session. This method differs from the GetAccessibleDatabases method in that it 
# returns the DatabaseDescription object associated with the current session. You can only call
# this method after the user has logged in to a particular database.


print "DB name = ", $dbDesc->GetDatabaseName(), "\n";
print "DB set name = ", $dbDesc->GetDatabaseSetName(), "\n";
print "DB connect string = ", $dbDesc->GetDatabaseConnectString(), "\n";
print "User login name = ", $sessionObj->GetUserLoginName(), "\n";  
print "User full name = ", $sessionObj->GetUserFullName(), "\n";  
print "User email = ", $sessionObj->GetUserEmail(), "\n";  
print "User phone = ", $sessionObj->GetUserPhone(), "\n";  
print "Misc user info = ", $sessionObj->GetUserMiscInfo(), "\n";  
print "User groups: \n";
$userGroups = $sessionObj->GetUserGroups();  
if (!@$userGroups) 
     {  # Code to handle if no user groups exist 
        print "This user does not belong to any groups\n";
     }  
else
     {  # Print out all groups 
        foreach $groupname (@$userGroups) 
             { print "Group $groupname\n"; }
     }  
CQSession::Unbuild($sessionObj);

단원 체크포인트

이제, ClearQuest API를 사용하여 세션을 가져오고 데이터베이스에 로그인하는 방법을 학습했으므로, 실제 ClearQuest 클라이언트 유스 케이스(예: 조회, 차트, 보고서 실행 및 작성과, 레코드 보기, 수정 및 작성)를 수행하는 방법에 대한 학습을 시작할 수 있습니다.

피드백