github.com/silveraid/fabric-ca@v1.1.0-preview.0.20180127000700-71974f53ab08/lib/spi/userregistry.go (about) 1 /* 2 Copyright IBM Corp. 2016 All Rights Reserved. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 /* 18 * This file defines the user registry interface used by the fabric-ca server. 19 */ 20 21 package spi 22 23 import ( 24 "github.com/hyperledger/fabric-ca/api" 25 "github.com/jmoiron/sqlx" 26 ) 27 28 // UserInfo contains information about a user 29 type UserInfo struct { 30 Name string 31 Pass string `mask:"password"` 32 Type string 33 Affiliation string 34 Attributes []api.Attribute 35 State int 36 MaxEnrollments int 37 Level int 38 } 39 40 // DbTxResult returns information on any affiliations and/or identities affected 41 // during a database transaction 42 type DbTxResult struct { 43 Affiliations []Affiliation 44 Identities []User 45 } 46 47 // User is the SPI for a user 48 type User interface { 49 // Returns the enrollment ID of the user 50 GetName() string 51 // Return the type of the user 52 GetType() string 53 // Return the max enrollments of the user 54 GetMaxEnrollments() int 55 // Login the user with a password 56 Login(password string, caMaxEnrollment int) error 57 // Get the complete path for the user's affiliation. 58 GetAffiliationPath() []string 59 // GetAttribute returns the value for an attribute name 60 GetAttribute(name string) (*api.Attribute, error) 61 // GetAttributes returns the requested attributes 62 GetAttributes(attrNames []string) ([]api.Attribute, error) 63 // ModifyAttributes adds, removes, or deletes attribute 64 ModifyAttributes(attrs []api.Attribute) error 65 // LoginComplete completes the login process by incrementing the state of the user 66 LoginComplete() error 67 // Revoke will revoke the user, setting the state of the user to be -1 68 Revoke() error 69 // GetLevel returns the level of the user, level is used to verify if the user needs migration 70 GetLevel() int 71 // SetLevel sets the level of the user 72 SetLevel(level int) error 73 } 74 75 // UserRegistry is the API for retreiving users and groups 76 type UserRegistry interface { 77 GetUser(id string, attrs []string) (User, error) 78 InsertUser(user *UserInfo) error 79 UpdateUser(user *UserInfo, updatePass bool) error 80 DeleteUser(id string) (User, error) 81 GetAffiliation(name string) (Affiliation, error) 82 GetAllAffiliations(name string) (*sqlx.Rows, error) 83 InsertAffiliation(name string, prekey string, level int) error 84 // GetProperties returns the properties by name from the database 85 GetProperties(name []string) (map[string]string, error) 86 GetUserLessThanLevel(version int) ([]User, error) 87 GetFilteredUsers(affiliation, types string) (*sqlx.Rows, error) 88 DeleteAffiliation(name string, force, identityRemoval, isRegistrar bool) (*DbTxResult, error) 89 ModifyAffiliation(oldAffiliation, newAffiliation string, force, isRegistrar bool) (*DbTxResult, error) 90 GetAffiliationTree(name string) (*DbTxResult, error) 91 }