Skip to content

Commit

Permalink
Merge branch 'main' into database-views-management-via-separated-files
Browse files Browse the repository at this point in the history
  • Loading branch information
GutoVeronezi authored Nov 1, 2023
2 parents e70aa6b + 288f066 commit 7ba2f4a
Show file tree
Hide file tree
Showing 59 changed files with 3,434 additions and 56 deletions.
2 changes: 2 additions & 0 deletions api/src/main/java/com/cloud/user/AccountService.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ User createUser(String userName, String password, String firstName, String lastN

UserAccount getActiveUserAccount(String username, Long domainId);

List<UserAccount> getActiveUserAccountByEmail(String email, Long domainId);

UserAccount updateUser(UpdateUserCmd updateUserCmd);

Account getActiveAccountById(long accountId);
Expand Down
2 changes: 1 addition & 1 deletion api/src/main/java/com/cloud/user/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public interface User extends OwnedBy, InternalIdentity {

// UNKNOWN and NATIVE can be used interchangeably
public enum Source {
LDAP, SAML2, SAML2DISABLED, UNKNOWN, NATIVE
OAUTH2, LDAP, SAML2, SAML2DISABLED, UNKNOWN, NATIVE
}

public static final long UID_SYSTEM = 1;
Expand Down
5 changes: 5 additions & 0 deletions api/src/main/java/org/apache/cloudstack/api/ApiConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,8 @@ public class ApiConstants {
public static final String SERVICE_CAPABILITY_LIST = "servicecapabilitylist";
public static final String CAN_CHOOSE_SERVICE_CAPABILITY = "canchooseservicecapability";
public static final String PROVIDER = "provider";
public static final String OAUTH_PROVIDER = "oauthprovider";
public static final String OAUTH_SECRET_KEY = "secretkey";
public static final String MANAGED = "managed";
public static final String CAPACITY_BYTES = "capacitybytes";
public static final String CAPACITY_IOPS = "capacityiops";
Expand Down Expand Up @@ -1056,6 +1058,9 @@ public class ApiConstants {
public static final String VNF_CONFIGURE_MANAGEMENT = "vnfconfiguremanagement";
public static final String VNF_CIDR_LIST = "vnfcidrlist";

public static final String CLIENT_ID = "clientid";
public static final String REDIRECT_URI = "redirecturi";

/**
* This enum specifies IO Drivers, each option controls specific policies on I/O.
* Qemu guests support "threads" and "native" options Since 0.8.8 ; "io_uring" is supported Since 6.3.0 (QEMU 5.0).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,4 @@ public void execute() {
response.setObjectName("keypair");
setResponseObject(response);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,4 @@ public void execute() {
response.setResponseName(getCommandName());
setResponseObject(response);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -142,5 +142,4 @@ public void execute() throws ResourceUnavailableException, InsufficientCapacityE
response.setObjectName(ApiConstants.USER_DATA);
setResponseObject(response);
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package org.apache.cloudstack.auth;

import com.cloud.utils.component.Adapter;
import com.cloud.utils.exception.CloudRuntimeException;

public interface UserOAuth2Authenticator extends Adapter {
/**
* Returns the unique name of the provider
* @return returns provider name
*/
String getName();

/**
* Returns description about the OAuth2 provider plugin
* @return returns description
*/
String getDescription();

/**
* Verifies if the logged in user is
* @return returns true if its valid user
*/
boolean verifyUser(String email, String secretCode);

/**
* Verifies the code provided by provider and fetches email
* @return returns email
*/
String verifyCodeAndFetchEmail(String secretCode);


/**
* Fetches email using the accessToken
* @return returns email
*/
String getUserEmailAddress() throws CloudRuntimeException;
}
5 changes: 5 additions & 0 deletions client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@
<artifactId>cloud-plugin-user-authenticator-md5</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloud-plugin-user-authenticator-oauth2</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloud-plugin-user-authenticator-pbkdf2</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
class="org.apache.cloudstack.spring.lifecycle.registry.ExtensionRegistry">
<property name="orderConfigKey" value="user.authenticators.order" />
<property name="excludeKey" value="user.authenticators.exclude" />
<property name="orderConfigDefault" value="PBKDF2,SHA256SALT,MD5,LDAP,SAML2,PLAINTEXT" />
<property name="orderConfigDefault" value="PBKDF2,SHA256SALT,MD5,LDAP,SAML2,PLAINTEXT,OAUTH2" />
</bean>

<bean id="userTwoFactorAuthenticatorsRegistry"
Expand All @@ -47,7 +47,7 @@
class="org.apache.cloudstack.spring.lifecycle.registry.ExtensionRegistry">
<property name="orderConfigKey" value="pluggableApi.authenticators.order" />
<property name="excludeKey" value="pluggableApi.authenticators.exclude" />
<property name="orderConfigDefault" value="SAML2Auth" />
<property name="orderConfigDefault" value="SAML2Auth,OAUTH2Auth" />
</bean>

<bean id="userPasswordEncodersRegistry"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public interface UserAccountDao extends GenericDao<UserAccountVO, Long> {

UserAccount getUserAccount(String username, Long domainId);

List<UserAccountVO> getUserAccountByEmail(String email, Long domainId);

boolean validateUsernameInDomain(String username, Long domainId);

UserAccount getUserByApiKey(String apiKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,18 @@ public UserAccount getUserAccount(String username, Long domainId) {
return findOneBy(sc);
}

@Override
public List<UserAccountVO> getUserAccountByEmail(String email, Long domainId) {
if (email == null) {
return null;
}

SearchCriteria<UserAccountVO> sc = createSearchCriteria();
sc.addAnd("email", SearchCriteria.Op.EQ, email);
sc.addAnd("domainId", SearchCriteria.Op.EQ, domainId);
return listBy(sc);
}

@Override
public boolean validateUsernameInDomain(String username, Long domainId) {
UserAccount userAcct = getUserAccount(username, domainId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,11 @@ public UserAccount getActiveUserAccount(String username, Long domainId) {
return null;
}

@Override
public List<UserAccount> getActiveUserAccountByEmail(String email, Long domainId) {
return null;
}

@Override
public User getActiveUser(long arg0) {
return _systemUser;
Expand Down
1 change: 1 addition & 0 deletions plugins/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@

<module>user-authenticators/ldap</module>
<module>user-authenticators/md5</module>
<module>user-authenticators/oauth2</module>
<module>user-authenticators/pbkdf2</module>
<module>user-authenticators/plain-text</module>
<module>user-authenticators/saml2</module>
Expand Down
63 changes: 63 additions & 0 deletions plugins/user-authenticators/oauth2/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>cloud-plugin-user-authenticator-oauth2</artifactId>
<name>Apache CloudStack Plugin - User Authenticator OAuth2</name>
<parent>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloudstack-plugins</artifactId>
<version>4.19.0.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloud-utils</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloud-framework-config</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-docs</artifactId>
<version>v1-rev20220609-1.32.1</version>
</dependency>
<dependency>
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-oauth2</artifactId>
<version>v2-rev20200213-1.32.1</version>
</dependency>
<dependency>
<groupId>com.google.oauth-client</groupId>
<artifactId>google-oauth-client-servlet</artifactId>
<version>1.34.1</version>
</dependency>
<dependency>
<groupId>com.google.http-client</groupId>
<artifactId>google-http-client-jackson2</artifactId>
<version>1.20.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
//
package org.apache.cloudstack.oauth2;

import com.cloud.utils.component.PluggableService;
import org.apache.cloudstack.api.auth.PluggableAPIAuthenticator;
import org.apache.cloudstack.auth.UserOAuth2Authenticator;
import org.apache.cloudstack.framework.config.ConfigKey;
import org.apache.cloudstack.oauth2.api.command.RegisterOAuthProviderCmd;
import org.apache.cloudstack.oauth2.api.command.UpdateOAuthProviderCmd;
import org.apache.cloudstack.oauth2.vo.OauthProviderVO;

import java.util.List;

public interface OAuth2AuthManager extends PluggableAPIAuthenticator, PluggableService {
public static ConfigKey<Boolean> OAuth2IsPluginEnabled = new ConfigKey<Boolean>("Advanced", Boolean.class, "oauth2.enabled", "false",
"Indicates whether OAuth plugin is enabled or not", false);
public static final ConfigKey<String> OAuth2Plugins = new ConfigKey<String>("Advanced", String.class, "oauth2.plugins", "google,github",
"List of OAuth plugins", true);
public static final ConfigKey<String> OAuth2PluginsExclude = new ConfigKey<String>("Advanced", String.class, "oauth2.plugins.exclude", "",
"List of OAuth plugins which are excluded", true);

/**
* Lists user OAuth2 provider plugins
* @return list of providers
*/
List<UserOAuth2Authenticator> listUserOAuth2AuthenticationProviders();

/**
* Finds user OAuth2 provider by name
* @param providerName name of the provider
* @return OAuth2 provider
*/
UserOAuth2Authenticator getUserOAuth2AuthenticationProvider(final String providerName);

String verifyCodeAndFetchEmail(String code, String provider);

OauthProviderVO registerOauthProvider(RegisterOAuthProviderCmd cmd);

List<OauthProviderVO> listOauthProviders(String provider, String uuid);

boolean deleteOauthProvider(Long id);

OauthProviderVO updateOauthProvider(UpdateOAuthProviderCmd cmd);
}
Loading

0 comments on commit 7ba2f4a

Please sign in to comment.