Skip to content

Commit 235e4fe

Browse files
Oauth2 integration with CloudStack (#7996)
OAuth2, the industry-standard authorization or authentication framework, simplifies the process of granting access to resources. CloudStack supports OAuth2 authentication wherein users can login into CloudStack without using a username and password. Support for Google and Github providers has been added. Other OAuth2 providers can be easily integrated with CloudStack using its plugin framework. The login page will show provider options when the OAuth2 is enabled and corresponding providers are configured. "OAuth configuration" sub-section is present under "Configuration" where admins can register the corresponding OAuth providers.
1 parent 67eddd7 commit 235e4fe

File tree

59 files changed

+3427
-31
lines changed

Some content is hidden

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

59 files changed

+3427
-31
lines changed

api/src/main/java/com/cloud/user/AccountService.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ User createUser(String userName, String password, String firstName, String lastN
7070

7171
UserAccount getActiveUserAccount(String username, Long domainId);
7272

73+
List<UserAccount> getActiveUserAccountByEmail(String email, Long domainId);
74+
7375
UserAccount updateUser(UpdateUserCmd updateUserCmd);
7476

7577
Account getActiveAccountById(long accountId);

api/src/main/java/com/cloud/user/User.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public interface User extends OwnedBy, InternalIdentity {
2424

2525
// UNKNOWN and NATIVE can be used interchangeably
2626
public enum Source {
27-
LDAP, SAML2, SAML2DISABLED, UNKNOWN, NATIVE
27+
OAUTH2, LDAP, SAML2, SAML2DISABLED, UNKNOWN, NATIVE
2828
}
2929

3030
public static final long UID_SYSTEM = 1;

api/src/main/java/org/apache/cloudstack/api/ApiConstants.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,8 @@ public class ApiConstants {
594594
public static final String SERVICE_CAPABILITY_LIST = "servicecapabilitylist";
595595
public static final String CAN_CHOOSE_SERVICE_CAPABILITY = "canchooseservicecapability";
596596
public static final String PROVIDER = "provider";
597+
public static final String OAUTH_PROVIDER = "oauthprovider";
598+
public static final String OAUTH_SECRET_KEY = "secretkey";
597599
public static final String MANAGED = "managed";
598600
public static final String CAPACITY_BYTES = "capacitybytes";
599601
public static final String CAPACITY_IOPS = "capacityiops";
@@ -1056,6 +1058,9 @@ public class ApiConstants {
10561058
public static final String VNF_CONFIGURE_MANAGEMENT = "vnfconfiguremanagement";
10571059
public static final String VNF_CIDR_LIST = "vnfcidrlist";
10581060

1061+
public static final String CLIENT_ID = "clientid";
1062+
public static final String REDIRECT_URI = "redirecturi";
1063+
10591064
/**
10601065
* This enum specifies IO Drivers, each option controls specific policies on I/O.
10611066
* Qemu guests support "threads" and "native" options Since 0.8.8 ; "io_uring" is supported Since 6.3.0 (QEMU 5.0).

api/src/main/java/org/apache/cloudstack/api/command/user/ssh/CreateSSHKeyPairCmd.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,5 +95,4 @@ public void execute() {
9595
response.setObjectName("keypair");
9696
setResponseObject(response);
9797
}
98-
99-
}
98+
}

api/src/main/java/org/apache/cloudstack/api/command/user/userdata/ListUserDataCmd.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,5 +76,4 @@ public void execute() {
7676
response.setResponseName(getCommandName());
7777
setResponseObject(response);
7878
}
79-
80-
}
79+
}

api/src/main/java/org/apache/cloudstack/api/command/user/userdata/RegisterUserDataCmd.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,5 +142,4 @@ public void execute() throws ResourceUnavailableException, InsufficientCapacityE
142142
response.setObjectName(ApiConstants.USER_DATA);
143143
setResponseObject(response);
144144
}
145-
146-
}
145+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package org.apache.cloudstack.auth;
18+
19+
import com.cloud.utils.component.Adapter;
20+
import com.cloud.utils.exception.CloudRuntimeException;
21+
22+
public interface UserOAuth2Authenticator extends Adapter {
23+
/**
24+
* Returns the unique name of the provider
25+
* @return returns provider name
26+
*/
27+
String getName();
28+
29+
/**
30+
* Returns description about the OAuth2 provider plugin
31+
* @return returns description
32+
*/
33+
String getDescription();
34+
35+
/**
36+
* Verifies if the logged in user is
37+
* @return returns true if its valid user
38+
*/
39+
boolean verifyUser(String email, String secretCode);
40+
41+
/**
42+
* Verifies the code provided by provider and fetches email
43+
* @return returns email
44+
*/
45+
String verifyCodeAndFetchEmail(String secretCode);
46+
47+
48+
/**
49+
* Fetches email using the accessToken
50+
* @return returns email
51+
*/
52+
String getUserEmailAddress() throws CloudRuntimeException;
53+
}

client/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,11 @@
161161
<artifactId>cloud-plugin-user-authenticator-md5</artifactId>
162162
<version>${project.version}</version>
163163
</dependency>
164+
<dependency>
165+
<groupId>org.apache.cloudstack</groupId>
166+
<artifactId>cloud-plugin-user-authenticator-oauth2</artifactId>
167+
<version>${project.version}</version>
168+
</dependency>
164169
<dependency>
165170
<groupId>org.apache.cloudstack</groupId>
166171
<artifactId>cloud-plugin-user-authenticator-pbkdf2</artifactId>

core/src/main/resources/META-INF/cloudstack/core/spring-core-registry-core-context.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
class="org.apache.cloudstack.spring.lifecycle.registry.ExtensionRegistry">
3434
<property name="orderConfigKey" value="user.authenticators.order" />
3535
<property name="excludeKey" value="user.authenticators.exclude" />
36-
<property name="orderConfigDefault" value="PBKDF2,SHA256SALT,MD5,LDAP,SAML2,PLAINTEXT" />
36+
<property name="orderConfigDefault" value="PBKDF2,SHA256SALT,MD5,LDAP,SAML2,PLAINTEXT,OAUTH2" />
3737
</bean>
3838

3939
<bean id="userTwoFactorAuthenticatorsRegistry"
@@ -47,7 +47,7 @@
4747
class="org.apache.cloudstack.spring.lifecycle.registry.ExtensionRegistry">
4848
<property name="orderConfigKey" value="pluggableApi.authenticators.order" />
4949
<property name="excludeKey" value="pluggableApi.authenticators.exclude" />
50-
<property name="orderConfigDefault" value="SAML2Auth" />
50+
<property name="orderConfigDefault" value="SAML2Auth,OAUTH2Auth" />
5151
</bean>
5252

5353
<bean id="userPasswordEncodersRegistry"

engine/schema/src/main/java/com/cloud/user/dao/UserAccountDao.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ public interface UserAccountDao extends GenericDao<UserAccountVO, Long> {
2727

2828
UserAccount getUserAccount(String username, Long domainId);
2929

30+
List<UserAccountVO> getUserAccountByEmail(String email, Long domainId);
31+
3032
boolean validateUsernameInDomain(String username, Long domainId);
3133

3234
UserAccount getUserByApiKey(String apiKey);

0 commit comments

Comments
 (0)