Skip to content

Commit ccd47c1

Browse files
committed
Implemented Project Invitations
1 parent d32241e commit ccd47c1

45 files changed

Lines changed: 1660 additions & 117 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

api/src/com/cloud/acl/SecurityChecker.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
*/
2222
package com.cloud.acl;
2323

24+
import com.cloud.acl.SecurityChecker.AccessType;
2425
import com.cloud.dc.DataCenter;
2526
import com.cloud.domain.Domain;
2627
import com.cloud.exception.PermissionDeniedException;
@@ -39,16 +40,18 @@ public interface SecurityChecker extends Adapter {
3940
public enum AccessType {
4041
ListEntry,
4142
ModifyEntry,
43+
ModifyProject
4244
}
4345
/**
4446
* Checks if the account owns the object.
4547
*
4648
* @param caller account to check against.
49+
* @param accessType TODO
4750
* @param object object that the account is trying to access.
4851
* @return true if access allowed. false if this adapter cannot authenticate ownership.
4952
* @throws PermissionDeniedException if this adapter is suppose to authenticate ownership and the check failed.
5053
*/
51-
boolean checkAccess(Account caller, Domain domain) throws PermissionDeniedException;
54+
boolean checkAccess(Account caller, Domain domain, AccessType accessType) throws PermissionDeniedException;
5255

5356
/**
5457
* Checks if the user belongs to an account that owns the object.

api/src/com/cloud/api/ApiConstants.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,5 +262,8 @@ public class ApiConstants {
262262
public static final String MAX_GUESTS_LIMIT = "maxguestslimit";
263263
public static final String PROJECT_ID = "projectid";
264264
public static final String PROJECT = "project";
265+
public static final String ROLE = "role";
266+
public static final String USER = "user";
267+
public static final String ACTIVE_ONLY = "activeonly";
265268

266269
}

api/src/com/cloud/api/ResponseGenerator.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
import com.cloud.api.response.NetworkOfferingResponse;
4545
import com.cloud.api.response.NetworkResponse;
4646
import com.cloud.api.response.PodResponse;
47+
import com.cloud.api.response.ProjectAccountResponse;
48+
import com.cloud.api.response.ProjectInvitationResponse;
4749
import com.cloud.api.response.ProjectResponse;
4850
import com.cloud.api.response.RemoteAccessVpnResponse;
4951
import com.cloud.api.response.ResourceCountResponse;
@@ -92,6 +94,8 @@
9294
import com.cloud.offering.ServiceOffering;
9395
import com.cloud.org.Cluster;
9496
import com.cloud.projects.Project;
97+
import com.cloud.projects.ProjectAccount;
98+
import com.cloud.projects.ProjectInvitation;
9599
import com.cloud.storage.Snapshot;
96100
import com.cloud.storage.StoragePool;
97101
import com.cloud.storage.Volume;
@@ -221,5 +225,9 @@ public interface ResponseGenerator {
221225
FirewallResponse createFirewallResponse(FirewallRule fwRule);
222226

223227
HypervisorCapabilitiesResponse createHypervisorCapabilitiesResponse(HypervisorCapabilities hpvCapabilities);
228+
229+
ProjectAccountResponse createProjectAccountResponse(ProjectAccount projectAccount);
230+
231+
ProjectInvitationResponse createProjectInvitationResponse(ProjectInvitation invite);
224232

225233
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/**
2+
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
3+
*
4+
* This software is licensed under the GNU General Public License v3 or later.
5+
*
6+
* It is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or any later version.
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*
17+
*/
18+
19+
package com.cloud.api.commands;
20+
21+
import org.apache.log4j.Logger;
22+
23+
import com.cloud.api.ApiConstants;
24+
import com.cloud.api.BaseCmd;
25+
import com.cloud.api.Implementation;
26+
import com.cloud.api.Parameter;
27+
import com.cloud.api.ServerApiException;
28+
import com.cloud.api.response.SuccessResponse;
29+
import com.cloud.user.Account;
30+
31+
@Implementation(description="Adds acoount to a project", responseObject=SuccessResponse.class)
32+
public class AddAccountToProjectCmd extends BaseCmd {
33+
public static final Logger s_logger = Logger.getLogger(AddAccountToProjectCmd.class.getName());
34+
35+
private static final String s_name = "addaccounttoprojectresponse";
36+
37+
/////////////////////////////////////////////////////
38+
//////////////// API parameters /////////////////////
39+
/////////////////////////////////////////////////////
40+
41+
@Parameter(name=ApiConstants.PROJECT_ID, type=CommandType.LONG, required=true, description="id of the project to add the account to")
42+
private Long projectId;
43+
44+
@Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, required=true, description="name of the account to be added to the project")
45+
private String accountName;
46+
47+
/////////////////////////////////////////////////////
48+
/////////////////// Accessors ///////////////////////
49+
/////////////////////////////////////////////////////
50+
51+
52+
public String getAccountName() {
53+
return accountName;
54+
}
55+
56+
public Long getProjectId() {
57+
return projectId;
58+
}
59+
60+
public void setProjectId(Long projectId) {
61+
this.projectId = projectId;
62+
}
63+
64+
@Override
65+
public String getCommandName() {
66+
return s_name;
67+
}
68+
69+
/////////////////////////////////////////////////////
70+
/////////////// API Implementation///////////////////
71+
/////////////////////////////////////////////////////
72+
73+
@Override
74+
public void execute(){
75+
boolean result = _projectService.addAccountToProject(getProjectId(), getAccountName());
76+
if (result) {
77+
SuccessResponse response = new SuccessResponse(getCommandName());
78+
this.setResponseObject(response);
79+
} else {
80+
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to add account to the project");
81+
}
82+
}
83+
84+
@Override
85+
public long getEntityOwnerId() {
86+
//TODO - return project entity ownerId
87+
return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
88+
}
89+
}

api/src/com/cloud/api/commands/CreateProjectCmd.java

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -80,20 +80,7 @@ public String getCommandName() {
8080

8181
@Override
8282
public long getEntityOwnerId() {
83-
Account account = UserContext.current().getCaller();
84-
if ((account == null) || isAdmin(account.getType())) {
85-
if ((domainId != null) && (accountName != null)) {
86-
Account userAccount = _responseGenerator.findAccountByNameDomain(accountName, domainId);
87-
if (userAccount != null) {
88-
return userAccount.getId();
89-
}
90-
}
91-
}
92-
93-
if (account != null) {
94-
return account.getId();
95-
}
96-
83+
//TODO - return project entity ownerId
9784
return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
9885
}
9986

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/**
2+
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
3+
*
4+
* This software is licensed under the GNU General Public License v3 or later.
5+
*
6+
* It is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or any later version.
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*
17+
*/
18+
19+
package com.cloud.api.commands;
20+
21+
import org.apache.log4j.Logger;
22+
23+
import com.cloud.api.ApiConstants;
24+
import com.cloud.api.BaseCmd;
25+
import com.cloud.api.Implementation;
26+
import com.cloud.api.Parameter;
27+
import com.cloud.api.ServerApiException;
28+
import com.cloud.api.response.SuccessResponse;
29+
import com.cloud.user.Account;
30+
31+
@Implementation(description="Deletes account from the project", responseObject=SuccessResponse.class)
32+
public class DeleteAccountFromProjectCmd extends BaseCmd {
33+
public static final Logger s_logger = Logger.getLogger(DeleteProjectCmd.class.getName());
34+
35+
private static final String s_name = "deleteaccountfromprojectresponse";
36+
37+
/////////////////////////////////////////////////////
38+
//////////////// API parameters /////////////////////
39+
/////////////////////////////////////////////////////
40+
@Parameter(name=ApiConstants.PROJECT_ID, type=CommandType.LONG, required=true, description="id of the project to remove the account from")
41+
private Long projectId;
42+
43+
@Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, required=true, description="name of the account to be removed from the project")
44+
private String accountName;
45+
46+
/////////////////////////////////////////////////////
47+
/////////////////// Accessors ///////////////////////
48+
/////////////////////////////////////////////////////
49+
50+
51+
52+
53+
@Override
54+
public String getCommandName() {
55+
return s_name;
56+
}
57+
58+
/////////////////////////////////////////////////////
59+
/////////////// API Implementation///////////////////
60+
/////////////////////////////////////////////////////
61+
62+
public Long getProjectId() {
63+
return projectId;
64+
}
65+
66+
public String getAccountName() {
67+
return accountName;
68+
}
69+
70+
@Override
71+
public void execute(){
72+
boolean result = _projectService.deleteAccountFromProject(projectId, accountName);
73+
if (result) {
74+
SuccessResponse response = new SuccessResponse(getCommandName());
75+
this.setResponseObject(response);
76+
} else {
77+
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete account from the project");
78+
}
79+
}
80+
81+
82+
@Override
83+
public long getEntityOwnerId() {
84+
//TODO - return project entity ownerId
85+
return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
86+
}
87+
}

api/src/com/cloud/api/commands/DeleteProjectCmd.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@
2828
import com.cloud.api.ServerApiException;
2929
import com.cloud.api.response.SuccessResponse;
3030
import com.cloud.event.EventTypes;
31-
import com.cloud.exception.InvalidParameterValueException;
32-
import com.cloud.projects.Project;
31+
import com.cloud.user.Account;
3332
import com.cloud.user.UserContext;
3433

3534
@Implementation(description="Deletes a project", responseObject=SuccessResponse.class)
@@ -87,11 +86,7 @@ public String getEventDescription() {
8786

8887
@Override
8988
public long getEntityOwnerId() {
90-
Project project = _projectService.getProject(id);
91-
if (project == null) {
92-
throw new InvalidParameterValueException("Project id=" + id + " doesn't exist");
93-
} else {
94-
return _projectService.getProject(id).getProjectAccountId();
95-
}
89+
//TODO - return project entity ownerId
90+
return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
9691
}
9792
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/**
2+
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
3+
*
4+
* This software is licensed under the GNU General Public License v3 or later.
5+
*
6+
* It is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or any later version.
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*
17+
*/
18+
package com.cloud.api.commands;
19+
20+
import org.apache.log4j.Logger;
21+
22+
import com.cloud.api.ApiConstants;
23+
import com.cloud.api.BaseCmd;
24+
import com.cloud.api.Implementation;
25+
import com.cloud.api.Parameter;
26+
import com.cloud.api.ServerApiException;
27+
import com.cloud.api.response.SuccessResponse;
28+
import com.cloud.user.Account;
29+
30+
@Implementation(description="Makes account to join the project", responseObject=SuccessResponse.class)
31+
public class JoinProjectCmd extends BaseCmd {
32+
public static final Logger s_logger = Logger.getLogger(JoinProjectCmd.class.getName());
33+
private static final String s_name = "joinprojectresponse";
34+
35+
/////////////////////////////////////////////////////
36+
//////////////// API parameters /////////////////////
37+
/////////////////////////////////////////////////////
38+
@Parameter(name=ApiConstants.PROJECT_ID, required=true, type=CommandType.LONG, description="list by project id")
39+
private Long projectId;
40+
41+
@Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, description="list invitations for specified account; this parameter has to be specified with domainId")
42+
private String accountName;
43+
44+
45+
/////////////////////////////////////////////////////
46+
/////////////////// Accessors ///////////////////////
47+
/////////////////////////////////////////////////////
48+
public Long getProjectId() {
49+
return projectId;
50+
}
51+
52+
public String getAccountName() {
53+
return accountName;
54+
}
55+
56+
@Override
57+
public String getCommandName() {
58+
return s_name;
59+
}
60+
61+
/////////////////////////////////////////////////////
62+
/////////////// API Implementation///////////////////
63+
/////////////////////////////////////////////////////
64+
65+
@Override
66+
public long getEntityOwnerId() {
67+
//TODO - return project entity ownerId
68+
return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
69+
}
70+
71+
72+
@Override
73+
public void execute(){
74+
boolean result = _projectService.joinProject(projectId, accountName);
75+
if (result) {
76+
SuccessResponse response = new SuccessResponse(getCommandName());
77+
this.setResponseObject(response);
78+
} else {
79+
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to join the project");
80+
}
81+
}
82+
}

0 commit comments

Comments
 (0)