반응형
블로그 이미지
개발자로서 현장에서 일하면서 새로 접하는 기술들이나 알게된 정보 등을 정리하기 위한 블로그입니다. 운 좋게 미국에서 큰 회사들의 프로젝트에서 컬설턴트로 일하고 있어서 새로운 기술들을 접할 기회가 많이 있습니다. 미국의 IT 프로젝트에서 사용되는 툴들에 대해 많은 분들과 정보를 공유하고 싶습니다.
솔웅

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

글 보관함

카테고리

Database Authentication

2012. 9. 12. 21:01 | Posted by 솔웅


반응형

Database Authentication


DatabaseAuthentication 클래스는 열결된 데이터베이스에 있는 authentication과 user/group 정보를 제공합니다. 데이터베이스는 main configuration file에 셋업된 디폴트 데이터베이스를 사용할 수도 있고 그 자체의 credential과 세팅을 가지고 있는 별도의 시스템을 사용할 수도 있습니다. 여러분은 이 authentication data를 찾는데 사용되는 테이블을 customize 할 수 있습니다. 그리고 비밀전호 hash를 위한 알고리즘을 지정할 수도 있습니다. authority도 최소한의 configuration으로 새로운 series of table들을 쉽게 셋업할 수 있도록 디폴트 세팅 세트를 제공합니다.


Note : 현재 이 authority에서는 유저나 그룹을 생성하거나 관리하는 기능을 제공하지는 않습니다. 이 글은 여러분이 이미 만들어진 시스템에 연결하는 상황 그리고 여러분이 유저와 그룹을 관리하는 상황을 가정하고 작성되었습니다.




Configuration


DatabaseAuthentication authority는 여러 configuration value들을 가지고 있습니다. 모두 optional 입니다. 아래 value들이 데이터베이스에 연결하는데 영향을 미치는 것들입니다.

  • DB_TYPE - database system은 PDO를 통해 mysql과 sqlite를 지원합니다. 
  • DB_HOST - used by db systems that are hosted on a server
  • DB_USER - used by db systems that require a user to authenticate
  • DB_PASS - used by db systems that require a password
  • DB_DBNAME - used by db systems that require a database
  • DB_FILE - used by db systems the use a file (i.e. sqlite).


위 값들 중 빠진 값들은 SITE_DIR/config/site.ini에서 connectivity settings 을 가져와서 디폴트로 사용할 겁니다. 데이터베이스에 query를 어떻게 할지에 대한 여러 옵션들이 있습니다. 이 때 유저와 그룹 모두를 사용할 필요는 없습니다. 한가지만 필요하면 그걸 사용하시면 됩니다.


아래 값들은 데이터가 위치한 데이터베이스 테이블의 authority를 나타냅니다 :


  • DB_USER_TABLE - (users) The name of the table that stores the user records. This table should at least have fields for userID, password and email. It can also have fields for first/last name or full name. Each row should contain a single user entry
  • DB_GROUP_TABLE (groups) The name of the table that stores group information. It should have fields for shortname and group id. Each row should contain a single group entry.
  • DB_GROUPMEMBERS_TABLE - (groupmembers) The name of the table that stores the members of each group, it should have a field for the group name/id and the userID of the user. Each row should contain an entry that contains the group name and userID. The system will search for members that match the group name.


아래 값들은 어떤 필드들을 사용할지에 대해 authority에 알려 줍니다. :


  • DB_USER_USERID_FIELD (userID)- stores the userID in the user table. For systems that use the email address as the key, you should include the email field
  • DB_USER_PASSWORD_FIELD (password) -stores a hashed value of the user’s password. See DB_USER_PASSWORD_HASH for possible hashing algorithms (Default is md5)
  • DB_USER_EMAIL_FIELD (email) - stores the email in the user table
  • DB_USER_FIRSTNAME_FIELD (empty) - stores the first name of user. Won’t be used unless it is specified
  • DB_USER_LASTNAME_FIELD (empty) - stores the last name of user. Won’t be used unless it is specified
  • DB_USER_FULLNAME_FIELD (empty) - stores the full name of user. Won’t be used unless it is specified
  • DB_GROUP_GROUPNAME_FIELD (group) - stores the short name of the group in the group table
  • DB_GROUP_GID_FIELD - (gid) - stores the group id of the group in the group table. Should be numerical
  • DB_GROUPMEMBER_GROUP_FIELD (gid) - which field to use when looking up groups in the group member table. This is typically the same value as the group name or gid field
  • DB_GROUPMEMBER_USER_FIELD (userID) - which field to use when looking up user in the group member table. This is typically either the userID or the email
  • DB_GROUPMEMBER_AUTHORITY_FIELD - If present you can store the authority index in this field. This allows the system to map group members to other authorities.


다른 값들은 어떻게 그룹 멤버쉽이 키가 되는지를 알려줍니다.


  • DB_GROUP_GROUPMEMBER_PROPERTY - (gid) - This is not stored in the database, but refers to which field will be used to look up group information in the group member table. Valid values are gid or group (i.e. the shortname) gid is the default.


암호 해싱 방법과 관련한 값들도 있습니다.


  • DB_USER_PASSWORD_HASH (md5) - This is a string that represents a valid hashing function. It indicates what

    hashing algorithm is used to store the password. See hash_algos() for a list of valid hashing algorithms. Keep in mind that available algorithms may differ by PHP version and platform. You can also use the hmac_ prefix to use the hmac signing method (i.e. hmac_sha1). This requires setting the DB_USER_PASSWORD_KEY value.

  • DB_USER_PASSWORD_KEY (empty) - Necessary if you use the more secure hmac variant hashing algorithms. This uses a shared key to sign the value using hash_hmac

  • DB_USER_PASSWORD_SALT_BEFORE (empty) - If present this string will be prepended to any string as a salt value before hashing. This is useful if you are using fixed salts.

  • DB_USER_PASSWORD_SALT_AFTER (empty) - If present this string will be appended to any string as a salt value before hashing. This is useful if you are using fixed salts.

  • DB_USER_PASSWORD_SALT_FIELD_BEFORE (empty) - If present the value of this field for the user will be prepended to any string as a salt value before hashing. This is useful if you are using variable salts.

  • DB_USER_PASSWORD_SALT_FIELD_AFTER (empty) - If present the value of this field for the user will be appended to any string as a salt value before hashing. This is useful if you are using variable salts.


How it Works


User Authentication


USER_LOGIN을 FORM으로 해서 user authentication 을 지원한다면 authority는 USER_TABLE을 볼겁니다. 그리고 타입된 값과 맞는 DB_USER_USERID_FIELDDB_USER_EMAIL_FIELD 의 레코드 값을 찾을 겁니다. 해당 record를 찾으면 DB_USER_USERID_FIELD에 있는 값이 type 된 패스워드의 hashed 값과 매치 되는 지를 볼 거구요. (이때 DB_USER_PASSWORD_HASH algorithm을 사용합니다.) 데이터베이스에서 사용한 해쉬 알고리즘과 configuration에서 지정한 해쉬 알고리즘이 동일해야 합니다.


User Lookup


Users는 DB_USER_TABLE를 살피고 요청된 값과 DB_USER_USERID_FIELD or DB_USER_EMAIL_FIELD의 record 가 맞는지  봅니다. 만약에 맞는것을 찾으면 user object는 생성됩니다. 생성되는 것들은 값이 있는 경우 다음의 내용이 포함됩니다. B_USER_USERID_FIELD, DB_USER_EMAIL_FIELD and DB_USER_FIRSTNAME_FIELD,*DB_USER_LASTNAME_FIELD* and DB_USER_FULLNAME_FIELD


Group Lookup


Groups은 을 살피고 요청된 값과 DB_GROUP_GROUPNAME_FIELD or DB_GROUP_GID_FIELD의 record가 맞는지 봅니다. 만약에 맞는 것을 찾으면 group object가 생성됩니다. 생성되는 것들은 DB_GROUP_GROUPNAME_FIELD and DB_GROUP_GID_FIELD 값입니다.


Group Membership Lookup


Group membership은 DB_GROUPMEMBERS_TABLE안에서 query 됩니다. getMembers() 메소드는 DB_GROUPMEMBER_USER_FIELD를 사용해서 유저 객체 배열을 만듭니다.  DB_GROUPMEMBER_GROUP_FIELD 와 매치되는 모든 users는 return 됩니다. (DB_GROUP_GROUPMEMBER_PROPERTY,를 사용해서 리턴됩니다. 예:gid,short name) 그 user 객체들은 DB_GROUPMEMBER_AUTHORITY_FIELD에 의해 authority reference 되서 생성됩니다. 만약에 authority field 가 없으면 그룹과 같은 authority를 사용합니다. (예: DB_USER_TABLE를 사용할 겁니다.) 테이블의 다른 authority를 참조할 수 있습니다. (예: ldap users, google users 등)


Using Default Values


여러분의 reference database를 include 하고 싶으시면 아래와 같이 정의된 테이블의 모든 디폴트 값을 사용할 수 있습니다.



CREATE TABLE users (userID varchar(64), password varchar(32), email varchar(64),

firstname varchar(50), lastname varchar(50)); CREATE TABLE groups (`group` varchar(16), gid int); CREATE TABLE groupmembers (gid int, authority varchar(32), userID varchar(64));


이것은 디폴트 값들과 호환되는 테이블 구조입니다.


반응형