diff --git a/ApiDocs/_apidoc.js b/ApiDocs/_apidoc.js index e69de29..90706b7 100644 --- a/ApiDocs/_apidoc.js +++ b/ApiDocs/_apidoc.js @@ -0,0 +1,1742 @@ +/** + * @api {ServiceMethod: create} /organizations/create create + * @apiName CreateOrganization + * @apiGroup Organization + * @apiVersion 2.1.3-SNAPSHOT + * @apiPermission Request / Response / Error-response + * + * @apiDescription This operation enables any user with valid Token to create the specific organization and store its information (metadata). + * + * @apiParam {Object} token The requested token issued by relevant authority (Auth0) + * @apiParam {String} name Specified organization name + * @apiParam {String} email Specified organization e-mail + * + * @apiSuccess {Object[]} apiKeys List of all API keys (Array of objects) for the relevant organization + * @apiSuccess {String} id Generated id for the created organization + * @apiSuccess {String} name Specified organization name + * @apiSuccess {String} email Specified organization e-mail + * @apiSuccess {String} ownerId id for clients already generated by relevant authority (Auth0) + * + * @apiError {String} field Duplication of the Organization name + * + * @apiErrorExample {json} WebSocket + * Request: + * { + * "q":"/organizations/create", + * "sid": 1, + * "d":{ + * "token": { + * "token":"Auth0-TOKEN" + * }, + * "name":"specifiedOrganizationName", + * "email":"specifiedOrganization@email.com" + * } + * } + * + * Response: + * { + * "q":"/organizations/create", + * "sid":1, + * "d":{ + * "apiKeys":[], + * "id":"ORG-ID", + * "name":"specifiedOrganizationName", + * "email":"specifiedOrganization@email.com", + * "ownerId":"id@clients" + * } + * + * } + * + * { + * "sig":1, + * "sid":1 + * } + * + * Error Response: + * { + * "sig":2, + * "q":"/io.scalecube.services.error/500", + * "sid":1, + * "d":{ + * "errorCode":500, + * "errorMessage":"Organization name: 'org name' already in use" + * } + * } + * + * @apiErrorExample {json} RSocket + * Request: + * { + * "metadata":{ + * "q": "/organizations/create" + * }, + * "data":{ + * "token": { + * "token":"Auth0-TOKEN" + * }, + * "name":"specifiedOrganizationName", + * "email":"specifiedOrganization@email.com" + * } + * } + * + * Response: + * { + * "data":{ + * "apiKeys":[], + * "id":"ORG-ID", + * "name":"specifiedOrganizationName", + * "email":"specifiedOrganization@email.com", + * "ownerId":"id@clients" + * }, + * "metadata":{ + * "q": "/organizations/create" + * } + * } + * + * Error Response: + * { + * "data":{ + * "errorCode":500, + * "errorMessage":"Organization name: 'org name' already in use" + * }, + * "metadata":{ + * "q":"/io.scalecube.services.error/500" + * } + * } + * + * @apiErrorExample{json} HTTP + * Request: + * https://localhost:port/organizations/create (endpoint url) + * + * Body: + * { + * "token": { + * "token":"Auth0-TOKEN" + * }, + * "name":"specifiedOrganizationName", + * "email":"specifiedOrganization@email.com" + * } + * + * Response: + * { + * "apiKeys":[], + * "id":"ORG-ID", + * "name":"specifiedOrganizationName", + * "email":"specifiedOrganization@email.com", + * "ownerId":"id@clients" + * } + * + * Error Response: + * { + * "errorCode":500, + * "errorMessage":"Organization name: 'org name' already in use" + * } + */{ + "name": "Organization service", + "version": "2.1.3-SNAPSHOT", + "description": "Organization service API", + "title": "API documentation for the Organization Service", + "template": { + "forceLanguage" : "en" + }, + "order": [ + "Overview", + "GettingStarted", + "TransportProtocols", + "InteractiveAPIExplorer", + "CreateOrganization", + "GetOrganization", + "UpdateOrganization", + "DeleteOrganization", + "LeaveOrganization", + "GetUserOrganizationsMembership", + "InviteMember", + "GetOrganizationMembers", + "UpdateOrganizationMemberRole", + "KickoutMember", + "AddOrganizationApiKey", + "DeleteOrganizationApiKey" + ] +} +/** + * @api {ServiceMethod: getUserOrganizationsMembership} /organizations/getUserOrganizationsMembership getUserOrganizationsMembership + * @apiName GetUserOrganizationsMembership + * @apiGroup Member + * @apiVersion 2.1.3-SNAPSHOT + * @apiPermission Request / Response / Error-response + * + * @apiDescription This operation enables each organization member to get the list of all relevant organizations (full info) which the member was invited. + * >Note: this method returns all organization info thus API keys with: + * >
-all accessible permission levels ("Owner" | "Admin" | "Member") will be returned only for the related Organization Owner + * >
-"Admin" | "Member" permission levels will be returned only for the related Organization Admin + * >
-"Member" permission level will be returned only for the related Organization Member + * + * @apiParam {Object} token The requested token issued by relevant authority (Auth0) + * + * @apiSuccess {Object[]} organizations List of all Organizations (Array of objects) which the member was invited + * @apiSuccess {Object[]} organizations.apiKeys List of all API keys (Array of objects) for the relevant organization + * @apiSuccess {String} organizations.id Already generated id for the created organization + * @apiSuccess {String} organizations.name Organization name + * @apiSuccess {String} organizations.email Organization e-mail + * @apiSuccess {String} organizations.ownerId id for clients already generated by relevant authority (Auth0) + * + * @apiError {String} field Invalid or expired token + * + * @apiErrorExample {json} WebSocket + * Request: + * { + * "q":"/organizations/getUserOrganizationsMembership", + * "sid": 1, + * "d":{ + * "token": { + * "token":"Auth0-TOKEN" + * } + * } + * } + * + * Response: + * { + * "q":"/organizations/getUserOrganizationsMembership", + * "sid":1, + * "d":{ + * "apiKeys":[], + * "id":"ORG-ID", + * "name":"specifiedOrganizationName", + * "email":"specifiedOrganization@email.com", + * "ownerId":"id@clients" + * } + * + * } + * + * { + * "sig":1, + * "sid":1 + * } + * + * Error Response: + * { + * "sig":2, + * "q":"/io.scalecube.services.error/500", + * "sid":1, + * "d":{ + * "errorCode":500, + * "errorMessage":"Token verification failed" + * } + * } + * + * @apiErrorExample {json} RSocket + * Request: + * { + * "metadata":{ + * "q": "/organizations/getUserOrganizationsMembership" + * }, + * "data":{ + * "token": { + * "token":"Auth0-TOKEN" + * } + * } + * } + * + * Response: + * { + * "data":{ + * "apiKeys":[], + * "id":"ORG-ID", + * "name":"specifiedOrganizationName", + * "email":"specifiedOrganization@email.com", + * "ownerId":"id@clients" + * }, + * "metadata":{ + * "q": "/organizations/getUserOrganizationsMembership" + * } + * } + * + * Error Response: + * { + * "data":{ + * "errorCode":500, + * "errorMessage":"Token verification failed" + * }, + * "metadata":{ + * "q":"/io.scalecube.services.error/500" + * } + * } + * + * @apiErrorExample{json} HTTP + * Request: + * https://localhost:port/organizations/getUserOrganizationsMembership (endpoint url) + * + * Body: + * { + * "token": { + * "token":"Auth0-TOKEN" + * } + * } + * + * Response: + * { + * "apiKeys":[], + * "id":"ORG-ID", + * "name":"specifiedOrganizationName", + * "email":"specifiedOrganization@email.com", + * "ownerId":"id@clients" + * } + * + * Error Response: + * { + * "errorCode":500, + * "errorMessage":"Token verification failed" + * } + *//** + * @api {ServiceMethod: kickoutMember} /organizations/kickoutMember kickoutMember + * @apiName KickoutMember + * @apiGroup Member + * @apiVersion 2.1.3-SNAPSHOT + * @apiPermission Request / Response / Error-response + * + * @apiDescription This operation enables only organization managers (Owner | Admin) to remove the existent organization member with any accessible role. + *
Nevertheless at least one Owner (origin or granted one) should be persisted in the organization + * + * @apiParam {Object} token The requested token issued by relevant authority (Auth0) + * @apiParam {String} organizationId Already stored id for the specific organization + * @apiParam {String} userId Already stored id for the specific organization issued by relevant authority (Auth0) + * + * @apiSuccess Acknowledgment Empty object + * + * @apiError {String} field Single (last one) organization Owner is requested to be removed from the relevant organization + * + * @apiErrorExample {json} WebSocket + * Request: + * { + * "q":"/organizations/kickoutMember", + * "sid": 1, + * "d":{ + * "token": { + * "token":"Auth0-TOKEN" + * }, + * "organizationId":"ORG-ID", + * "userId": "id@clients" + * } + * } + * + * Response: + * { + * "q":"/organizations/kickoutMember", + * "sid":1, + * "d":{} + * + * } + * + * { + * "sig":1, + * "sid":1 + * } + * + * Error Response: + * { + * "sig":2, + * "q":"/io.scalecube.services.error/500", + * "sid":1, + * "d":{ + * "errorCode":500, + * "errorMessage":"At least one Owner should be persisted in the organization: 'ORG-ID'" + * } + * } + * + * @apiErrorExample {json} RSocket + * Request: + * { + * "metadata":{ + * "q": "/organizations/kickoutMember" + * }, + * "data":{ + * "token": { + * "token":"Auth0-TOKEN" + * }, + * "organizationId":"ORG-ID", + * "userId": "id@clients" + * } + * } + * + * Response: + * { + * "data":{}, + * "metadata":{ + * "q": "/organizations/kickoutMember" + * } + * } + * + * Error Response: + * { + * "data":{ + * "errorCode":500, + * "errorMessage":"At least one Owner should be persisted in the organization: 'ORG-ID'" + * }, + * "metadata":{ + * "q":"/io.scalecube.services.error/500" + * } + * } + * + * @apiErrorExample{json} HTTP + * Request: + * https://localhost:port/organizations/kickoutMember (endpoint url) + * + * Body: + * { + * "token": { + * "token":"Auth0-TOKEN" + * }, + * "organizationId":"ORG-ID", + * "userId": "id@clients" + * } + * + * Response: + * { + * + * } + * + * Error Response: + * { + * "errorCode":500, + * "errorMessage":"At least one Owner should be persisted in the organization: 'ORG-ID'" + * } + */ +/** + * @api {ServiceMethod: addOrganizationApiKey} /organizations/addOrganizationApiKey addOrganizationApiKey + * @apiName AddOrganizationApiKey + * @apiGroup ApiKey + * @apiVersion 2.1.3-SNAPSHOT + * @apiPermission Request / Response / Error-response + * + * @apiDescription This operation enables only organization managers (Owner | Admin) to create the API keys (token) for the relevant organization and further + * to be used (write and read ability) by potential users of the Configuration service according to appropriate permission level. + * Each API key got the unique name which couldn't be duplicated. Thus Owners could issue the API keys with all accessible roles but the Admins are restricted by the "Admin" or "Member" role API keys issuing. + * >Note: this method returns all organization info thus API keys with: + * >
-all accessible permission levels ("Owner" | "Admin" | "Member") will be returned only for the related Organization Owner + * >
-"Admin" | "Member" permission levels will be returned only for the related Organization Admin + * >
-"Member" permission level will be returned only for the related Organization Member + * + * @apiParam {Object} token The requested token issued by relevant authority (Auth0) + * @apiParam {String} organizationId Already stored org-id for the specific organization + * @apiParam {String} apiKeyName Specified name for the relevant API key + * @apiParam {Map} claims () Describes given identity on some role + * @apiParam {Object} claims.role Specified role (Owner/Admin/Member - permission level for the relevant API key) + * + * @apiSuccess {Object[]} apiKeys List of all API keys (Array of Objects) in the relevant organization + * @apiSuccess {String} id Stored org-id for the relevant organization + * @apiSuccess {String} name Organization name + * @apiSuccess {String} email Organization e-mail + * @apiSuccess {String} ownerId id for clients already generated by relevant authority (Auth0) + * + * @apiError {String} field API key name duplication + * + * @apiErrorExample {json} WebSocket + * Request: + * { + * "q":"/organizations/addOrganizationApiKey", + * "sid": 1, + * "d":{ + * "token": { + * "token":"Auth0-TOKEN" + * }, + * "organizationId":"ORG-ID", + * "apiKeyName": "specifiedApiKeyName", + * "claims": { + * "role":"Owner" + * } + * } + * } + * + * Response: + * { + * "q":"/organizations/addOrganizationApiKey", + * "sid":1, + * "d":{ + * "apiKeys": [ + * { + * "name": "specifiedApiKeyName", + * "claims": {"role": "Owner"}, + * "key": "API-TOKEN" + * } + * ], + * "id":"ORG-ID", + * "name":"specifiedOrganizationName", + * "email":"specifiedOrganization@email.com", + * "ownerId":"id@clients" + * } + * + * } + * + * { + * "sig":1, + * "sid":1 + * } + * + * Error Response: + * { + * "sig":2, + * "q":"/io.scalecube.services.error/500", + * "sid":1, + * "d":{ + * "errorCode":500, + * "errorMessage":"apiKey name:'specifiedApiKeyName' already exists" + * } + * } + * + * @apiErrorExample {json} RSocket + * Request: + * { + * "metadata":{ + * "q": "/organizations/addOrganizationApiKey" + * }, + * "data":{ + * "token": { + * "token":"Auth0-TOKEN" + * }, + * "organizationId":"ORG-ID", + * "apiKeyName": "specifiedApiKeyName", + * "claims": { + * "role":"Admin" + * } + * } + * } + * + * Response: + * { + * "data":{ + * "apiKeys": [ + * { + * "name": "specifiedApiKeyName", + * "claims": {"role": "Admin"}, + * "key": "API-TOKEN" + * }, + * { + * "name": "specifiedApiKeyName", + * "claims": {"role": "Owner"}, + * "key": "API-TOKEN" + * } + * ], + * "id":"ORG-ID", + * "name":"specifiedOrganizationName", + * "email":"specifiedOrganization@email.com", + * "ownerId":"id@clients" + * }, + * "metadata":{ + * "q": "/organizations/addOrganizationApiKey" + * } + * } + * + * Error Response: + * { + * "data":{ + * "errorCode":500, + * "errorMessage":"apiKey name:'specifiedApiKeyName' already exists" + * }, + * "metadata":{ + * "q":"/io.scalecube.services.error/500" + * } + * } + * + * @apiErrorExample{json} HTTP + * Request: + * https://localhost:port/organizations/addOrganizationApiKey (endpoint url) + * + * Body: + * { + * "token": { + * "token":"Auth0-TOKEN" + * }, + * "organizationId":"ORG-ID", + * "apiKeyName": "specifiedApiKeyName", + * "claims": { + * "role":"Member" + * } + * + * Response: + * { + * "apiKeys": [ + * { + * "name": "specifiedApiKeyName", + * "claims": {"role": "Member"}, + * "key": "API-TOKEN" + * }, + * { + * "name": "specifiedApiKeyName", + * "claims": {"role": "Admin"}, + * "key": "API-TOKEN" + * }, + * { + * "name": "specifiedApiKeyName", + * "claims": {"role": "Owner"}, + * "key": "API-TOKEN" + * } + * ], + * "id":"ORG-ID", + * "name":"specifiedOrganizationName", + * "email":"specifiedOrganization@email.com", + * "ownerId":"id@clients" + * } + * + * Error Response: + * { + * "errorCode":500, + * "errorMessage":"apiKey name:'specifiedApiKeyName' already exists" + * } + *//** + * @api {ServiceMethod: delete} /organizations/delete delete + * @apiName DeleteOrganization + * @apiGroup Organization + * @apiVersion 2.1.3-SNAPSHOT + * @apiPermission Request / Response / Error-response + * + * @apiDescription This operation enables only Owners to delete relevant organization. + *
All relevant API keys issued for organization also deleted thus become invalid after specific period of time is left upon this operation was done. + * + * @apiParam {Object} token The requested token issued by relevant authority (Auth0) + * @apiParam {String} organizationId Already stored id for the specific organization + * + * @apiSuccess {Boolean} deleted The "true" statement + * @apiSuccess {String} organizationId Already Stored id for the specific organization + * + * @apiError {String} field Invalid or non-existent organization id + * + * @apiErrorExample {json} WebSocket + * Request: + * { + * "q":"/organizations/delete", + * "sid": 1, + * "d":{ + * "token": { + * "token":"Auth0-TOKEN" + * }, + * "organizationId":"ORG-ID" + * } + * } + * + * Response: + * { + * "q":"/organizations/delete", + * "sid":1, + * "d":{ + * "deleted": true, + * "organizationId": "ORG-ID" + * } + * + * } + * + * { + * "sig":1, + * "sid":1 + * } + * + * Error Response: + * { + * "sig":2, + * "q":"/io.scalecube.services.error/500", + * "sid":1, + * "d":{ + * "errorCode":500, + * "errorMessage":"ORG-ID" + * } + * } + * + * @apiErrorExample {json} RSocket + * Request: + * { + * "metadata":{ + * "q": "/organizations/delete" + * }, + * "data":{ + * "token": { + * "token":"Auth0-TOKEN" + * }, + * "organizationId":"ORG-ID" + * } + * } + * + * Response: + * { + * "data":{ + * "deleted": true, + * "organizationId": "ORG-ID" + * }, + * "metadata":{ + * "q": "/organizations/delete" + * } + * } + * + * Error Response: + * { + * "data":{ + * "errorCode":500, + * "errorMessage":"ORG-ID" + * }, + * "metadata":{ + * "q":"/io.scalecube.services.error/500" + * } + * } + * + * @apiErrorExample{json} HTTP + * Request: + * https://localhost:port/organizations/delete (endpoint url) + * + * Body: + * { + * "token": { + * "token":"Auth0-TOKEN" + * }, + * "organizationId":"ORG-ID" + * } + * + * Response: + * { + * "deleted": true, + * "organizationId": "ORG-ID" + * } + * + * Error Response: + * { + * "errorCode":500, + * "errorMessage":"ORG-ID" + * } + *//** + * @api {ServiceMethod: deleteOrganizationApiKey} /organizations/deleteOrganizationApiKey deleteOrganizationApiKey + * @apiName DeleteOrganizationApiKey + * @apiGroup ApiKey + * @apiVersion 2.1.3-SNAPSHOT + * @apiPermission Request / Response / Error-response + * + * @apiDescription This operation enables only organization managers (Owner | Admin) to delete the API keys (token) from the relevant organization. + * + * >Note: this method returns all organization info thus API keys with: + * >
-all accessible permission levels ("Owner" | "Admin" | "Member") will be returned only for the related Organization Owner + * >
-"Admin" | "Member" permission levels will be returned only for the related Organization Admin + * >
-"Member" permission level will be returned only for the related Organization Member + * + * @apiParam {Object} token The requested token issued by relevant authority (Auth0) + * @apiParam {String} organizationId Already stored id for the specific organization + * @apiParam {String} apiKeyName Specified name for the relevant API key + * + * @apiSuccess {Object[]} apiKeys List of all API keys (Array of Objects) in the relevant organization + * @apiSuccess {String} id Stored org-id for the relevant organization + * @apiSuccess {String} name Organization name + * @apiSuccess {String} email Organization e-mail + * @apiSuccess {String} ownerId id for clients already generated by relevant authority (Auth0) + * + * @apiError {String} field Permission denied for specified organization member either organization outsider + * + * @apiErrorExample {json} WebSocket + * Request: + * { + * "q":"/organizations/deleteOrganizationApiKey", + * "sid": 1, + * "d":{ + * "token": { + * "token":"Auth0-TOKEN" + * }, + * "organizationId":"ORG-ID", + * "apiKeyName": "specifiedApiKeyName", + * } + * } + * + * Response: + * { + * "q":"/organizations/deleteOrganizationApiKey", + * "sid":1, + * "d":{ + * "apiKeys":[], + * "id":"ORG-ID", + * "name":"specifiedOrganizationName", + * "email":"specifiedOrganization@email.com", + * "ownerId":"id@clients" + * } + * + * } + * + * { + * "sig":1, + * "sid":1 + * } + * + * Error Response: + * { + * "sig":2, + * "q":"/io.scalecube.services.error/500", + * "sid":1, + * "d":{ + * "errorCode":500, + * "errorMessage":"user: 'id@clients', name: 'null', not in role Owner or Admin of organization: 'specifiedOrganizationName'" + * } + * } + * + * @apiErrorExample {json} RSocket + * Request: + * { + * "metadata":{ + * "q": "/organizations/deleteOrganizationApiKey" + * }, + * "data":{ + * "token": { + * "token":"Auth0-TOKEN" + * }, + * "organizationId":"ORG-ID", + * "apiKeyName": "specifiedApiKeyName", + * } + * } + * + * Response: + * { + * "data":{ + * "apiKeys":[], + * "id":"ORG-ID", + * "name":"specifiedOrganizationName", + * "email":"specifiedOrganization@email.com", + * "ownerId":"id@clients" + * }, + * "metadata":{ + * "q": "/organizations/deleteOrganizationApiKey" + * } + * } + * + * Error Response: + * { + * "data":{ + * "errorCode":500, + * "errorMessage":"user: 'id@clients', name: 'null', not in role Owner or Admin of organization: 'specifiedOrganizationName'" + * }, + * "metadata":{ + * "q":"/io.scalecube.services.error/500" + * } + * } + * + * @apiErrorExample{json} HTTP + * Request: + * https://localhost:port/organizations/createRepository (endpoint url) + * + * Body: + * { + * "token": { + * "token":"Auth0-TOKEN" + * }, + * "organizationId":"ORG-ID", + * "apiKeyName": "specifiedApiKeyName", + * } + * + * Response: + * { + * "apiKeys":[], + * "id":"ORG-ID", + * "name":"specifiedOrganizationName", + * "email":"specifiedOrganization@email.com", + * "ownerId":"id@clients" + * } + * + * Error Response: + * { + * "errorCode":500, + * "errorMessage":"user: 'id@clients', name: 'null', not in role Owner or Admin of organization: 'specifiedOrganizationName'" + * } + *//** + * @api {ServiceMethod: getOrganization} /organizations/getOrganization getOrganization + * @apiName GetOrganization + * @apiGroup Organization + * @apiVersion 2.1.3-SNAPSHOT + * @apiPermission Request / Response / Error-response + * + * @apiDescription This operation enables all members of the relevant organization to get the full organization information. + * >Note: this method returns all organization info thus API keys with: + * >
-all accessible permission levels ("Owner" | "Admin" | "Member") will be returned only for the related Organization Owner + * >
-"Admin" | "Member" permission levels will be returned only for the related Organization Admin + * >
-"Member" permission level will be returned only for the related Organization Member + * + * @apiParam {Object} token The requested token issued by relevant authority (Auth0) + * @apiParam {String} organizationId Already stored id for the specific organization + * + * @apiSuccess {Object[]} apiKeys List of all API keys (Array of objects) for the relevant organization + * @apiSuccess {String} id Already generated id for the created organization + * @apiSuccess {String} name Organization name + * @apiSuccess {String} email Organization e-mail + * @apiSuccess {String} ownerId id for clients already generated by relevant authority (Auth0) + * + * @apiError {String} field user isn't the member (outsider) of the specified organization + * + * @apiErrorExample {json} WebSocket + * Request: + * { + * "q":"/organizations/getOrganization", + * "sid": 1, + * "d":{ + * "token": { + * "token":"Auth0-TOKEN" + * }, + * "organizationId":"ORG-ID" + * } + * } + * + * Response: + * { + * "q":"/organizations/getOrganization", + * "sid":1, + * "d":{ + * "apiKeys":[], + * "id":"ORG-ID", + * "name":"specifiedOrganizationName", + * "email":"specifiedOrganization@email.com", + * "ownerId":"id@clients" + * } + * + * { + * "sig":1, + * "sid":1 + * } + * + * Error Response: + * { + * "sig":2, + * "q":"/io.scalecube.services.error/500", + * "sid":1, + * "d":{ + * errorCode":500, + * "errorMessage":"user: 'null', name: 'id@clients', is not a member of organization: 'ORG-ID'" + * } + * } + * + * @apiErrorExample {json} RSocket + * Request: + * { + * "metadata":{ + * "q": "/organizations/getOrganization" + * }, + * "data":{ + * "token": { + * "token":"Auth0-TOKEN" + * }, + * "name":"specifiedOrganizationName", + * "email":"specifiedOrganization@email.com" + * } + * } + * + * Response: + * { + * "data":{ + * "apiKeys":[], + * "id":"ORG-ID", + * "name":"specifiedOrganizationName", + * "email":"specifiedOrganization@email.com", + * "ownerId":"id@clients" + * }, + * "metadata":{ + * "q": "/organizations/getOrganization" + * } + * } + * + * Error Response: + * { + * "data":{ + * "errorCode":500, + * "errorMessage":"user: 'null', name: 'id@clients', is not a member of organization: 'ORG-ID'" + * }, + * "metadata":{ + * "q":"/io.scalecube.services.error/500" + * } + * } + * + * @apiErrorExample{json} HTTP + * Request: + * https://localhost:port/organizations/getOrganization (endpoint url) + * + * Body: + * { + * "token": { + * "token":"Auth0-TOKEN" + * }, + * "organizationId":"ORG-ID" + * } + * + * Response: + * { + * "apiKeys":[], + * "id":"ORG-ID", + * "name":"specifiedOrganizationName", + * "email":"specifiedOrganization@email.com", + * "ownerId":"id@clients" + * } + * + * Error Response: + * { + * "errorCode":500, + * "errorMessage":"user: 'null', name: 'id@clients', is not a member of organization: 'ORG-ID'" + * } + *//** + * @api {ServiceMethod: leaveOrganization} /organizations/leaveOrganization leaveOrganization + * @apiName LeaveOrganization + * @apiGroup Organization + * @apiVersion 2.1.3-SNAPSHOT + * @apiPermission Request / Response / Error-response + * + * @apiDescription This operation enables each organization member to step-out (leave) from the relevant organization. + *
Nevertheless at least one Owner (origin or granted one) should be persisted in the organization. + * + * @apiParam {Object} token The requested token issued by relevant authority (Auth0) + * @apiParam {String} organizationId Already stored id for the specific organization + * + * @apiSuccess Acknowledgment Empty object + * + * @apiError {String} field Single (last one) organization Owner requested to leave the relevant organization + * + * @apiErrorExample {json} WebSocket + * Request: + * { + * "q":"/organizations/leaveOrganization", + * "sid": 1, + * "d":{ + * "token": { + * "token":"Auth0-TOKEN" + * }, + * "organizationId":"ORG-ID" + * } + * } + * + * Response: + * { + * "q":"/organizations/leaveOrganization", + * "sid":1, + * "d":{} + * + * } + * + * { + * "sig":1, + * "sid":1 + * } + * + * Error Response: + * { + * "sig":2, + * "q":"/io.scalecube.services.error/500", + * "sid":1, + * "d":{ + * "errorCode":500, + * "errorMessage":"At least one Owner should be persisted in the organization: 'ORG-ID'" + * } + * } + * + * @apiErrorExample {json} RSocket + * Request: + * { + * "metadata":{ + * "q": "/organizations/leaveOrganization" + * }, + * "data":{ + * "token": { + * "token":"Auth0-TOKEN" + * }, + * "organizationId":"ORG-ID" + * } + * } + * + * Response: + * { + * "data":{}, + * "metadata":{ + * "q": "/organizations/leaveOrganization" + * } + * } + * + * Error Response: + * { + * "data":{ + * "errorCode":500, + * "errorMessage":"At least one Owner should be persisted in the organization: 'ORG-ID'" + * }, + * "metadata":{ + * "q":"/io.scalecube.services.error/500" + * } + * } + * + * @apiErrorExample{json} HTTP + * Request: + * https://localhost:port/organizations/leaveOrganization (endpoint url) + * + * Body: + * { + * "token": { + * "token":"Auth0-TOKEN" + * }, + * "organizationId":"ORG-ID" + * } + * + * Response: + * { + * + * } + * + * Error Response: + * { + * "errorCode":500, + * "errorMessage":"At least one Owner should be persisted in the organization: 'ORG-ID'" + * } + *//** + * @apiDefine BadRequestError + * @apiVersion 2.1.3-SNAPSHOT + * @apiError BadRequestError The request didn't pass validation + * + * @apiErrorExample Error-Response: + * { + * "errorCode": "400" + * "errorMessage": "Bad request." + * } + */ + +/** + * @apiDefine InternalServerError + * + * @apiError (Error 500) InternalServerError Error happened during request processing + * + * @apiErrorExample Error-Response: + * { + * "errorCode": "500" + * "errorMessage": "Error message" + * } + */ + +/** + * @apiDefine ServiceUnavailableError + * + * @apiError (Error 503) ServiceUnavailableError Service in not available to accept requests + * + * @apiErrorExample Error-Response: + * { + * "errorCode": "503" + * "errorMessage": "No reachable member with such service: %s" + * } + */ +/** + * @api {ServiceMethod: updateOrganization} /organizations/updateOrganization updateOrganization + * @apiName UpdateOrganization + * @apiGroup Organization + * @apiVersion 2.1.3-SNAPSHOT + * @apiPermission Request / Response / Error-response + * + * @apiDescription This operation enables only organization managers (Owner | Admin) to update (edit) + * the specific organization information (name or email) optionally. + * >Note: this method returns all organization info thus API keys with: + * >
-all accessible permission levels ("Owner" | "Admin" | "Member") will be returned only for the related Organization Owner + * >
-"Admin" | "Member" permission levels will be returned only for the related Organization Admin + * >
-"Member" permission level will be returned only for the related Organization Member + * + * @apiParam {Object} token The requested token issued by relevant authority (Auth0) + * @apiParam {String} organizationId Already stored id for the specific organization + * @apiParam {String} name New specified organization name + * @apiParam {String} email New specified organization e-mail + * + * @apiSuccess {Object[]} apiKeys List of all API keys (Array of objects) for the relevant organization + * @apiSuccess {String} id Already generated id for the created organization + * @apiSuccess {String} name New specified organization name + * @apiSuccess {String} email New specified organization e-mail + * @apiSuccess {String} ownerId id for clients already generated by relevant authority (Auth0) + * + * @apiError {String} field Organization e-mail wasn't specified + * + * @apiErrorExample {json} WebSocket + * Request: + * { + * "q":"/organizations/updateOrganization", + * "sid": 1, + * "d":{ + * "token": { + * "token":"Auth0-TOKEN" + * }, + * "organizationId":"ORG-ID", + * "name":"newSpecifiedOrganizationName", + * "email":"newSpecifiedOrganization@email.com" + * } + * } + * + * Response: + * { + * "q":"/organizations/updateOrganization", + * "sid":1, + * "d":{ + * "apiKeys":[], + * "id":"ORG-ID", + * "name":"newSpecifiedOrganizationName", + * "email":"newSpecifiedOrganization@email.com", + * "ownerId":"id@clients" + * } + * + * } + * + * { + * "sig":1, + * "sid":1 + * } + * + * Error Response: + * { + * "sig":2, + * "q":"/io.scalecube.services.error/500", + * "sid":1, + * "d":{ + * "errorCode":500, + * "errorMessage":"Organization email cannot be empty" + * } + * } + * + * @apiErrorExample {json} RSocket + * Request: + * { + * "metadata":{ + * "q": "/organizations/updateOrganization" + * }, + * "data":{ + * "token": { + * "token":"Auth0-TOKEN" + * }, + * "organizationId":"ORG-ID", + * "name":"newSpecifiedOrganizationName", + * "email":"newSpecifiedOrganization@email.com" + * } + * } + * + * Response: + * { + * "data":{ + * "apiKeys":[], + * "id":"ORG-ID", + * "name":"newSpecifiedOrganizationName", + * "email":"newSpecifiedOrganization@email.com", + * "ownerId":"id@clients" + * }, + * "metadata":{ + * "q": "/organizations/updateOrganization" + * } + * } + * + * Error Response: + * { + * "data":{ + * "errorCode":500, + * "errorMessage":"Organization email cannot be empty" + * }, + * "metadata":{ + * "q":"/io.scalecube.services.error/500" + * } + * } + * + * @apiErrorExample{json} HTTP + * Request: + * https://localhost:port/organizations/updateOrganization (endpoint url) + * + * Body: + * { + * "token": { + * "token":"Auth0-TOKEN" + * }, + * "organizationId":"ORG-ID", + * "name":"newSpecifiedOrganizationName", + * "email":"newSpecifiedOrganization@email.com" + * } + * + * Response: + * { + * "apiKeys":[], + * "id":"ORG-ID", + * "name":"newSpecifiedOrganizationName", + * "email":"newSpecifiedOrganization@email.com", + * "ownerId":"id@clients" + * } + * + * Error Response: + * { + * "errorCode":500, + * "errorMessage":"Organization email cannot be empty" + * } + *//** + * @api {ServiceMethod: inviteMember} /organizations/inviteMember inviteMember + * @apiName InviteMember + * @apiGroup Member + * @apiVersion 2.1.3-SNAPSHOT + * @apiPermission Request / Response / Error-response + * + * @apiDescription This operation enables only organization managers (Owner | Admin) to invite a valid user + * (which client id issued by relevant authority - Auth0) to step into relevant organization with relevant member's role (permission level). + * + * @apiParam {Object} token The requested token issued by relevant authority (Auth0) + * @apiParam {String} organizationId Already stored id for the specific organization + * @apiParam {String} userId Already stored id for the specific organization issued by relevant authority (Auth0) + * @apiParam {String} role Specified permission level (roles: Owner/Admin/Member) granted for the organization members + * + * @apiSuccess Acknowledgment Empty object + * + * @apiError {String} field Invalid role for specified organization member is applied + * + * @apiErrorExample {json} WebSocket + * Request: + * { + * "q":"/organizations/inviteMember", + * "sid": 1, + * "d":{ + * "token": { + * "token":"Auth0-TOKEN" + * }, + * "organizationId":"ORG-ID", + * "userId": "id@clients", + * "role": "Owner" + * } + * } + * + * Response: + * { + * "q":"/organizations/inviteMember", + * "sid":1, + * "d":{} + * + * } + * + * { + * "sig":1, + * "sid":1 + * } + * + * Error Response: + * { + * "sig":2, + * "q":"/io.scalecube.services.error/500", + * "sid":1, + * "d":{ + * "errorCode":500, + * "errorMessage":"Unknown role: Boss" + * } + * } + * + * @apiErrorExample {json} RSocket + * Request: + * { + * "metadata":{ + * "q": "/organizations/inviteMember" + * }, + * "data":{ + * "token": { + * "token":"Auth0-TOKEN" + * }, + * "organizationId":"ORG-ID", + * "userId": "id@clients", + * "role": "Admin" + * } + * } + * + * Response: + * { + * "data":{}, + * "metadata":{ + * "q": "/organizations/inviteMember" + * } + * } + * + * Error Response: + * { + * "data":{ + * "errorCode":500, + * "errorMessage":"Unknown role: Boss" + * }, + * "metadata":{ + * "q":"/io.scalecube.services.error/500" + * } + * } + * + * @apiErrorExample{json} HTTP + * Request: + * https://localhost:port/organizations/inviteMember (endpoint url) + * + * Body: + * { + * "token": { + * "token":"Auth0-TOKEN" + * }, + * "organizationId":"ORG-ID", + * "userId": "id@clients", + * "role": "Member" + * } + * + * Response: + * { + * + * } + * + * Error Response: + * { + * "errorCode":500, + * "errorMessage":"Unknown role: Boss" + * } + *//** + * @api {ServiceMethod: updateOrganizationMemberRole} /organizations/updateOrganizationMemberRole updateOrganizationMemberRole + * @apiName UpdateOrganizationMemberRole + * @apiGroup Member + * @apiVersion 2.1.3-SNAPSHOT + * @apiPermission Request / Response / Error-response + * + * @apiDescription This operation enables only organization managers (Owner | Admin) to upgrade/downgrade relevant organization members' roles. + *
Any of the members who posses Admin role couldn't upgrade themselves whereby only the members with higher - Owner roles are able to do that. + * Nevertheless any member with Admin or Owner role could downgrade themselves as do the members with Owner role could downgrade the members with Admin role. + * Furthermore at least one Owner (origin or granted one) should be persisted in the organization. + * + * @apiParam {Object} token The requested token issued by relevant authority (Auth0) + * @apiParam {String} organizationId Already stored id for the specific organization + * @apiParam {String} userId Already stored id for the specific organization issued by relevant authority (Auth0) + * @apiParam {String} role any of accessible member's role (Owner/Admin/Member) + * + * @apiSuccess Acknowledgment Empty object + * + * @apiError {String} field Invalid role for specified organization member is applied + * + * @apiErrorExample {json} WebSocket + * Request: + * { + * "q":"/organizations/updateOrganizationMemberRole", + * "sid": 1, + * "d":{ + * "token": { + * "token":"Auth0-TOKEN" + * }, + * "organizationId":"ORG-ID", + * "userId": "id@clients", + * "role": "Owner" + * } + * } + * + * Response: + * { + * "q":"/organizations/updateOrganizationMemberRole", + * "sid":1, + * "d":{} + * + * } + * + * { + * "sig":1, + * "sid":1 + * } + * + * Error Response: + * { + * "sig":2, + * "q":"/io.scalecube.services.error/500", + * "sid":1, + * "d":{ + * "errorCode":500, + * "errorMessage":"Unknown role: Boss" + * } + * } + * + * @apiErrorExample {json} RSocket + * Request: + * { + * "metadata":{ + * "q": "/organizations/updateOrganizationMemberRole" + * }, + * "data":{ + * "token": { + * "token":"Auth0-TOKEN" + * }, + * "organizationId":"ORG-ID", + * "userId": "id@clients", + * "role": "Admin" + * } + * } + * + * Response: + * { + * "data":{}, + * "metadata":{ + * "q": "/organizations/updateOrganizationMemberRole" + * } + * } + * + * Error Response: + * { + * "data":{ + * "errorCode":500, + * "errorMessage":"Unknown role: Boss" + * }, + * "metadata":{ + * "q":"/io.scalecube.services.error/500" + * } + * } + * + * @apiErrorExample{json} HTTP + * Request: + * https://localhost:port/organizations/updateOrganizationMemberRole (endpoint url) + * + * Body: + * { + * "token": { + * "token":"Auth0-TOKEN" + * }, + * "organizationId":"ORG-ID", + * "userId": "id@clients", + * "role": "Member" + * } + * + * Response: + * { + * + * } + * + * Error Response: + * { + * "errorCode":500, + * "errorMessage":"Unknown role: Boss" + * } + *//** + * @api . Getting Started + * @apiName GettingStarted + * @apiGroup Overview + * @apiVersion 2.1.3-SNAPSHOT + * @apiDescription Organization service enable you to integrate the API in order to create and manage the organizations. + * Besides the origin owner unique ability to create the organization there is a necessity for each organization member to achieve appropriate + * managers' permission level (roles: Owner | Admin) granted by other managers of the relevant organization for management ability. + * Thus each organization could be deleted or relevant credentials updated, authorized users could be invited to and removed from the relevant organization, + * each member could get the info about the relevant organization and also to know the own membership in the all related organizations. + * Organization managers could provide and delete the relevant API keys (permission level with appropriate assigned role: Owner | Admin | Member) which are + * vital leverage (write or read permission provision) for the Configuration service management and security purpose. + * + * >Note: API keys assigned with some of the relevant roles (Owner | Admin | Member) are visible to organization members' similar roles only via + * permission level (role) in the specific Organization: + * >
-Owner could observe all accessible API keys + * >
-Admin could observe only the "Admin" and "Member" API keys + * >
-Member could observe only the "Member" API keys + * + * Getting Started + * + * + * All API endpoints documented below are the integral part of Configuration service host address. + *
You can try out any query in realtime using our interactive API. + * Actually service requires authentication, so there is a necessity to get the token issued via secured authority. + * Thus, firstly we recommend to create an account in Auth0 and issue the token whereby to perform the valid requests across all service endpoints. + * + * Validation for the object entities is handled by Scalecube services and do the next upon the request object: + * >~ ignores any excessive keys and values added besides the required parameters + * >
~ doesn't ignore the keys duplicates and takes the last values which applied for each of the relevant key duplicate + * + * >Contracts validation is implemented for specific parameters which value type is string and can only contain characters + * in range A-Z, a-z, 0-9 as well as underscore, period, dash & percent. Appropriate validation will be added soon. + */ + + /** + * @api . Transport protocols API + * @apiName TransportProtocols + * @apiGroup Overview + * @apiVersion 2.1.3-SNAPSHOT + * @apiPermission Successful requests and responses + * @apiDescription You are able to manage the service API through the three types of transport protocols which are supported. + *
Upon relevant Host address was set the request should contain the following structure according to transport protocol usage: + + + * @apiParamExample {json} WebSocket: + Request: + { + "q": "/serviceName/method_name", + "sid":int, + "d": { + "relevant request parameters and values" + } + } + + Response: + { + "q":"/serviceName/method_name", + "sid":int, + "d":{ + "relevant response parameters and values" + } + } + { + "sig":1, + "sid":int + } + + * @apiParamExample {json} RSocket: + Request: + { + "metadata": { + "q": "/serviceName/method_name" + }, + "data": { + "relevant request parameters and values" + } + } + + Response: + { + "data":{ + "relevant response parameters and values" + }, + "metadata":{ + "q": "/serviceName/method_name" + } + } + * @apiParamExample {json} HTTP: + Request: + https://localhost:port/serviceName/method_name (endpoint url) + + Body: + { + "relevant request parameters and values" + } + + Response: + { + "relevant response parameters and values" + } + */ + + /** + * @api . Interactive API Explorer + * @apiName InteractiveAPIExplorer + * @apiGroup Overview + * @apiVersion 2.1.3-SNAPSHOT + * @apiDescription WebSocket and RSocket transports are accessible to apply via in-house developed API Explorer called Sandbox thus to connect and run follow up the next steps: + + *//** + * @api {ServiceMethod: getOrganizationMembers} /organizations/getOrganizationMembers getOrganizationMembers + * @apiName GetOrganizationMembers + * @apiGroup Member + * @apiVersion 2.1.3-SNAPSHOT + * @apiPermission Request / Response / Error-response + * + * @apiDescription This operation enables only organization managers (Owner | Admin) to fetch all the members from the relevant organization. + * + * @apiParam {Object} token The requested token issued by relevant authority (Auth0) + * @apiParam {String} organizationId Already stored id for the specific organization + * + * @apiSuccess {Object[]} members List of all the members (Array of Objects) in the specified organization + * + * @apiError {String} field user isn't the manager either outsider of the specified organization + * + * @apiErrorExample {json} WebSocket + * Request: + * { + * "q":"/organizations/getOrganizationMembers", + * "sid": 1, + * "d":{ + * "token": { + * "token":"Auth0-TOKEN" + * }, + * "organizationId":"ORG-ID" + * } + * } + * + * Response: + * { + * "q":"/organizations/getOrganizationMembers", + * "sid":1, + * "d":{ + * "members":[ + * {"id":"id@clients","role":"Owner"}, + * {"id":"id@clients","role":"Admin"}, + * {"id":"id@clients","role":"Member"} + * ] + * } + * + * } + * + * { + * "sig":1, + * "sid":1 + * } + * + * Error Response: + * { + * "sig":2, + * "q":"/io.scalecube.services.error/500", + * "sid":1, + * "d":{ + * "errorCode":500, + * "errorMessage":"user: 'id@clients', name: 'null', not in role Owner or Admin of organization: 'specifiedOrganizationName'" + * } + * } + * + * @apiErrorExample {json} RSocket + * Request: + * { + * "metadata":{ + * "q": "/organizations/getOrganizationMembers" + * }, + * "data":{ + * "token": { + * "token":"Auth0-TOKEN" + * }, + * "organizationId":"ORG-ID" + * } + * } + * + * Response: + * { + * "data":{ + * "members":[ + * {"id":"id@clients","role":"Owner"}, + * {"id":"id@clients","role":"Admin"}, + * {"id":"id@clients","role":"Member"} + * ] + * }, + * "metadata":{ + * "q": "/organizations/getOrganizationMembers" + * } + * } + * + * Error Response: + * { + * "data":{ + * "errorCode":500, + * "errorMessage":"user: 'id@clients', name: 'null', not in role Owner or Admin of organization: 'specifiedOrganizationName'" + * }, + * "metadata":{ + * "q":"/io.scalecube.services.error/500" + * } + * } + * + * @apiErrorExample{json} HTTP + * Request: + * https://localhost:port/organizations/getOrganizationMembers (endpoint url) + * + * Body: + * { + * "token": { + * "token":"Auth0-TOKEN" + * }, + * "organizationId":"ORG-ID" + * } + * + * Response: + * { + * "members":[ + * {"id":"id@clients","role":"Owner"}, + * {"id":"id@clients","role":"Admin"}, + * {"id":"id@clients","role":"Member"} + * ] + * } + * + * Error Response: + * { + * "errorCode":500, + * "errorMessage":"user: 'id@clients', name: 'null', not in role Owner or Admin of organization: 'specifiedOrganizationName'" + * } + */ \ No newline at end of file diff --git a/pom.xml b/pom.xml index a67a6cf..d576498 100644 --- a/pom.xml +++ b/pom.xml @@ -5,11 +5,11 @@ io.scalecube scalecube-parent-pom - 0.0.18 + 0.0.19 scalecube-organization-parent - 2.1.2-SNAPSHOT + 2.1.3-SNAPSHOT pom @@ -25,15 +25,15 @@ 0.3.9 - 2.4.10 - 1.0.3 + 2.5.4 + 1.0.7 5.3.2 2.9.8 3.1.0 - 2.6.0 + 2.7.3 1.7.7 2.11.1 - 4.1.31.Final + 4.1.34.Final 1.3 0.6.0 Californium-SR5 diff --git a/scalecube-organization-api/pom.xml b/scalecube-organization-api/pom.xml index d33a34b..8f10ff7 100644 --- a/scalecube-organization-api/pom.xml +++ b/scalecube-organization-api/pom.xml @@ -4,7 +4,7 @@ io.scalecube scalecube-organization-parent - 2.1.2-SNAPSHOT + 2.1.3-SNAPSHOT scalecube-organization-api diff --git a/scalecube-organization-api/src/main/java/io/scalecube/account/api/CreateUserResponse.java b/scalecube-organization-api/src/main/java/io/scalecube/account/api/CreateUserResponse.java deleted file mode 100644 index acd7382..0000000 --- a/scalecube-organization-api/src/main/java/io/scalecube/account/api/CreateUserResponse.java +++ /dev/null @@ -1,3 +0,0 @@ -package io.scalecube.account.api; - -public class CreateUserResponse {} diff --git a/scalecube-organization-api/src/main/java/io/scalecube/account/api/FindUserRequest.java b/scalecube-organization-api/src/main/java/io/scalecube/account/api/FindUserRequest.java deleted file mode 100644 index 250450d..0000000 --- a/scalecube-organization-api/src/main/java/io/scalecube/account/api/FindUserRequest.java +++ /dev/null @@ -1,16 +0,0 @@ -package io.scalecube.account.api; - -public class FindUserRequest { - - private Token token; - - private String fullNameOrEmail; - - public String fullNameOrEmail() { - return this.fullNameOrEmail; - } - - public Token token() { - return this.token; - } -} diff --git a/scalecube-organization-api/src/main/java/io/scalecube/account/api/OrganizationMember.java b/scalecube-organization-api/src/main/java/io/scalecube/account/api/OrganizationMember.java index e2980d7..acc0b52 100644 --- a/scalecube-organization-api/src/main/java/io/scalecube/account/api/OrganizationMember.java +++ b/scalecube-organization-api/src/main/java/io/scalecube/account/api/OrganizationMember.java @@ -1,15 +1,16 @@ package io.scalecube.account.api; import java.util.Objects; +import java.util.StringJoiner; /** Represents an organization member. */ public class OrganizationMember { - private String id; + private String id; private String role; /** Constructs an empty organization member. */ - public OrganizationMember() {} + OrganizationMember() {} /** * Constructs an organization member using the user and role arguments. @@ -45,6 +46,9 @@ public int hashCode() { @Override public String toString() { - return super.toString() + String.format("[userId=%s, role=%s]", id, role); + return new StringJoiner(", ", OrganizationMember.class.getSimpleName() + "[", "]") + .add("id='" + id + "'") + .add("role='" + role + "'") + .toString(); } } diff --git a/scalecube-organization/pom.xml b/scalecube-organization/pom.xml index cb75de6..3e129a6 100644 --- a/scalecube-organization/pom.xml +++ b/scalecube-organization/pom.xml @@ -4,7 +4,7 @@ io.scalecube scalecube-organization-parent - 2.1.2-SNAPSHOT + 2.1.3-SNAPSHOT scalecube-organization diff --git a/scalecube-organization/src/main/java/io/scalecube/organization/OrganizationServiceImpl.java b/scalecube-organization/src/main/java/io/scalecube/organization/OrganizationServiceImpl.java index 0f1dff0..16e3023 100644 --- a/scalecube-organization/src/main/java/io/scalecube/organization/OrganizationServiceImpl.java +++ b/scalecube-organization/src/main/java/io/scalecube/organization/OrganizationServiceImpl.java @@ -40,7 +40,7 @@ import io.scalecube.organization.operation.LeaveOrganization; import io.scalecube.organization.operation.UpdateOrganization; import io.scalecube.organization.operation.UpdateOrganizationMemberRole; -import io.scalecube.organization.repository.OrganizationsDataAccess; +import io.scalecube.organization.repository.OrganizationsRepository; import io.scalecube.organization.tokens.TokenVerifier; import io.scalecube.organization.tokens.store.KeyStore; import java.security.KeyPairGenerator; @@ -54,7 +54,7 @@ public class OrganizationServiceImpl implements OrganizationService { private static final Logger logger = LoggerFactory.getLogger(OrganizationServiceImpl.class); private final TokenVerifier tokenVerifier; - private final OrganizationsDataAccess repository; + private final OrganizationsRepository repository; private final KeyStore keyStore; private final KeyPairGenerator keyPairGenerator; @@ -66,7 +66,7 @@ public class OrganizationServiceImpl implements OrganizationService { * @param tokenVerifier token verifier */ public OrganizationServiceImpl( - OrganizationsDataAccess repository, KeyStore keyStore, TokenVerifier tokenVerifier) { + OrganizationsRepository repository, KeyStore keyStore, TokenVerifier tokenVerifier) { this.repository = repository; this.keyStore = keyStore; this.tokenVerifier = tokenVerifier; @@ -92,7 +92,7 @@ public Mono createOrganization(CreateOrganizationReq logger.debug("createOrganization: exit, return: {}", response); result.success(response); } catch (ServiceOperationException ex) { - logger.error("createOrganization: ERROR: {}", ex); + logger.error("createOrganization: ERROR", ex); result.error(ex.getCause()); } }); @@ -117,7 +117,7 @@ public Mono getUserOrganizationsMembership(GetMembershipR response.organizations().length); result.success(response); } catch (ServiceOperationException ex) { - logger.error("getUserOrganizationsMembership: ERROR: {}", ex); + logger.error("getUserOrganizationsMembership: ERROR", ex); result.error(ex.getCause()); } }); @@ -139,7 +139,7 @@ public Mono deleteOrganization(DeleteOrganizationReq logger.debug("deleteOrganization: exit, request: {}, response: {}", request, response); result.success(response); } catch (ServiceOperationException ex) { - logger.error("deleteOrganization: ERROR: {}", ex); + logger.error("deleteOrganization: ERROR", ex); result.error(ex.getCause()); } }); @@ -161,7 +161,7 @@ public Mono updateOrganization(UpdateOrganizationReq logger.debug("updateOrganization: exit, response: {}, request: {}", response, request); result.success(response); } catch (ServiceOperationException ex) { - logger.error("updateOrganization: ERROR: {}", ex); + logger.error("updateOrganization: ERROR", ex); result.error(ex.getCause()); } }); @@ -185,7 +185,7 @@ public Mono getOrganizationMembers( response.members().length); result.success(response); } catch (ServiceOperationException ex) { - logger.error("getOrganizationMembers: ERROR: {}", ex); + logger.error("getOrganizationMembers: ERROR", ex); result.error(ex.getCause()); } }); @@ -207,7 +207,7 @@ public Mono inviteMember( logger.debug("inviteMember: return response: {}, request: {}", response, request); result.success(response); } catch (ServiceOperationException ex) { - logger.error("inviteMember: ERROR: {}", ex); + logger.error("inviteMember: ERROR", ex); result.error(ex.getCause()); } }); @@ -229,7 +229,7 @@ public Mono kickoutMember( logger.debug("kickoutMember: exit, response: {}, request: {}", response, request); result.success(response); } catch (ServiceOperationException ex) { - logger.error("kickoutMember: ERROR: {}", ex); + logger.error("kickoutMember: ERROR", ex); result.error(ex.getCause()); } }); @@ -250,7 +250,7 @@ public Mono leaveOrganization(LeaveOrganizationReques logger.debug("leaveOrganization: exit, response: {}, request: {}", response, request); result.success(response); } catch (ServiceOperationException ex) { - logger.error("leaveOrganization: ERROR: {}", ex); + logger.error("leaveOrganization: ERROR", ex); result.error(ex.getCause()); } }); @@ -274,7 +274,7 @@ public Mono addOrganizationApiKey(AddOrganizationApiKey "addOrganizationApiKey: exit, response: {}, request: {}", response, request); result.success(response); } catch (ServiceOperationException ex) { - logger.error("addOrganizationApiKey: ERROR: {}", ex); + logger.error("addOrganizationApiKey: ERROR", ex); result.error(ex.getCause()); } }); @@ -297,7 +297,7 @@ public Mono deleteOrganizationApiKey( "deleteOrganizationApiKey: exit, response: {}, request: {}", response, request); result.success(response); } catch (ServiceOperationException ex) { - logger.error("deleteOrganizationApiKey: ERROR: {}", ex); + logger.error("deleteOrganizationApiKey: ERROR", ex); result.error(ex.getCause()); } }); @@ -318,7 +318,7 @@ public Mono getOrganization(GetOrganizationRequest requ logger.debug("getOrganization: exit, response: {}, request: {}", response, request); result.success(response); } catch (ServiceOperationException ex) { - logger.error("getOrganization: ERROR: {}", ex); + logger.error("getOrganization: ERROR", ex); result.error(ex.getCause()); } }); @@ -341,7 +341,7 @@ public Mono updateOrganizationMemberRole( "updateOrganizationMemberRole: exit, response: {}, request: {}", response, request); result.success(response); } catch (ServiceOperationException ex) { - logger.error("updateOrganizationMemberRole: ERROR: {}", ex); + logger.error("updateOrganizationMemberRole: ERROR", ex); result.error(ex.getCause()); } }); @@ -361,7 +361,7 @@ public Mono getPublicKey(GetPublicKeyRequest request) { .doOnSuccess( response -> logger.debug("getPublicKey: exit: response: {}, request: {}", response, request)) - .doOnError(th -> logger.error("getPublicKey: ERROR: {}", th)); + .doOnError(th -> logger.error("getPublicKey: ERROR", th)); } private KeyPairGenerator keyPairGenerator() { diff --git a/scalecube-organization/src/main/java/io/scalecube/organization/domain/Entity.java b/scalecube-organization/src/main/java/io/scalecube/organization/domain/Entity.java new file mode 100644 index 0000000..4e888b1 --- /dev/null +++ b/scalecube-organization/src/main/java/io/scalecube/organization/domain/Entity.java @@ -0,0 +1,19 @@ +package io.scalecube.organization.domain; + +public abstract class Entity { + + protected String id; + private long version; + + public String id() { + return id; + } + + public long version() { + return version; + } + + public void version(long version) { + this.version = version; + } +} diff --git a/scalecube-organization/src/main/java/io/scalecube/organization/domain/Organization.java b/scalecube-organization/src/main/java/io/scalecube/organization/domain/Organization.java new file mode 100644 index 0000000..83bb30b --- /dev/null +++ b/scalecube-organization/src/main/java/io/scalecube/organization/domain/Organization.java @@ -0,0 +1,108 @@ +package io.scalecube.organization.domain; + +import static java.util.Objects.requireNonNull; + +import io.scalecube.account.api.ApiKey; +import io.scalecube.account.api.OrganizationMember; +import io.scalecube.account.api.Role; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; +import java.util.StringJoiner; + +/** Represents an Organization. */ +public class Organization extends Entity { + + private String name; + private String email; + private String keyId; + private Set members = new HashSet<>(); + private Set apiKeys = new HashSet<>(); + + Organization() {} + + /** + * Creates new instance of organization. + * + * @param id organization id. + * @param name organization name. + * @param email organization email. + * @param keyId organization key id. + * @param creatorUserId user id of organization creator. + */ + public Organization(String id, String name, String email, String keyId, String creatorUserId) { + this.id = requireNonNull(id, "organization id cannot be null"); + this.name = requireNonNull(name, "organization name cannot be null"); + this.email = requireNonNull(email, "organization email cannot be null"); + this.keyId = requireNonNull(keyId, "organization keyId cannot be null"); + + addMember( + new OrganizationMember( + requireNonNull(creatorUserId, "organization creator id cannot be null"), + Role.Owner.name())); + } + + public String name() { + return name; + } + + public String email() { + return email; + } + + public String keyId() { + return keyId; + } + + public Set members() { + return Collections.unmodifiableSet(members); + } + + public Set apiKeys() { + return Collections.unmodifiableSet(apiKeys); + } + + public void changeName(String name) { + this.name = name; + } + + public void changeEmail(String email) { + this.email = email; + } + + public void addMember(OrganizationMember member) { + members.add(member); + } + + public void removeMember(String userId) { + members.removeIf(member -> member.id().equals(userId)); + } + + public boolean isMember(String userId) { + return members.stream().anyMatch(member -> member.id().equals(userId)); + } + + public void updateMemberRole(String userId, Role role) { + removeMember(userId); + addMember(new OrganizationMember(userId, role.name())); + } + + public void addApiKey(ApiKey apiKey) { + apiKeys.add(apiKey); + } + + public void removeApiKey(String apiKeyName) { + apiKeys.removeIf(apiKey -> apiKey.name().equals(apiKeyName)); + } + + @Override + public String toString() { + return new StringJoiner(", ", Organization.class.getSimpleName() + "[", "]") + .add("id='" + id + "'") + .add("name='" + name + "'") + .add("email='" + email + "'") + .add("keyId='" + keyId + "'") + .add("members=" + members) + .toString(); + } +} diff --git a/scalecube-organization/src/main/java/io/scalecube/organization/operation/AddOrganizationApiKey.java b/scalecube-organization/src/main/java/io/scalecube/organization/operation/AddOrganizationApiKey.java index 289d5ff..62a9c5a 100644 --- a/scalecube-organization/src/main/java/io/scalecube/organization/operation/AddOrganizationApiKey.java +++ b/scalecube-organization/src/main/java/io/scalecube/organization/operation/AddOrganizationApiKey.java @@ -6,14 +6,13 @@ import io.scalecube.account.api.OrganizationServiceException; import io.scalecube.account.api.Role; import io.scalecube.account.api.Token; -import io.scalecube.organization.repository.OrganizationsDataAccess; +import io.scalecube.organization.domain.Organization; +import io.scalecube.organization.repository.OrganizationsRepository; import io.scalecube.organization.repository.exception.AccessPermissionException; import io.scalecube.organization.tokens.TokenVerifier; import io.scalecube.organization.tokens.store.ApiKeyBuilder; import io.scalecube.organization.tokens.store.KeyStore; -import java.util.Arrays; import java.util.EnumSet; -import java.util.stream.Stream; public class AddOrganizationApiKey extends ServiceOperation { @@ -32,7 +31,7 @@ protected GetOrganizationResponse process( checkSuperUserAccess(organization, context.profile()); - Role callerRole = getRole(context.profile().getUserId(), organization); + Role callerRole = getRole(context.profile().userId(), organization); if (request.claims() != null) { String roleClaim = request.claims().get("role"); @@ -48,8 +47,8 @@ protected GetOrganizationResponse process( throw new AccessPermissionException( String.format( "user: '%s', name: '%s', role: '%s' cannot add api key with higher role '%s'", - context.profile().getUserId(), - context.profile().getName(), + context.profile().userId(), + context.profile().name(), callerRole, targetRole)); } @@ -57,16 +56,13 @@ protected GetOrganizationResponse process( } ApiKey apiKey = ApiKeyBuilder.build(keyStore, organization, request); - int newLength = organization.apiKeys().length + 1; - ApiKey[] apiKeys = Arrays.copyOf(organization.apiKeys(), newLength); - apiKeys[organization.apiKeys().length] = apiKey; + organization.addApiKey(apiKey); - Organization clonedOrg = Organization.builder().apiKey(apiKeys).copy(organization); - context.repository().updateOrganizationDetails(context.profile(), organization, clonedOrg); + context.repository().save(organization.id(), organization); - Role role = getRole(context.profile().getUserId(), organization); - return getOrganizationResponse(clonedOrg, apiKeyFilterBy(role)); + Role role = getRole(context.profile().userId(), organization); + return getOrganizationResponse(organization, apiKeyFilterBy(role)); } @Override @@ -77,7 +73,7 @@ protected void validate(AddOrganizationApiKeyRequest request, OperationServiceCo requireNonNullOrEmpty(request.apiKeyName(), "apiKeyName is a required argument"); Organization organization = getOrganization(request.organizationId()); boolean alreadyExists = - Stream.of(organization.apiKeys()) + organization.apiKeys().stream() .anyMatch(existingKey -> existingKey.name().equals(request.apiKeyName())); if (alreadyExists) { throw new IllegalArgumentException( @@ -96,7 +92,7 @@ public static Builder builder() { public static class Builder { private TokenVerifier tokenVerifier; - private OrganizationsDataAccess repository; + private OrganizationsRepository repository; private KeyStore keyStore; public Builder tokenVerifier(TokenVerifier tokenVerifier) { @@ -104,7 +100,7 @@ public Builder tokenVerifier(TokenVerifier tokenVerifier) { return this; } - public Builder repository(OrganizationsDataAccess repository) { + public Builder repository(OrganizationsRepository repository) { this.repository = repository; return this; } diff --git a/scalecube-organization/src/main/java/io/scalecube/organization/operation/CreateOrganization.java b/scalecube-organization/src/main/java/io/scalecube/organization/operation/CreateOrganization.java index ce2fd77..4e713b7 100644 --- a/scalecube-organization/src/main/java/io/scalecube/organization/operation/CreateOrganization.java +++ b/scalecube-organization/src/main/java/io/scalecube/organization/operation/CreateOrganization.java @@ -1,11 +1,12 @@ package io.scalecube.organization.operation; +import io.scalecube.account.api.ApiKey; import io.scalecube.account.api.CreateOrganizationRequest; import io.scalecube.account.api.CreateOrganizationResponse; import io.scalecube.account.api.OrganizationInfo; import io.scalecube.account.api.Token; -import io.scalecube.organization.repository.OrganizationsDataAccess; -import io.scalecube.organization.repository.exception.AccessPermissionException; +import io.scalecube.organization.domain.Organization; +import io.scalecube.organization.repository.OrganizationsRepository; import io.scalecube.organization.tokens.IdGenerator; import io.scalecube.organization.tokens.TokenVerifier; import io.scalecube.organization.tokens.store.KeyStore; @@ -31,14 +32,10 @@ public static Builder builder() { @Override protected CreateOrganizationResponse process( - CreateOrganizationRequest request, OperationServiceContext context) throws Throwable { + CreateOrganizationRequest request, OperationServiceContext context) { String id = "ORG-" + IdGenerator.generateId(); validate( - new OrganizationInfo.Builder() - .id(id) - .email(request.email()) - .name(request.name()) - .build(), + new OrganizationInfo.Builder().id(id).email(request.email()).name(request.name()).build(), context); Organization organization = createOrganization(request, context, id); @@ -47,7 +44,7 @@ protected CreateOrganizationResponse process( generateOrganizationKeyPair(organization); } catch (Exception ex) { // failed to persist organization secret rollback - context.repository().deleteOrganization(context.profile(), organization); + context.repository().deleteById(organization.id()); throw ex; } @@ -55,23 +52,21 @@ protected CreateOrganizationResponse process( OrganizationInfo.builder() .id(organization.id()) .name(organization.name()) - .apiKeys(organization.apiKeys()) - .email(organization.email())); + .email(organization.email()) + .apiKeys(organization.apiKeys().toArray(new ApiKey[0]))); } private Organization createOrganization( - CreateOrganizationRequest request, OperationServiceContext context, String id) - throws AccessPermissionException { - return context - .repository() - .createOrganization( - context.profile(), - Organization.builder() - .id(id) - .name(request.name()) - .email(request.email()) - .keyId(UUID.randomUUID().toString()) - .build()); + CreateOrganizationRequest request, OperationServiceContext context, String id) { + Organization organization = + new Organization( + id, + request.name(), + request.email(), + UUID.randomUUID().toString(), + context.profile().userId()); + + return context.repository().save(organization.id(), organization); } private void generateOrganizationKeyPair(Organization organization) { @@ -86,7 +81,7 @@ protected Token getToken(CreateOrganizationRequest request) { public static class Builder { private TokenVerifier tokenVerifier; - private OrganizationsDataAccess repository; + private OrganizationsRepository repository; private KeyPairGenerator keyPairGenerator; private KeyStore keyStore; @@ -95,7 +90,7 @@ public Builder tokenVerifier(TokenVerifier tokenVerifier) { return this; } - public Builder repository(OrganizationsDataAccess repository) { + public Builder repository(OrganizationsRepository repository) { this.repository = repository; return this; } diff --git a/scalecube-organization/src/main/java/io/scalecube/organization/operation/DeleteOrganization.java b/scalecube-organization/src/main/java/io/scalecube/organization/operation/DeleteOrganization.java index c33a678..05d20f6 100644 --- a/scalecube-organization/src/main/java/io/scalecube/organization/operation/DeleteOrganization.java +++ b/scalecube-organization/src/main/java/io/scalecube/organization/operation/DeleteOrganization.java @@ -3,13 +3,14 @@ import io.scalecube.account.api.DeleteOrganizationRequest; import io.scalecube.account.api.DeleteOrganizationResponse; import io.scalecube.account.api.Token; -import io.scalecube.organization.repository.OrganizationsDataAccess; +import io.scalecube.organization.domain.Organization; +import io.scalecube.organization.repository.OrganizationsRepository; import io.scalecube.organization.tokens.TokenVerifier; public class DeleteOrganization extends ServiceOperation { - private DeleteOrganization(TokenVerifier tokenVerifier, OrganizationsDataAccess repository) { + private DeleteOrganization(TokenVerifier tokenVerifier, OrganizationsRepository repository) { super(tokenVerifier, repository); } @@ -18,7 +19,7 @@ protected DeleteOrganizationResponse process( DeleteOrganizationRequest request, OperationServiceContext context) throws Throwable { Organization organization = getOrganization(request.organizationId()); checkOwnerAccess(organization, context.profile()); - context.repository().deleteOrganization(context.profile(), organization); + context.repository().deleteById(organization.id()); return new DeleteOrganizationResponse(organization.id(), true); } @@ -40,14 +41,14 @@ public static Builder builder() { public static class Builder { private TokenVerifier tokenVerifier; - private OrganizationsDataAccess repository; + private OrganizationsRepository repository; public Builder tokenVerifier(TokenVerifier tokenVerifier) { this.tokenVerifier = tokenVerifier; return this; } - public Builder repository(OrganizationsDataAccess repository) { + public Builder repository(OrganizationsRepository repository) { this.repository = repository; return this; } diff --git a/scalecube-organization/src/main/java/io/scalecube/organization/operation/DeleteOrganizationApiKey.java b/scalecube-organization/src/main/java/io/scalecube/organization/operation/DeleteOrganizationApiKey.java index 1ba315a..91a3387 100644 --- a/scalecube-organization/src/main/java/io/scalecube/organization/operation/DeleteOrganizationApiKey.java +++ b/scalecube-organization/src/main/java/io/scalecube/organization/operation/DeleteOrganizationApiKey.java @@ -1,20 +1,18 @@ package io.scalecube.organization.operation; -import io.scalecube.account.api.ApiKey; import io.scalecube.account.api.DeleteOrganizationApiKeyRequest; import io.scalecube.account.api.GetOrganizationResponse; import io.scalecube.account.api.Role; import io.scalecube.account.api.Token; -import io.scalecube.organization.repository.OrganizationsDataAccess; +import io.scalecube.organization.domain.Organization; +import io.scalecube.organization.repository.OrganizationsRepository; import io.scalecube.organization.tokens.TokenVerifier; -import java.util.Arrays; -import java.util.List; public class DeleteOrganizationApiKey extends ServiceOperation { private DeleteOrganizationApiKey( - TokenVerifier tokenVerifier, OrganizationsDataAccess repository) { + TokenVerifier tokenVerifier, OrganizationsRepository repository) { super(tokenVerifier, repository); } @@ -29,20 +27,11 @@ protected GetOrganizationResponse process( checkSuperUserAccess(organization, context.profile()); - List apiKeys = Arrays.asList(organization.apiKeys()); - Organization newOrg = - Organization.builder() - .apiKey( - apiKeys - .stream() - .filter(api -> !api.name().equals(request.apiKeyName())) - .toArray(ApiKey[]::new)) - .copy(organization); + organization.removeApiKey(request.apiKeyName()); + context.repository().save(organization.id(), organization); - context.repository().updateOrganizationDetails(context.profile(), organization, newOrg); - - Role role = getRole(context.profile().getUserId(), organization); - return getOrganizationResponse(newOrg, apiKeyFilterBy(role)); + Role role = getRole(context.profile().userId(), organization); + return getOrganizationResponse(organization, apiKeyFilterBy(role)); } @Override @@ -64,14 +53,14 @@ public static Builder builder() { public static class Builder { private TokenVerifier tokenVerifier; - private OrganizationsDataAccess repository; + private OrganizationsRepository repository; public Builder tokenVerifier(TokenVerifier tokenVerifier) { this.tokenVerifier = tokenVerifier; return this; } - public Builder repository(OrganizationsDataAccess repository) { + public Builder repository(OrganizationsRepository repository) { this.repository = repository; return this; } diff --git a/scalecube-organization/src/main/java/io/scalecube/organization/operation/GetOrganization.java b/scalecube-organization/src/main/java/io/scalecube/organization/operation/GetOrganization.java index 66b9adb..a084503 100644 --- a/scalecube-organization/src/main/java/io/scalecube/organization/operation/GetOrganization.java +++ b/scalecube-organization/src/main/java/io/scalecube/organization/operation/GetOrganization.java @@ -4,13 +4,14 @@ import io.scalecube.account.api.GetOrganizationResponse; import io.scalecube.account.api.Role; import io.scalecube.account.api.Token; -import io.scalecube.organization.repository.OrganizationsDataAccess; +import io.scalecube.organization.domain.Organization; +import io.scalecube.organization.repository.OrganizationsRepository; import io.scalecube.organization.tokens.TokenVerifier; public class GetOrganization extends ServiceOperation { - private GetOrganization(TokenVerifier tokenVerifier, OrganizationsDataAccess repository) { + private GetOrganization(TokenVerifier tokenVerifier, OrganizationsRepository repository) { super(tokenVerifier, repository); } @@ -19,7 +20,7 @@ protected GetOrganizationResponse process( GetOrganizationRequest request, OperationServiceContext context) throws Throwable { Organization organization = getOrganization(request.organizationId()); checkMemberAccess(organization, context.profile()); - Role role = getRole(context.profile().getUserId(), organization); + Role role = getRole(context.profile().userId(), organization); return getOrganizationResponse(organization, apiKeyFilterBy(role)); } @@ -41,14 +42,14 @@ public static Builder builder() { public static class Builder { private TokenVerifier tokenVerifier; - private OrganizationsDataAccess repository; + private OrganizationsRepository repository; public Builder tokenVerifier(TokenVerifier tokenVerifier) { this.tokenVerifier = tokenVerifier; return this; } - public Builder repository(OrganizationsDataAccess repository) { + public Builder repository(OrganizationsRepository repository) { this.repository = repository; return this; } diff --git a/scalecube-organization/src/main/java/io/scalecube/organization/operation/GetOrganizationMembers.java b/scalecube-organization/src/main/java/io/scalecube/organization/operation/GetOrganizationMembers.java index 32f3162..b350959 100644 --- a/scalecube-organization/src/main/java/io/scalecube/organization/operation/GetOrganizationMembers.java +++ b/scalecube-organization/src/main/java/io/scalecube/organization/operation/GetOrganizationMembers.java @@ -4,14 +4,14 @@ import io.scalecube.account.api.GetOrganizationMembersResponse; import io.scalecube.account.api.OrganizationMember; import io.scalecube.account.api.Token; -import io.scalecube.organization.repository.OrganizationsDataAccess; +import io.scalecube.organization.domain.Organization; +import io.scalecube.organization.repository.OrganizationsRepository; import io.scalecube.organization.tokens.TokenVerifier; -import java.util.Collection; public class GetOrganizationMembers extends ServiceOperation { - private GetOrganizationMembers(TokenVerifier tokenVerifier, OrganizationsDataAccess repository) { + private GetOrganizationMembers(TokenVerifier tokenVerifier, OrganizationsRepository repository) { super(tokenVerifier, repository); } @@ -21,11 +21,9 @@ protected GetOrganizationMembersResponse process( Organization organization = getOrganization(request.organizationId()); checkSuperUserAccess(organization, context.profile()); - Collection organizationMembers = - context.repository().getOrganizationMembers(organization); - OrganizationMember[] members = new OrganizationMember[organizationMembers.size()]; - return new GetOrganizationMembersResponse(organizationMembers.toArray(members)); + return new GetOrganizationMembersResponse( + organization.members().toArray(new OrganizationMember[0])); } @Override @@ -46,14 +44,14 @@ public static Builder builder() { public static class Builder { private TokenVerifier tokenVerifier; - private OrganizationsDataAccess repository; + private OrganizationsRepository repository; public Builder tokenVerifier(TokenVerifier tokenVerifier) { this.tokenVerifier = tokenVerifier; return this; } - public Builder repository(OrganizationsDataAccess repository) { + public Builder repository(OrganizationsRepository repository) { this.repository = repository; return this; } diff --git a/scalecube-organization/src/main/java/io/scalecube/organization/operation/GetUserOrganizationsMembership.java b/scalecube-organization/src/main/java/io/scalecube/organization/operation/GetUserOrganizationsMembership.java index e2f9af0..5ab606f 100644 --- a/scalecube-organization/src/main/java/io/scalecube/organization/operation/GetUserOrganizationsMembership.java +++ b/scalecube-organization/src/main/java/io/scalecube/organization/operation/GetUserOrganizationsMembership.java @@ -5,14 +5,15 @@ import io.scalecube.account.api.OrganizationInfo; import io.scalecube.account.api.Role; import io.scalecube.account.api.Token; -import io.scalecube.organization.repository.OrganizationsDataAccess; +import io.scalecube.organization.repository.OrganizationsRepository; import io.scalecube.organization.tokens.TokenVerifier; +import java.util.stream.StreamSupport; public class GetUserOrganizationsMembership extends ServiceOperation { private GetUserOrganizationsMembership( - TokenVerifier tokenVerifier, OrganizationsDataAccess repository) { + TokenVerifier tokenVerifier, OrganizationsRepository repository) { super(tokenVerifier, repository); } @@ -20,14 +21,12 @@ private GetUserOrganizationsMembership( protected GetMembershipResponse process( GetMembershipRequest request, OperationServiceContext context) { return new GetMembershipResponse( - context - .repository() - .getUserMembership(context.profile().getUserId()) - .stream() + StreamSupport.stream(context.repository().findAll().spliterator(), false) + .filter(organization -> organization.isMember(context.profile().userId())) .map( - item -> { - Role role = getRole(context.profile().getUserId(), item); - return organizationInfo(item, apiKeyFilterBy(role)).build(); + organization -> { + Role role = getRole(context.profile().userId(), organization); + return organizationInfo(organization, apiKeyFilterBy(role)).build(); }) .toArray(OrganizationInfo[]::new)); } @@ -43,14 +42,14 @@ public static Builder builder() { public static class Builder { private TokenVerifier tokenVerifier; - private OrganizationsDataAccess repository; + private OrganizationsRepository repository; public Builder tokenVerifier(TokenVerifier tokenVerifier) { this.tokenVerifier = tokenVerifier; return this; } - public Builder repository(OrganizationsDataAccess repository) { + public Builder repository(OrganizationsRepository repository) { this.repository = repository; return this; } diff --git a/scalecube-organization/src/main/java/io/scalecube/organization/operation/InviteMember.java b/scalecube-organization/src/main/java/io/scalecube/organization/operation/InviteMember.java index ed9ba75..0a08565 100644 --- a/scalecube-organization/src/main/java/io/scalecube/organization/operation/InviteMember.java +++ b/scalecube-organization/src/main/java/io/scalecube/organization/operation/InviteMember.java @@ -2,16 +2,18 @@ import io.scalecube.account.api.InviteOrganizationMemberRequest; import io.scalecube.account.api.InviteOrganizationMemberResponse; +import io.scalecube.account.api.OrganizationMember; import io.scalecube.account.api.Role; import io.scalecube.account.api.Token; -import io.scalecube.organization.repository.OrganizationsDataAccess; +import io.scalecube.organization.domain.Organization; +import io.scalecube.organization.repository.OrganizationsRepository; import io.scalecube.organization.repository.exception.AccessPermissionException; import io.scalecube.organization.tokens.TokenVerifier; public class InviteMember extends ServiceOperation { - private InviteMember(TokenVerifier tokenVerifier, OrganizationsDataAccess repository) { + private InviteMember(TokenVerifier tokenVerifier, OrganizationsRepository repository) { super(tokenVerifier, repository); } @@ -22,21 +24,21 @@ protected InviteOrganizationMemberResponse process( checkSuperUserAccess(organization, context.profile()); Role invitedMemberRole = toRole(request.role()); - Role callerRole = getRole(context.profile().getUserId(), organization); + Role callerRole = getRole(context.profile().userId(), organization); if (invitedMemberRole.isHigherThan(callerRole)) { throw new AccessPermissionException( String.format( "user: '%s', name: '%s', role: '%s' cannot invite to a higher role: '%s'", - context.profile().getUserId(), - context.profile().getName(), + context.profile().userId(), + context.profile().name(), callerRole, invitedMemberRole.toString())); } - context - .repository() - .invite(context.profile(), organization, request.userId(), invitedMemberRole); + organization.addMember(new OrganizationMember(request.userId(), invitedMemberRole.name())); + context.repository().save(organization.id(), organization); + return new InviteOrganizationMemberResponse(); } @@ -59,14 +61,14 @@ public static Builder builder() { public static class Builder { private TokenVerifier tokenVerifier; - private OrganizationsDataAccess repository; + private OrganizationsRepository repository; public Builder tokenVerifier(TokenVerifier tokenVerifier) { this.tokenVerifier = tokenVerifier; return this; } - public Builder repository(OrganizationsDataAccess repository) { + public Builder repository(OrganizationsRepository repository) { this.repository = repository; return this; } diff --git a/scalecube-organization/src/main/java/io/scalecube/organization/operation/KickoutMember.java b/scalecube-organization/src/main/java/io/scalecube/organization/operation/KickoutMember.java index 8ce7e19..6d0fdca 100644 --- a/scalecube-organization/src/main/java/io/scalecube/organization/operation/KickoutMember.java +++ b/scalecube-organization/src/main/java/io/scalecube/organization/operation/KickoutMember.java @@ -4,7 +4,8 @@ import io.scalecube.account.api.KickoutOrganizationMemberResponse; import io.scalecube.account.api.Role; import io.scalecube.account.api.Token; -import io.scalecube.organization.repository.OrganizationsDataAccess; +import io.scalecube.organization.domain.Organization; +import io.scalecube.organization.repository.OrganizationsRepository; import io.scalecube.organization.repository.exception.AccessPermissionException; import io.scalecube.organization.repository.exception.EntityNotFoundException; import io.scalecube.organization.tokens.TokenVerifier; @@ -12,7 +13,7 @@ public class KickoutMember extends ServiceOperation { - private KickoutMember(TokenVerifier tokenVerifier, OrganizationsDataAccess repository) { + private KickoutMember(TokenVerifier tokenVerifier, OrganizationsRepository repository) { super(tokenVerifier, repository); } @@ -23,7 +24,10 @@ protected KickoutOrganizationMemberResponse process( checkSuperUserAccess(organization, context.profile()); ensureCallerIsInHigherRoleThanKickedOutUser(request, context, organization); checkLastOwner(request.userId(), organization); - context.repository().kickout(context.profile(), organization, request.userId()); + + organization.removeMember(request.userId()); + context.repository().save(organization.id(), organization); + return new KickoutOrganizationMemberResponse(); } @@ -33,7 +37,7 @@ private void ensureCallerIsInHigherRoleThanKickedOutUser( Organization organization) throws EntityNotFoundException, AccessPermissionException { - Role callerRole = getRole(context.profile().getUserId(), organization); + Role callerRole = getRole(context.profile().userId(), organization); Role targetRole = getRole(request.userId(), organization); if (targetRole.isHigherThan(callerRole)) { @@ -41,8 +45,8 @@ private void ensureCallerIsInHigherRoleThanKickedOutUser( String.format( "user: '%s', name: '%s', role: '%s' cannot kickout " + "user: '%s' in role '%s' of organization: '%s'", - context.profile().getUserId(), - context.profile().getName(), + context.profile().userId(), + context.profile().name(), callerRole, request.userId(), targetRole, @@ -69,14 +73,14 @@ public static Builder builder() { public static class Builder { private TokenVerifier tokenVerifier; - private OrganizationsDataAccess repository; + private OrganizationsRepository repository; public Builder tokenVerifier(TokenVerifier tokenVerifier) { this.tokenVerifier = tokenVerifier; return this; } - public Builder repository(OrganizationsDataAccess repository) { + public Builder repository(OrganizationsRepository repository) { this.repository = repository; return this; } diff --git a/scalecube-organization/src/main/java/io/scalecube/organization/operation/LeaveOrganization.java b/scalecube-organization/src/main/java/io/scalecube/organization/operation/LeaveOrganization.java index 206a846..e41d6b9 100644 --- a/scalecube-organization/src/main/java/io/scalecube/organization/operation/LeaveOrganization.java +++ b/scalecube-organization/src/main/java/io/scalecube/organization/operation/LeaveOrganization.java @@ -3,22 +3,26 @@ import io.scalecube.account.api.LeaveOrganizationRequest; import io.scalecube.account.api.LeaveOrganizationResponse; import io.scalecube.account.api.Token; -import io.scalecube.organization.repository.OrganizationsDataAccess; +import io.scalecube.organization.domain.Organization; +import io.scalecube.organization.repository.OrganizationsRepository; import io.scalecube.organization.tokens.TokenVerifier; public class LeaveOrganization extends ServiceOperation { - private LeaveOrganization(TokenVerifier tokenVerifier, OrganizationsDataAccess repository) { + private LeaveOrganization(TokenVerifier tokenVerifier, OrganizationsRepository repository) { super(tokenVerifier, repository); } @Override protected LeaveOrganizationResponse process( - LeaveOrganizationRequest request, OperationServiceContext context) throws Throwable { + LeaveOrganizationRequest request, OperationServiceContext context) { Organization organization = getOrganization(request.organizationId()); - checkLastOwner(context.profile().getUserId(), organization); - context.repository().leave(organization, context.profile().getUserId()); + checkLastOwner(context.profile().userId(), organization); + + organization.removeMember(context.profile().userId()); + context.repository().save(organization.id(), organization); + return new LeaveOrganizationResponse(); } @@ -40,14 +44,14 @@ public static Builder builder() { public static class Builder { private TokenVerifier tokenVerifier; - private OrganizationsDataAccess repository; + private OrganizationsRepository repository; public Builder tokenVerifier(TokenVerifier tokenVerifier) { this.tokenVerifier = tokenVerifier; return this; } - public Builder repository(OrganizationsDataAccess repository) { + public Builder repository(OrganizationsRepository repository) { this.repository = repository; return this; } diff --git a/scalecube-organization/src/main/java/io/scalecube/organization/operation/OperationServiceContext.java b/scalecube-organization/src/main/java/io/scalecube/organization/operation/OperationServiceContext.java index 35faec3..eb563d5 100644 --- a/scalecube-organization/src/main/java/io/scalecube/organization/operation/OperationServiceContext.java +++ b/scalecube-organization/src/main/java/io/scalecube/organization/operation/OperationServiceContext.java @@ -1,13 +1,13 @@ package io.scalecube.organization.operation; -import io.scalecube.organization.repository.OrganizationsDataAccess; -import io.scalecube.security.Profile; +import io.scalecube.organization.repository.OrganizationsRepository; +import io.scalecube.security.api.Profile; public class OperationServiceContext { private final Profile profile; - private final OrganizationsDataAccess repository; + private final OrganizationsRepository repository; - public OperationServiceContext(Profile profile, OrganizationsDataAccess repository) { + public OperationServiceContext(Profile profile, OrganizationsRepository repository) { this.profile = profile; this.repository = repository; } @@ -16,7 +16,7 @@ public Profile profile() { return profile; } - public OrganizationsDataAccess repository() { + public OrganizationsRepository repository() { return repository; } } diff --git a/scalecube-organization/src/main/java/io/scalecube/organization/operation/Organization.java b/scalecube-organization/src/main/java/io/scalecube/organization/operation/Organization.java deleted file mode 100644 index 3afc274..0000000 --- a/scalecube-organization/src/main/java/io/scalecube/organization/operation/Organization.java +++ /dev/null @@ -1,119 +0,0 @@ -package io.scalecube.organization.operation; - -import io.scalecube.account.api.ApiKey; - -/** Represents an Organization. */ -public class Organization { - - private String id; - private String name; - private String email; - private String keyId; - private ApiKey[] apiKeys; - - Organization() {} - - private Organization(String id, String name, String email, String keyId, ApiKey[] apiKeys) { - this.id = id; - this.name = name; - this.email = email; - this.keyId = keyId; - this.apiKeys = apiKeys; - } - - private Organization(Builder builder) { - this.id = builder.id; - this.name = builder.name; - this.email = builder.email; - this.keyId = builder.keyId; - this.apiKeys = builder.apiKeys; - } - - public String id() { - return id; - } - - public String name() { - return name; - } - - public String email() { - return email; - } - - public String keyId() { - return keyId; - } - - public ApiKey[] apiKeys() { - return apiKeys; - } - - public static Builder builder() { - return new Builder(); - } - - public static class Builder { - - private String id; - private String name; - private String email; - private String keyId; - private ApiKey[] apiKeys = {}; - - public Builder id(String id) { - this.id = id; - return this; - } - - public Builder name(String name) { - this.name = name; - return this; - } - - public Builder email(String email) { - this.email = email; - return this; - } - - public Builder keyId(String keyId) { - this.keyId = keyId; - return this; - } - - public Builder apiKey(ApiKey[] apiKeys) { - this.apiKeys = apiKeys; - return this; - } - - /** - * Creates a copy of the Organization source argument. - * - * @param source The source to copy from - * @return an Organization object which a shallow copy of the source argument. - */ - public Organization copy(Organization source) { - String email = this.email == null ? source.email : this.email; - String name = this.name == null ? source.name : this.name; - ApiKey[] apiKeys = this.apiKeys == null ? source.apiKeys : this.apiKeys; - return new Organization(source.id(), name, email, source.keyId(), apiKeys); - } - - public Organization build() { - return new Organization(this); - } - } - - @Override - public String toString() { - return "Organization [id=" - + id - + ", name=" - + name - + ", email=" - + email - + ", keyId=" - + keyId - + "]"; - } -} diff --git a/scalecube-organization/src/main/java/io/scalecube/organization/operation/OrganizationInfoOperation.java b/scalecube-organization/src/main/java/io/scalecube/organization/operation/OrganizationInfoOperation.java index ed64dfb..d1fef3c 100644 --- a/scalecube-organization/src/main/java/io/scalecube/organization/operation/OrganizationInfoOperation.java +++ b/scalecube-organization/src/main/java/io/scalecube/organization/operation/OrganizationInfoOperation.java @@ -1,7 +1,7 @@ package io.scalecube.organization.operation; import io.scalecube.account.api.OrganizationInfo; -import io.scalecube.organization.repository.OrganizationsDataAccess; +import io.scalecube.organization.repository.OrganizationsRepository; import io.scalecube.organization.repository.exception.InvalidInputException; import io.scalecube.organization.repository.exception.NameAlreadyInUseException; import io.scalecube.organization.tokens.TokenVerifier; @@ -9,8 +9,7 @@ public abstract class OrganizationInfoOperation extends ServiceOperation { private static final String VALID_ORG_NAME_CHARS_REGEX = "^[.%a-zA-Z0-9_-]*$"; - protected OrganizationInfoOperation( - TokenVerifier tokenVerifier, OrganizationsDataAccess repository) { + OrganizationInfoOperation(TokenVerifier tokenVerifier, OrganizationsRepository repository) { super(tokenVerifier, repository); } @@ -26,7 +25,7 @@ protected void validate(OrganizationInfo info, OperationServiceContext context) + "underscore, period, dash & percent"); } - if (context.repository().existByName(info.name())) { + if (context.repository().existsByName(info.name())) { throw new NameAlreadyInUseException( String.format("Organization name: '%s' already in use", info.name())); } diff --git a/scalecube-organization/src/main/java/io/scalecube/organization/operation/ServiceOperation.java b/scalecube-organization/src/main/java/io/scalecube/organization/operation/ServiceOperation.java index f165cc0..729421e 100644 --- a/scalecube-organization/src/main/java/io/scalecube/organization/operation/ServiceOperation.java +++ b/scalecube-organization/src/main/java/io/scalecube/organization/operation/ServiceOperation.java @@ -8,12 +8,12 @@ import io.scalecube.account.api.Role; import io.scalecube.account.api.ServiceOperationException; import io.scalecube.account.api.Token; -import io.scalecube.organization.repository.OrganizationsDataAccess; +import io.scalecube.organization.domain.Organization; +import io.scalecube.organization.repository.OrganizationsRepository; import io.scalecube.organization.repository.exception.AccessPermissionException; import io.scalecube.organization.repository.exception.EntityNotFoundException; import io.scalecube.organization.tokens.TokenVerifier; -import io.scalecube.security.Profile; -import java.util.Arrays; +import io.scalecube.security.api.Profile; import java.util.Objects; import java.util.function.Predicate; @@ -26,9 +26,9 @@ public abstract class ServiceOperation { private final TokenVerifier tokenVerifier; - private final OrganizationsDataAccess repository; + private final OrganizationsRepository repository; - protected ServiceOperation(TokenVerifier tokenVerifier, OrganizationsDataAccess repository) { + protected ServiceOperation(TokenVerifier tokenVerifier, OrganizationsRepository repository) { this.tokenVerifier = tokenVerifier; this.repository = repository; } @@ -77,13 +77,7 @@ protected Organization getOrganization(String id) throws OrganizationNotFoundExc Objects.requireNonNull(repository, "repository"); try { - Organization organization = repository.getOrganization(id); - - if (organization == null) { - throw new OrganizationNotFoundException(id); - } - - return organization; + return repository.findById(id).orElseThrow(() -> new OrganizationNotFoundException(id)); } catch (EntityNotFoundException e) { throw new OrganizationNotFoundException(id); } @@ -96,11 +90,10 @@ protected GetOrganizationResponse getOrganizationResponse( protected OrganizationInfo.Builder organizationInfo( Organization organization, Predicate filter) { - ApiKey[] apiKeys = Arrays.stream(organization.apiKeys()).filter(filter).toArray(ApiKey[]::new); return OrganizationInfo.builder() .id(organization.id()) .name(organization.name()) - .apiKeys(apiKeys) + .apiKeys(organization.apiKeys().stream().filter(filter).toArray(ApiKey[]::new)) .email(organization.email()); } @@ -115,39 +108,33 @@ protected static void requireNonNullOrEmpty(Object object, String message) { protected void checkMemberAccess(Organization organization, Profile profile) throws AccessPermissionException, EntityNotFoundException { - if (!isOwner(organization, profile) - && !repository.isMember(profile.getUserId(), organization)) { + if (!isOwner(organization, profile) && !organization.isMember(profile.userId())) { throw new AccessPermissionException( String.format( "user: '%s', name: '%s', is not a member of organization: '%s'", - profile.getName(), profile.getUserId(), organization.id())); + profile.name(), profile.userId(), organization.id())); } } protected boolean isOwner(Organization organization, Profile profile) - throws EntityNotFoundException, AccessPermissionException { - return isInRole(profile.getUserId(), organization, Role.Owner); + throws EntityNotFoundException { + return isInRole(profile.userId(), organization, Role.Owner); } protected boolean isLastOwner(Organization organization, String userId) throws EntityNotFoundException { - return repository - .getOrganizationMembers(organization) - .stream() + return organization.members().stream() .filter(member -> !member.id().equals(userId)) .noneMatch(member -> Role.Owner.name().equals(member.role())); } protected boolean isSuperUser(Organization organization, Profile profile) - throws EntityNotFoundException, AccessPermissionException { - return isOwner(organization, profile) - || isInRole(profile.getUserId(), organization, Role.Admin); + throws EntityNotFoundException { + return isOwner(organization, profile) || isInRole(profile.userId(), organization, Role.Admin); } protected Role getRole(String userId, Organization organization) throws EntityNotFoundException { - return repository - .getOrganizationMembers(organization) - .stream() + return organization.members().stream() .filter(i -> Objects.equals(i.id(), userId)) .map(i -> Role.valueOf(i.role())) .findFirst() @@ -158,15 +145,13 @@ protected Role toRole(String role) { try { return Role.valueOf(role); } catch (Throwable ex) { - throw new IllegalArgumentException("role: " + role); + throw new IllegalArgumentException("Unknown role: " + role); } } protected boolean isInRole(String userId, Organization organization, Role role) throws EntityNotFoundException { - return repository - .getOrganizationMembers(organization) - .stream() + return organization.members().stream() .anyMatch(i -> Objects.equals(i.id(), userId) && Objects.equals(i.role(), role.toString())); } @@ -175,7 +160,7 @@ protected static void throwNotOrgOwnerException(Profile owner, Organization orga throw new AccessPermissionException( String.format( "user: '%s', name: '%s', is not in role Owner of organization: '%s'", - owner.getName(), owner.getUserId(), organization.name())); + owner.name(), owner.userId(), organization.name())); } protected void checkOwnerAccess(Organization organization, Profile profile) @@ -191,7 +176,7 @@ protected void checkSuperUserAccess(Organization organization, Profile profile) throw new AccessPermissionException( String.format( "user: '%s', name: '%s', not in role Owner or Admin of organization: '%s'", - profile.getUserId(), profile.getName(), organization.name())); + profile.userId(), profile.name(), organization.name())); } } diff --git a/scalecube-organization/src/main/java/io/scalecube/organization/operation/UpdateOrganization.java b/scalecube-organization/src/main/java/io/scalecube/organization/operation/UpdateOrganization.java index ceb7cb9..10b1da6 100644 --- a/scalecube-organization/src/main/java/io/scalecube/organization/operation/UpdateOrganization.java +++ b/scalecube-organization/src/main/java/io/scalecube/organization/operation/UpdateOrganization.java @@ -5,13 +5,14 @@ import io.scalecube.account.api.Token; import io.scalecube.account.api.UpdateOrganizationRequest; import io.scalecube.account.api.UpdateOrganizationResponse; -import io.scalecube.organization.repository.OrganizationsDataAccess; +import io.scalecube.organization.domain.Organization; +import io.scalecube.organization.repository.OrganizationsRepository; import io.scalecube.organization.tokens.TokenVerifier; public class UpdateOrganization extends OrganizationInfoOperation { - private UpdateOrganization(TokenVerifier tokenVerifier, OrganizationsDataAccess repository) { + private UpdateOrganization(TokenVerifier tokenVerifier, OrganizationsRepository repository) { super(tokenVerifier, repository); } @@ -19,18 +20,16 @@ private UpdateOrganization(TokenVerifier tokenVerifier, OrganizationsDataAccess protected UpdateOrganizationResponse process( UpdateOrganizationRequest request, OperationServiceContext context) throws Throwable { Organization organization = getOrganization(request.organizationId()); + checkSuperUserAccess(organization, context.profile()); - Organization orgUpdate = - Organization.builder() - .name(request.name()) - .email(request.email()) - .apiKey(organization.apiKeys()) - .copy(organization); - context.repository().updateOrganizationDetails(context.profile(), organization, orgUpdate); + organization.changeName(request.name()); + organization.changeEmail(request.email()); + + context.repository().save(organization.id(), organization); - Role role = getRole(context.profile().getUserId(), organization); - return new UpdateOrganizationResponse(organizationInfo(orgUpdate, apiKeyFilterBy(role))); + Role role = getRole(context.profile().userId(), organization); + return new UpdateOrganizationResponse(organizationInfo(organization, apiKeyFilterBy(role))); } @Override @@ -58,14 +57,14 @@ public static Builder builder() { public static class Builder { private TokenVerifier tokenVerifier; - private OrganizationsDataAccess repository; + private OrganizationsRepository repository; public Builder tokenVerifier(TokenVerifier tokenVerifier) { this.tokenVerifier = tokenVerifier; return this; } - public Builder repository(OrganizationsDataAccess repository) { + public Builder repository(OrganizationsRepository repository) { this.repository = repository; return this; } diff --git a/scalecube-organization/src/main/java/io/scalecube/organization/operation/UpdateOrganizationMemberRole.java b/scalecube-organization/src/main/java/io/scalecube/organization/operation/UpdateOrganizationMemberRole.java index 1d00ec0..cc8b5b1 100644 --- a/scalecube-organization/src/main/java/io/scalecube/organization/operation/UpdateOrganizationMemberRole.java +++ b/scalecube-organization/src/main/java/io/scalecube/organization/operation/UpdateOrganizationMemberRole.java @@ -5,11 +5,12 @@ import io.scalecube.account.api.Token; import io.scalecube.account.api.UpdateOrganizationMemberRoleRequest; import io.scalecube.account.api.UpdateOrganizationMemberRoleResponse; -import io.scalecube.organization.repository.OrganizationsDataAccess; +import io.scalecube.organization.domain.Organization; +import io.scalecube.organization.repository.OrganizationsRepository; import io.scalecube.organization.repository.exception.AccessPermissionException; import io.scalecube.organization.repository.exception.EntityNotFoundException; import io.scalecube.organization.tokens.TokenVerifier; -import io.scalecube.security.Profile; +import io.scalecube.security.api.Profile; /** * Encapsulates the processing of a request to update the role of an organization member. This @@ -22,7 +23,7 @@ public class UpdateOrganizationMemberRole UpdateOrganizationMemberRoleRequest, UpdateOrganizationMemberRoleResponse> { private UpdateOrganizationMemberRole( - TokenVerifier tokenVerifier, OrganizationsDataAccess repository) { + TokenVerifier tokenVerifier, OrganizationsRepository repository) { super(tokenVerifier, repository); } @@ -35,9 +36,10 @@ protected Token getToken(UpdateOrganizationMemberRoleRequest request) { protected UpdateOrganizationMemberRoleResponse process( UpdateOrganizationMemberRoleRequest request, OperationServiceContext context) { Organization organization = getOrganization(request.organizationId()); - context - .repository() - .updateOrganizationMemberRole(organization, request.userId(), request.role()); + + organization.updateMemberRole(request.userId(), Role.valueOf(request.role())); + + context.repository().save(organization.id(), organization); return new UpdateOrganizationMemberRoleResponse(); } @@ -53,9 +55,9 @@ protected void validate( Organization organization = getOrganization(request.organizationId()); Profile caller = context.profile(); - Role callerRole = getRole(context.profile().getUserId(), organization); + Role callerRole = getRole(context.profile().userId(), organization); - checkIsMember(request.userId(), context, organization); + checkIsMember(request.userId(), organization); checkSuperUserAccess(organization, caller); checkIfRequestToUpdateUserRoleIsValidForCaller( toRole(request.role()), context.profile(), callerRole); @@ -69,10 +71,7 @@ private void checkIfRequestToUpdateUserRoleIsValidForCaller( throw new AccessPermissionException( String.format( "user: '%s', name: '%s', role: '%s'," + " cannot promote to a higher role: '%s'", - profile.getUserId(), - profile.getName(), - callerRole.toString(), - targetRole.toString())); + profile.userId(), profile.name(), callerRole.toString(), targetRole.toString())); } } @@ -89,18 +88,17 @@ private void checkIfAdminCallerIsTryingToDowngradeAnOwner( String.format( "user: '%s', name: '%s', role: %s," + " cannot downgrade user id: %s, in higher role: '%s'.", - caller.getUserId(), - caller.getName(), + caller.userId(), + caller.name(), callerRole.toString(), request.userId(), updateUserCurrentRole.toString())); } } - private void checkIsMember( - String userId, OperationServiceContext context, Organization organization) + private void checkIsMember(String userId, Organization organization) throws NotAnOrganizationMemberException { - if (!context.repository().isMember(userId, organization)) { + if (!organization.isMember(userId)) { throw new NotAnOrganizationMemberException( String.format( "user: %s, is not a member of organization: %s", userId, organization.id())); @@ -113,14 +111,14 @@ public static Builder builder() { public static class Builder { private TokenVerifier tokenVerifier; - private OrganizationsDataAccess repository; + private OrganizationsRepository repository; public UpdateOrganizationMemberRole.Builder tokenVerifier(TokenVerifier tokenVerifier) { this.tokenVerifier = tokenVerifier; return this; } - public UpdateOrganizationMemberRole.Builder repository(OrganizationsDataAccess repository) { + public UpdateOrganizationMemberRole.Builder repository(OrganizationsRepository repository) { this.repository = repository; return this; } diff --git a/scalecube-organization/src/main/java/io/scalecube/organization/repository/OrganizationMembersRepositoryAdmin.java b/scalecube-organization/src/main/java/io/scalecube/organization/repository/OrganizationMembersRepositoryAdmin.java deleted file mode 100644 index 683a253..0000000 --- a/scalecube-organization/src/main/java/io/scalecube/organization/repository/OrganizationMembersRepositoryAdmin.java +++ /dev/null @@ -1,24 +0,0 @@ -package io.scalecube.organization.repository; - -import io.scalecube.organization.operation.Organization; - -/** - * An abstraction to administrative operations on the Organization members repository. Whenever an - * organization is created, a side-car bucket named the ORG_ID-members gets auto created. - */ -public interface OrganizationMembersRepositoryAdmin { - - /** - * Creates a members repository for the organization argument. - * - * @param organization The organization for which a members repository should be created. - */ - void createRepository(Organization organization); - - /** - * Deletes a members repository of the organization argument. - * - * @param organization The organization for which the members repository should be deleted. - */ - void deleteRepository(Organization organization); -} diff --git a/scalecube-organization/src/main/java/io/scalecube/organization/repository/OrganizationsDataAccess.java b/scalecube-organization/src/main/java/io/scalecube/organization/repository/OrganizationsDataAccess.java deleted file mode 100644 index b8bfbdb..0000000 --- a/scalecube-organization/src/main/java/io/scalecube/organization/repository/OrganizationsDataAccess.java +++ /dev/null @@ -1,156 +0,0 @@ -package io.scalecube.organization.repository; - -import io.scalecube.account.api.OrganizationMember; -import io.scalecube.account.api.Role; -import io.scalecube.organization.operation.Organization; -import io.scalecube.organization.repository.exception.AccessPermissionException; -import io.scalecube.organization.repository.exception.DuplicateKeyException; -import io.scalecube.organization.repository.exception.EntityNotFoundException; -import io.scalecube.security.Profile; -import java.util.Collection; - -/** - * Data access abstraction to organizations data providers. Implementing classes may persist the - * data in different ways (e.g. in-memory, file on disk, DB). Data persistence is not enforced and - * therefore not guaranteed and it is in the scope of the implementing class. - */ -public interface OrganizationsDataAccess { - - /** - * Returns true if an Organization corresponding to the name argument exists in the - * underlying data provider. - * - * @param name organization's name criteria - * @return true if an Organization corresponding to the name argument exists in the - * underlying data provider; false otherwise - */ - boolean existByName(String name); - - /** - * Returns an Organization object corresponding to the id argument in the underlying - * data provider. - * - * @param id The organization id criteria. - * @return An organization object. - * @throws EntityNotFoundException in case an entity with a corresponding id is not found in the - * underlying data provider. - */ - Organization getOrganization(String id) throws EntityNotFoundException; - - /** - * Creates an Organization entry in the underlying data provider with the organization - * and owner arguments. - * - * @param owner Organization owner. - * @param organization The new organization to be created. - * @return An organization object. - * @throws AccessPermissionException In case of insufficient privileges. - * @throws DuplicateKeyException In case an organization with the same id already exists in the - * underlying data provider. - */ - Organization createOrganization(Profile owner, Organization organization) - throws AccessPermissionException, DuplicateKeyException; - - /** - * Deletes an Organization entry in the underlying data provider with the corresponding to the - * organization argument. - * - * @param owner Organization owner. - * @param organization The organization to be deleted. - * @throws AccessPermissionException In case of insufficient privileges. - * @throws EntityNotFoundException In case an organization with the same id does not exists in the - * underlying data provider. - */ - void deleteOrganization(Profile owner, Organization organization) - throws EntityNotFoundException, AccessPermissionException; - - /** - * Returns a list of organizations of which the tokenVerifier argument is a member of - * those organizations. - * - * @param userId The id of the tokenVerifier criteria. - * @return a list of Organization objects. - */ - Collection getUserMembership(String userId); - - /** - * Updates the source organization with the update organization in the - * underlying data provider. - * - * @param owner The organization owner. - * @param source The organization source. - * @param update The updated organization. - * @throws AccessPermissionException In case of insufficient privileges. - */ - void updateOrganizationDetails(Profile owner, Organization source, Organization update) - throws AccessPermissionException; - - /** - * Returns a membership list of an organization corresponding to the id argument in - * the underlying data provider. - * - * @param organization The organization id criteria. - * @return A collection of OrganizationMember objects. - * @throws EntityNotFoundException In case organization is not found. - */ - Collection getOrganizationMembers(Organization organization) - throws EntityNotFoundException; - - /** - * Invites the tokenVerifier argument to join the organization - * argument. - * - * @param owner The Organization owner - * @param organization The Organization to join. - * @param userId The invited user id. - * @param targetRole The invited user role. - * @throws AccessPermissionException In case of insufficient privileges. - * @throws EntityNotFoundException In case the organization does not exists in the underlying data - * provider. - */ - void invite(Profile owner, Organization organization, String userId, Role targetRole) - throws AccessPermissionException, EntityNotFoundException; - - /** - * Kicks out the tokenVerifier argument from the organization - * argument. - * - * @param owner The Organization owner - * @param organization The Organization from which the tokenVerifier is to be kicked out. - * @param userId The kicked out user id. - * @throws EntityNotFoundException In case the organization does not exists in the underlying data - * provider. - */ - void kickout(Profile owner, Organization organization, String userId) - throws EntityNotFoundException; - - /** - * Enables the tokenVerifier to leave the organization. - * - * @param organization The organization of which the tokenVerifier wishes to leave. - * @param userId The id of the tokenVerifier requesting to leave the organization. - * @throws EntityNotFoundException In case the organization is not found in the underlying data - * provider. - */ - void leave(Organization organization, String userId) throws EntityNotFoundException; - - /** - * Determines if the user corresponding to the userId argument is a member of the organization - * argument. - * - * @param userId the user id criteria - * @param organization the organization criteria - * @return true if the user is a member of the organization; false otherwise. - */ - boolean isMember(String userId, Organization organization); - - /** - * Updates the organization membership of the user corrsponding to the userId argument to the role - * argument. - * - * @param organization the organization criteria - * @param userId the user id criteria - * @param role the new role - */ - void updateOrganizationMemberRole(Organization organization, String userId, String role); -} diff --git a/scalecube-organization/src/main/java/io/scalecube/organization/repository/OrganizationsDataAccessImpl.java b/scalecube-organization/src/main/java/io/scalecube/organization/repository/OrganizationsDataAccessImpl.java deleted file mode 100644 index 76b4729..0000000 --- a/scalecube-organization/src/main/java/io/scalecube/organization/repository/OrganizationsDataAccessImpl.java +++ /dev/null @@ -1,178 +0,0 @@ -package io.scalecube.organization.repository; - -import static java.util.Objects.requireNonNull; - -import io.scalecube.account.api.OrganizationMember; -import io.scalecube.account.api.Role; -import io.scalecube.organization.operation.Organization; -import io.scalecube.organization.repository.exception.DuplicateKeyException; -import io.scalecube.organization.repository.exception.EntityNotFoundException; -import io.scalecube.security.Profile; -import java.util.Collection; -import java.util.Collections; -import java.util.Objects; -import java.util.stream.Collectors; -import java.util.stream.StreamSupport; - -public final class OrganizationsDataAccessImpl implements OrganizationsDataAccess { - - private final Repository organizations; - private final UserOrganizationMembershipRepository membershipRepository; - private final OrganizationMembersRepositoryAdmin membersAdmin; - - /** - * Creates instance of Organizations Data Access. - * - * @param organizationRepository organization repository. - * @param membershipRepository membership repository. - * @param repositoryAdmin admin repository. - */ - public OrganizationsDataAccessImpl( - Repository organizationRepository, - UserOrganizationMembershipRepository membershipRepository, - OrganizationMembersRepositoryAdmin repositoryAdmin) { - this.organizations = organizationRepository; - this.membershipRepository = membershipRepository; - this.membersAdmin = repositoryAdmin; - } - - private static void requireNonNullId(String id) { - requireNonNull(id, "id cannot be null"); - } - - private static void requireNonNullProfile(Profile profile) { - requireNonNull(profile, "Profile cannot be null"); - } - - private static void requireNonNullOrganization(Organization org) { - requireNonNull(org, "Organization cannot be null"); - requireNonNull(org.id(), "Organization Id cannot be null"); - } - - @Override - public boolean existByName(String name) { - requireNonNullId(name); - return organizations.existByProperty("name", name); - } - - @Override - public Organization getOrganization(String id) throws EntityNotFoundException { - requireNonNullId(id); - return organizations.findById(id).orElseThrow(() -> new EntityNotFoundException(id)); - } - - @Override - public Organization createOrganization(Profile owner, Organization organization) - throws DuplicateKeyException { - requireNonNullProfile(owner); - requireNonNullOrganization(organization); - - // create members repository for the organization - membersAdmin.createRepository(organization); - - try { - membershipRepository.addMember( - organization, new OrganizationMember(owner.getUserId(), Role.Owner.toString())); - return organizations.save(organization.id(), organization); - } catch (Throwable throwable) { - // rollback - membersAdmin.deleteRepository(organization); - throw throwable; - } - } - - @Override - public void deleteOrganization(Profile owner, Organization organization) - throws EntityNotFoundException { - requireNonNullProfile(owner); - requireNonNullOrganization(organization); - verifyOrganizationExists(organization); - membersAdmin.deleteRepository(organization); - organizations.deleteById(organization.id()); - } - - @Override - public Collection getUserMembership(String userId) { - requireNonNull(userId, "userId"); - return Collections.unmodifiableCollection( - StreamSupport.stream(organizations.findAll().spliterator(), false) - .filter(org -> isMember(userId, org)) - .collect(Collectors.toList())); - } - - @Override - public void updateOrganizationDetails(Profile owner, Organization org, Organization update) { - requireNonNullProfile(owner); - requireNonNullOrganization(org); - requireNonNullOrganization(update); - - if (Objects.equals(org.id(), update.id())) { - organizations.save(org.id(), update); - } - } - - @Override - public Collection getOrganizationMembers(Organization organization) { - requireNonNull(organization); - return membershipRepository.getMembers(organization); - } - - @Override - public void invite(Profile owner, Organization organization, String userId, Role role) - throws EntityNotFoundException { - requireNonNullProfile(owner); - requireNonNullOrganization(organization); - requireNonNull(userId, "userId"); - requireNonNull(role, "role"); - verifyOrganizationExists(organization); - addMember(userId, organization, role); - } - - private void addMember(String userId, Organization organization, Role role) { - if (!isMember(userId, organization)) { - membershipRepository.addMember(organization, new OrganizationMember(userId, role.toString())); - } - } - - @Override - public void kickout(Profile owner, Organization organization, String userId) - throws EntityNotFoundException { - requireNonNullOrganization(organization); - requireNonNull(userId, "userId"); - verifyOrganizationExists(organization); - - if (membershipRepository.isMember(userId, organization)) { - leave(organization, userId); - } - } - - @Override - public void leave(Organization organization, String userId) throws EntityNotFoundException { - requireNonNullOrganization(organization); - requireNonNull(userId, "userId"); - verifyOrganizationExists(organization); - - if (membershipRepository.isMember(userId, organization)) { - membershipRepository.removeMember(userId, organization); - } - } - - @Override - public boolean isMember(String userId, Organization organization) { - return membershipRepository.isMember(userId, organization); - } - - @Override - public void updateOrganizationMemberRole(Organization organization, String userId, String role) { - if (membershipRepository.isMember(userId, organization)) { - membershipRepository.removeMember(userId, organization); - membershipRepository.addMember(organization, new OrganizationMember(userId, role)); - } - } - - private void verifyOrganizationExists(Organization organization) throws EntityNotFoundException { - if (!organizations.existsById(organization.id())) { - throw new EntityNotFoundException(organization.id()); - } - } -} diff --git a/scalecube-organization/src/main/java/io/scalecube/organization/repository/OrganizationsRepository.java b/scalecube-organization/src/main/java/io/scalecube/organization/repository/OrganizationsRepository.java new file mode 100644 index 0000000..88353ff --- /dev/null +++ b/scalecube-organization/src/main/java/io/scalecube/organization/repository/OrganizationsRepository.java @@ -0,0 +1,14 @@ +package io.scalecube.organization.repository; + +import io.scalecube.organization.domain.Organization; + +public interface OrganizationsRepository extends Repository { + + /** + * Returns whether an organization with the given name exists. + * + * @param name organization name. + * @return {@code true} if an entity with the given id exists, {@code false} otherwise. + */ + boolean existsByName(String name); +} diff --git a/scalecube-organization/src/main/java/io/scalecube/organization/repository/UserOrganizationMembershipRepository.java b/scalecube-organization/src/main/java/io/scalecube/organization/repository/UserOrganizationMembershipRepository.java deleted file mode 100644 index c3ecd59..0000000 --- a/scalecube-organization/src/main/java/io/scalecube/organization/repository/UserOrganizationMembershipRepository.java +++ /dev/null @@ -1,56 +0,0 @@ -package io.scalecube.organization.repository; - -import io.scalecube.account.api.OrganizationMember; -import io.scalecube.organization.operation.Organization; -import java.util.Collection; -import java.util.Optional; - -/** An abstraction of user organization membership data access. */ -public interface UserOrganizationMembershipRepository { - - /** - * Adds the member argument to the organization argument, in the - * underlying data provider. - * - * @param organization The organization ao add the member to. - * @param member The member to add. - */ - void addMember(Organization organization, OrganizationMember member); - - /** - * Determines if the tokenVerifier argument is a member of the organization - * argument. - * - * @param userId The user id criteria. - * @param organization The organization criteria. - * @return True if the tokenVerifier is a member of the organization; false otherwise. - */ - boolean isMember(String userId, Organization organization); - - /** - * Returns a list of members in the organization argument. - * - * @param organization Organization criteria. - * @return A list of OrganizationMember objects. - */ - Collection getMembers(Organization organization); - - /** - * Removes the tokenVerifier argument from the organization argument, in - * the underlying data provider. - * - * @param organization The organization ao add the member to. - * @param userId The id of the tokenVerifier to remove. - */ - void removeMember(String userId, Organization organization); - - /** - * Returns an organization membership info of the tokenVerifier argument in the - * organization argument. - * - * @param userId Profile criteria. - * @param organization Organization criteria. - * @return Optional of OrganizationMember. - */ - Optional getMember(String userId, Organization organization); -} diff --git a/scalecube-organization/src/main/java/io/scalecube/organization/repository/couchbase/CouchbaseEntityRepository.java b/scalecube-organization/src/main/java/io/scalecube/organization/repository/couchbase/CouchbaseEntityRepository.java deleted file mode 100644 index 158e2e5..0000000 --- a/scalecube-organization/src/main/java/io/scalecube/organization/repository/couchbase/CouchbaseEntityRepository.java +++ /dev/null @@ -1,183 +0,0 @@ -package io.scalecube.organization.repository.couchbase; - -import static com.couchbase.client.java.query.Select.select; -import static com.couchbase.client.java.query.dsl.Expression.i; -import static java.util.Objects.requireNonNull; - -import com.couchbase.client.java.Bucket; -import com.couchbase.client.java.Cluster; -import com.couchbase.client.java.document.JsonDocument; -import com.couchbase.client.java.document.RawJsonDocument; -import com.couchbase.client.java.query.N1qlQuery; -import com.couchbase.client.java.query.SimpleN1qlQuery; -import io.scalecube.organization.repository.Repository; -import io.scalecube.organization.repository.exception.DataRetrievalFailureException; -import io.scalecube.organization.repository.exception.OperationInterruptedException; -import io.scalecube.organization.repository.exception.QueryTimeoutException; -import java.util.Optional; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeoutException; -import rx.Observable; - -/** - * Abstract base couchbase Repository implementation. - * - * @param This repository entity type. - * @param This repository entity Id type which extends java.lang.String. - */ -abstract class CouchbaseEntityRepository implements Repository { - - private final CouchbaseExceptionTranslator exceptionTranslator = - new CouchbaseExceptionTranslator(); - private final TranslationService translationService = new JacksonTranslationService(); - protected final CouchbaseSettings settings; - protected final Cluster cluster; - private final Class type; - private String bucketName; - - CouchbaseEntityRepository( - CouchbaseSettings settings, Cluster cluster, String bucketName, Class type) { - this.settings = requireNonNull(settings); - this.cluster = requireNonNull(cluster); - this.type = requireNonNull(type); - this.bucketName = bucketName; - } - - String getBucketName() { - return bucketName; - } - - @Override - public boolean existByProperty(String propertyName, Object propertyValue) { - return false; - } - - @Override - public Optional findById(I id) { - return findById(client(), id); - } - - protected Optional findById(Bucket client, I id) { - requireNonNull(id); - return toEntity(execute(() -> client.get(id), client)); - } - - private Optional toEntity(JsonDocument document) { - T entity = null; - - if (document != null) { - entity = translationService.decode(document.content().toString(), type); - } - - return Optional.ofNullable(entity); - } - - @Override - public boolean existsById(I id) { - return existsById(client(), id); - } - - protected boolean existsById(Bucket client, I id) { - requireNonNull(id); - return execute(() -> client.exists(id), client); - } - - @Override - public T save(I id, T entity) { - return save(client(), id, entity); - } - - protected T save(Bucket client, I id, T entity) { - requireNonNull(id); - requireNonNull(entity); - - execute( - () -> client.upsert(RawJsonDocument.create(id, translationService.encode(entity))), client); - return entity; - } - - @Override - public void deleteById(I id) { - requireNonNull(id); - deleteById(client(), id); - } - - protected void deleteById(Bucket client, I id) { - execute(() -> client.remove(id), client); - } - - @Override - public Iterable findAll() { - return findAll(client()); - } - - protected Iterable findAll(Bucket client) { - requireNonNull(client); - final SimpleN1qlQuery query = N1qlQuery.simple(select("*").from(i(client.name()))); - - try { - return executeAsync(client.async().query(query)) - .flatMap( - result -> - result - .rows() - .mergeWith( - result - .errors() - .flatMap( - error -> - Observable.error( - new DataRetrievalFailureException( - "N1QL error: " + error.toString())))) - .flatMap( - row -> - Observable.just( - translationService.decode( - row.value().get(client.name()).toString(), type))) - .toList()) - .toBlocking() - .single(); - } finally { - client.close(); - } - } - - protected Bucket client() { - return cluster.openBucket(bucketName, settings.password()); - } - - private Observable executeAsync(Observable asyncAction) { - return asyncAction.onErrorResumeNext( - e -> { - if (e instanceof RuntimeException) { - return Observable.error( - exceptionTranslator.translateExceptionIfPossible((RuntimeException) e)); - } else if (e instanceof TimeoutException) { - return Observable.error(new QueryTimeoutException(e.getMessage(), e)); - } else if (e instanceof InterruptedException) { - return Observable.error(new OperationInterruptedException(e.getMessage(), e)); - } else if (e instanceof ExecutionException) { - return Observable.error(new OperationInterruptedException(e.getMessage(), e)); - } else { - return Observable.error(e); - } - }); - } - - protected R execute(BucketCallback action, Bucket client) { - requireNonNull(client); - requireNonNull(action); - - try { - return action.doInBucket(); - } catch (RuntimeException ex) { - throw exceptionTranslator.translateExceptionIfPossible(ex); - } catch (TimeoutException ex) { - throw new QueryTimeoutException(ex.getMessage(), ex); - } catch (InterruptedException | ExecutionException ex) { - throw new OperationInterruptedException(ex.getMessage(), ex); - } finally { - client.close(); - } - } -} diff --git a/scalecube-organization/src/main/java/io/scalecube/organization/repository/couchbase/CouchbaseOrganizationMembersRepositoryAdmin.java b/scalecube-organization/src/main/java/io/scalecube/organization/repository/couchbase/CouchbaseOrganizationMembersRepositoryAdmin.java deleted file mode 100644 index 19211f4..0000000 --- a/scalecube-organization/src/main/java/io/scalecube/organization/repository/couchbase/CouchbaseOrganizationMembersRepositoryAdmin.java +++ /dev/null @@ -1,91 +0,0 @@ -package io.scalecube.organization.repository.couchbase; - -import com.couchbase.client.java.Cluster; -import io.scalecube.organization.operation.Organization; -import io.scalecube.organization.repository.OrganizationMembersRepositoryAdmin; -import io.scalecube.organization.repository.couchbase.admin.AdminOperationContext; -import io.scalecube.organization.repository.couchbase.admin.AdminOperationsFactory; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -final class CouchbaseOrganizationMembersRepositoryAdmin - implements OrganizationMembersRepositoryAdmin { - - private static final Logger logger = - LoggerFactory.getLogger(CouchbaseOrganizationMembersRepositoryAdmin.class); - private final CouchbaseSettings settings; - private final Cluster cluster; - - CouchbaseOrganizationMembersRepositoryAdmin(CouchbaseSettings settings, Cluster cluster) { - this.settings = settings; - this.cluster = cluster; - } - - @Override - public void createRepository(Organization organization) { - logger.debug("createRepository: enter: organization: {}", organization); - String bucketName = getOrgMembersBucketName(organization); - AdminOperationsFactory.insertBucket().execute(operationContext(bucketName)); - - try { - createPrimaryIndex(bucketName); - insertUser(operationContext(bucketName, organization)); - } catch (Throwable throwable) { - logger.error("createRepository: organization: {}, error: {}", organization, throwable); - // rollback - cluster.clusterManager().removeBucket(bucketName); - throw throwable; - } - logger.debug("createRepository: exit: organization: {}", organization); - } - - /** - * To enable select queries on the members bucket, this method creates a primary index on the - * bucket. - * - * @param bucketName the bucket name to create the index - */ - private void createPrimaryIndex(String bucketName) { - logger.debug("createPrimaryIndex: enter: name: {}", bucketName); - AdminOperationsFactory.createPrimaryIndex().execute(operationContext(bucketName)); - logger.debug("createPrimaryIndex: exit: name: {}", bucketName); - } - - /** - * Couchbase Server 5.0 introduced role-based access control (RBAC). By creating a user with same - * name as the org-members-bucket, we limit the access to this bucket only with the need for a - * password when opening the bucket. - * - * @param operationContext the bucket name and organization object - */ - private void insertUser(AdminOperationContext operationContext) { - logger.debug("insetUser: enter: name: {}", operationContext); - AdminOperationsFactory.insertUser().execute(operationContext); - logger.debug("insetUser: exit: name: {}", operationContext); - } - - @Override - public void deleteRepository(Organization organization) { - logger.debug("deleteRepository: enter: organization: {}", organization); - String bucketName = getOrgMembersBucketName(organization); - AdminOperationsFactory.deleteRepository().execute(operationContext(bucketName)); - logger.debug("deleteRepository: exit: organization: {}", organization); - } - - private AdminOperationContext operationContext(String bucketName) { - return operationContext(bucketName, null); - } - - private AdminOperationContext operationContext(String bucketName, Organization organization) { - return AdminOperationContext.builder() - .settings(settings) - .cluster(cluster) - .name(bucketName) - .organization(organization) - .build(); - } - - private String getOrgMembersBucketName(Organization organization) { - return String.format(settings.bucketNamePattern(), organization.id()); - } -} diff --git a/scalecube-organization/src/main/java/io/scalecube/organization/repository/couchbase/CouchbaseOrganizationRepository.java b/scalecube-organization/src/main/java/io/scalecube/organization/repository/couchbase/CouchbaseOrganizationRepository.java deleted file mode 100644 index 8deda99..0000000 --- a/scalecube-organization/src/main/java/io/scalecube/organization/repository/couchbase/CouchbaseOrganizationRepository.java +++ /dev/null @@ -1,35 +0,0 @@ -package io.scalecube.organization.repository.couchbase; - -import com.couchbase.client.java.Bucket; -import com.couchbase.client.java.Cluster; -import com.couchbase.client.java.query.N1qlQuery; -import com.couchbase.client.java.query.N1qlQueryResult; -import com.couchbase.client.java.query.N1qlQueryRow; -import io.scalecube.organization.operation.Organization; -import java.util.List; -import java.util.Objects; - -class CouchbaseOrganizationRepository extends CouchbaseEntityRepository { - - private static final String QUERY_PATTERN = "select count(id) from %s where %s = '%s'"; - private static final String NAME_PROPERTY = "name"; - - CouchbaseOrganizationRepository(CouchbaseSettings settings, Cluster cluster) { - super(settings, cluster, settings.organizationsBucketName(), Organization.class); - } - - @Override - public boolean existByProperty(String propertyName, Object propertyValue) { - Bucket client = client(); - return execute(() -> isOrganizationNameExists(propertyValue.toString(), client), client); - } - - private boolean isOrganizationNameExists(String orgName, Bucket bucket) { - N1qlQuery query = - N1qlQuery.simple( - String.format(QUERY_PATTERN, getBucketName(), NAME_PROPERTY, orgName), null); - N1qlQueryResult queryResult = bucket.query(query); - List rows = queryResult.allRows(); - return !rows.isEmpty() && Objects.equals(1, rows.get(0).value().get("$1")); - } -} diff --git a/scalecube-organization/src/main/java/io/scalecube/organization/repository/couchbase/CouchbaseOrganizationsRepository.java b/scalecube-organization/src/main/java/io/scalecube/organization/repository/couchbase/CouchbaseOrganizationsRepository.java new file mode 100644 index 0000000..a2d9f82 --- /dev/null +++ b/scalecube-organization/src/main/java/io/scalecube/organization/repository/couchbase/CouchbaseOrganizationsRepository.java @@ -0,0 +1,21 @@ +package io.scalecube.organization.repository.couchbase; + +import static java.util.Objects.requireNonNull; + +import com.couchbase.client.java.Bucket; +import io.scalecube.organization.domain.Organization; +import io.scalecube.organization.repository.OrganizationsRepository; + +public class CouchbaseOrganizationsRepository extends CouchbaseRepository + implements OrganizationsRepository { + + CouchbaseOrganizationsRepository(Bucket bucket) { + super(bucket, Organization.class); + } + + @Override + public boolean existsByName(String name) { + requireNonNull(name, "organization name cannot be null"); + return existByProperty("name", name); + } +} diff --git a/scalecube-organization/src/main/java/io/scalecube/organization/repository/couchbase/CouchbaseRepository.java b/scalecube-organization/src/main/java/io/scalecube/organization/repository/couchbase/CouchbaseRepository.java new file mode 100644 index 0000000..010fb54 --- /dev/null +++ b/scalecube-organization/src/main/java/io/scalecube/organization/repository/couchbase/CouchbaseRepository.java @@ -0,0 +1,168 @@ +package io.scalecube.organization.repository.couchbase; + +import static com.couchbase.client.java.query.Select.select; +import static com.couchbase.client.java.query.dsl.Expression.i; +import static java.util.Objects.requireNonNull; + +import com.couchbase.client.java.Bucket; +import com.couchbase.client.java.document.JsonDocument; +import com.couchbase.client.java.document.RawJsonDocument; +import com.couchbase.client.java.query.N1qlQuery; +import com.couchbase.client.java.query.N1qlQueryResult; +import com.couchbase.client.java.query.N1qlQueryRow; +import com.couchbase.client.java.query.SimpleN1qlQuery; +import io.scalecube.organization.domain.Entity; +import io.scalecube.organization.repository.Repository; +import io.scalecube.organization.repository.exception.DataRetrievalFailureException; +import io.scalecube.organization.repository.exception.OperationInterruptedException; +import io.scalecube.organization.repository.exception.QueryTimeoutException; +import java.util.List; +import java.util.Optional; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeoutException; +import rx.Observable; + +/** + * Abstract base couchbase Repository implementation. + * + * @param This repository entity type. + */ +abstract class CouchbaseRepository implements Repository { + + private static final String ID_CANNOT_BE_NULL = "id cannot be null"; + + private static final String SELECT_COUNT_BY_DOCUMENT_FIELD_QUERY = + "select count(id) as count from %s where %s = '%s'"; + + private final CouchbaseExceptionTranslator exceptionTranslator = + new CouchbaseExceptionTranslator(); + private final TranslationService translationService = new JacksonTranslationService(); + + private final Bucket bucket; + private final Class type; + + CouchbaseRepository(Bucket bucket, Class type) { + this.bucket = requireNonNull(bucket, "bucket cannot be null"); + this.type = requireNonNull(type, "entity type cannot be null"); + } + + @Override + public boolean existByProperty(String propertyName, Object propertyValue) { + requireNonNull(propertyName, "property name cannot be null"); + + N1qlQuery query = + N1qlQuery.simple( + String.format( + SELECT_COUNT_BY_DOCUMENT_FIELD_QUERY, bucket.name(), propertyName, propertyValue)); + N1qlQueryResult queryResult = bucket.query(query); + List rows = queryResult.allRows(); + return !rows.isEmpty() && rows.get(0).value().getInt("count") > 0; + } + + @Override + public Optional findById(String id) { + requireNonNull(id, ID_CANNOT_BE_NULL); + return toEntity(execute(() -> bucket.get(id))); + } + + private Optional toEntity(JsonDocument document) { + T entity = null; + + if (document != null) { + entity = translationService.decode(document.content().toString(), type); + entity.version(document.cas()); + } + + return Optional.ofNullable(entity); + } + + @Override + public boolean existsById(String id) { + requireNonNull(id, ID_CANNOT_BE_NULL); + return execute(() -> bucket.exists(id)); + } + + @Override + public T save(String id, T entity) { + requireNonNull(id, ID_CANNOT_BE_NULL); + requireNonNull(entity, type.getSimpleName() + " cannot be null"); + + RawJsonDocument document = + RawJsonDocument.create(id, translationService.encode(entity), entity.version()); + + execute( + () -> { + if (entity.version() == 0) { + return bucket.insert(document); + } else { + return bucket.replace(document); + } + }); + + return entity; + } + + @Override + public void deleteById(String id) { + requireNonNull(id, ID_CANNOT_BE_NULL); + execute(() -> bucket.remove(id)); + } + + @Override + public Iterable findAll() { + final SimpleN1qlQuery query = N1qlQuery.simple(select("*").from(i(bucket.name()))); + + return executeAsync(bucket.async().query(query)) + .flatMap( + result -> + result + .rows() + .mergeWith( + result + .errors() + .flatMap( + error -> + Observable.error( + new DataRetrievalFailureException( + "N1QL error: " + error.toString())))) + .flatMap( + row -> + Observable.just( + translationService.decode( + row.value().get(bucket.name()).toString(), type))) + .toList()) + .toBlocking() + .single(); + } + + private Observable executeAsync(Observable asyncAction) { + return asyncAction.onErrorResumeNext( + e -> { + if (e instanceof RuntimeException) { + return Observable.error( + exceptionTranslator.translateExceptionIfPossible((RuntimeException) e)); + } else if (e instanceof TimeoutException) { + return Observable.error(new QueryTimeoutException(e.getMessage(), e)); + } else if (e instanceof InterruptedException) { + return Observable.error(new OperationInterruptedException(e.getMessage(), e)); + } else if (e instanceof ExecutionException) { + return Observable.error(new OperationInterruptedException(e.getMessage(), e)); + } else { + return Observable.error(e); + } + }); + } + + private R execute(BucketCallback action) { + requireNonNull(action); + try { + return action.doInBucket(); + } catch (RuntimeException ex) { + throw exceptionTranslator.translateExceptionIfPossible(ex); + } catch (TimeoutException ex) { + throw new QueryTimeoutException(ex.getMessage(), ex); + } catch (InterruptedException | ExecutionException ex) { + throw new OperationInterruptedException(ex.getMessage(), ex); + } + } +} diff --git a/scalecube-organization/src/main/java/io/scalecube/organization/repository/couchbase/CouchbaseRepositoryFactory.java b/scalecube-organization/src/main/java/io/scalecube/organization/repository/couchbase/CouchbaseRepositoryFactory.java index 0eee6aa..f5da862 100644 --- a/scalecube-organization/src/main/java/io/scalecube/organization/repository/couchbase/CouchbaseRepositoryFactory.java +++ b/scalecube-organization/src/main/java/io/scalecube/organization/repository/couchbase/CouchbaseRepositoryFactory.java @@ -1,17 +1,14 @@ package io.scalecube.organization.repository.couchbase; +import com.couchbase.client.java.Bucket; import com.couchbase.client.java.Cluster; import com.couchbase.client.java.CouchbaseCluster; -import io.scalecube.organization.operation.Organization; -import io.scalecube.organization.repository.Repository; -import io.scalecube.organization.repository.UserOrganizationMembershipRepository; +import io.scalecube.organization.repository.OrganizationsRepository; import java.util.List; public final class CouchbaseRepositoryFactory { - private final CouchbaseSettings settings; - private final Cluster cluster; - private final CouchbaseCluster adminCluster; + private final Bucket bucket; /** * Creates a couchbase repository factory, initializes two couchbase clusters. @@ -19,22 +16,17 @@ public final class CouchbaseRepositoryFactory { * @param settings the settings */ public CouchbaseRepositoryFactory(CouchbaseSettings settings) { - this.settings = settings; List nodes = settings.hosts(); - adminCluster = nodes.isEmpty() ? CouchbaseCluster.create() : CouchbaseCluster.create(nodes); - adminCluster.authenticate(settings.username(), settings.password()); - cluster = nodes.isEmpty() ? CouchbaseCluster.create() : CouchbaseCluster.create(nodes); - } - public Repository organizations() { - return new CouchbaseOrganizationRepository(settings, cluster); - } + Cluster cluster = nodes.isEmpty() ? CouchbaseCluster.create() : CouchbaseCluster.create(nodes); - public UserOrganizationMembershipRepository organizationMembers() { - return new CouchbaseUserOrganizationMembershipRepository(settings, cluster); + bucket = + cluster + .authenticate(settings.username(), settings.password()) + .openBucket(settings.organizationsBucketName()); } - public CouchbaseOrganizationMembersRepositoryAdmin organizationMembersRepositoryAdmin() { - return new CouchbaseOrganizationMembersRepositoryAdmin(settings, adminCluster); + public OrganizationsRepository organizations() { + return new CouchbaseOrganizationsRepository(bucket); } } diff --git a/scalecube-organization/src/main/java/io/scalecube/organization/repository/couchbase/CouchbaseSettings.java b/scalecube-organization/src/main/java/io/scalecube/organization/repository/couchbase/CouchbaseSettings.java index 8fd68a4..0753aba 100644 --- a/scalecube-organization/src/main/java/io/scalecube/organization/repository/couchbase/CouchbaseSettings.java +++ b/scalecube-organization/src/main/java/io/scalecube/organization/repository/couchbase/CouchbaseSettings.java @@ -1,20 +1,13 @@ package io.scalecube.organization.repository.couchbase; -import com.couchbase.client.java.bucket.BucketType; import java.util.List; +import java.util.StringJoiner; public final class CouchbaseSettings { private List hosts; private String username; private String password; - private List userRoles; - private String bucketNamePattern; - private String bucketType; - private int bucketQuota; - private int bucketReplicas; - private boolean bucketIndexReplicas; - private boolean bucketEnableFlush; private String organizationsBucketName; public List hosts() { @@ -29,53 +22,17 @@ public String password() { return password; } - public List userRoles() { - return userRoles; - } - - public String bucketNamePattern() { - return bucketNamePattern; - } - - public BucketType bucketType() { - return BucketType.valueOf(bucketType); - } - - public int bucketQuota() { - return bucketQuota; - } - - public int bucketReplicas() { - return bucketReplicas; - } - - public boolean bucketIndexReplicas() { - return bucketIndexReplicas; - } - - public boolean bucketEnableFlush() { - return bucketEnableFlush; - } - public String organizationsBucketName() { return organizationsBucketName; } @Override public String toString() { - final StringBuilder sb = new StringBuilder("CouchbaseSettings{"); - sb.append("hosts=").append(hosts); - sb.append(", username='").append(username).append('\''); - sb.append(", password='").append(password).append('\''); - sb.append(", userRoles=").append(userRoles); - sb.append(", bucketNamePattern='").append(bucketNamePattern).append('\''); - sb.append(", bucketType='").append(bucketType).append('\''); - sb.append(", bucketQuota=").append(bucketQuota); - sb.append(", bucketReplicas=").append(bucketReplicas); - sb.append(", bucketIndexReplicas=").append(bucketIndexReplicas); - sb.append(", bucketEnableFlush=").append(bucketEnableFlush); - sb.append(", organizationsBucketName='").append(organizationsBucketName).append('\''); - sb.append('}'); - return sb.toString(); + return new StringJoiner(", ", CouchbaseSettings.class.getSimpleName() + "[", "]") + .add("hosts=" + hosts) + .add("username='" + username + "'") + .add("password='" + password + "'") + .add("organizationsBucketName='" + organizationsBucketName + "'") + .toString(); } } diff --git a/scalecube-organization/src/main/java/io/scalecube/organization/repository/couchbase/CouchbaseUserOrganizationMembershipRepository.java b/scalecube-organization/src/main/java/io/scalecube/organization/repository/couchbase/CouchbaseUserOrganizationMembershipRepository.java deleted file mode 100644 index 9344ec2..0000000 --- a/scalecube-organization/src/main/java/io/scalecube/organization/repository/couchbase/CouchbaseUserOrganizationMembershipRepository.java +++ /dev/null @@ -1,59 +0,0 @@ -package io.scalecube.organization.repository.couchbase; - -import com.couchbase.client.java.Bucket; -import com.couchbase.client.java.Cluster; -import io.scalecube.account.api.OrganizationMember; -import io.scalecube.organization.operation.Organization; -import io.scalecube.organization.repository.UserOrganizationMembershipRepository; -import io.scalecube.organization.repository.couchbase.admin.PasswordGenerator; -import java.util.Collection; -import java.util.Optional; -import java.util.stream.Collectors; -import java.util.stream.StreamSupport; - -final class CouchbaseUserOrganizationMembershipRepository - extends CouchbaseEntityRepository - implements UserOrganizationMembershipRepository { - - CouchbaseUserOrganizationMembershipRepository(CouchbaseSettings settings, Cluster cluster) { - super(settings, cluster, null, OrganizationMember.class); - } - - @Override - public void addMember(Organization org, OrganizationMember member) { - save(client(org), member.id(), member); - } - - @Override - public boolean isMember(String userId, Organization organization) { - return existsById(client(organization), userId); - } - - @Override - public Collection getMembers(Organization organization) { - return StreamSupport.stream(findAll(client(organization)).spliterator(), false) - .collect(Collectors.toList()); - } - - @Override - public void removeMember(String userId, Organization organization) { - deleteById(client(organization), userId); - } - - @Override - public Optional getMember(String userId, Organization organization) { - return findById(client(organization), userId); - } - - private Bucket client(Organization organization) { - return client(getBucketName(organization), PasswordGenerator.md5Hash(organization.id())); - } - - private Bucket client(String bucketName, String bucketPassword) { - return cluster.openBucket(bucketName, bucketPassword); - } - - private String getBucketName(Organization organization) { - return String.format(settings.bucketNamePattern(), organization.id()); - } -} diff --git a/scalecube-organization/src/main/java/io/scalecube/organization/repository/couchbase/admin/AdminOperationContext.java b/scalecube-organization/src/main/java/io/scalecube/organization/repository/couchbase/admin/AdminOperationContext.java deleted file mode 100644 index 020c9ad..0000000 --- a/scalecube-organization/src/main/java/io/scalecube/organization/repository/couchbase/admin/AdminOperationContext.java +++ /dev/null @@ -1,80 +0,0 @@ -package io.scalecube.organization.repository.couchbase.admin; - -import com.couchbase.client.java.Cluster; -import io.scalecube.organization.operation.Organization; -import io.scalecube.organization.repository.couchbase.CouchbaseSettings; -import java.util.Objects; - -/** Represents a data structure used to execute an admin operation. */ -public final class AdminOperationContext { - private final CouchbaseSettings settings; - private final Cluster cluster; - private final String name; - private final Organization organization; - - private AdminOperationContext(Builder builder) { - this.settings = builder.settings; - this.cluster = builder.cluster; - this.name = builder.name; - this.organization = builder.organization; - } - - public static Builder builder() { - return new Builder(); - } - - public CouchbaseSettings settings() { - return settings; - } - - public Cluster cluster() { - return cluster; - } - - public String name() { - return name; - } - - public Organization organization() { - return organization; - } - - public static class Builder { - private CouchbaseSettings settings; - private Cluster cluster; - private String name; - private Organization organization; - - public Builder settings(CouchbaseSettings settings) { - this.settings = settings; - return this; - } - - public Builder cluster(Cluster cluster) { - this.cluster = cluster; - return this; - } - - public Builder name(String name) { - this.name = name; - return this; - } - - /** - * Constructs an instance of {@link AdminOperationContext} using this builder fields. - * - * @return an instance of {@link AdminOperationContext} - */ - public AdminOperationContext build() { - Objects.requireNonNull(settings, "settings"); - Objects.requireNonNull(cluster, "cluster"); - Objects.requireNonNull(name, "name"); - return new AdminOperationContext(this); - } - - public Builder organization(Organization organization) { - this.organization = organization; - return this; - } - } -} diff --git a/scalecube-organization/src/main/java/io/scalecube/organization/repository/couchbase/admin/AdminOperationsFactory.java b/scalecube-organization/src/main/java/io/scalecube/organization/repository/couchbase/admin/AdminOperationsFactory.java deleted file mode 100644 index f116d06..0000000 --- a/scalecube-organization/src/main/java/io/scalecube/organization/repository/couchbase/admin/AdminOperationsFactory.java +++ /dev/null @@ -1,23 +0,0 @@ -package io.scalecube.organization.repository.couchbase.admin; - -import com.couchbase.client.java.cluster.BucketSettings; -import com.couchbase.client.java.query.N1qlQueryResult; - -/** Factory class for constructing admin operation classes. */ -public abstract class AdminOperationsFactory { - public static Operation insertBucket() { - return new InsertBucketOperation(); - } - - public static Operation createPrimaryIndex() { - return new CreatePrimaryIndexOperation(); - } - - public static Operation insertUser() { - return new InsertUserOperation(); - } - - public static Operation deleteRepository() { - return new DeleteRepositoryOperation(); - } -} diff --git a/scalecube-organization/src/main/java/io/scalecube/organization/repository/couchbase/admin/CreatePrimaryIndexOperation.java b/scalecube-organization/src/main/java/io/scalecube/organization/repository/couchbase/admin/CreatePrimaryIndexOperation.java deleted file mode 100644 index 75cc07e..0000000 --- a/scalecube-organization/src/main/java/io/scalecube/organization/repository/couchbase/admin/CreatePrimaryIndexOperation.java +++ /dev/null @@ -1,28 +0,0 @@ -package io.scalecube.organization.repository.couchbase.admin; - -import com.couchbase.client.java.document.json.JsonObject; -import com.couchbase.client.java.query.N1qlQuery; -import com.couchbase.client.java.query.N1qlQueryResult; -import io.scalecube.organization.repository.exception.CreatePrimaryIndexException; - -final class CreatePrimaryIndexOperation extends Operation { - private static final String CREATE_PRIMARY_INDEX = - "CREATE PRIMARY INDEX `%s-primary-idx` ON `%s`"; - - @Override - public N1qlQueryResult execute(AdminOperationContext context) { - N1qlQuery index = - N1qlQuery.simple(String.format(CREATE_PRIMARY_INDEX, context.name(), context.name())); - N1qlQueryResult queryResult = context.cluster().openBucket(context.name()).query(index); - - if (!queryResult.finalSuccess()) { - StringBuilder buffer = new StringBuilder(); - for (JsonObject error : queryResult.errors()) { - buffer.append(error); - } - throw new CreatePrimaryIndexException(buffer.toString()); - } - - return queryResult; - } -} diff --git a/scalecube-organization/src/main/java/io/scalecube/organization/repository/couchbase/admin/DeleteRepositoryOperation.java b/scalecube-organization/src/main/java/io/scalecube/organization/repository/couchbase/admin/DeleteRepositoryOperation.java deleted file mode 100644 index e586597..0000000 --- a/scalecube-organization/src/main/java/io/scalecube/organization/repository/couchbase/admin/DeleteRepositoryOperation.java +++ /dev/null @@ -1,13 +0,0 @@ -package io.scalecube.organization.repository.couchbase.admin; - -import com.couchbase.client.java.cluster.AuthDomain; - -final class DeleteRepositoryOperation extends Operation { - - @Override - public Boolean execute(AdminOperationContext context) { - context.cluster().clusterManager().removeUser(AuthDomain.LOCAL, context.name()); - context.cluster().clusterManager().removeBucket(context.name()); - return true; - } -} diff --git a/scalecube-organization/src/main/java/io/scalecube/organization/repository/couchbase/admin/InsertBucketOperation.java b/scalecube-organization/src/main/java/io/scalecube/organization/repository/couchbase/admin/InsertBucketOperation.java deleted file mode 100644 index 2ad448d..0000000 --- a/scalecube-organization/src/main/java/io/scalecube/organization/repository/couchbase/admin/InsertBucketOperation.java +++ /dev/null @@ -1,23 +0,0 @@ -package io.scalecube.organization.repository.couchbase.admin; - -import com.couchbase.client.java.cluster.BucketSettings; -import com.couchbase.client.java.cluster.DefaultBucketSettings; - -final class InsertBucketOperation extends Operation { - - @Override - public BucketSettings execute(AdminOperationContext context) { - return context - .cluster() - .clusterManager() - .insertBucket( - new DefaultBucketSettings.Builder() - .type(context.settings().bucketType()) - .name(context.name()) - .quota(context.settings().bucketQuota()) - .replicas(context.settings().bucketReplicas()) - .indexReplicas(context.settings().bucketIndexReplicas()) - .enableFlush(context.settings().bucketEnableFlush()) - .build()); - } -} diff --git a/scalecube-organization/src/main/java/io/scalecube/organization/repository/couchbase/admin/InsertUserOperation.java b/scalecube-organization/src/main/java/io/scalecube/organization/repository/couchbase/admin/InsertUserOperation.java deleted file mode 100644 index 5899c4e..0000000 --- a/scalecube-organization/src/main/java/io/scalecube/organization/repository/couchbase/admin/InsertUserOperation.java +++ /dev/null @@ -1,30 +0,0 @@ -package io.scalecube.organization.repository.couchbase.admin; - -import com.couchbase.client.java.cluster.AuthDomain; -import com.couchbase.client.java.cluster.UserRole; -import com.couchbase.client.java.cluster.UserSettings; -import java.util.stream.Collectors; - -final class InsertUserOperation extends Operation { - - @Override - public Boolean execute(AdminOperationContext context) { - context - .cluster() - .clusterManager() - .upsertUser( - AuthDomain.LOCAL, - context.name(), - UserSettings.build() - .password(PasswordGenerator.md5Hash(context.organization().id())) - .name(context.name()) - .roles( - context - .settings() - .userRoles() - .stream() - .map(role -> new UserRole(role, context.name())) - .collect(Collectors.toList()))); - return true; - } -} diff --git a/scalecube-organization/src/main/java/io/scalecube/organization/repository/couchbase/admin/Operation.java b/scalecube-organization/src/main/java/io/scalecube/organization/repository/couchbase/admin/Operation.java deleted file mode 100644 index b5a79b9..0000000 --- a/scalecube-organization/src/main/java/io/scalecube/organization/repository/couchbase/admin/Operation.java +++ /dev/null @@ -1,17 +0,0 @@ -package io.scalecube.organization.repository.couchbase.admin; - -/** - * Represents a Couchbase admin operation. - * - * @param return type of the admin operation - */ -public abstract class Operation { - - /** - * Executes this admin operation and return a value. - * - * @param context context for executing the operation - * @return a result of the operation execution - */ - public abstract R execute(AdminOperationContext context); -} diff --git a/scalecube-organization/src/main/java/io/scalecube/organization/repository/couchbase/admin/PasswordGenerator.java b/scalecube-organization/src/main/java/io/scalecube/organization/repository/couchbase/admin/PasswordGenerator.java deleted file mode 100644 index 91d66c1..0000000 --- a/scalecube-organization/src/main/java/io/scalecube/organization/repository/couchbase/admin/PasswordGenerator.java +++ /dev/null @@ -1,38 +0,0 @@ -package io.scalecube.organization.repository.couchbase.admin; - -import java.math.BigInteger; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; - -public final class PasswordGenerator { - - private static final String salt = "DGE$5SGr@3VsHYUMas2323E4d57vfBfFSTRU@!DSH(*%FDSdfg13sgfsg"; - - /** - * Returns a digest string form of the message argument. - * - * @param message the message to digest - * @return a digest string - */ - public static String md5Hash(String message) { - String md5 = ""; - if (null == message) { - return null; - } - - message = message + salt; // adding a salt to the string before it gets hashed. - try { - MessageDigest digest = - MessageDigest.getInstance("MD5"); // Create MessageDigest object for MD5 - digest.update( - message.getBytes(), 0, message.length()); // Update input string in message digest - md5 = - new BigInteger(1, digest.digest()) - .toString(16); // Converts message digest value in base 16 (hex) - - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - } - return md5; - } -} diff --git a/scalecube-organization/src/main/java/io/scalecube/organization/repository/exception/CreatePrimaryIndexException.java b/scalecube-organization/src/main/java/io/scalecube/organization/repository/exception/CreatePrimaryIndexException.java deleted file mode 100644 index 2fe247d..0000000 --- a/scalecube-organization/src/main/java/io/scalecube/organization/repository/exception/CreatePrimaryIndexException.java +++ /dev/null @@ -1,8 +0,0 @@ -package io.scalecube.organization.repository.exception; - -public class CreatePrimaryIndexException extends DataAccessException { - - public CreatePrimaryIndexException(String message) { - super(message); - } -} diff --git a/scalecube-organization/src/main/java/io/scalecube/organization/server/DiscoveryOptions.java b/scalecube-organization/src/main/java/io/scalecube/organization/server/DiscoveryOptions.java index 9c96b9f..3ca3b65 100644 --- a/scalecube-organization/src/main/java/io/scalecube/organization/server/DiscoveryOptions.java +++ b/scalecube-organization/src/main/java/io/scalecube/organization/server/DiscoveryOptions.java @@ -1,6 +1,6 @@ package io.scalecube.organization.server; -import io.scalecube.services.transport.api.Address; +import io.scalecube.transport.Address; import java.util.List; import java.util.Optional; @@ -17,7 +17,7 @@ public int servicePort() { } public Integer discoveryPort() { - return discoveryPort; + return discoveryPort != null ? discoveryPort : 0; } /** diff --git a/scalecube-organization/src/main/java/io/scalecube/organization/server/OrganizationServiceRunner.java b/scalecube-organization/src/main/java/io/scalecube/organization/server/OrganizationServiceRunner.java index 3c0c319..45d9a77 100644 --- a/scalecube-organization/src/main/java/io/scalecube/organization/server/OrganizationServiceRunner.java +++ b/scalecube-organization/src/main/java/io/scalecube/organization/server/OrganizationServiceRunner.java @@ -3,8 +3,6 @@ import io.scalecube.account.api.OrganizationService; import io.scalecube.organization.OrganizationServiceImpl; import io.scalecube.organization.config.AppConfiguration; -import io.scalecube.organization.repository.OrganizationsDataAccess; -import io.scalecube.organization.repository.OrganizationsDataAccessImpl; import io.scalecube.organization.repository.couchbase.CouchbaseRepositoryFactory; import io.scalecube.organization.repository.couchbase.CouchbaseSettings; import io.scalecube.organization.tokens.Auth0PublicKeyProvider; @@ -13,7 +11,9 @@ import io.scalecube.organization.tokens.store.KeyStore; import io.scalecube.organization.tokens.store.VaultKeyStore; import io.scalecube.services.Microservices; -import java.security.NoSuchAlgorithmException; +import io.scalecube.services.discovery.ScalecubeServiceDiscovery; +import io.scalecube.services.transport.rsocket.RSocketServiceTransport; +import io.scalecube.services.transport.rsocket.RSocketTransportResources; import java.util.HashMap; import java.util.Map; import org.slf4j.Logger; @@ -34,7 +34,7 @@ public static void main(String[] args) throws Exception { Thread.currentThread().join(); } - private static void start() throws NoSuchAlgorithmException { + private static void start() { DiscoveryOptions discoveryOptions = AppConfiguration.configRegistry() .objectProperty("io.scalecube.organization", DiscoveryOptions.class) @@ -45,13 +45,20 @@ private static void start() throws NoSuchAlgorithmException { Microservices.builder() .discovery( - options -> - options - .seeds(discoveryOptions.seeds()) - .port(discoveryOptions.discoveryPort()) - .memberHost(discoveryOptions.memberHost()) - .memberPort(discoveryOptions.memberPort())) - .transport(options -> options.port(discoveryOptions.servicePort())) + (serviceEndpoint) -> + new ScalecubeServiceDiscovery(serviceEndpoint) + .options( + opts -> + opts.seedMembers(discoveryOptions.seeds()) + .port(discoveryOptions.discoveryPort()) + .memberHost(discoveryOptions.memberHost()) + .memberPort(discoveryOptions.memberPort()))) + .transport( + opts -> + opts.resources(RSocketTransportResources::new) + .client(RSocketServiceTransport.INSTANCE::clientTransport) + .server(RSocketServiceTransport.INSTANCE::serverTransport) + .port(discoveryOptions.servicePort())) .services(createOrganizationService()) .startAwait(); } @@ -65,15 +72,10 @@ private static OrganizationService createOrganizationService() { CouchbaseRepositoryFactory factory = new CouchbaseRepositoryFactory(settings); - OrganizationsDataAccess dataAccess = - new OrganizationsDataAccessImpl( - factory.organizations(), - factory.organizationMembers(), - factory.organizationMembersRepositoryAdmin()); KeyStore keyStore = new VaultKeyStore(); TokenVerifier tokenVerifier = new TokenVerifierImpl(new Auth0PublicKeyProvider()); - return new OrganizationServiceImpl(dataAccess, keyStore, tokenVerifier); + return new OrganizationServiceImpl(factory.organizations(), keyStore, tokenVerifier); } private static Map couchbaseSettingsBindingMap() { @@ -82,13 +84,6 @@ private static Map couchbaseSettingsBindingMap() { bindingMap.put("hosts", "couchbase.hosts"); bindingMap.put("username", "couchbase.username"); bindingMap.put("password", "couchbase.password"); - bindingMap.put("userRoles", "organizations.members.userRoles"); - bindingMap.put("bucketNamePattern", "organizations.members.bucketNamePattern"); - bindingMap.put("bucketType", "organizations.members.bucketType"); - bindingMap.put("bucketQuota", "organizations.members.bucketQuota"); - bindingMap.put("bucketReplicas", "organizations.members.bucketReplicas"); - bindingMap.put("bucketIndexReplicas", "organizations.members.bucketIndexReplicas"); - bindingMap.put("bucketEnableFlush", "organizations.members.bucketEnableFlush"); bindingMap.put("organizationsBucketName", "organizations.bucket"); return bindingMap; diff --git a/scalecube-organization/src/main/java/io/scalecube/organization/tokens/TokenVerifier.java b/scalecube-organization/src/main/java/io/scalecube/organization/tokens/TokenVerifier.java index c74fa25..66a817c 100644 --- a/scalecube-organization/src/main/java/io/scalecube/organization/tokens/TokenVerifier.java +++ b/scalecube-organization/src/main/java/io/scalecube/organization/tokens/TokenVerifier.java @@ -1,7 +1,7 @@ package io.scalecube.organization.tokens; import io.scalecube.account.api.Token; -import io.scalecube.security.Profile; +import io.scalecube.security.api.Profile; public interface TokenVerifier { diff --git a/scalecube-organization/src/main/java/io/scalecube/organization/tokens/TokenVerifierImpl.java b/scalecube-organization/src/main/java/io/scalecube/organization/tokens/TokenVerifierImpl.java index 2e1d6c0..48e86fe 100644 --- a/scalecube-organization/src/main/java/io/scalecube/organization/tokens/TokenVerifierImpl.java +++ b/scalecube-organization/src/main/java/io/scalecube/organization/tokens/TokenVerifierImpl.java @@ -1,12 +1,12 @@ package io.scalecube.organization.tokens; import io.scalecube.account.api.Token; -import io.scalecube.security.JwtAuthenticator; -import io.scalecube.security.JwtAuthenticatorImpl; -import io.scalecube.security.Profile; +import io.scalecube.security.api.Profile; +import io.scalecube.security.jwt.DefaultJwtAuthenticator; +import io.scalecube.security.jwt.JwtAuthenticator; import java.security.PublicKey; +import java.time.Duration; import java.util.Objects; -import java.util.Optional; public class TokenVerifierImpl implements TokenVerifier { @@ -23,10 +23,9 @@ public Profile verify(Token token) throws InvalidTokenException { Objects.requireNonNull(token.token(), "token"); final PublicKey publicKey = publicKeyProvider.getPublicKey(token.token()); Objects.requireNonNull(publicKey, "Token signing key"); - JwtAuthenticator authenticator = - new JwtAuthenticatorImpl.Builder().keyResolver(map -> Optional.of(publicKey)).build(); + JwtAuthenticator authenticator = new DefaultJwtAuthenticator(map -> publicKey); - return authenticator.authenticate(token.token()); + return authenticator.authenticate(token.token()).block(Duration.ofSeconds(10)); // todo } catch (Exception e) { throw new InvalidTokenException("Token verification failed", e); } diff --git a/scalecube-organization/src/main/java/io/scalecube/organization/tokens/store/ApiKeyBuilder.java b/scalecube-organization/src/main/java/io/scalecube/organization/tokens/store/ApiKeyBuilder.java index 3e6d84d..4fb532e 100644 --- a/scalecube-organization/src/main/java/io/scalecube/organization/tokens/store/ApiKeyBuilder.java +++ b/scalecube-organization/src/main/java/io/scalecube/organization/tokens/store/ApiKeyBuilder.java @@ -5,7 +5,7 @@ import io.scalecube.account.api.Role; import io.scalecube.config.LongConfigProperty; import io.scalecube.organization.config.AppConfiguration; -import io.scalecube.organization.operation.Organization; +import io.scalecube.organization.domain.Organization; import io.scalecube.organization.tokens.JwtApiKey; import java.security.PrivateKey; import java.util.HashMap; diff --git a/scalecube-organization/src/main/resources/couchbase.config.properties b/scalecube-organization/src/main/resources/couchbase.config.properties index 99a76a8..025fe06 100644 --- a/scalecube-organization/src/main/resources/couchbase.config.properties +++ b/scalecube-organization/src/main/resources/couchbase.config.properties @@ -1,13 +1 @@ -# roles in community version -organizations.members.userRoles=bucket_full_access -# roles in enterprise version -#organizations.members.bucket.user.roles=data_reader,data_writer,query_select - -organizations.members.bucketNamePattern=%s-members -organizations.members.bucketType=COUCHBASE -organizations.members.bucketQuota=100 -organizations.members.bucketReplicas=2 -organizations.members.bucketIndexReplicas=true -organizations.members.bucketEnableFlush=false - organizations.bucket=organizations diff --git a/scalecube-organization/src/test/java/io/scalecube/organization/Base.java b/scalecube-organization/src/test/java/io/scalecube/organization/Base.java index fb94cce..bb9b381 100644 --- a/scalecube-organization/src/test/java/io/scalecube/organization/Base.java +++ b/scalecube-organization/src/test/java/io/scalecube/organization/Base.java @@ -11,37 +11,26 @@ import io.scalecube.account.api.OrganizationService; import io.scalecube.account.api.Role; import io.scalecube.account.api.Token; -import io.scalecube.organization.operation.Organization; -import io.scalecube.organization.repository.OrganizationMembersRepositoryAdmin; -import io.scalecube.organization.repository.OrganizationsDataAccess; -import io.scalecube.organization.repository.OrganizationsDataAccessImpl; -import io.scalecube.organization.repository.Repository; -import io.scalecube.organization.repository.UserOrganizationMembershipRepository; -import io.scalecube.organization.repository.inmem.InMemoryOrganizationMembersRepositoryAdmin; +import io.scalecube.organization.domain.Organization; +import io.scalecube.organization.repository.OrganizationsRepository; import io.scalecube.organization.repository.inmem.InMemoryOrganizationRepository; -import io.scalecube.organization.repository.inmem.InMemoryUserOrganizationMembershipRepository; import io.scalecube.organization.token.store.PropertiesFileKeyStore; import io.scalecube.organization.tokens.TokenVerifier; import io.scalecube.organization.tokens.store.KeyStore; -import io.scalecube.security.Profile; +import io.scalecube.security.api.Profile; import java.io.File; -import java.security.KeyPairGenerator; -import java.security.NoSuchAlgorithmException; import java.util.Collections; import java.util.Objects; import java.util.Random; import java.util.concurrent.atomic.AtomicReference; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; public class Base { - protected static KeyPairGenerator keyPairGenerator; - protected final Profile testProfile = Profile.builder() .userId("1") @@ -102,24 +91,14 @@ public class Base { protected String organizationId; protected Organization organisation; protected Token token = new Token("user1"); - protected Repository organizationRepository; - protected UserOrganizationMembershipRepository orgMembersRepository; - private OrganizationMembersRepositoryAdmin admin; + protected OrganizationsRepository organizationRepository; protected Base() { - orgMembersRepository = new InMemoryUserOrganizationMembershipRepository(); organizationRepository = new InMemoryOrganizationRepository(); - admin = new InMemoryOrganizationMembersRepositoryAdmin(); service = createService(testProfile); new File("keystore.properties").deleteOnExit(); } - @BeforeAll - static void beforeAll() throws NoSuchAlgorithmException { - keyPairGenerator = KeyPairGenerator.getInstance("RSA"); - keyPairGenerator.initialize(2048); - } - protected static String randomString() { int targetStringLength = 10; @@ -157,18 +136,16 @@ protected void addMemberToOrganization(String organisationId, Profile profile, R StepVerifier.create( this.service.inviteMember( new InviteOrganizationMemberRequest( - token, organisationId, profile.getUserId(), role.toString()))) + token, organisationId, profile.userId(), role.toString()))) .assertNext(Assertions::assertNotNull) .verifyComplete(); } protected OrganizationService createService(Profile profile) { - OrganizationsDataAccess dataAccess = - new OrganizationsDataAccessImpl(organizationRepository, orgMembersRepository, admin); TokenVerifier tokenVerifier = token -> Objects.equals(profile, invalidProfile) ? null : profile; KeyStore keyStore = new PropertiesFileKeyStore(); - return new OrganizationServiceImpl(dataAccess, keyStore, tokenVerifier); + return new OrganizationServiceImpl(organizationRepository, keyStore, tokenVerifier); } protected static void assertMonoCompletesWithError( diff --git a/scalecube-organization/src/test/java/io/scalecube/organization/InviteMemberTest.java b/scalecube-organization/src/test/java/io/scalecube/organization/InviteMemberTest.java index 7679a90..7337392 100644 --- a/scalecube-organization/src/test/java/io/scalecube/organization/InviteMemberTest.java +++ b/scalecube-organization/src/test/java/io/scalecube/organization/InviteMemberTest.java @@ -26,7 +26,7 @@ void inviteMember() { response -> assertTrue( Arrays.stream(response.members()) - .anyMatch(member -> testProfile2.getUserId().equals(member.id())))) + .anyMatch(member -> testProfile2.userId().equals(member.id())))) .verifyComplete(); } @@ -35,7 +35,7 @@ void inviteMemberNullRoleShouldFailWithIllegalArgumentException() { assertMonoCompletesWithError( service.inviteMember( new InviteOrganizationMemberRequest( - token, organizationId, testProfile5.getUserId(), null)), + token, organizationId, testProfile5.userId(), null)), IllegalArgumentException.class); } @@ -44,7 +44,7 @@ void inviteMemberEmptyRoleShouldFailWithIllegalArgumentException() { assertMonoCompletesWithError( service.inviteMember( new InviteOrganizationMemberRequest( - token, organizationId, testProfile5.getUserId(), "")), + token, organizationId, testProfile5.userId(), "")), IllegalArgumentException.class); } @@ -53,7 +53,7 @@ void inviteMemberInvalidRoleShouldFailWithIllegalArgumentException() { assertMonoCompletesWithError( service.inviteMember( new InviteOrganizationMemberRequest( - token, organizationId, testProfile5.getUserId(), "bla")), + token, organizationId, testProfile5.userId(), "bla")), IllegalArgumentException.class); } @@ -64,7 +64,7 @@ void inviteMemberHigherRoleShouldFailWithAccessPermissionException() { createService(testProfile2) .inviteMember( new InviteOrganizationMemberRequest( - token, organizationId, testProfile5.getUserId(), Role.Owner.toString())), + token, organizationId, testProfile5.userId(), Role.Owner.toString())), AccessPermissionException.class); } @@ -73,7 +73,7 @@ void inviteMemberEmptyOrgIdShouldFailWithIllegalArgumentException() { assertMonoCompletesWithError( service.inviteMember( new InviteOrganizationMemberRequest( - token, "", testProfile5.getUserId(), Role.Member.toString())), + token, "", testProfile5.userId(), Role.Member.toString())), IllegalArgumentException.class); } @@ -82,7 +82,7 @@ void inviteMemberNullOrgIdShouldFailWithNullPointerException() { assertMonoCompletesWithError( service.inviteMember( new InviteOrganizationMemberRequest( - token, null, testProfile5.getUserId(), Role.Member.toString())), + token, null, testProfile5.userId(), Role.Member.toString())), NullPointerException.class); } @@ -108,7 +108,7 @@ void inviteMemberEmptyTokenShouldFailWithIllegalArgumentException() { assertMonoCompletesWithError( service.inviteMember( new InviteOrganizationMemberRequest( - new Token(""), organizationId, testProfile5.getUserId(), Role.Member.toString())), + new Token(""), organizationId, testProfile5.userId(), Role.Member.toString())), IllegalArgumentException.class); } @@ -117,7 +117,7 @@ void inviteMemberNullTokenShouldFailWithNullPointerException() { assertMonoCompletesWithError( service.inviteMember( new InviteOrganizationMemberRequest( - null, organizationId, testProfile5.getUserId(), Role.Member.toString())), + null, organizationId, testProfile5.userId(), Role.Member.toString())), NullPointerException.class); } @@ -126,7 +126,7 @@ void inviteMemberNullInnerTokenShouldFailWithNullPointerException() { assertMonoCompletesWithError( service.inviteMember( new InviteOrganizationMemberRequest( - new Token(null), organizationId, testProfile5.getUserId(), Role.Member.toString())), + new Token(null), organizationId, testProfile5.userId(), Role.Member.toString())), NullPointerException.class); } @@ -135,7 +135,7 @@ void inviteMemberOrgNotExistsShouldFailWithOrganizationNotFoundException() { assertMonoCompletesWithError( service.inviteMember( new InviteOrganizationMemberRequest( - token, "orgNotExists", testProfile5.getUserId(), Role.Member.toString())), + token, "orgNotExists", testProfile5.userId(), Role.Member.toString())), OrganizationNotFoundException.class); } @@ -145,7 +145,7 @@ void inviteMemberShouldFailWithInvalidAuthenticationToken() { createService(invalidProfile) .inviteMember( new InviteOrganizationMemberRequest( - token, organizationId, testProfile5.getUserId(), Role.Member.toString())), + token, organizationId, testProfile5.userId(), Role.Member.toString())), InvalidAuthenticationToken.class); } } diff --git a/scalecube-organization/src/test/java/io/scalecube/organization/KickoutMemberTest.java b/scalecube-organization/src/test/java/io/scalecube/organization/KickoutMemberTest.java index 51b74f7..694f1b9 100644 --- a/scalecube-organization/src/test/java/io/scalecube/organization/KickoutMemberTest.java +++ b/scalecube-organization/src/test/java/io/scalecube/organization/KickoutMemberTest.java @@ -25,7 +25,7 @@ void kickoutMember() { StepVerifier.create( service.kickoutMember( new KickoutOrganizationMemberRequest( - organizationId, token, testProfile5.getUserId()))) + organizationId, token, testProfile5.userId()))) .expectSubscription() .assertNext( x -> @@ -39,7 +39,7 @@ void kickoutMember() { Arrays.stream(response.members()) .map(OrganizationMember::id) .collect(Collectors.toList()); - assertThat(members, not(hasItem(testProfile5.getUserId()))); + assertThat(members, not(hasItem(testProfile5.userId()))); }) .verifyComplete()) .verifyComplete(); @@ -51,7 +51,7 @@ void kickoutMemberInvalidUserShouldFailWithInvalidAuthenticationToken() { createService(invalidProfile) .kickoutMember( new KickoutOrganizationMemberRequest( - organizationId, token, testProfile5.getUserId())), + organizationId, token, testProfile5.userId())), InvalidAuthenticationToken.class); } @@ -59,7 +59,7 @@ void kickoutMemberInvalidUserShouldFailWithInvalidAuthenticationToken() { void kickoutMemberEmptyOrgIdShouldFailWithIllegalArgumentException() { assertMonoCompletesWithError( service.kickoutMember( - new KickoutOrganizationMemberRequest("", token, testProfile5.getUserId())), + new KickoutOrganizationMemberRequest("", token, testProfile5.userId())), IllegalArgumentException.class); } @@ -67,7 +67,7 @@ void kickoutMemberEmptyOrgIdShouldFailWithIllegalArgumentException() { void kickoutMemberNullOrgIdShouldFailWithNullPointerException() { assertMonoCompletesWithError( service.kickoutMember( - new KickoutOrganizationMemberRequest(null, token, testProfile5.getUserId())), + new KickoutOrganizationMemberRequest(null, token, testProfile5.userId())), NullPointerException.class); } @@ -76,7 +76,7 @@ void kickoutMemberEmptyTokenShouldFailWithIllegalArgumentException() { assertMonoCompletesWithError( service.kickoutMember( new KickoutOrganizationMemberRequest( - organizationId, new Token(""), testProfile5.getUserId())), + organizationId, new Token(""), testProfile5.userId())), IllegalArgumentException.class); } @@ -84,7 +84,7 @@ organizationId, new Token(""), testProfile5.getUserId())), void kickoutMemberNullTokenShouldFailWithNullPointerException() { assertMonoCompletesWithError( service.kickoutMember( - new KickoutOrganizationMemberRequest(organizationId, null, testProfile5.getUserId())), + new KickoutOrganizationMemberRequest(organizationId, null, testProfile5.userId())), NullPointerException.class); } @@ -93,7 +93,7 @@ void kickoutMemberNullInnerTokenShouldFailWithNullPointerException() { assertMonoCompletesWithError( service.kickoutMember( new KickoutOrganizationMemberRequest( - organizationId, new Token(null), testProfile5.getUserId())), + organizationId, new Token(null), testProfile5.userId())), NullPointerException.class); } @@ -115,7 +115,7 @@ void kickoutMemberNullUserIdShouldFailWithNullPointerException() { void kickoutMemberOrgNotExistsShouldFailWithOrganizationNotFoundException() { assertMonoCompletesWithError( service.kickoutMember( - new KickoutOrganizationMemberRequest("orgNotExists", token, testProfile5.getUserId())), + new KickoutOrganizationMemberRequest("orgNotExists", token, testProfile5.userId())), OrganizationNotFoundException.class); } @@ -125,7 +125,7 @@ void kickoutMemberNotOrgOwnerShouldFailWithAccessPermissionException() { createService(testProfile5) .kickoutMember( new KickoutOrganizationMemberRequest( - organizationId, token, testProfile5.getUserId())), + organizationId, token, testProfile5.userId())), AccessPermissionException.class); } } diff --git a/scalecube-organization/src/test/java/io/scalecube/organization/LeaveOrganizationTest.java b/scalecube-organization/src/test/java/io/scalecube/organization/LeaveOrganizationTest.java index 97b0be5..5cc08df 100644 --- a/scalecube-organization/src/test/java/io/scalecube/organization/LeaveOrganizationTest.java +++ b/scalecube-organization/src/test/java/io/scalecube/organization/LeaveOrganizationTest.java @@ -38,7 +38,7 @@ void leaveOrganization() { not( hasItem( new OrganizationMember( - testProfile5.getUserId(), Role.Member.toString()))))) + testProfile5.userId(), Role.Member.toString()))))) .verifyComplete()) .verifyComplete(); } diff --git a/scalecube-organization/src/test/java/io/scalecube/organization/OrganizationMembersTest.java b/scalecube-organization/src/test/java/io/scalecube/organization/OrganizationMembersTest.java index 08f8276..0cd8873 100644 --- a/scalecube-organization/src/test/java/io/scalecube/organization/OrganizationMembersTest.java +++ b/scalecube-organization/src/test/java/io/scalecube/organization/OrganizationMembersTest.java @@ -43,8 +43,8 @@ void getOrganizationMembers() { assertThat(membersCount, is(2L)); List ids = members.get().map(OrganizationMember::id).collect(Collectors.toList()); - assertThat(ids, hasItem(testProfile4.getUserId())); - assertThat(ids, hasItem(testProfile5.getUserId())); + assertThat(ids, hasItem(testProfile4.userId())); + assertThat(ids, hasItem(testProfile5.userId())); }) .verifyComplete(); } diff --git a/scalecube-organization/src/test/java/io/scalecube/organization/OrganizationServiceApiKeyTest.java b/scalecube-organization/src/test/java/io/scalecube/organization/OrganizationServiceApiKeyTest.java index b1ccd04..6e90d74 100644 --- a/scalecube-organization/src/test/java/io/scalecube/organization/OrganizationServiceApiKeyTest.java +++ b/scalecube-organization/src/test/java/io/scalecube/organization/OrganizationServiceApiKeyTest.java @@ -11,9 +11,9 @@ import io.scalecube.account.api.Role; import io.scalecube.account.api.Token; import io.scalecube.account.api.UpdateOrganizationMemberRoleRequest; -import io.scalecube.organization.operation.Organization; +import io.scalecube.organization.domain.Organization; import io.scalecube.organization.repository.exception.AccessPermissionException; -import io.scalecube.security.Profile; +import io.scalecube.security.api.Profile; import java.util.HashMap; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Disabled; @@ -42,7 +42,7 @@ void addOrganizationApiKey(Role role) { .assertNext( x -> { Organization org = getOrganizationFromRepository(organizationId); - assertThat(org.apiKeys()[0].name(), equalTo(apiKeyName)); + assertThat(org.apiKeys().iterator().next().name(), equalTo(apiKeyName)); }) .verifyComplete(); } @@ -74,7 +74,7 @@ void failToAddOrganizationApiKeyByNonOwner() { StepVerifier.create( service.updateOrganizationMemberRole( new UpdateOrganizationMemberRoleRequest( - token, organizationId2, testProfile.getUserId(), Role.Member.toString()))) + token, organizationId2, testProfile.userId(), Role.Member.toString()))) .assertNext(Assertions::assertNotNull) .verifyComplete(); final HashMap claims = new HashMap<>(); @@ -217,7 +217,7 @@ void addOrganizationApiKeyByAdmin() { StepVerifier.create( service.updateOrganizationMemberRole( new UpdateOrganizationMemberRoleRequest( - token, organizationId, adminUser.getUserId(), Role.Admin.toString()))) + token, organizationId, adminUser.userId(), Role.Admin.toString()))) .assertNext(Assertions::assertNotNull) .verifyComplete(); // add api key by admin @@ -229,7 +229,7 @@ void addOrganizationApiKeyByAdmin() { .assertNext( x -> { Organization org = getOrganizationFromRepository(organizationId); - assertThat(org.apiKeys()[0].name(), equalTo("apiKey")); + assertThat(org.apiKeys().iterator().next().name(), equalTo("apiKey")); }) .verifyComplete(); } diff --git a/scalecube-organization/src/test/java/io/scalecube/organization/UpdateOrganizationTest.java b/scalecube-organization/src/test/java/io/scalecube/organization/UpdateOrganizationTest.java index c2288e5..754fe4f 100644 --- a/scalecube-organization/src/test/java/io/scalecube/organization/UpdateOrganizationTest.java +++ b/scalecube-organization/src/test/java/io/scalecube/organization/UpdateOrganizationTest.java @@ -15,7 +15,7 @@ import io.scalecube.account.api.Token; import io.scalecube.account.api.UpdateOrganizationMemberRoleRequest; import io.scalecube.account.api.UpdateOrganizationRequest; -import io.scalecube.organization.operation.Organization; +import io.scalecube.organization.domain.Organization; import io.scalecube.organization.repository.exception.AccessPermissionException; import io.scalecube.organization.repository.exception.NameAlreadyInUseException; import java.util.Arrays; @@ -118,9 +118,10 @@ void updateOrganizationNotAMemberShouldFail() { @Test void updateOrganizationNotAdminShouldFail() { - orgMembersRepository.addMember( - getOrganizationFromRepository(organizationId), - new OrganizationMember(testProfile2.getUserId(), Role.Member.toString())); + Organization organization = getOrganizationFromRepository(organizationId); + organization.addMember(new OrganizationMember(testProfile2.userId(), Role.Member.name())); + organizationRepository.save(organizationId, organization); + assertMonoCompletesWithError( createService(testProfile2) .updateOrganization( @@ -131,9 +132,8 @@ void updateOrganizationNotAdminShouldFail() { @Test void updateOrganization() { - orgMembersRepository.addMember( - getOrganizationFromRepository(organizationId), - new OrganizationMember(testAdminProfile.getUserId(), Role.Admin.toString())); + Organization organization = getOrganizationFromRepository(organizationId); + organization.addMember(new OrganizationMember(testAdminProfile.userId(), Role.Admin.name())); StepVerifier.create( service.addOrganizationApiKey( @@ -163,7 +163,7 @@ void updateOrganizationMemberRole() { StepVerifier.create( service.updateOrganizationMemberRole( new UpdateOrganizationMemberRoleRequest( - token, organizationId, testProfile5.getUserId(), Role.Admin.toString()))) + token, organizationId, testProfile5.userId(), Role.Admin.toString()))) .expectSubscription() .assertNext( x -> @@ -178,7 +178,7 @@ void updateOrganizationMemberRole() { Arrays.stream(r.members()) .anyMatch( i -> - Objects.equals(i.id(), testProfile5.getUserId()) + Objects.equals(i.id(), testProfile5.userId()) && Objects.equals( i.role(), Role.Admin.toString()))))) .verifyComplete(); @@ -189,7 +189,7 @@ void updateOrganizationMemberRoleNotMemberShouldFail() { StepVerifier.create( service.updateOrganizationMemberRole( new UpdateOrganizationMemberRoleRequest( - token, organizationId, testProfile5.getUserId(), Role.Admin.toString()))) + token, organizationId, testProfile5.userId(), Role.Admin.toString()))) .expectSubscription() .verifyError(NotAnOrganizationMemberException.class); } @@ -202,7 +202,7 @@ void updateOrganizationMemberRoleNotaSuperUserShouldFail() { createService(testProfile2) .updateOrganizationMemberRole( new UpdateOrganizationMemberRoleRequest( - token, organizationId, testProfile5.getUserId(), Role.Admin.toString())), + token, organizationId, testProfile5.userId(), Role.Admin.toString())), AccessPermissionException.class); } @@ -215,7 +215,7 @@ void updateOrganizationMemberRoleCallerNotOwnerTryingToPromoteToOwnerShouldFail( StepVerifier.create( service.updateOrganizationMemberRole( new UpdateOrganizationMemberRoleRequest( - token, organizationId, testProfile2.getUserId(), Role.Admin.toString()))) + token, organizationId, testProfile2.userId(), Role.Admin.toString()))) .assertNext(Assertions::assertNotNull) .verifyComplete(); @@ -223,7 +223,7 @@ void updateOrganizationMemberRoleCallerNotOwnerTryingToPromoteToOwnerShouldFail( createService(testProfile2) .updateOrganizationMemberRole( new UpdateOrganizationMemberRoleRequest( - token, organizationId, testProfile5.getUserId(), Role.Owner.toString())), + token, organizationId, testProfile5.userId(), Role.Owner.toString())), AccessPermissionException.class); } @@ -237,7 +237,7 @@ void updateOrganizationMemberRoleCallerNotOwnerTryingToDowngradeUserShouldFail() StepVerifier.create( service.updateOrganizationMemberRole( new UpdateOrganizationMemberRoleRequest( - token, organizationId, testProfile5.getUserId(), Role.Owner.toString()))) + token, organizationId, testProfile5.userId(), Role.Owner.toString()))) .assertNext(Assertions::assertNotNull) .verifyComplete(); @@ -245,7 +245,7 @@ void updateOrganizationMemberRoleCallerNotOwnerTryingToDowngradeUserShouldFail() StepVerifier.create( service.updateOrganizationMemberRole( new UpdateOrganizationMemberRoleRequest( - token, organizationId, testProfile2.getUserId(), Role.Admin.toString()))) + token, organizationId, testProfile2.userId(), Role.Admin.toString()))) .assertNext(Assertions::assertNotNull) .verifyComplete(); @@ -254,7 +254,7 @@ void updateOrganizationMemberRoleCallerNotOwnerTryingToDowngradeUserShouldFail() createService(testProfile2) .updateOrganizationMemberRole( new UpdateOrganizationMemberRoleRequest( - token, organizationId, testProfile5.getUserId(), Role.Admin.toString())), + token, organizationId, testProfile5.userId(), Role.Admin.toString())), AccessPermissionException.class); } @@ -281,7 +281,7 @@ void updateOrganizationMemberRoleWithNullOrgIdShouldFailWithNullPointerException assertMonoCompletesWithError( service.updateOrganizationMemberRole( new UpdateOrganizationMemberRoleRequest( - token, null, testProfile5.getUserId(), Role.Admin.toString())), + token, null, testProfile5.userId(), Role.Admin.toString())), NullPointerException.class); } @@ -290,7 +290,7 @@ void updateOrganizationMemberRoleWithEmptyOrgIdShouldFailWithIllegalArgumentExce assertMonoCompletesWithError( service.updateOrganizationMemberRole( new UpdateOrganizationMemberRoleRequest( - token, "", testProfile5.getUserId(), Role.Admin.toString())), + token, "", testProfile5.userId(), Role.Admin.toString())), IllegalArgumentException.class); } @@ -299,7 +299,7 @@ void updateOrganizationMemberRoleWithNonExistOrgShouldFailWithOrganizationNotFou assertMonoCompletesWithError( service.updateOrganizationMemberRole( new UpdateOrganizationMemberRoleRequest( - token, "bla", testProfile5.getUserId(), Role.Admin.toString())), + token, "bla", testProfile5.userId(), Role.Admin.toString())), OrganizationNotFoundException.class); } @@ -308,7 +308,7 @@ void updateOrganizationMemberRoleWithNullTokenShouldFailWithNullPointerException assertMonoCompletesWithError( service.updateOrganizationMemberRole( new UpdateOrganizationMemberRoleRequest( - null, organizationId, testProfile5.getUserId(), Role.Admin.toString())), + null, organizationId, testProfile5.userId(), Role.Admin.toString())), NullPointerException.class); } @@ -317,17 +317,16 @@ void updateOrganizationMemberRoleWithNullInnerTokenShouldFailWithNullPointerExce assertMonoCompletesWithError( service.updateOrganizationMemberRole( new UpdateOrganizationMemberRoleRequest( - new Token(null), organizationId, testProfile5.getUserId(), Role.Admin.toString())), + new Token(null), organizationId, testProfile5.userId(), Role.Admin.toString())), NullPointerException.class); } @Test - void - updateOrganizationMemberRoleWithEmptyInnerTokenShouldFailWithIllegalArgumentException() { + void updateOrganizationMemberRoleWithEmptyInnerTokenShouldFailWithIllegalArgumentException() { assertMonoCompletesWithError( service.updateOrganizationMemberRole( new UpdateOrganizationMemberRoleRequest( - new Token(""), organizationId, testProfile5.getUserId(), Role.Admin.toString())), + new Token(""), organizationId, testProfile5.userId(), Role.Admin.toString())), IllegalArgumentException.class); } @@ -336,7 +335,7 @@ void updateOrganizationMemberRoleWithEmptyRoleShouldFailWithIllegalArgumentExcep assertMonoCompletesWithError( service.updateOrganizationMemberRole( new UpdateOrganizationMemberRoleRequest( - token, organizationId, testProfile5.getUserId(), "")), + token, organizationId, testProfile5.userId(), "")), IllegalArgumentException.class); } @@ -345,19 +344,18 @@ void updateOrganizationMemberRoleWithNullRoleShouldFailWithNullPointerException( assertMonoCompletesWithError( service.updateOrganizationMemberRole( new UpdateOrganizationMemberRoleRequest( - token, organizationId, testProfile5.getUserId(), null)), + token, organizationId, testProfile5.userId(), null)), NullPointerException.class); } @Test - void - updateOrganizationMemberRoleInvalidRoleEnumValueShouldFailWithIllegalArgumentException() { + void updateOrganizationMemberRoleInvalidRoleEnumValueShouldFailWithIllegalArgumentException() { addMemberToOrganization(organizationId, testProfile5); assertMonoCompletesWithError( service.updateOrganizationMemberRole( new UpdateOrganizationMemberRoleRequest( - token, organizationId, testProfile5.getUserId(), "invalid role enum value")), + token, organizationId, testProfile5.userId(), "invalid role enum value")), IllegalArgumentException.class); } } diff --git a/scalecube-organization/src/test/java/io/scalecube/organization/UserMembershipTest.java b/scalecube-organization/src/test/java/io/scalecube/organization/UserMembershipTest.java index be5e65c..7b6ce29 100644 --- a/scalecube-organization/src/test/java/io/scalecube/organization/UserMembershipTest.java +++ b/scalecube-organization/src/test/java/io/scalecube/organization/UserMembershipTest.java @@ -10,7 +10,7 @@ import io.scalecube.account.api.OrganizationInfo; import io.scalecube.account.api.OrganizationMember; import io.scalecube.account.api.Token; -import io.scalecube.security.Profile; +import io.scalecube.security.api.Profile; import java.util.Arrays; import java.util.List; import java.util.Objects; @@ -88,11 +88,9 @@ void getOrganizationMembership() { private void assertGetOrganizationsMembership(String organisationId, Profile profile) { List members = - orgMembersRepository - .getMembers(getOrganizationFromRepository(organisationId)) - .stream() + getOrganizationFromRepository(organisationId).members().stream() .map(OrganizationMember::id) .collect(Collectors.toList()); - assertThat(members, hasItem(profile.getUserId())); + assertThat(members, hasItem(profile.userId())); } } diff --git a/scalecube-organization/src/test/java/io/scalecube/organization/fixtures/InMemoryOrganizationServiceFixture.java b/scalecube-organization/src/test/java/io/scalecube/organization/fixtures/InMemoryOrganizationServiceFixture.java index d0c8c77..864ff1d 100644 --- a/scalecube-organization/src/test/java/io/scalecube/organization/fixtures/InMemoryOrganizationServiceFixture.java +++ b/scalecube-organization/src/test/java/io/scalecube/organization/fixtures/InMemoryOrganizationServiceFixture.java @@ -2,12 +2,8 @@ import io.scalecube.account.api.OrganizationService; import io.scalecube.organization.OrganizationServiceImpl; -import io.scalecube.organization.repository.OrganizationsDataAccess; -import io.scalecube.organization.repository.OrganizationsDataAccessImpl; -import io.scalecube.organization.repository.inmem.InMemoryOrganizationMembersRepositoryAdmin; import io.scalecube.organization.repository.inmem.InMemoryOrganizationRepository; import io.scalecube.organization.repository.inmem.InMemoryPublicKeyProvider; -import io.scalecube.organization.repository.inmem.InMemoryUserOrganizationMembershipRepository; import io.scalecube.organization.token.store.PropertiesFileKeyStore; import io.scalecube.organization.tokens.TokenVerifierImpl; import io.scalecube.organization.tokens.store.KeyStore; @@ -21,17 +17,13 @@ public class InMemoryOrganizationServiceFixture implements Fixture { @Override public void setUp() throws TestAbortedException { - OrganizationsDataAccess repository = - new OrganizationsDataAccessImpl( - new InMemoryOrganizationRepository(), - new InMemoryUserOrganizationMembershipRepository(), - new InMemoryOrganizationMembersRepositoryAdmin()); + InMemoryOrganizationRepository organizationRepository = new InMemoryOrganizationRepository(); TokenVerifierImpl tokenVerifier = new TokenVerifierImpl(new InMemoryPublicKeyProvider()); KeyStore keyStore = new PropertiesFileKeyStore(); - service = new OrganizationServiceImpl(repository, keyStore, tokenVerifier); + service = new OrganizationServiceImpl(organizationRepository, keyStore, tokenVerifier); } @Override diff --git a/scalecube-organization/src/test/java/io/scalecube/organization/it/AddOrganizationApiKeyIntegrationTest.java b/scalecube-organization/src/test/java/io/scalecube/organization/it/AddOrganizationApiKeyIntegrationTest.java index 6434af0..6b1dc1f 100644 --- a/scalecube-organization/src/test/java/io/scalecube/organization/it/AddOrganizationApiKeyIntegrationTest.java +++ b/scalecube-organization/src/test/java/io/scalecube/organization/it/AddOrganizationApiKeyIntegrationTest.java @@ -14,7 +14,7 @@ import io.scalecube.account.api.Token; import io.scalecube.organization.fixtures.InMemoryOrganizationServiceFixture; import io.scalecube.organization.repository.inmem.InMemoryPublicKeyProvider; -import io.scalecube.security.Profile; +import io.scalecube.security.api.Profile; import io.scalecube.test.fixtures.Fixtures; import io.scalecube.test.fixtures.WithFixture; import java.time.Duration; @@ -54,7 +54,7 @@ void testAddAllApiKeysForEachAccessibleRoleOfTheOwner(OrganizationService servic service .createOrganization( new CreateOrganizationRequest( - RandomStringUtils.randomAlphabetic(10), userA.getEmail(), userAToken)) + RandomStringUtils.randomAlphabetic(10), userA.email(), userAToken)) .map(OrganizationInfo::id) .block(TIMEOUT); @@ -139,7 +139,7 @@ void testAddAllApiKeysForEachAccessibleRoleOfTheAdmin(OrganizationService servic service .createOrganization( new CreateOrganizationRequest( - RandomStringUtils.randomAlphabetic(10), userA.getEmail(), userAToken)) + RandomStringUtils.randomAlphabetic(10), userA.email(), userAToken)) .map(OrganizationInfo::id) .block(TIMEOUT); @@ -157,7 +157,7 @@ void testAddAllApiKeysForEachAccessibleRoleOfTheAdmin(OrganizationService servic service .inviteMember( new InviteOrganizationMemberRequest( - userAToken, organizationId, userB.getUserId(), Role.Admin.name())) + userAToken, organizationId, userB.userId(), Role.Admin.name())) .block(TIMEOUT); // user "B" creates API keys for the organization with roles: "admin" and "member" @@ -227,7 +227,7 @@ void testFailToAddOwnerApiKeyByAdmin(OrganizationService service) { String organizationId = service .createOrganization( - new CreateOrganizationRequest(organizationName, userA.getEmail(), userAToken)) + new CreateOrganizationRequest(organizationName, userA.email(), userAToken)) .map(OrganizationInfo::id) .block(TIMEOUT); @@ -235,7 +235,7 @@ void testFailToAddOwnerApiKeyByAdmin(OrganizationService service) { service .inviteMember( new InviteOrganizationMemberRequest( - userAToken, organizationId, userB.getUserId(), Role.Admin.name())) + userAToken, organizationId, userB.userId(), Role.Admin.name())) .block(TIMEOUT); // user "B" creates API keys for the organization with roles: "owner" @@ -249,7 +249,7 @@ void testFailToAddOwnerApiKeyByAdmin(OrganizationService service) { .expectErrorMessage( String.format( "user: '%s', name: '%s', role: 'Admin' cannot add api key with higher role 'Owner'", - userB.getUserId(), userB.getName())) + userB.userId(), userB.name())) .verify(); } @@ -267,7 +267,7 @@ void testFailToAddMemberApiKeyByMember(OrganizationService service) { String organizationId = service .createOrganization( - new CreateOrganizationRequest(organizationName, userA.getEmail(), userAToken)) + new CreateOrganizationRequest(organizationName, userA.email(), userAToken)) .map(OrganizationInfo::id) .block(TIMEOUT); @@ -275,7 +275,7 @@ void testFailToAddMemberApiKeyByMember(OrganizationService service) { service .inviteMember( new InviteOrganizationMemberRequest( - userAToken, organizationId, userB.getUserId(), Role.Member.name())) + userAToken, organizationId, userB.userId(), Role.Member.name())) .block(TIMEOUT); // user "B" creates API keys for the organization with roles: "member" @@ -289,7 +289,7 @@ void testFailToAddMemberApiKeyByMember(OrganizationService service) { .expectErrorMessage( String.format( "user: '%s', name: '%s', not in role Owner or Admin of organization: '%s'", - userB.getUserId(), userB.getName(), organizationName)) + userB.userId(), userB.name(), organizationName)) .verify(); } @@ -306,7 +306,7 @@ void testFailToAddApiKeyWithDuplicatedName(OrganizationService service) { service .createOrganization( new CreateOrganizationRequest( - RandomStringUtils.randomAlphabetic(10), userA.getEmail(), userAToken)) + RandomStringUtils.randomAlphabetic(10), userA.email(), userAToken)) .map(OrganizationInfo::id) .block(TIMEOUT); @@ -346,7 +346,7 @@ void testFailToAddApiKeyAfterOwnerWasRemoved(OrganizationService service) { String organizationId = service .createOrganization( - new CreateOrganizationRequest(organizationName, userA.getEmail(), userAToken)) + new CreateOrganizationRequest(organizationName, userA.email(), userAToken)) .map(OrganizationInfo::id) .block(TIMEOUT); @@ -354,7 +354,7 @@ void testFailToAddApiKeyAfterOwnerWasRemoved(OrganizationService service) { service .inviteMember( new InviteOrganizationMemberRequest( - userAToken, organizationId, userB.getUserId(), Role.Owner.name())) + userAToken, organizationId, userB.userId(), Role.Owner.name())) .block(TIMEOUT); // the user "A" leaves own organization @@ -373,7 +373,7 @@ void testFailToAddApiKeyAfterOwnerWasRemoved(OrganizationService service) { .expectErrorMessage( String.format( "user: '%s', name: '%s', not in role Owner or Admin of organization: '%s'", - userA.getUserId(), userA.getName(), organizationName)) + userA.userId(), userA.name(), organizationName)) .verify(); } @@ -390,7 +390,7 @@ void testFailToAddApiKeWithInvalidRole(OrganizationService service) { String organizationId = service .createOrganization( - new CreateOrganizationRequest(organizationName, userA.getEmail(), userAToken)) + new CreateOrganizationRequest(organizationName, userA.email(), userAToken)) .map(OrganizationInfo::id) .block(TIMEOUT); diff --git a/scalecube-organization/src/test/java/io/scalecube/organization/it/CreateOrganizationIntegrationTest.java b/scalecube-organization/src/test/java/io/scalecube/organization/it/CreateOrganizationIntegrationTest.java index 4ecda6d..e6bbb66 100644 --- a/scalecube-organization/src/test/java/io/scalecube/organization/it/CreateOrganizationIntegrationTest.java +++ b/scalecube-organization/src/test/java/io/scalecube/organization/it/CreateOrganizationIntegrationTest.java @@ -13,7 +13,7 @@ import io.scalecube.organization.repository.exception.NameAlreadyInUseException; import io.scalecube.organization.repository.inmem.InMemoryPublicKeyProvider; import io.scalecube.organization.tokens.InvalidTokenException; -import io.scalecube.security.Profile; +import io.scalecube.security.api.Profile; import io.scalecube.test.fixtures.Fixtures; import io.scalecube.test.fixtures.WithFixture; import java.time.Duration; @@ -46,13 +46,13 @@ void testOrganizationCreation(OrganizationService service) { StepVerifier.create( service.createOrganization( - new CreateOrganizationRequest(organizationName, userA.getEmail(), userAToken))) + new CreateOrganizationRequest(organizationName, userA.email(), userAToken))) .assertNext( organization -> { assertNotNull(organization.id()); assertTrue(organization.id().startsWith("ORG-")); assertEquals(organizationName, organization.name()); - assertEquals(userA.getEmail(), organization.email()); + assertEquals(userA.email(), organization.email()); assertNotNull(organization.apiKeys()); assertEquals(0, organization.apiKeys().length); }) @@ -70,7 +70,7 @@ void testFailOrganizationCreationWithInvalidToken(OrganizationService service) { StepVerifier.create( service.createOrganization( new CreateOrganizationRequest( - "organizationName", userA.getEmail(), new Token("invalid")))) + "organizationName", userA.email(), new Token("invalid")))) .expectErrorMatches( ex -> ex instanceof InvalidTokenException @@ -89,13 +89,13 @@ void testFailOrganizationCreationWithExistingName(OrganizationService service) { service .createOrganization( - new CreateOrganizationRequest(organizationName, userA.getEmail(), userAToken)) + new CreateOrganizationRequest(organizationName, userA.email(), userAToken)) .map(OrganizationInfo::id) .block(TIMEOUT); StepVerifier.create( service.createOrganization( - new CreateOrganizationRequest(organizationName, userA.getEmail(), userAToken))) + new CreateOrganizationRequest(organizationName, userA.email(), userAToken))) .expectErrorMatches( ex -> ex instanceof NameAlreadyInUseException @@ -133,7 +133,7 @@ void testFailOrganizationCreationWithDeniedSymbolsName(OrganizationService servi StepVerifier.create( service.createOrganization( - new CreateOrganizationRequest(organizationName, userA.getEmail(), userAToken))) + new CreateOrganizationRequest(organizationName, userA.email(), userAToken))) .expectErrorMatches( ex -> ex instanceof InvalidInputException diff --git a/scalecube-organization/src/test/java/io/scalecube/organization/it/DeleteOrganizationApiKeyIntegrationTest.java b/scalecube-organization/src/test/java/io/scalecube/organization/it/DeleteOrganizationApiKeyIntegrationTest.java index 7fd5c17..9852a4b 100644 --- a/scalecube-organization/src/test/java/io/scalecube/organization/it/DeleteOrganizationApiKeyIntegrationTest.java +++ b/scalecube-organization/src/test/java/io/scalecube/organization/it/DeleteOrganizationApiKeyIntegrationTest.java @@ -15,7 +15,7 @@ import io.scalecube.account.api.Token; import io.scalecube.organization.fixtures.InMemoryOrganizationServiceFixture; import io.scalecube.organization.repository.inmem.InMemoryPublicKeyProvider; -import io.scalecube.security.Profile; +import io.scalecube.security.api.Profile; import io.scalecube.test.fixtures.Fixtures; import io.scalecube.test.fixtures.WithFixture; import java.time.Duration; @@ -53,7 +53,7 @@ void testDeleteApiKeysByOwner(OrganizationService service) { service .createOrganization( new CreateOrganizationRequest( - RandomStringUtils.randomAlphabetic(10), userA.getEmail(), userAToken)) + RandomStringUtils.randomAlphabetic(10), userA.email(), userAToken)) .map(OrganizationInfo::id) .block(TIMEOUT); @@ -128,7 +128,7 @@ void testDeleteApiKeysByAdmin(OrganizationService service) { service .createOrganization( new CreateOrganizationRequest( - RandomStringUtils.randomAlphabetic(10), userA.getEmail(), userAToken)) + RandomStringUtils.randomAlphabetic(10), userA.email(), userAToken)) .map(OrganizationInfo::id) .block(TIMEOUT); @@ -149,7 +149,7 @@ void testDeleteApiKeysByAdmin(OrganizationService service) { service .inviteMember( new InviteOrganizationMemberRequest( - userAToken, organizationId, userB.getUserId(), Role.Admin.name())) + userAToken, organizationId, userB.userId(), Role.Admin.name())) .block(TIMEOUT); // the user "B" deletes the API keys which were assigned roles: "admin" and "member" @@ -204,7 +204,7 @@ void testFailToDeleteMemberApiKeysByMemberRole(OrganizationService service) { String organizationId = service .createOrganization( - new CreateOrganizationRequest(organizationName, userA.getEmail(), userAToken)) + new CreateOrganizationRequest(organizationName, userA.email(), userAToken)) .map(OrganizationInfo::id) .block(TIMEOUT); @@ -225,7 +225,7 @@ void testFailToDeleteMemberApiKeysByMemberRole(OrganizationService service) { service .inviteMember( new InviteOrganizationMemberRequest( - userAToken, organizationId, userB.getUserId(), Role.Member.name())) + userAToken, organizationId, userB.userId(), Role.Member.name())) .block(TIMEOUT); // the user "B" deletes the API key which was assigned roles "member" @@ -236,7 +236,7 @@ void testFailToDeleteMemberApiKeysByMemberRole(OrganizationService service) { .expectErrorMessage( String.format( "user: '%s', name: '%s', not in role Owner or Admin of organization: '%s'", - userB.getUserId(), userB.getName(), organizationName)) + userB.userId(), userB.name(), organizationName)) .verify(); } @@ -252,7 +252,7 @@ void testFailToDeleteNonExistingApiKey(OrganizationService service) { String organizationId = service .createOrganization( - new CreateOrganizationRequest(organizationName, userA.getEmail(), userAToken)) + new CreateOrganizationRequest(organizationName, userA.email(), userAToken)) .map(OrganizationInfo::id) .block(TIMEOUT); diff --git a/scalecube-organization/src/test/java/io/scalecube/organization/it/DeleteOrganizationIntegrationTest.java b/scalecube-organization/src/test/java/io/scalecube/organization/it/DeleteOrganizationIntegrationTest.java index 7971398..b93b1bd 100644 --- a/scalecube-organization/src/test/java/io/scalecube/organization/it/DeleteOrganizationIntegrationTest.java +++ b/scalecube-organization/src/test/java/io/scalecube/organization/it/DeleteOrganizationIntegrationTest.java @@ -16,7 +16,7 @@ import io.scalecube.organization.fixtures.InMemoryOrganizationServiceFixture; import io.scalecube.organization.repository.inmem.InMemoryPublicKeyProvider; import io.scalecube.organization.tokens.InvalidTokenException; -import io.scalecube.security.Profile; +import io.scalecube.security.api.Profile; import io.scalecube.test.fixtures.Fixtures; import io.scalecube.test.fixtures.WithFixture; import java.time.Duration; @@ -50,7 +50,7 @@ void testOrganizationDeletion(OrganizationService service) { String organizationId = service .createOrganization( - new CreateOrganizationRequest(organizationName, userA.getEmail(), userAToken)) + new CreateOrganizationRequest(organizationName, userA.email(), userAToken)) .map(OrganizationInfo::id) .block(TIMEOUT); @@ -82,7 +82,7 @@ void testOrganizationDeletionWithGrantedMember(OrganizationService service) { String organizationId = service .createOrganization( - new CreateOrganizationRequest(organizationName, userA.getEmail(), userAToken)) + new CreateOrganizationRequest(organizationName, userA.email(), userAToken)) .map(OrganizationInfo::id) .block(TIMEOUT); @@ -90,14 +90,14 @@ void testOrganizationDeletionWithGrantedMember(OrganizationService service) { service .inviteMember( new InviteOrganizationMemberRequest( - userAToken, organizationId, userB.getUserId(), Role.Member.name())) + userAToken, organizationId, userB.userId(), Role.Member.name())) .block(TIMEOUT); // "A" user updates the "B" user to "owner" in his organization service .updateOrganizationMemberRole( new UpdateOrganizationMemberRoleRequest( - userAToken, organizationId, userB.getUserId(), Role.Owner.name())) + userAToken, organizationId, userB.userId(), Role.Owner.name())) .block(TIMEOUT); // "B" user deletes "A" user created organization @@ -127,7 +127,7 @@ void testFailOrganizationDeletionWithRemovedFromOwnOrganizationUser(Organization String organizationId = service .createOrganization( - new CreateOrganizationRequest(organizationName, userA.getEmail(), userAToken)) + new CreateOrganizationRequest(organizationName, userA.email(), userAToken)) .map(OrganizationInfo::id) .block(TIMEOUT); @@ -135,7 +135,7 @@ void testFailOrganizationDeletionWithRemovedFromOwnOrganizationUser(Organization service .inviteMember( new InviteOrganizationMemberRequest( - userAToken, organizationId, userB.getUserId(), Role.Owner.name())) + userAToken, organizationId, userB.userId(), Role.Owner.name())) .block(TIMEOUT); // "A" user leaves own organization @@ -149,7 +149,7 @@ void testFailOrganizationDeletionWithRemovedFromOwnOrganizationUser(Organization .expectErrorMessage( String.format( "user: '%s', name: '%s', is not in role Owner of organization: '%s'", - userA.getName(), userA.getUserId(), organizationName)) + userA.name(), userA.userId(), organizationName)) .verify(); } @@ -169,7 +169,7 @@ void testFailOrganizationDeletionWithGrantedAdminRoleMember(OrganizationService String organizationId = service .createOrganization( - new CreateOrganizationRequest(organizationName, userA.getEmail(), userAToken)) + new CreateOrganizationRequest(organizationName, userA.email(), userAToken)) .map(OrganizationInfo::id) .block(TIMEOUT); @@ -177,14 +177,14 @@ void testFailOrganizationDeletionWithGrantedAdminRoleMember(OrganizationService service .inviteMember( new InviteOrganizationMemberRequest( - userAToken, organizationId, userB.getUserId(), Role.Member.name())) + userAToken, organizationId, userB.userId(), Role.Member.name())) .block(TIMEOUT); // "A" user updates the "B" user to "owner" in his organization service .updateOrganizationMemberRole( new UpdateOrganizationMemberRoleRequest( - userAToken, organizationId, userB.getUserId(), Role.Admin.name())) + userAToken, organizationId, userB.userId(), Role.Admin.name())) .block(TIMEOUT); // "B" user deletes organization @@ -193,7 +193,7 @@ void testFailOrganizationDeletionWithGrantedAdminRoleMember(OrganizationService .expectErrorMessage( String.format( "user: '%s', name: '%s', is not in role Owner of organization: '%s'", - userB.getName(), userB.getUserId(), organizationName)) + userB.name(), userB.userId(), organizationName)) .verify(); } @@ -213,7 +213,7 @@ void testFailOrganizationDeletionWithGrantedMemberRoleMember(OrganizationService String organizationId = service .createOrganization( - new CreateOrganizationRequest(organizationName, userA.getEmail(), userAToken)) + new CreateOrganizationRequest(organizationName, userA.email(), userAToken)) .map(OrganizationInfo::id) .block(TIMEOUT); @@ -221,14 +221,14 @@ void testFailOrganizationDeletionWithGrantedMemberRoleMember(OrganizationService service .inviteMember( new InviteOrganizationMemberRequest( - userAToken, organizationId, userB.getUserId(), Role.Member.name())) + userAToken, organizationId, userB.userId(), Role.Member.name())) .block(TIMEOUT); // "A" user updates the "B" user to "owner" in his organization service .updateOrganizationMemberRole( new UpdateOrganizationMemberRoleRequest( - userAToken, organizationId, userB.getUserId(), Role.Member.name())) + userAToken, organizationId, userB.userId(), Role.Member.name())) .block(TIMEOUT); // "B" user deletes organization @@ -237,7 +237,7 @@ void testFailOrganizationDeletionWithGrantedMemberRoleMember(OrganizationService .expectErrorMessage( String.format( "user: '%s', name: '%s', is not in role Owner of organization: '%s'", - userB.getName(), userB.getUserId(), organizationName)) + userB.name(), userB.userId(), organizationName)) .verify(); } @@ -253,7 +253,7 @@ void testFailOrganizationDeletionWithExpiredToken(OrganizationService service) { String organizationId = service .createOrganization( - new CreateOrganizationRequest(organizationName, userA.getEmail(), userAToken)) + new CreateOrganizationRequest(organizationName, userA.email(), userAToken)) .map(OrganizationInfo::id) .block(TIMEOUT); @@ -279,7 +279,7 @@ void testFailOrganizationDeletionNonExistingOrganization(OrganizationService ser service .createOrganization( - new CreateOrganizationRequest(organizationName, userA.getEmail(), userAToken)) + new CreateOrganizationRequest(organizationName, userA.email(), userAToken)) .map(OrganizationInfo::id) .block(TIMEOUT); diff --git a/scalecube-organization/src/test/java/io/scalecube/organization/it/GetOrganizationIntegrationTest.java b/scalecube-organization/src/test/java/io/scalecube/organization/it/GetOrganizationIntegrationTest.java index 91a96b3..484878e 100644 --- a/scalecube-organization/src/test/java/io/scalecube/organization/it/GetOrganizationIntegrationTest.java +++ b/scalecube-organization/src/test/java/io/scalecube/organization/it/GetOrganizationIntegrationTest.java @@ -16,7 +16,7 @@ import io.scalecube.account.api.Token; import io.scalecube.organization.fixtures.InMemoryOrganizationServiceFixture; import io.scalecube.organization.repository.inmem.InMemoryPublicKeyProvider; -import io.scalecube.security.Profile; +import io.scalecube.security.api.Profile; import io.scalecube.test.fixtures.Fixtures; import io.scalecube.test.fixtures.WithFixture; import java.time.Duration; @@ -57,7 +57,7 @@ void testGetOrganizationInfoByOwner(OrganizationService service) { String organizationId = service .createOrganization( - new CreateOrganizationRequest(organizationName, userA.getEmail(), userAToken)) + new CreateOrganizationRequest(organizationName, userA.email(), userAToken)) .map(OrganizationInfo::id) .block(TIMEOUT); @@ -82,7 +82,7 @@ void testGetOrganizationInfoByOwner(OrganizationService service) { service .inviteMember( new InviteOrganizationMemberRequest( - userAToken, organizationId, userB.getUserId(), Role.Owner.name())) + userAToken, organizationId, userB.userId(), Role.Owner.name())) .block(TIMEOUT); // the user "B" requested to get the user's "A" organization info @@ -112,7 +112,7 @@ void testGetOrganizationInfoByAdmin(OrganizationService service) { String organizationId = service .createOrganization( - new CreateOrganizationRequest(organizationName, userA.getEmail(), userAToken)) + new CreateOrganizationRequest(organizationName, userA.email(), userAToken)) .map(OrganizationInfo::id) .block(TIMEOUT); @@ -139,7 +139,7 @@ void testGetOrganizationInfoByAdmin(OrganizationService service) { service .inviteMember( new InviteOrganizationMemberRequest( - userAToken, organizationId, userB.getUserId(), Role.Admin.name())) + userAToken, organizationId, userB.userId(), Role.Admin.name())) .block(TIMEOUT); // the user "B" requested to get the user's "A" organization info @@ -169,7 +169,7 @@ void testGetOrganizationInfoByMember(OrganizationService service) { String organizationId = service .createOrganization( - new CreateOrganizationRequest(organizationName, userA.getEmail(), userAToken)) + new CreateOrganizationRequest(organizationName, userA.email(), userAToken)) .map(OrganizationInfo::id) .block(TIMEOUT); @@ -196,7 +196,7 @@ void testGetOrganizationInfoByMember(OrganizationService service) { service .inviteMember( new InviteOrganizationMemberRequest( - userAToken, organizationId, userB.getUserId(), Role.Member.name())) + userAToken, organizationId, userB.userId(), Role.Member.name())) .block(TIMEOUT); // the user "B" requested to get the user's "A" organization info @@ -226,7 +226,7 @@ void testFailToGetOrganizationInfoBecauseOwnerWasRemoved(OrganizationService ser String organizationId = service .createOrganization( - new CreateOrganizationRequest(organizationName, userA.getEmail(), userAToken)) + new CreateOrganizationRequest(organizationName, userA.email(), userAToken)) .map(OrganizationInfo::id) .block(TIMEOUT); @@ -234,7 +234,7 @@ void testFailToGetOrganizationInfoBecauseOwnerWasRemoved(OrganizationService ser service .inviteMember( new InviteOrganizationMemberRequest( - userAToken, organizationId, userB.getUserId(), Role.Owner.name())) + userAToken, organizationId, userB.userId(), Role.Owner.name())) .block(TIMEOUT); // the user "A" leaves own organization @@ -248,7 +248,7 @@ void testFailToGetOrganizationInfoBecauseOwnerWasRemoved(OrganizationService ser .expectErrorMessage( String.format( "user: '%s', name: '%s', is not a member of organization: '%s'", - userA.getName(), userA.getUserId(), organizationId)) + userA.name(), userA.userId(), organizationId)) .verify(); } diff --git a/scalecube-organization/src/test/java/io/scalecube/organization/it/GetOrganizationMembersTest.java b/scalecube-organization/src/test/java/io/scalecube/organization/it/GetOrganizationMembersTest.java index 0cdacd8..0bdb55f 100644 --- a/scalecube-organization/src/test/java/io/scalecube/organization/it/GetOrganizationMembersTest.java +++ b/scalecube-organization/src/test/java/io/scalecube/organization/it/GetOrganizationMembersTest.java @@ -45,19 +45,19 @@ void getMembersByOwner(OrganizationService organizationService) { organizationService .createOrganization( new CreateOrganizationRequest( - RandomStringUtils.randomAlphabetic(10), USER_A.getEmail(), tokenA)) + RandomStringUtils.randomAlphabetic(10), USER_A.email(), tokenA)) .block(TIMEOUT); organizationService .inviteMember( new InviteOrganizationMemberRequest( - tokenA, organizationA.id(), USER_B.getUserId(), Role.Member.name())) + tokenA, organizationA.id(), USER_B.userId(), Role.Member.name())) .block(TIMEOUT); organizationService .inviteMember( new InviteOrganizationMemberRequest( - tokenA, organizationA.id(), USER_C.getUserId(), Role.Member.name())) + tokenA, organizationA.id(), USER_C.userId(), Role.Member.name())) .block(TIMEOUT); StepVerifier.create( @@ -71,11 +71,11 @@ void getMembersByOwner(OrganizationService organizationService) { .collect(Collectors.toList()); assertTrue( - members.contains(USER_A.getUserId()), "member A is not found in organization"); + members.contains(USER_A.userId()), "member A is not found in organization"); assertTrue( - members.contains(USER_B.getUserId()), "member B is not found in organization"); + members.contains(USER_B.userId()), "member B is not found in organization"); assertTrue( - members.contains(USER_C.getUserId()), "member C is not found in organization"); + members.contains(USER_C.userId()), "member C is not found in organization"); }) .verifyComplete(); } @@ -91,13 +91,13 @@ void getMembersByAdmin(OrganizationService organizationService) { organizationService .createOrganization( new CreateOrganizationRequest( - RandomStringUtils.randomAlphabetic(10), USER_A.getEmail(), tokenA)) + RandomStringUtils.randomAlphabetic(10), USER_A.email(), tokenA)) .block(TIMEOUT); organizationService .inviteMember( new InviteOrganizationMemberRequest( - tokenA, organizationA.id(), USER_B.getUserId(), Role.Admin.name())) + tokenA, organizationA.id(), USER_B.userId(), Role.Admin.name())) .block(TIMEOUT); StepVerifier.create( @@ -111,9 +111,9 @@ void getMembersByAdmin(OrganizationService organizationService) { .collect(Collectors.toList()); assertTrue( - members.contains(USER_A.getUserId()), "member A is not found in organization"); + members.contains(USER_A.userId()), "member A is not found in organization"); assertTrue( - members.contains(USER_B.getUserId()), "member B is not found in organization"); + members.contains(USER_B.userId()), "member B is not found in organization"); }) .verifyComplete(); } @@ -129,13 +129,13 @@ void getMembersByMember(OrganizationService organizationService) { organizationService .createOrganization( new CreateOrganizationRequest( - RandomStringUtils.randomAlphabetic(10), USER_A.getEmail(), tokenA)) + RandomStringUtils.randomAlphabetic(10), USER_A.email(), tokenA)) .block(TIMEOUT); organizationService .inviteMember( new InviteOrganizationMemberRequest( - tokenA, organizationA.id(), USER_B.getUserId(), Role.Member.name())) + tokenA, organizationA.id(), USER_B.userId(), Role.Member.name())) .block(TIMEOUT); StepVerifier.create( @@ -147,7 +147,7 @@ void getMembersByMember(OrganizationService organizationService) { assertEquals( String.format( "user: '%s', name: '%s', not in role Owner or Admin of organization: '%s'", - USER_B.getUserId(), USER_B.getName(), organizationA.name()), + USER_B.userId(), USER_B.name(), organizationA.name()), e.getMessage()); }) .verify(); @@ -164,18 +164,18 @@ void getMembersByRemovedAdmin(OrganizationService organizationService) { organizationService .createOrganization( new CreateOrganizationRequest( - RandomStringUtils.randomAlphabetic(10), USER_A.getEmail(), tokenA)) + RandomStringUtils.randomAlphabetic(10), USER_A.email(), tokenA)) .block(TIMEOUT); organizationService .inviteMember( new InviteOrganizationMemberRequest( - tokenA, organizationA.id(), USER_B.getUserId(), Role.Admin.name())) + tokenA, organizationA.id(), USER_B.userId(), Role.Admin.name())) .block(TIMEOUT); organizationService .kickoutMember( - new KickoutOrganizationMemberRequest(organizationA.id(), tokenA, USER_B.getUserId())) + new KickoutOrganizationMemberRequest(organizationA.id(), tokenA, USER_B.userId())) .block(TIMEOUT); StepVerifier.create( @@ -187,7 +187,7 @@ void getMembersByRemovedAdmin(OrganizationService organizationService) { assertEquals( String.format( "user: '%s', name: '%s', not in role Owner or Admin of organization: '%s'", - USER_B.getUserId(), USER_B.getName(), organizationA.name()), + USER_B.userId(), USER_B.name(), organizationA.name()), e.getMessage()); }) .verify(); diff --git a/scalecube-organization/src/test/java/io/scalecube/organization/it/GetUserMembershipTest.java b/scalecube-organization/src/test/java/io/scalecube/organization/it/GetUserMembershipTest.java index 0fb1811..34c0fed 100644 --- a/scalecube-organization/src/test/java/io/scalecube/organization/it/GetUserMembershipTest.java +++ b/scalecube-organization/src/test/java/io/scalecube/organization/it/GetUserMembershipTest.java @@ -49,14 +49,14 @@ void getUserMembershipOfMember(OrganizationService organizationService) { organizationService .createOrganization( new CreateOrganizationRequest( - RandomStringUtils.randomAlphabetic(10), USER_A.getEmail(), tokenA)) + RandomStringUtils.randomAlphabetic(10), USER_A.email(), tokenA)) .block(TIMEOUT); CreateOrganizationResponse organizationB = organizationService .createOrganization( new CreateOrganizationRequest( - RandomStringUtils.randomAlphabetic(10), USER_B.getEmail(), tokenB)) + RandomStringUtils.randomAlphabetic(10), USER_B.email(), tokenB)) .block(TIMEOUT); organizationService @@ -98,13 +98,13 @@ void getUserMembershipOfMember(OrganizationService organizationService) { organizationService .inviteMember( new InviteOrganizationMemberRequest( - tokenA, organizationA.id(), USER_C.getUserId(), Role.Member.name())) + tokenA, organizationA.id(), USER_C.userId(), Role.Member.name())) .block(TIMEOUT); organizationService .inviteMember( new InviteOrganizationMemberRequest( - tokenB, organizationB.id(), USER_C.getUserId(), Role.Member.name())) + tokenB, organizationB.id(), USER_C.userId(), Role.Member.name())) .block(TIMEOUT); StepVerifier.create( @@ -142,14 +142,14 @@ void getUserMembershipOfAdmin(OrganizationService organizationService) { organizationService .createOrganization( new CreateOrganizationRequest( - RandomStringUtils.randomAlphabetic(10), USER_A.getEmail(), tokenA)) + RandomStringUtils.randomAlphabetic(10), USER_A.email(), tokenA)) .block(TIMEOUT); CreateOrganizationResponse organizationB = organizationService .createOrganization( new CreateOrganizationRequest( - RandomStringUtils.randomAlphabetic(10), USER_B.getEmail(), tokenB)) + RandomStringUtils.randomAlphabetic(10), USER_B.email(), tokenB)) .block(TIMEOUT); organizationService @@ -191,13 +191,13 @@ void getUserMembershipOfAdmin(OrganizationService organizationService) { organizationService .inviteMember( new InviteOrganizationMemberRequest( - tokenA, organizationA.id(), USER_C.getUserId(), Role.Admin.name())) + tokenA, organizationA.id(), USER_C.userId(), Role.Admin.name())) .block(TIMEOUT); organizationService .inviteMember( new InviteOrganizationMemberRequest( - tokenB, organizationB.id(), USER_C.getUserId(), Role.Admin.name())) + tokenB, organizationB.id(), USER_C.userId(), Role.Admin.name())) .block(TIMEOUT); StepVerifier.create( @@ -247,7 +247,7 @@ void getUserMembershipOfOwner(OrganizationService organizationService) { organizationService .createOrganization( new CreateOrganizationRequest( - RandomStringUtils.randomAlphabetic(10), USER_A.getEmail(), tokenA)) + RandomStringUtils.randomAlphabetic(10), USER_A.email(), tokenA)) .block(TIMEOUT); organizationService @@ -280,7 +280,7 @@ void getUserMembershipOfOwner(OrganizationService organizationService) { organizationService .inviteMember( new InviteOrganizationMemberRequest( - tokenA, organizationA.id(), USER_B.getUserId(), Role.Owner.name())) + tokenA, organizationA.id(), USER_B.userId(), Role.Owner.name())) .block(TIMEOUT); StepVerifier.create( @@ -309,7 +309,7 @@ void getUserMembershipOfNotInvitedMember(OrganizationService organizationService organizationService .createOrganization( new CreateOrganizationRequest( - RandomStringUtils.randomAlphabetic(10), USER_A.getEmail(), tokenA)) + RandomStringUtils.randomAlphabetic(10), USER_A.email(), tokenA)) .block(TIMEOUT); StepVerifier.create( diff --git a/scalecube-organization/src/test/java/io/scalecube/organization/it/InviteMemberTest.java b/scalecube-organization/src/test/java/io/scalecube/organization/it/InviteMemberTest.java index a4fb435..212e912 100644 --- a/scalecube-organization/src/test/java/io/scalecube/organization/it/InviteMemberTest.java +++ b/scalecube-organization/src/test/java/io/scalecube/organization/it/InviteMemberTest.java @@ -45,21 +45,21 @@ void inviteUserToMultipleOrganizationsByMultipleOwners(OrganizationService organ organizationService .createOrganization( new CreateOrganizationRequest( - RandomStringUtils.randomAlphabetic(10), USER_A.getEmail(), tokenA)) + RandomStringUtils.randomAlphabetic(10), USER_A.email(), tokenA)) .block(TIMEOUT); CreateOrganizationResponse organizationB = organizationService .createOrganization( new CreateOrganizationRequest( - RandomStringUtils.randomAlphabetic(10), USER_B.getEmail(), tokenB)) + RandomStringUtils.randomAlphabetic(10), USER_B.email(), tokenB)) .block(TIMEOUT); StepVerifier.create( organizationService .inviteMember( new InviteOrganizationMemberRequest( - tokenA, organizationA.id(), USER_C.getUserId(), Role.Member.name())) + tokenA, organizationA.id(), USER_C.userId(), Role.Member.name())) .then( organizationService.getOrganizationMembers( new GetOrganizationMembersRequest(organizationA.id(), tokenA)))) @@ -69,8 +69,8 @@ void inviteUserToMultipleOrganizationsByMultipleOwners(OrganizationService organ Stream.of(response.members()) .collect(Collectors.toMap(OrganizationMember::id, OrganizationMember::role)); - assertNotNull(members.get(USER_C.getUserId()), "member is not found in organization"); - assertEquals(Role.Member.name(), members.get(USER_C.getUserId())); + assertNotNull(members.get(USER_C.userId()), "member is not found in organization"); + assertEquals(Role.Member.name(), members.get(USER_C.userId())); }) .verifyComplete(); @@ -78,7 +78,7 @@ void inviteUserToMultipleOrganizationsByMultipleOwners(OrganizationService organ organizationService .inviteMember( new InviteOrganizationMemberRequest( - tokenB, organizationB.id(), USER_C.getUserId(), Role.Member.name())) + tokenB, organizationB.id(), USER_C.userId(), Role.Member.name())) .then( organizationService.getOrganizationMembers( new GetOrganizationMembersRequest(organizationB.id(), tokenB)))) @@ -88,8 +88,8 @@ void inviteUserToMultipleOrganizationsByMultipleOwners(OrganizationService organ Stream.of(response.members()) .collect(Collectors.toMap(OrganizationMember::id, OrganizationMember::role)); - assertNotNull(members.get(USER_C.getUserId()), "member is not found in organization"); - assertEquals(Role.Member.name(), members.get(USER_C.getUserId())); + assertNotNull(members.get(USER_C.userId()), "member is not found in organization"); + assertEquals(Role.Member.name(), members.get(USER_C.userId())); }) .verifyComplete(); } @@ -104,21 +104,21 @@ void inviteUserToMultipleOrganizationsBySingleOwner(OrganizationService organiza organizationService .createOrganization( new CreateOrganizationRequest( - RandomStringUtils.randomAlphabetic(10), USER_A.getEmail(), tokenA)) + RandomStringUtils.randomAlphabetic(10), USER_A.email(), tokenA)) .block(TIMEOUT); CreateOrganizationResponse organizationA2 = organizationService .createOrganization( new CreateOrganizationRequest( - RandomStringUtils.randomAlphabetic(10), USER_A.getEmail(), tokenA)) + RandomStringUtils.randomAlphabetic(10), USER_A.email(), tokenA)) .block(TIMEOUT); StepVerifier.create( organizationService .inviteMember( new InviteOrganizationMemberRequest( - tokenA, organizationA1.id(), USER_B.getUserId(), Role.Owner.name())) + tokenA, organizationA1.id(), USER_B.userId(), Role.Owner.name())) .then( organizationService.getOrganizationMembers( new GetOrganizationMembersRequest(organizationA1.id(), tokenA)))) @@ -128,8 +128,8 @@ void inviteUserToMultipleOrganizationsBySingleOwner(OrganizationService organiza Stream.of(response.members()) .collect(Collectors.toMap(OrganizationMember::id, OrganizationMember::role)); - assertNotNull(members.get(USER_B.getUserId()), "member is not found in organization"); - assertEquals(Role.Owner.name(), members.get(USER_B.getUserId())); + assertNotNull(members.get(USER_B.userId()), "member is not found in organization"); + assertEquals(Role.Owner.name(), members.get(USER_B.userId())); }) .verifyComplete(); @@ -137,7 +137,7 @@ void inviteUserToMultipleOrganizationsBySingleOwner(OrganizationService organiza organizationService .inviteMember( new InviteOrganizationMemberRequest( - tokenA, organizationA2.id(), USER_B.getUserId(), Role.Owner.name())) + tokenA, organizationA2.id(), USER_B.userId(), Role.Owner.name())) .then( organizationService.getOrganizationMembers( new GetOrganizationMembersRequest(organizationA2.id(), tokenA)))) @@ -147,8 +147,8 @@ void inviteUserToMultipleOrganizationsBySingleOwner(OrganizationService organiza Stream.of(response.members()) .collect(Collectors.toMap(OrganizationMember::id, OrganizationMember::role)); - assertNotNull(members.get(USER_B.getUserId()), "member is not found in organization"); - assertEquals(Role.Owner.name(), members.get(USER_B.getUserId())); + assertNotNull(members.get(USER_B.userId()), "member is not found in organization"); + assertEquals(Role.Owner.name(), members.get(USER_B.userId())); }) .verifyComplete(); } @@ -164,20 +164,20 @@ void inviteUserToOrganizationByAdmin(OrganizationService organizationService) { organizationService .createOrganization( new CreateOrganizationRequest( - RandomStringUtils.randomAlphabetic(10), USER_A.getEmail(), tokenA)) + RandomStringUtils.randomAlphabetic(10), USER_A.email(), tokenA)) .block(TIMEOUT); organizationService .inviteMember( new InviteOrganizationMemberRequest( - tokenA, organizationA.id(), USER_B.getUserId(), Role.Admin.name())) + tokenA, organizationA.id(), USER_B.userId(), Role.Admin.name())) .block(TIMEOUT); StepVerifier.create( organizationService .inviteMember( new InviteOrganizationMemberRequest( - tokenB, organizationA.id(), USER_C.getUserId(), Role.Member.name())) + tokenB, organizationA.id(), USER_C.userId(), Role.Member.name())) .then( organizationService.getOrganizationMembers( new GetOrganizationMembersRequest(organizationA.id(), tokenB)))) @@ -187,8 +187,8 @@ void inviteUserToOrganizationByAdmin(OrganizationService organizationService) { Stream.of(response.members()) .collect(Collectors.toMap(OrganizationMember::id, OrganizationMember::role)); - assertNotNull(members.get(USER_C.getUserId()), "member is not found in organization"); - assertEquals(Role.Member.name(), members.get(USER_C.getUserId())); + assertNotNull(members.get(USER_C.userId()), "member is not found in organization"); + assertEquals(Role.Member.name(), members.get(USER_C.userId())); }) .verifyComplete(); } @@ -204,20 +204,20 @@ void inviteUserToOrganizationByOwner(OrganizationService organizationService) { organizationService .createOrganization( new CreateOrganizationRequest( - RandomStringUtils.randomAlphabetic(10), USER_A.getEmail(), tokenA)) + RandomStringUtils.randomAlphabetic(10), USER_A.email(), tokenA)) .block(TIMEOUT); organizationService .inviteMember( new InviteOrganizationMemberRequest( - tokenA, organizationA.id(), USER_B.getUserId(), Role.Owner.name())) + tokenA, organizationA.id(), USER_B.userId(), Role.Owner.name())) .block(TIMEOUT); StepVerifier.create( organizationService .inviteMember( new InviteOrganizationMemberRequest( - tokenB, organizationA.id(), USER_C.getUserId(), Role.Admin.name())) + tokenB, organizationA.id(), USER_C.userId(), Role.Admin.name())) .then( organizationService.getOrganizationMembers( new GetOrganizationMembersRequest(organizationA.id(), tokenB)))) @@ -227,8 +227,8 @@ void inviteUserToOrganizationByOwner(OrganizationService organizationService) { Stream.of(response.members()) .collect(Collectors.toMap(OrganizationMember::id, OrganizationMember::role)); - assertNotNull(members.get(USER_C.getUserId()), "member is not found in organization"); - assertEquals(Role.Admin.name(), members.get(USER_C.getUserId())); + assertNotNull(members.get(USER_C.userId()), "member is not found in organization"); + assertEquals(Role.Admin.name(), members.get(USER_C.userId())); }) .verifyComplete(); } @@ -242,20 +242,20 @@ void inviteExistentUser(OrganizationService organizationService) { organizationService .createOrganization( new CreateOrganizationRequest( - RandomStringUtils.randomAlphabetic(10), USER_A.getEmail(), tokenA)) + RandomStringUtils.randomAlphabetic(10), USER_A.email(), tokenA)) .block(TIMEOUT); organizationService .inviteMember( new InviteOrganizationMemberRequest( - tokenA, organizationA.id(), USER_B.getUserId(), Role.Member.name())) + tokenA, organizationA.id(), USER_B.userId(), Role.Member.name())) .block(TIMEOUT); StepVerifier.create( organizationService .inviteMember( new InviteOrganizationMemberRequest( - tokenA, organizationA.id(), USER_B.getUserId(), Role.Admin.name())) + tokenA, organizationA.id(), USER_B.userId(), Role.Admin.name())) .then( organizationService.getOrganizationMembers( new GetOrganizationMembersRequest(organizationA.id(), tokenA)))) @@ -265,8 +265,8 @@ void inviteExistentUser(OrganizationService organizationService) { Stream.of(response.members()) .collect(Collectors.toMap(OrganizationMember::id, OrganizationMember::role)); - assertNotNull(members.get(USER_B.getUserId()), "member is not found in organization"); - assertEquals(Role.Member.name(), members.get(USER_B.getUserId())); + assertNotNull(members.get(USER_B.userId()), "member is not found in organization"); + assertEquals(Role.Member.name(), members.get(USER_B.userId())); }) .verifyComplete(); } @@ -282,26 +282,26 @@ void inviteUnauthorizedUser(OrganizationService organizationService) { organizationService .createOrganization( new CreateOrganizationRequest( - RandomStringUtils.randomAlphabetic(10), USER_A.getEmail(), tokenA)) + RandomStringUtils.randomAlphabetic(10), USER_A.email(), tokenA)) .block(TIMEOUT); organizationService .inviteMember( new InviteOrganizationMemberRequest( - tokenA, organizationA.id(), USER_B.getUserId(), Role.Member.name())) + tokenA, organizationA.id(), USER_B.userId(), Role.Member.name())) .block(TIMEOUT); StepVerifier.create( organizationService.inviteMember( new InviteOrganizationMemberRequest( - tokenB, organizationA.id(), USER_C.getUserId(), Role.Member.name()))) + tokenB, organizationA.id(), USER_C.userId(), Role.Member.name()))) .expectErrorSatisfies( e -> { assertEquals(AccessPermissionException.class, e.getClass()); assertEquals( String.format( "user: '%s', name: '%s', not in role Owner or Admin of organization: '%s'", - USER_B.getUserId(), USER_B.getName(), organizationA.name()), + USER_B.userId(), USER_B.name(), organizationA.name()), e.getMessage()); }) .verify(); @@ -318,31 +318,31 @@ void inviteUserByRemovedOwner(OrganizationService organizationService) { organizationService .createOrganization( new CreateOrganizationRequest( - RandomStringUtils.randomAlphabetic(10), USER_A.getEmail(), tokenA)) + RandomStringUtils.randomAlphabetic(10), USER_A.email(), tokenA)) .block(TIMEOUT); organizationService .inviteMember( new InviteOrganizationMemberRequest( - tokenA, organizationA.id(), USER_B.getUserId(), Role.Owner.name())) + tokenA, organizationA.id(), USER_B.userId(), Role.Owner.name())) .block(TIMEOUT); organizationService .kickoutMember( - new KickoutOrganizationMemberRequest(organizationA.id(), tokenB, USER_A.getUserId())) + new KickoutOrganizationMemberRequest(organizationA.id(), tokenB, USER_A.userId())) .block(TIMEOUT); StepVerifier.create( organizationService.inviteMember( new InviteOrganizationMemberRequest( - tokenA, organizationA.id(), USER_C.getUserId(), Role.Member.name()))) + tokenA, organizationA.id(), USER_C.userId(), Role.Member.name()))) .expectErrorSatisfies( e -> { assertEquals(AccessPermissionException.class, e.getClass()); assertEquals( String.format( "user: '%s', name: '%s', not in role Owner or Admin of organization: '%s'", - USER_A.getUserId(), USER_A.getName(), organizationA.name()), + USER_A.userId(), USER_A.name(), organizationA.name()), e.getMessage()); }) .verify(); @@ -359,26 +359,26 @@ void inviteUserAsOwnerByAdmin(OrganizationService organizationService) { organizationService .createOrganization( new CreateOrganizationRequest( - RandomStringUtils.randomAlphabetic(10), USER_A.getEmail(), tokenA)) + RandomStringUtils.randomAlphabetic(10), USER_A.email(), tokenA)) .block(TIMEOUT); organizationService .inviteMember( new InviteOrganizationMemberRequest( - tokenA, organizationA.id(), USER_B.getUserId(), Role.Admin.name())) + tokenA, organizationA.id(), USER_B.userId(), Role.Admin.name())) .block(TIMEOUT); StepVerifier.create( organizationService.inviteMember( new InviteOrganizationMemberRequest( - tokenB, organizationA.id(), USER_C.getUserId(), Role.Owner.name()))) + tokenB, organizationA.id(), USER_C.userId(), Role.Owner.name()))) .expectErrorSatisfies( e -> { assertEquals(AccessPermissionException.class, e.getClass()); assertEquals( String.format( "user: '%s', name: '%s', role: '%s' cannot invite to a higher role: '%s'", - USER_B.getUserId(), USER_B.getName(), Role.Admin.name(), Role.Owner.name()), + USER_B.userId(), USER_B.name(), Role.Admin.name(), Role.Owner.name()), e.getMessage()); }) .verify(); @@ -393,7 +393,7 @@ void inviteUsingExpiredToken(OrganizationService organizationService) { StepVerifier.create( organizationService.inviteMember( new InviteOrganizationMemberRequest( - tokenA, "ORG-organization-1", USER_B.getUserId(), Role.Member.name()))) + tokenA, "ORG-organization-1", USER_B.userId(), Role.Member.name()))) .expectErrorSatisfies( e -> { assertEquals(InvalidTokenException.class, e.getClass()); diff --git a/scalecube-organization/src/test/java/io/scalecube/organization/it/KickoutMemberTest.java b/scalecube-organization/src/test/java/io/scalecube/organization/it/KickoutMemberTest.java index e70c85a..d24b0da 100644 --- a/scalecube-organization/src/test/java/io/scalecube/organization/it/KickoutMemberTest.java +++ b/scalecube-organization/src/test/java/io/scalecube/organization/it/KickoutMemberTest.java @@ -45,20 +45,20 @@ void kickoutMemberByOwner(OrganizationService organizationService) { organizationService .createOrganization( new CreateOrganizationRequest( - RandomStringUtils.randomAlphabetic(10), USER_A.getEmail(), tokenA)) + RandomStringUtils.randomAlphabetic(10), USER_A.email(), tokenA)) .block(TIMEOUT); organizationService .inviteMember( new InviteOrganizationMemberRequest( - tokenA, organizationA.id(), USER_B.getUserId(), Role.Member.name())) + tokenA, organizationA.id(), USER_B.userId(), Role.Member.name())) .block(TIMEOUT); StepVerifier.create( organizationService .kickoutMember( new KickoutOrganizationMemberRequest( - organizationA.id(), tokenA, USER_B.getUserId())) + organizationA.id(), tokenA, USER_B.userId())) .then( organizationService.getOrganizationMembers( new GetOrganizationMembersRequest(organizationA.id(), tokenA)))) @@ -69,7 +69,7 @@ void kickoutMemberByOwner(OrganizationService organizationService) { .map(OrganizationMember::id) .collect(Collectors.toList()); - assertFalse(members.contains(USER_B.getUserId()), "member is found in organization"); + assertFalse(members.contains(USER_B.userId()), "member is found in organization"); }) .verifyComplete(); } @@ -85,30 +85,30 @@ void kickoutMemberAndOwnerByOwner(OrganizationService organizationService) { organizationService .createOrganization( new CreateOrganizationRequest( - RandomStringUtils.randomAlphabetic(10), USER_A.getEmail(), tokenA)) + RandomStringUtils.randomAlphabetic(10), USER_A.email(), tokenA)) .block(TIMEOUT); organizationService .inviteMember( new InviteOrganizationMemberRequest( - tokenA, organizationA.id(), USER_B.getUserId(), Role.Owner.name())) + tokenA, organizationA.id(), USER_B.userId(), Role.Owner.name())) .block(TIMEOUT); organizationService .inviteMember( new InviteOrganizationMemberRequest( - tokenA, organizationA.id(), USER_C.getUserId(), Role.Member.name())) + tokenA, organizationA.id(), USER_C.userId(), Role.Member.name())) .block(TIMEOUT); StepVerifier.create( organizationService .kickoutMember( new KickoutOrganizationMemberRequest( - organizationA.id(), tokenB, USER_A.getUserId())) + organizationA.id(), tokenB, USER_A.userId())) .then( organizationService.kickoutMember( new KickoutOrganizationMemberRequest( - organizationA.id(), tokenB, USER_C.getUserId()))) + organizationA.id(), tokenB, USER_C.userId()))) .then( organizationService.getOrganizationMembers( new GetOrganizationMembersRequest(organizationA.id(), tokenB)))) @@ -119,8 +119,8 @@ void kickoutMemberAndOwnerByOwner(OrganizationService organizationService) { .map(OrganizationMember::id) .collect(Collectors.toList()); - assertFalse(members.contains(USER_A.getUserId()), "member is found in organization"); - assertFalse(members.contains(USER_C.getUserId()), "member is found in organization"); + assertFalse(members.contains(USER_A.userId()), "member is found in organization"); + assertFalse(members.contains(USER_C.userId()), "member is found in organization"); }) .verifyComplete(); } @@ -136,36 +136,36 @@ void kickoutByAdmin(OrganizationService organizationService) { organizationService .createOrganization( new CreateOrganizationRequest( - RandomStringUtils.randomAlphabetic(10), USER_A.getEmail(), tokenA)) + RandomStringUtils.randomAlphabetic(10), USER_A.email(), tokenA)) .block(TIMEOUT); organizationService .inviteMember( new InviteOrganizationMemberRequest( - tokenA, organizationA.id(), USER_B.getUserId(), Role.Admin.name())) + tokenA, organizationA.id(), USER_B.userId(), Role.Admin.name())) .block(TIMEOUT); organizationService .inviteMember( new InviteOrganizationMemberRequest( - tokenA, organizationA.id(), USER_C.getUserId(), Role.Admin.name())) + tokenA, organizationA.id(), USER_C.userId(), Role.Admin.name())) .block(TIMEOUT); organizationService .inviteMember( new InviteOrganizationMemberRequest( - tokenA, organizationA.id(), USER_D.getUserId(), Role.Member.name())) + tokenA, organizationA.id(), USER_D.userId(), Role.Member.name())) .block(TIMEOUT); StepVerifier.create( organizationService .kickoutMember( new KickoutOrganizationMemberRequest( - organizationA.id(), tokenB, USER_C.getUserId())) + organizationA.id(), tokenB, USER_C.userId())) .then( organizationService.kickoutMember( new KickoutOrganizationMemberRequest( - organizationA.id(), tokenB, USER_D.getUserId()))) + organizationA.id(), tokenB, USER_D.userId()))) .then( organizationService.getOrganizationMembers( new GetOrganizationMembersRequest(organizationA.id(), tokenB)))) @@ -176,8 +176,8 @@ void kickoutByAdmin(OrganizationService organizationService) { .map(OrganizationMember::id) .collect(Collectors.toList()); - assertFalse(members.contains(USER_C.getUserId()), "member is found in organization"); - assertFalse(members.contains(USER_D.getUserId()), "member is found in organization"); + assertFalse(members.contains(USER_C.userId()), "member is found in organization"); + assertFalse(members.contains(USER_D.userId()), "member is found in organization"); }) .verifyComplete(); } @@ -193,26 +193,26 @@ void kickoutAdminByOwner(OrganizationService organizationService) { organizationService .createOrganization( new CreateOrganizationRequest( - RandomStringUtils.randomAlphabetic(10), USER_A.getEmail(), tokenA)) + RandomStringUtils.randomAlphabetic(10), USER_A.email(), tokenA)) .block(TIMEOUT); organizationService .inviteMember( new InviteOrganizationMemberRequest( - tokenA, organizationA.id(), USER_B.getUserId(), Role.Owner.name())) + tokenA, organizationA.id(), USER_B.userId(), Role.Owner.name())) .block(TIMEOUT); organizationService .inviteMember( new InviteOrganizationMemberRequest( - tokenA, organizationA.id(), USER_C.getUserId(), Role.Admin.name())) + tokenA, organizationA.id(), USER_C.userId(), Role.Admin.name())) .block(TIMEOUT); StepVerifier.create( organizationService .kickoutMember( new KickoutOrganizationMemberRequest( - organizationA.id(), tokenB, USER_C.getUserId())) + organizationA.id(), tokenB, USER_C.userId())) .then( organizationService.getOrganizationMembers( new GetOrganizationMembersRequest(organizationA.id(), tokenB)))) @@ -223,7 +223,7 @@ void kickoutAdminByOwner(OrganizationService organizationService) { .map(OrganizationMember::id) .collect(Collectors.toList()); - assertFalse(members.contains(USER_C.getUserId()), "member is found in organization"); + assertFalse(members.contains(USER_C.userId()), "member is found in organization"); }) .verifyComplete(); } @@ -239,20 +239,20 @@ void kickoutYourselfByOwner(OrganizationService organizationService) { organizationService .createOrganization( new CreateOrganizationRequest( - RandomStringUtils.randomAlphabetic(10), USER_A.getEmail(), tokenA)) + RandomStringUtils.randomAlphabetic(10), USER_A.email(), tokenA)) .block(TIMEOUT); organizationService .inviteMember( new InviteOrganizationMemberRequest( - tokenA, organizationA.id(), USER_B.getUserId(), Role.Owner.name())) + tokenA, organizationA.id(), USER_B.userId(), Role.Owner.name())) .block(TIMEOUT); StepVerifier.create( organizationService .kickoutMember( new KickoutOrganizationMemberRequest( - organizationA.id(), tokenA, USER_A.getUserId())) + organizationA.id(), tokenA, USER_A.userId())) .then( organizationService.getOrganizationMembers( new GetOrganizationMembersRequest(organizationA.id(), tokenB)))) @@ -263,7 +263,7 @@ void kickoutYourselfByOwner(OrganizationService organizationService) { .map(OrganizationMember::id) .collect(Collectors.toList()); - assertFalse(members.contains(USER_A.getUserId()), "member is found in organization"); + assertFalse(members.contains(USER_A.userId()), "member is found in organization"); }) .verifyComplete(); } @@ -279,20 +279,20 @@ void kickoutYourselfByAdmin(OrganizationService organizationService) { organizationService .createOrganization( new CreateOrganizationRequest( - RandomStringUtils.randomAlphabetic(10), USER_A.getEmail(), tokenA)) + RandomStringUtils.randomAlphabetic(10), USER_A.email(), tokenA)) .block(TIMEOUT); organizationService .inviteMember( new InviteOrganizationMemberRequest( - tokenA, organizationA.id(), USER_B.getUserId(), Role.Admin.name())) + tokenA, organizationA.id(), USER_B.userId(), Role.Admin.name())) .block(TIMEOUT); StepVerifier.create( organizationService .kickoutMember( new KickoutOrganizationMemberRequest( - organizationA.id(), tokenB, USER_B.getUserId())) + organizationA.id(), tokenB, USER_B.userId())) .then( organizationService.getOrganizationMembers( new GetOrganizationMembersRequest(organizationA.id(), tokenA)))) @@ -303,7 +303,7 @@ void kickoutYourselfByAdmin(OrganizationService organizationService) { .map(OrganizationMember::id) .collect(Collectors.toList()); - assertFalse(members.contains(USER_B.getUserId()), "member is found in organization"); + assertFalse(members.contains(USER_B.userId()), "member is found in organization"); }) .verifyComplete(); } @@ -318,13 +318,13 @@ void kickoutSingleOwnerByOwner(OrganizationService organizationService) { organizationService .createOrganization( new CreateOrganizationRequest( - RandomStringUtils.randomAlphabetic(10), USER_A.getEmail(), tokenA)) + RandomStringUtils.randomAlphabetic(10), USER_A.email(), tokenA)) .block(TIMEOUT); StepVerifier.create( organizationService.kickoutMember( new KickoutOrganizationMemberRequest( - organizationA.id(), tokenA, USER_A.getUserId()))) + organizationA.id(), tokenA, USER_A.userId()))) .expectErrorSatisfies( e -> { assertEquals(IllegalStateException.class, e.getClass()); @@ -348,28 +348,28 @@ void kickoutSingleOwnerByAdmin(OrganizationService organizationService) { organizationService .createOrganization( new CreateOrganizationRequest( - RandomStringUtils.randomAlphabetic(10), USER_A.getEmail(), tokenA)) + RandomStringUtils.randomAlphabetic(10), USER_A.email(), tokenA)) .block(TIMEOUT); organizationService .inviteMember( new InviteOrganizationMemberRequest( - tokenA, organizationA.id(), USER_B.getUserId(), Role.Admin.name())) + tokenA, organizationA.id(), USER_B.userId(), Role.Admin.name())) .block(TIMEOUT); StepVerifier.create( organizationService.kickoutMember( new KickoutOrganizationMemberRequest( - organizationA.id(), tokenB, USER_A.getUserId()))) + organizationA.id(), tokenB, USER_A.userId()))) .expectErrorSatisfies( e -> { assertEquals(AccessPermissionException.class, e.getClass()); assertEquals( String.format( "user: '%s', name: '%s', role: 'Admin' cannot kickout user: '%s' in role 'Owner' of organization: '%s'", - USER_B.getUserId(), - USER_B.getName(), - USER_A.getUserId(), + USER_B.userId(), + USER_B.name(), + USER_A.userId(), organizationA.name()), e.getMessage()); }) @@ -387,32 +387,32 @@ void kickoutMemberByMember(OrganizationService organizationService) { organizationService .createOrganization( new CreateOrganizationRequest( - RandomStringUtils.randomAlphabetic(10), USER_A.getEmail(), tokenA)) + RandomStringUtils.randomAlphabetic(10), USER_A.email(), tokenA)) .block(TIMEOUT); organizationService .inviteMember( new InviteOrganizationMemberRequest( - tokenA, organizationA.id(), USER_B.getUserId(), Role.Member.name())) + tokenA, organizationA.id(), USER_B.userId(), Role.Member.name())) .block(TIMEOUT); organizationService .inviteMember( new InviteOrganizationMemberRequest( - tokenA, organizationA.id(), USER_C.getUserId(), Role.Member.name())) + tokenA, organizationA.id(), USER_C.userId(), Role.Member.name())) .block(TIMEOUT); StepVerifier.create( organizationService.kickoutMember( new KickoutOrganizationMemberRequest( - organizationA.id(), tokenB, USER_C.getUserId()))) + organizationA.id(), tokenB, USER_C.userId()))) .expectErrorSatisfies( e -> { assertEquals(AccessPermissionException.class, e.getClass()); assertEquals( String.format( "user: '%s', name: '%s', not in role Owner or Admin of organization: '%s'", - USER_B.getUserId(), USER_B.getName(), organizationA.name()), + USER_B.userId(), USER_B.name(), organizationA.name()), e.getMessage()); }) .verify(); @@ -429,31 +429,31 @@ void kickoutByMember(OrganizationService organizationService) { organizationService .createOrganization( new CreateOrganizationRequest( - RandomStringUtils.randomAlphabetic(10), USER_A.getEmail(), tokenA)) + RandomStringUtils.randomAlphabetic(10), USER_A.email(), tokenA)) .block(TIMEOUT); organizationService .inviteMember( new InviteOrganizationMemberRequest( - tokenA, organizationA.id(), USER_B.getUserId(), Role.Owner.name())) + tokenA, organizationA.id(), USER_B.userId(), Role.Owner.name())) .block(TIMEOUT); organizationService .kickoutMember( - new KickoutOrganizationMemberRequest(organizationA.id(), tokenB, USER_A.getUserId())) + new KickoutOrganizationMemberRequest(organizationA.id(), tokenB, USER_A.userId())) .block(TIMEOUT); StepVerifier.create( organizationService.kickoutMember( new KickoutOrganizationMemberRequest( - organizationA.id(), tokenA, USER_B.getUserId()))) + organizationA.id(), tokenA, USER_B.userId()))) .expectErrorSatisfies( e -> { assertEquals(AccessPermissionException.class, e.getClass()); assertEquals( String.format( "user: '%s', name: '%s', not in role Owner or Admin of organization: '%s'", - USER_A.getUserId(), USER_A.getName(), organizationA.name()), + USER_A.userId(), USER_A.name(), organizationA.name()), e.getMessage()); }) .verify(); @@ -468,7 +468,7 @@ void kickoutUsingExpiredToken(OrganizationService organizationService) { StepVerifier.create( organizationService.kickoutMember( new KickoutOrganizationMemberRequest( - "ORG-organization-1", tokenA, USER_B.getUserId()))) + "ORG-organization-1", tokenA, USER_B.userId()))) .expectErrorSatisfies( e -> { assertEquals(InvalidTokenException.class, e.getClass()); diff --git a/scalecube-organization/src/test/java/io/scalecube/organization/it/LeaveOrganizationIntegrationTest.java b/scalecube-organization/src/test/java/io/scalecube/organization/it/LeaveOrganizationIntegrationTest.java index ad1f718..d3f8a24 100644 --- a/scalecube-organization/src/test/java/io/scalecube/organization/it/LeaveOrganizationIntegrationTest.java +++ b/scalecube-organization/src/test/java/io/scalecube/organization/it/LeaveOrganizationIntegrationTest.java @@ -12,7 +12,7 @@ import io.scalecube.account.api.Token; import io.scalecube.organization.fixtures.InMemoryOrganizationServiceFixture; import io.scalecube.organization.repository.inmem.InMemoryPublicKeyProvider; -import io.scalecube.security.Profile; +import io.scalecube.security.api.Profile; import io.scalecube.test.fixtures.Fixtures; import io.scalecube.test.fixtures.WithFixture; import java.time.Duration; @@ -47,7 +47,7 @@ void testLeaveOrganizationByOwner(OrganizationService service) { service .createOrganization( new CreateOrganizationRequest( - RandomStringUtils.randomAlphabetic(10), userA.getEmail(), userAToken)) + RandomStringUtils.randomAlphabetic(10), userA.email(), userAToken)) .map(OrganizationInfo::id) .block(TIMEOUT); @@ -55,7 +55,7 @@ void testLeaveOrganizationByOwner(OrganizationService service) { service .inviteMember( new InviteOrganizationMemberRequest( - userAToken, organizationId, userB.getUserId(), Role.Owner.name())) + userAToken, organizationId, userB.userId(), Role.Owner.name())) .block(TIMEOUT); // the user "A" requested to leave its organization @@ -79,7 +79,7 @@ void testLeaveOrganizationByAdmin(OrganizationService service) { service .createOrganization( new CreateOrganizationRequest( - RandomStringUtils.randomAlphabetic(10), userA.getEmail(), userAToken)) + RandomStringUtils.randomAlphabetic(10), userA.email(), userAToken)) .map(OrganizationInfo::id) .block(TIMEOUT); @@ -87,7 +87,7 @@ void testLeaveOrganizationByAdmin(OrganizationService service) { service .inviteMember( new InviteOrganizationMemberRequest( - userAToken, organizationId, userB.getUserId(), Role.Admin.name())) + userAToken, organizationId, userB.userId(), Role.Admin.name())) .block(TIMEOUT); // the user "B" requested to leave its organization @@ -111,7 +111,7 @@ void testLeaveOrganizationByMember(OrganizationService service) { service .createOrganization( new CreateOrganizationRequest( - RandomStringUtils.randomAlphabetic(10), userA.getEmail(), userAToken)) + RandomStringUtils.randomAlphabetic(10), userA.email(), userAToken)) .map(OrganizationInfo::id) .block(TIMEOUT); @@ -119,7 +119,7 @@ void testLeaveOrganizationByMember(OrganizationService service) { service .inviteMember( new InviteOrganizationMemberRequest( - userAToken, organizationId, userB.getUserId(), Role.Member.name())) + userAToken, organizationId, userB.userId(), Role.Member.name())) .block(TIMEOUT); // the user "B" requested to leave its organization @@ -141,7 +141,7 @@ void testFailToLeaveOrganizationBySingleOwner(OrganizationService service) { service .createOrganization( new CreateOrganizationRequest( - RandomStringUtils.randomAlphabetic(10), userA.getEmail(), userAToken)) + RandomStringUtils.randomAlphabetic(10), userA.email(), userAToken)) .map(OrganizationInfo::id) .block(TIMEOUT); @@ -167,7 +167,7 @@ void testFailToLeaveOrganizationWithNonMember(OrganizationService service) { .createOrganization( new CreateOrganizationRequest( RandomStringUtils.randomAlphabetic(10), - TestProfiles.USER_A.getEmail(), + TestProfiles.USER_A.email(), userAToken)) .map(OrganizationInfo::id) .block(TIMEOUT); diff --git a/scalecube-organization/src/test/java/io/scalecube/organization/it/TestProfiles.java b/scalecube-organization/src/test/java/io/scalecube/organization/it/TestProfiles.java index 42212fa..cd4958e 100644 --- a/scalecube-organization/src/test/java/io/scalecube/organization/it/TestProfiles.java +++ b/scalecube-organization/src/test/java/io/scalecube/organization/it/TestProfiles.java @@ -1,6 +1,6 @@ package io.scalecube.organization.it; -import io.scalecube.security.Profile; +import io.scalecube.security.api.Profile; public interface TestProfiles { diff --git a/scalecube-organization/src/test/java/io/scalecube/organization/it/UpdateMemberRoleTest.java b/scalecube-organization/src/test/java/io/scalecube/organization/it/UpdateMemberRoleTest.java index fb47d80..bcf35e4 100644 --- a/scalecube-organization/src/test/java/io/scalecube/organization/it/UpdateMemberRoleTest.java +++ b/scalecube-organization/src/test/java/io/scalecube/organization/it/UpdateMemberRoleTest.java @@ -45,20 +45,20 @@ void updateMemberToAdminByOwner(OrganizationService organizationService) { organizationService .createOrganization( new CreateOrganizationRequest( - RandomStringUtils.randomAlphabetic(10), USER_A.getEmail(), tokenA)) + RandomStringUtils.randomAlphabetic(10), USER_A.email(), tokenA)) .block(TIMEOUT); organizationService .inviteMember( new InviteOrganizationMemberRequest( - tokenA, organizationA.id(), USER_B.getUserId(), Role.Member.name())) + tokenA, organizationA.id(), USER_B.userId(), Role.Member.name())) .block(TIMEOUT); StepVerifier.create( organizationService .updateOrganizationMemberRole( new UpdateOrganizationMemberRoleRequest( - tokenA, organizationA.id(), USER_B.getUserId(), Role.Admin.name())) + tokenA, organizationA.id(), USER_B.userId(), Role.Admin.name())) .then( organizationService.getOrganizationMembers( new GetOrganizationMembersRequest(organizationA.id(), tokenA)))) @@ -68,8 +68,8 @@ void updateMemberToAdminByOwner(OrganizationService organizationService) { Stream.of(response.members()) .collect(Collectors.toMap(OrganizationMember::id, OrganizationMember::role)); - assertNotNull(members.get(USER_B.getUserId()), "member is not found in organization"); - assertEquals(Role.Admin.name(), members.get(USER_B.getUserId())); + assertNotNull(members.get(USER_B.userId()), "member is not found in organization"); + assertEquals(Role.Admin.name(), members.get(USER_B.userId())); }) .verifyComplete(); } @@ -84,20 +84,20 @@ void updateMemberToOwnerByOwner(OrganizationService organizationService) { organizationService .createOrganization( new CreateOrganizationRequest( - RandomStringUtils.randomAlphabetic(10), USER_A.getEmail(), tokenA)) + RandomStringUtils.randomAlphabetic(10), USER_A.email(), tokenA)) .block(TIMEOUT); organizationService .inviteMember( new InviteOrganizationMemberRequest( - tokenA, organizationA.id(), USER_B.getUserId(), Role.Member.name())) + tokenA, organizationA.id(), USER_B.userId(), Role.Member.name())) .block(TIMEOUT); StepVerifier.create( organizationService .updateOrganizationMemberRole( new UpdateOrganizationMemberRoleRequest( - tokenA, organizationA.id(), USER_B.getUserId(), Role.Owner.name())) + tokenA, organizationA.id(), USER_B.userId(), Role.Owner.name())) .then( organizationService.getOrganizationMembers( new GetOrganizationMembersRequest(organizationA.id(), tokenA)))) @@ -107,8 +107,8 @@ void updateMemberToOwnerByOwner(OrganizationService organizationService) { Stream.of(response.members()) .collect(Collectors.toMap(OrganizationMember::id, OrganizationMember::role)); - assertNotNull(members.get(USER_B.getUserId()), "member is not found in organization"); - assertEquals(Role.Owner.name(), members.get(USER_B.getUserId())); + assertNotNull(members.get(USER_B.userId()), "member is not found in organization"); + assertEquals(Role.Owner.name(), members.get(USER_B.userId())); }) .verifyComplete(); } @@ -123,20 +123,20 @@ void updateAdminToOwnerByOwner(OrganizationService organizationService) { organizationService .createOrganization( new CreateOrganizationRequest( - RandomStringUtils.randomAlphabetic(10), USER_A.getEmail(), tokenA)) + RandomStringUtils.randomAlphabetic(10), USER_A.email(), tokenA)) .block(TIMEOUT); organizationService .inviteMember( new InviteOrganizationMemberRequest( - tokenA, organizationA.id(), USER_B.getUserId(), Role.Admin.name())) + tokenA, organizationA.id(), USER_B.userId(), Role.Admin.name())) .block(TIMEOUT); StepVerifier.create( organizationService .updateOrganizationMemberRole( new UpdateOrganizationMemberRoleRequest( - tokenA, organizationA.id(), USER_B.getUserId(), Role.Owner.name())) + tokenA, organizationA.id(), USER_B.userId(), Role.Owner.name())) .then( organizationService.getOrganizationMembers( new GetOrganizationMembersRequest(organizationA.id(), tokenA)))) @@ -146,8 +146,8 @@ void updateAdminToOwnerByOwner(OrganizationService organizationService) { Stream.of(response.members()) .collect(Collectors.toMap(OrganizationMember::id, OrganizationMember::role)); - assertNotNull(members.get(USER_B.getUserId()), "member is not found in organization"); - assertEquals(Role.Owner.name(), members.get(USER_B.getUserId())); + assertNotNull(members.get(USER_B.userId()), "member is not found in organization"); + assertEquals(Role.Owner.name(), members.get(USER_B.userId())); }) .verifyComplete(); } @@ -163,26 +163,26 @@ void updateMemberToAdminByAdmin(OrganizationService organizationService) { organizationService .createOrganization( new CreateOrganizationRequest( - RandomStringUtils.randomAlphabetic(10), USER_A.getEmail(), tokenA)) + RandomStringUtils.randomAlphabetic(10), USER_A.email(), tokenA)) .block(TIMEOUT); organizationService .inviteMember( new InviteOrganizationMemberRequest( - tokenA, organizationA.id(), USER_B.getUserId(), Role.Admin.name())) + tokenA, organizationA.id(), USER_B.userId(), Role.Admin.name())) .block(TIMEOUT); organizationService .inviteMember( new InviteOrganizationMemberRequest( - tokenA, organizationA.id(), USER_C.getUserId(), Role.Member.name())) + tokenA, organizationA.id(), USER_C.userId(), Role.Member.name())) .block(TIMEOUT); StepVerifier.create( organizationService .updateOrganizationMemberRole( new UpdateOrganizationMemberRoleRequest( - tokenB, organizationA.id(), USER_C.getUserId(), Role.Admin.name())) + tokenB, organizationA.id(), USER_C.userId(), Role.Admin.name())) .then( organizationService.getOrganizationMembers( new GetOrganizationMembersRequest(organizationA.id(), tokenB)))) @@ -192,8 +192,8 @@ void updateMemberToAdminByAdmin(OrganizationService organizationService) { Stream.of(response.members()) .collect(Collectors.toMap(OrganizationMember::id, OrganizationMember::role)); - assertNotNull(members.get(USER_C.getUserId()), "member is not found in organization"); - assertEquals(Role.Admin.name(), members.get(USER_C.getUserId())); + assertNotNull(members.get(USER_C.userId()), "member is not found in organization"); + assertEquals(Role.Admin.name(), members.get(USER_C.userId())); }) .verifyComplete(); } @@ -208,20 +208,20 @@ void updateOwnerToAdminByOwner(OrganizationService organizationService) { organizationService .createOrganization( new CreateOrganizationRequest( - RandomStringUtils.randomAlphabetic(10), USER_A.getEmail(), tokenA)) + RandomStringUtils.randomAlphabetic(10), USER_A.email(), tokenA)) .block(TIMEOUT); organizationService .inviteMember( new InviteOrganizationMemberRequest( - tokenA, organizationA.id(), USER_B.getUserId(), Role.Owner.name())) + tokenA, organizationA.id(), USER_B.userId(), Role.Owner.name())) .block(TIMEOUT); StepVerifier.create( organizationService .updateOrganizationMemberRole( new UpdateOrganizationMemberRoleRequest( - tokenA, organizationA.id(), USER_B.getUserId(), Role.Admin.name())) + tokenA, organizationA.id(), USER_B.userId(), Role.Admin.name())) .then( organizationService.getOrganizationMembers( new GetOrganizationMembersRequest(organizationA.id(), tokenA)))) @@ -231,8 +231,8 @@ void updateOwnerToAdminByOwner(OrganizationService organizationService) { Stream.of(response.members()) .collect(Collectors.toMap(OrganizationMember::id, OrganizationMember::role)); - assertNotNull(members.get(USER_B.getUserId()), "member is not found in organization"); - assertEquals(Role.Admin.name(), members.get(USER_B.getUserId())); + assertNotNull(members.get(USER_B.userId()), "member is not found in organization"); + assertEquals(Role.Admin.name(), members.get(USER_B.userId())); }) .verifyComplete(); } @@ -247,20 +247,20 @@ void updateOwnerToMemberByOwner(OrganizationService organizationService) { organizationService .createOrganization( new CreateOrganizationRequest( - RandomStringUtils.randomAlphabetic(10), USER_A.getEmail(), tokenA)) + RandomStringUtils.randomAlphabetic(10), USER_A.email(), tokenA)) .block(TIMEOUT); organizationService .inviteMember( new InviteOrganizationMemberRequest( - tokenA, organizationA.id(), USER_B.getUserId(), Role.Owner.name())) + tokenA, organizationA.id(), USER_B.userId(), Role.Owner.name())) .block(TIMEOUT); StepVerifier.create( organizationService .updateOrganizationMemberRole( new UpdateOrganizationMemberRoleRequest( - tokenA, organizationA.id(), USER_B.getUserId(), Role.Member.name())) + tokenA, organizationA.id(), USER_B.userId(), Role.Member.name())) .then( organizationService.getOrganizationMembers( new GetOrganizationMembersRequest(organizationA.id(), tokenA)))) @@ -270,8 +270,8 @@ void updateOwnerToMemberByOwner(OrganizationService organizationService) { Stream.of(response.members()) .collect(Collectors.toMap(OrganizationMember::id, OrganizationMember::role)); - assertNotNull(members.get(USER_B.getUserId()), "member is not found in organization"); - assertEquals(Role.Member.name(), members.get(USER_B.getUserId())); + assertNotNull(members.get(USER_B.userId()), "member is not found in organization"); + assertEquals(Role.Member.name(), members.get(USER_B.userId())); }) .verifyComplete(); } @@ -286,20 +286,20 @@ void updateAdminToMemberByOwner(OrganizationService organizationService) { organizationService .createOrganization( new CreateOrganizationRequest( - RandomStringUtils.randomAlphabetic(10), USER_A.getEmail(), tokenA)) + RandomStringUtils.randomAlphabetic(10), USER_A.email(), tokenA)) .block(TIMEOUT); organizationService .inviteMember( new InviteOrganizationMemberRequest( - tokenA, organizationA.id(), USER_B.getUserId(), Role.Admin.name())) + tokenA, organizationA.id(), USER_B.userId(), Role.Admin.name())) .block(TIMEOUT); StepVerifier.create( organizationService .updateOrganizationMemberRole( new UpdateOrganizationMemberRoleRequest( - tokenA, organizationA.id(), USER_B.getUserId(), Role.Member.name())) + tokenA, organizationA.id(), USER_B.userId(), Role.Member.name())) .then( organizationService.getOrganizationMembers( new GetOrganizationMembersRequest(organizationA.id(), tokenA)))) @@ -309,8 +309,8 @@ void updateAdminToMemberByOwner(OrganizationService organizationService) { Stream.of(response.members()) .collect(Collectors.toMap(OrganizationMember::id, OrganizationMember::role)); - assertNotNull(members.get(USER_B.getUserId()), "member is not found in organization"); - assertEquals(Role.Member.name(), members.get(USER_B.getUserId())); + assertNotNull(members.get(USER_B.userId()), "member is not found in organization"); + assertEquals(Role.Member.name(), members.get(USER_B.userId())); }) .verifyComplete(); } @@ -326,26 +326,26 @@ void updateAdminToMemberByAdmin(OrganizationService organizationService) { organizationService .createOrganization( new CreateOrganizationRequest( - RandomStringUtils.randomAlphabetic(10), USER_A.getEmail(), tokenA)) + RandomStringUtils.randomAlphabetic(10), USER_A.email(), tokenA)) .block(TIMEOUT); organizationService .inviteMember( new InviteOrganizationMemberRequest( - tokenA, organizationA.id(), USER_B.getUserId(), Role.Admin.name())) + tokenA, organizationA.id(), USER_B.userId(), Role.Admin.name())) .block(TIMEOUT); organizationService .inviteMember( new InviteOrganizationMemberRequest( - tokenA, organizationA.id(), USER_C.getUserId(), Role.Admin.name())) + tokenA, organizationA.id(), USER_C.userId(), Role.Admin.name())) .block(TIMEOUT); StepVerifier.create( organizationService .updateOrganizationMemberRole( new UpdateOrganizationMemberRoleRequest( - tokenB, organizationA.id(), USER_C.getUserId(), Role.Member.name())) + tokenB, organizationA.id(), USER_C.userId(), Role.Member.name())) .then( organizationService.getOrganizationMembers( new GetOrganizationMembersRequest(organizationA.id(), tokenB)))) @@ -355,8 +355,8 @@ void updateAdminToMemberByAdmin(OrganizationService organizationService) { Stream.of(response.members()) .collect(Collectors.toMap(OrganizationMember::id, OrganizationMember::role)); - assertNotNull(members.get(USER_C.getUserId()), "member is not found in organization"); - assertEquals(Role.Member.name(), members.get(USER_C.getUserId())); + assertNotNull(members.get(USER_C.userId()), "member is not found in organization"); + assertEquals(Role.Member.name(), members.get(USER_C.userId())); }) .verifyComplete(); } @@ -372,20 +372,20 @@ void updateOwnerToMemberByYourself(OrganizationService organizationService) { organizationService .createOrganization( new CreateOrganizationRequest( - RandomStringUtils.randomAlphabetic(10), USER_A.getEmail(), tokenA)) + RandomStringUtils.randomAlphabetic(10), USER_A.email(), tokenA)) .block(TIMEOUT); organizationService .inviteMember( new InviteOrganizationMemberRequest( - tokenA, organizationA.id(), USER_B.getUserId(), Role.Owner.name())) + tokenA, organizationA.id(), USER_B.userId(), Role.Owner.name())) .block(TIMEOUT); StepVerifier.create( organizationService .updateOrganizationMemberRole( new UpdateOrganizationMemberRoleRequest( - tokenA, organizationA.id(), USER_A.getUserId(), Role.Member.name())) + tokenA, organizationA.id(), USER_A.userId(), Role.Member.name())) .then( organizationService.getOrganizationMembers( new GetOrganizationMembersRequest(organizationA.id(), tokenB)))) @@ -395,8 +395,8 @@ void updateOwnerToMemberByYourself(OrganizationService organizationService) { Stream.of(response.members()) .collect(Collectors.toMap(OrganizationMember::id, OrganizationMember::role)); - assertNotNull(members.get(USER_A.getUserId()), "member is not found in organization"); - assertEquals(Role.Member.name(), members.get(USER_A.getUserId())); + assertNotNull(members.get(USER_A.userId()), "member is not found in organization"); + assertEquals(Role.Member.name(), members.get(USER_A.userId())); }) .verifyComplete(); } @@ -412,20 +412,20 @@ void updateAdminToMemberByYourself(OrganizationService organizationService) { organizationService .createOrganization( new CreateOrganizationRequest( - RandomStringUtils.randomAlphabetic(10), USER_A.getEmail(), tokenA)) + RandomStringUtils.randomAlphabetic(10), USER_A.email(), tokenA)) .block(TIMEOUT); organizationService .inviteMember( new InviteOrganizationMemberRequest( - tokenA, organizationA.id(), USER_B.getUserId(), Role.Admin.name())) + tokenA, organizationA.id(), USER_B.userId(), Role.Admin.name())) .block(TIMEOUT); StepVerifier.create( organizationService .updateOrganizationMemberRole( new UpdateOrganizationMemberRoleRequest( - tokenB, organizationA.id(), USER_B.getUserId(), Role.Member.name())) + tokenB, organizationA.id(), USER_B.userId(), Role.Member.name())) .then( organizationService.getOrganizationMembers( new GetOrganizationMembersRequest(organizationA.id(), tokenA)))) @@ -435,8 +435,8 @@ void updateAdminToMemberByYourself(OrganizationService organizationService) { Stream.of(response.members()) .collect(Collectors.toMap(OrganizationMember::id, OrganizationMember::role)); - assertNotNull(members.get(USER_B.getUserId()), "member is not found in organization"); - assertEquals(Role.Member.name(), members.get(USER_B.getUserId())); + assertNotNull(members.get(USER_B.userId()), "member is not found in organization"); + assertEquals(Role.Member.name(), members.get(USER_B.userId())); }) .verifyComplete(); } @@ -451,14 +451,14 @@ void updateLastOwnerToMember(OrganizationService organizationService) { organizationService .createOrganization( new CreateOrganizationRequest( - RandomStringUtils.randomAlphabetic(10), USER_A.getEmail(), tokenA)) + RandomStringUtils.randomAlphabetic(10), USER_A.email(), tokenA)) .block(TIMEOUT); StepVerifier.create( organizationService .updateOrganizationMemberRole( new UpdateOrganizationMemberRoleRequest( - tokenA, organizationA.id(), USER_A.getUserId(), Role.Member.name())) + tokenA, organizationA.id(), USER_A.userId(), Role.Member.name())) .then( organizationService.getOrganizationMembers( new GetOrganizationMembersRequest(organizationA.id(), tokenA)))) @@ -485,26 +485,26 @@ void updateMemberToOwnerByAdmin(OrganizationService organizationService) { organizationService .createOrganization( new CreateOrganizationRequest( - RandomStringUtils.randomAlphabetic(10), USER_A.getEmail(), tokenA)) + RandomStringUtils.randomAlphabetic(10), USER_A.email(), tokenA)) .block(TIMEOUT); organizationService .inviteMember( new InviteOrganizationMemberRequest( - tokenA, organizationA.id(), USER_B.getUserId(), Role.Member.name())) + tokenA, organizationA.id(), USER_B.userId(), Role.Member.name())) .block(TIMEOUT); organizationService .inviteMember( new InviteOrganizationMemberRequest( - tokenA, organizationA.id(), USER_C.getUserId(), Role.Admin.name())) + tokenA, organizationA.id(), USER_C.userId(), Role.Admin.name())) .block(TIMEOUT); StepVerifier.create( organizationService .updateOrganizationMemberRole( new UpdateOrganizationMemberRoleRequest( - tokenC, organizationA.id(), USER_B.getUserId(), Role.Owner.name())) + tokenC, organizationA.id(), USER_B.userId(), Role.Owner.name())) .then( organizationService.getOrganizationMembers( new GetOrganizationMembersRequest(organizationA.id(), tokenA)))) @@ -514,7 +514,7 @@ void updateMemberToOwnerByAdmin(OrganizationService organizationService) { assertEquals( String.format( "user: '%s', name: '%s', role: '%s', cannot promote to a higher role: '%s'", - USER_C.getUserId(), USER_C.getName(), Role.Admin.name(), Role.Owner.name()), + USER_C.userId(), USER_C.name(), Role.Admin.name(), Role.Owner.name()), e.getMessage()); }) .verify(); @@ -531,26 +531,26 @@ void updateByMember(OrganizationService organizationService) { organizationService .createOrganization( new CreateOrganizationRequest( - RandomStringUtils.randomAlphabetic(10), USER_A.getEmail(), tokenA)) + RandomStringUtils.randomAlphabetic(10), USER_A.email(), tokenA)) .block(TIMEOUT); organizationService .inviteMember( new InviteOrganizationMemberRequest( - tokenA, organizationA.id(), USER_B.getUserId(), Role.Admin.name())) + tokenA, organizationA.id(), USER_B.userId(), Role.Admin.name())) .block(TIMEOUT); organizationService .inviteMember( new InviteOrganizationMemberRequest( - tokenA, organizationA.id(), USER_C.getUserId(), Role.Member.name())) + tokenA, organizationA.id(), USER_C.userId(), Role.Member.name())) .block(TIMEOUT); StepVerifier.create( organizationService .updateOrganizationMemberRole( new UpdateOrganizationMemberRoleRequest( - tokenC, organizationA.id(), USER_B.getUserId(), Role.Member.name())) + tokenC, organizationA.id(), USER_B.userId(), Role.Member.name())) .then( organizationService.getOrganizationMembers( new GetOrganizationMembersRequest(organizationA.id(), tokenA)))) @@ -560,7 +560,7 @@ void updateByMember(OrganizationService organizationService) { assertEquals( String.format( "user: '%s', name: '%s', not in role Owner or Admin of organization: '%s'", - USER_C.getUserId(), USER_C.getName(), organizationA.name()), + USER_C.userId(), USER_C.name(), organizationA.name()), e.getMessage()); }) .verify(); @@ -577,31 +577,31 @@ void updateByRemovedOwner(OrganizationService organizationService) { organizationService .createOrganization( new CreateOrganizationRequest( - RandomStringUtils.randomAlphabetic(10), USER_A.getEmail(), tokenA)) + RandomStringUtils.randomAlphabetic(10), USER_A.email(), tokenA)) .block(TIMEOUT); organizationService .inviteMember( new InviteOrganizationMemberRequest( - tokenA, organizationA.id(), USER_B.getUserId(), Role.Owner.name())) + tokenA, organizationA.id(), USER_B.userId(), Role.Owner.name())) .block(TIMEOUT); organizationService .inviteMember( new InviteOrganizationMemberRequest( - tokenA, organizationA.id(), USER_C.getUserId(), Role.Member.name())) + tokenA, organizationA.id(), USER_C.userId(), Role.Member.name())) .block(TIMEOUT); organizationService .kickoutMember( - new KickoutOrganizationMemberRequest(organizationA.id(), tokenB, USER_A.getUserId())) + new KickoutOrganizationMemberRequest(organizationA.id(), tokenB, USER_A.userId())) .block(TIMEOUT); StepVerifier.create( organizationService .updateOrganizationMemberRole( new UpdateOrganizationMemberRoleRequest( - tokenA, organizationA.id(), USER_C.getUserId(), Role.Admin.name())) + tokenA, organizationA.id(), USER_C.userId(), Role.Admin.name())) .then( organizationService.getOrganizationMembers( new GetOrganizationMembersRequest(organizationA.id(), tokenB)))) @@ -611,7 +611,7 @@ void updateByRemovedOwner(OrganizationService organizationService) { assertEquals( String.format( "user: '%s', name: '%s', not in role Owner or Admin of organization: '%s'", - USER_A.getUserId(), USER_A.getName(), organizationA.name()), + USER_A.userId(), USER_A.name(), organizationA.name()), e.getMessage()); }) .verify(); @@ -626,7 +626,7 @@ void updateUsingExpiredToken(OrganizationService organizationService) { StepVerifier.create( organizationService.updateOrganizationMemberRole( new UpdateOrganizationMemberRoleRequest( - tokenA, "ORG-organizatnio-1", USER_B.getUserId(), Role.Member.name()))) + tokenA, "ORG-organizatnio-1", USER_B.userId(), Role.Member.name()))) .expectErrorSatisfies( e -> { assertEquals(InvalidTokenException.class, e.getClass()); diff --git a/scalecube-organization/src/test/java/io/scalecube/organization/it/UpdateOrganizationIntegrationTest.java b/scalecube-organization/src/test/java/io/scalecube/organization/it/UpdateOrganizationIntegrationTest.java index 65be5b6..fd91ae7 100644 --- a/scalecube-organization/src/test/java/io/scalecube/organization/it/UpdateOrganizationIntegrationTest.java +++ b/scalecube-organization/src/test/java/io/scalecube/organization/it/UpdateOrganizationIntegrationTest.java @@ -17,7 +17,7 @@ import io.scalecube.account.api.UpdateOrganizationRequest; import io.scalecube.organization.fixtures.InMemoryOrganizationServiceFixture; import io.scalecube.organization.repository.inmem.InMemoryPublicKeyProvider; -import io.scalecube.security.Profile; +import io.scalecube.security.api.Profile; import io.scalecube.test.fixtures.Fixtures; import io.scalecube.test.fixtures.WithFixture; import java.time.Duration; @@ -53,13 +53,13 @@ void testUpdateOrganizationByOwner(OrganizationService service) { String organizationName = RandomStringUtils.randomAlphabetic(10); String newOrganizationName = "new" + organizationName; - String newEmail = "new" + userA.getEmail(); + String newEmail = "new" + userA.email(); // create a single organization which will be owned by user "A" String organizationId = service .createOrganization( - new CreateOrganizationRequest(organizationName, userA.getEmail(), userAToken)) + new CreateOrganizationRequest(organizationName, userA.email(), userAToken)) .map(OrganizationInfo::id) .block(TIMEOUT); @@ -107,13 +107,13 @@ void testUpdateOrganizationByAdmin(OrganizationService service) { String organizationName = RandomStringUtils.randomAlphabetic(10); String newOrganizationName = "new" + organizationName; - String newEmail = "new" + userA.getEmail(); + String newEmail = "new" + userA.email(); // create a single organization which will be owned by user "A" String organizationId = service .createOrganization( - new CreateOrganizationRequest(organizationName, userA.getEmail(), userAToken)) + new CreateOrganizationRequest(organizationName, userA.email(), userAToken)) .map(OrganizationInfo::id) .block(TIMEOUT); @@ -140,7 +140,7 @@ void testUpdateOrganizationByAdmin(OrganizationService service) { service .inviteMember( new InviteOrganizationMemberRequest( - userAToken, organizationId, userB.getUserId(), Role.Admin.name())) + userAToken, organizationId, userB.userId(), Role.Admin.name())) .block(TIMEOUT); // user "B" updates repo name and email in the organization @@ -173,13 +173,13 @@ void testUpdateOrganizationByMember(OrganizationService service) { String organizationName = RandomStringUtils.randomAlphabetic(10); String newOrganizationName = "new" + organizationName; - String newEmail = "new" + userA.getEmail(); + String newEmail = "new" + userA.email(); // create a single organization which will be owned by user "A" String organizationId = service .createOrganization( - new CreateOrganizationRequest(organizationName, userA.getEmail(), userAToken)) + new CreateOrganizationRequest(organizationName, userA.email(), userAToken)) .map(OrganizationInfo::id) .block(TIMEOUT); @@ -187,14 +187,14 @@ void testUpdateOrganizationByMember(OrganizationService service) { service .inviteMember( new InviteOrganizationMemberRequest( - userAToken, organizationId, userB.getUserId(), Role.Member.name())) + userAToken, organizationId, userB.userId(), Role.Member.name())) .block(TIMEOUT); // the user "A" updates the user "B" role to "owner" in the own organization service .updateOrganizationMemberRole( new UpdateOrganizationMemberRoleRequest( - userAToken, organizationId, userB.getUserId(), Role.Owner.name())) + userAToken, organizationId, userB.userId(), Role.Owner.name())) .block(TIMEOUT); // user "B" updates repo name and email in the organization @@ -226,13 +226,13 @@ void testFailToUpdateOrganizationMemberByMember(OrganizationService service) { String organizationName = RandomStringUtils.randomAlphabetic(10); String newOrganizationName = "new" + organizationName; - String newEmail = "new" + userA.getEmail(); + String newEmail = "new" + userA.email(); // create a single organization which will be owned by user "A" String organizationId = service .createOrganization( - new CreateOrganizationRequest(organizationName, userA.getEmail(), userAToken)) + new CreateOrganizationRequest(organizationName, userA.email(), userAToken)) .map(OrganizationInfo::id) .block(TIMEOUT); @@ -240,7 +240,7 @@ void testFailToUpdateOrganizationMemberByMember(OrganizationService service) { service .inviteMember( new InviteOrganizationMemberRequest( - userAToken, organizationId, userB.getUserId(), Role.Member.name())) + userAToken, organizationId, userB.userId(), Role.Member.name())) .block(TIMEOUT); // user "B" updates repo name and email in the organization @@ -251,7 +251,7 @@ void testFailToUpdateOrganizationMemberByMember(OrganizationService service) { .expectErrorMessage( String.format( "user: '%s', name: '%s', not in role Owner or Admin of organization: '%s'", - userB.getUserId(), userB.getName(), organizationName)) + userB.userId(), userB.name(), organizationName)) .verify(); } @@ -265,13 +265,13 @@ void testFailToUpdateOrganizationBecauseOwnerWasRemoved(OrganizationService serv String organizationName = RandomStringUtils.randomAlphabetic(10); String newOrganizationName = "new" + organizationName; - String newEmail = "new" + userA.getEmail(); + String newEmail = "new" + userA.email(); // create a single organization which will be owned by user "A" String organizationId = service .createOrganization( - new CreateOrganizationRequest(organizationName, userA.getEmail(), userAToken)) + new CreateOrganizationRequest(organizationName, userA.email(), userAToken)) .map(OrganizationInfo::id) .block(TIMEOUT); @@ -279,7 +279,7 @@ void testFailToUpdateOrganizationBecauseOwnerWasRemoved(OrganizationService serv service .inviteMember( new InviteOrganizationMemberRequest( - userAToken, organizationId, userB.getUserId(), Role.Owner.name())) + userAToken, organizationId, userB.userId(), Role.Owner.name())) .block(TIMEOUT); // the user "A" leaves own organization @@ -295,7 +295,7 @@ void testFailToUpdateOrganizationBecauseOwnerWasRemoved(OrganizationService serv .expectErrorMessage( String.format( "user: '%s', name: '%s', not in role Owner or Admin of organization: '%s'", - userA.getUserId(), userA.getName(), organizationName)) + userA.userId(), userA.name(), organizationName)) .verify(); } @@ -315,14 +315,14 @@ void testFailToUpdateOrganizationBecauseNameIsDuplicated(OrganizationService ser String userAOrganizationId = service .createOrganization( - new CreateOrganizationRequest(userAOrganizationName, userA.getEmail(), userAToken)) + new CreateOrganizationRequest(userAOrganizationName, userA.email(), userAToken)) .map(OrganizationInfo::id) .block(TIMEOUT); // create a single organization which will be owned by user "B" service .createOrganization( - new CreateOrganizationRequest(userBOrganizationName, userB.getEmail(), userBToken)) + new CreateOrganizationRequest(userBOrganizationName, userB.email(), userBToken)) .map(OrganizationInfo::id) .block(TIMEOUT); @@ -330,7 +330,7 @@ void testFailToUpdateOrganizationBecauseNameIsDuplicated(OrganizationService ser StepVerifier.create( service.updateOrganization( new UpdateOrganizationRequest( - userAOrganizationId, userAToken, userBOrganizationName, userA.getEmail()))) + userAOrganizationId, userAToken, userBOrganizationName, userA.email()))) .expectErrorMessage( String.format("Organization name: '%s' already in use", userBOrganizationName)) .verify(); @@ -347,7 +347,7 @@ void testFailToUpdateNonExistingOrganization(OrganizationService service) { StepVerifier.create( service.updateOrganization( new UpdateOrganizationRequest( - nonExistingOrganizationId, userAToken, "fictionalName", userA.getEmail()))) + nonExistingOrganizationId, userAToken, "fictionalName", userA.email()))) .expectErrorSatisfies( e -> { assertEquals(OrganizationNotFoundException.class, e.getClass()); @@ -372,7 +372,7 @@ void testFailToUpdateOrganizationNameWithNotAllowedSymbols(OrganizationService s String organizationId = service .createOrganization( - new CreateOrganizationRequest(organizationName, userA.getEmail(), userAToken)) + new CreateOrganizationRequest(organizationName, userA.email(), userAToken)) .map(OrganizationInfo::id) .block(TIMEOUT); @@ -380,7 +380,7 @@ void testFailToUpdateOrganizationNameWithNotAllowedSymbols(OrganizationService s StepVerifier.create( service.updateOrganization( new UpdateOrganizationRequest( - organizationId, userAToken, incorrectName, userA.getEmail()))) + organizationId, userAToken, incorrectName, userA.email()))) .expectErrorMessage( "Organization name can only contain characters in range A-Z, a-z, 0-9 as well as underscore, period, dash & percent") .verify(); @@ -395,7 +395,7 @@ void testFailToUpdateOrganizationWithInvalidToken(OrganizationService service) { StepVerifier.create( service.updateOrganization( new UpdateOrganizationRequest( - "organizationId", new Token("invalid"), "name", userA.getEmail()))) + "organizationId", new Token("invalid"), "name", userA.email()))) .expectErrorMessage("Token verification failed") .verify(); } diff --git a/scalecube-organization/src/test/java/io/scalecube/organization/repository/couchbase/JacksonTranslationServiceTest.java b/scalecube-organization/src/test/java/io/scalecube/organization/repository/couchbase/JacksonTranslationServiceTest.java index 8b4110a..98312d1 100644 --- a/scalecube-organization/src/test/java/io/scalecube/organization/repository/couchbase/JacksonTranslationServiceTest.java +++ b/scalecube-organization/src/test/java/io/scalecube/organization/repository/couchbase/JacksonTranslationServiceTest.java @@ -6,11 +6,11 @@ import io.scalecube.account.api.OrganizationMember; import io.scalecube.account.api.Role; -import io.scalecube.organization.operation.Organization; -import io.scalecube.security.Profile; +import io.scalecube.organization.domain.Organization; +import io.scalecube.security.api.Profile; import org.junit.jupiter.api.Test; -public class JacksonTranslationServiceTest { +class JacksonTranslationServiceTest { private final Profile testProfile = Profile.builder() @@ -23,34 +23,43 @@ public class JacksonTranslationServiceTest { .build(); @Test - public void shouldEncodeUser() { + void shouldEncodeUser() { JacksonTranslationService service = new JacksonTranslationService(); String s = service.encode(testProfile); assertNotNull(s); } @Test - public void shouldEncodeUserOrgMembership() { + void shouldEncodeUserOrgMembership() { JacksonTranslationService service = new JacksonTranslationService(); OrganizationMember member = - new OrganizationMember(testProfile.getUserId(), Role.Owner.toString()); + new OrganizationMember(testProfile.userId(), Role.Owner.toString()); String s = service.encode(member); assertNotNull(s); } @Test - public void shouldEncodeOrganization() { + void shouldEncodeOrganization() { JacksonTranslationService service = new JacksonTranslationService(); - String s = service.encode(new Organization.Builder().name("myorg").build()); + String s = service.encode(new Organization("1", "TEST-ORG", "test@scalecube.io", "1", "1")); assertNotNull(s); } @Test - public void shouldDecodeOrganization() { + void shouldDecodeOrganization() { JacksonTranslationService service = new JacksonTranslationService(); - String s = service.encode(new Organization.Builder().name("myorg").build()); + String id = "org-id"; + String name = "org-name"; + String email = "test@scalecube.io"; + String keyId = "org-key-id"; + String ownerUserId = "owner-user-id"; + String s = service.encode(new Organization(id, name, email, keyId, ownerUserId)); Organization org = service.decode(s, Organization.class); assertNotNull(org); - assertThat(org.name(), is("myorg")); + assertThat(org.id(), is(id)); + assertThat(org.name(), is(name)); + assertThat(org.email(), is(email)); + assertThat(org.keyId(), is(keyId)); + assertThat(org.members().iterator().next().id(), is(ownerUserId)); } } diff --git a/scalecube-organization/src/test/java/io/scalecube/organization/repository/inmem/InMemoryOrganizationMembersRepositoryAdmin.java b/scalecube-organization/src/test/java/io/scalecube/organization/repository/inmem/InMemoryOrganizationMembersRepositoryAdmin.java deleted file mode 100644 index 5b43316..0000000 --- a/scalecube-organization/src/test/java/io/scalecube/organization/repository/inmem/InMemoryOrganizationMembersRepositoryAdmin.java +++ /dev/null @@ -1,21 +0,0 @@ -package io.scalecube.organization.repository.inmem; - -import io.scalecube.organization.operation.Organization; -import io.scalecube.organization.repository.OrganizationMembersRepositoryAdmin; -import java.util.HashSet; -import java.util.Set; - -public class InMemoryOrganizationMembersRepositoryAdmin - implements OrganizationMembersRepositoryAdmin { - private final Set set = new HashSet<>(); - - @Override - public void createRepository(Organization organization) { - set.add(organization); - } - - @Override - public void deleteRepository(Organization organization) { - set.remove(organization); - } -} diff --git a/scalecube-organization/src/test/java/io/scalecube/organization/repository/inmem/InMemoryOrganizationRepository.java b/scalecube-organization/src/test/java/io/scalecube/organization/repository/inmem/InMemoryOrganizationRepository.java index 0db0155..4a37a35 100644 --- a/scalecube-organization/src/test/java/io/scalecube/organization/repository/inmem/InMemoryOrganizationRepository.java +++ b/scalecube-organization/src/test/java/io/scalecube/organization/repository/inmem/InMemoryOrganizationRepository.java @@ -1,6 +1,13 @@ package io.scalecube.organization.repository.inmem; -import io.scalecube.organization.operation.Organization; +import io.scalecube.organization.domain.Organization; +import io.scalecube.organization.repository.OrganizationsRepository; -public class InMemoryOrganizationRepository - extends InMemoryEntityRepository {} +public class InMemoryOrganizationRepository extends InMemoryEntityRepository + implements OrganizationsRepository { + + @Override + public boolean existsByName(String name) { + return existByProperty("name", name); + } +} diff --git a/scalecube-organization/src/test/java/io/scalecube/organization/repository/inmem/InMemoryPublicKeyProvider.java b/scalecube-organization/src/test/java/io/scalecube/organization/repository/inmem/InMemoryPublicKeyProvider.java index bcdccd7..e417e42 100644 --- a/scalecube-organization/src/test/java/io/scalecube/organization/repository/inmem/InMemoryPublicKeyProvider.java +++ b/scalecube-organization/src/test/java/io/scalecube/organization/repository/inmem/InMemoryPublicKeyProvider.java @@ -7,7 +7,7 @@ import io.scalecube.account.api.Token; import io.scalecube.organization.tokens.InvalidTokenException; import io.scalecube.organization.tokens.PublicKeyProvider; -import io.scalecube.security.Profile; +import io.scalecube.security.api.Profile; import java.security.KeyPair; import java.security.KeyPairGenerator; import java.security.NoSuchAlgorithmException; @@ -21,7 +21,9 @@ public class InMemoryPublicKeyProvider implements PublicKeyProvider { static { try { - KEY_PAIR = KeyPairGenerator.getInstance("RSA").generateKeyPair(); + KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA"); + keyPairGenerator.initialize(2048); + KEY_PAIR = keyPairGenerator.generateKeyPair(); } catch (NoSuchAlgorithmException e) { throw new OrganizationServiceException("Error during initialing KeyPairGenerator", e); } @@ -41,15 +43,15 @@ public static Token token(Profile profile, Consumer consumer) { options -> consumer.accept( options - .setSubject(profile.getUserId()) - .setAudience(profile.getTenant()) + .setSubject(profile.userId()) + .setAudience(profile.tenant()) .setHeaderParam("kid", "42") - .claim("email", profile.getEmail()) + .claim("email", profile.email()) .claim("email_verified", profile.isEmailVerified()) - .claim("name", profile.getName()) - .claim("family_name", profile.getFamilyName()) - .claim("given_name", profile.getGivenName()) - .addClaims(profile.getClaims()))); + .claim("name", profile.name()) + .claim("family_name", profile.familyName()) + .claim("given_name", profile.givenName()) + .addClaims(profile.claims()))); } public static Token token(Consumer consumer) { diff --git a/scalecube-organization/src/test/java/io/scalecube/organization/repository/inmem/InMemoryUserOrganizationMembershipRepository.java b/scalecube-organization/src/test/java/io/scalecube/organization/repository/inmem/InMemoryUserOrganizationMembershipRepository.java deleted file mode 100644 index 40a1c79..0000000 --- a/scalecube-organization/src/test/java/io/scalecube/organization/repository/inmem/InMemoryUserOrganizationMembershipRepository.java +++ /dev/null @@ -1,52 +0,0 @@ -package io.scalecube.organization.repository.inmem; - -import io.scalecube.account.api.OrganizationMember; -import io.scalecube.organization.operation.Organization; -import io.scalecube.organization.repository.UserOrganizationMembershipRepository; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; - -public class InMemoryUserOrganizationMembershipRepository - implements UserOrganizationMembershipRepository { - - private final HashMap> map = new HashMap<>(); - - @Override - public void addMember(Organization org, OrganizationMember member) { - map.computeIfAbsent(org.id(), id -> new HashSet<>()).add(member); - } - - @Override - public boolean isMember(String userId, Organization organization) { - return map.getOrDefault(organization.id(), Collections.emptySet()) - .stream() - .map(OrganizationMember::id) - .anyMatch(userId::equals); - } - - @Override - public Collection getMembers(Organization organization) { - return map.getOrDefault(organization.id(), Collections.emptySet()); - } - - @Override - public void removeMember(String userId, Organization organization) { - if (isMember(userId, organization)) { - Optional member = getMember(userId, organization); - member.ifPresent(organizationMember -> map.get(organization.id()).remove(organizationMember)); - } - } - - @Override - public Optional getMember(String userId, Organization organization) { - return map.get(organization.id()) - .stream() - .filter(m -> Objects.equals(m.id(), userId)) - .findAny(); - } -}