Skip to content

Commit

Permalink
Add group & add graph endpoints to AzureEnvironment
Browse files Browse the repository at this point in the history
  • Loading branch information
jianghaolu committed Sep 13, 2016
1 parent 262a7ee commit fd4ce07
Show file tree
Hide file tree
Showing 10 changed files with 293 additions and 37 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for
* license information.
*/

package com.microsoft.azure.management.graphrbac;

import com.microsoft.azure.management.graphrbac.implementation.ADGroupInner;
import com.microsoft.azure.management.resources.fluentcore.model.Creatable;
import com.microsoft.azure.management.resources.fluentcore.model.Wrapper;

/**
* An immutable client-side representation of an Azure tenant.
*/
public interface Group extends

This comment has been minimized.

Copy link
@martinsawicki

martinsawicki Sep 13, 2016

"Group" seems to be too generic of a name. Remember discussion we had in the past about "Group" vs ResourceGroup and we settled on qualifying the word "group" b/c of multiple different uses. So this sounds like ActiveDirectoryGroup (since the inner is ADGroupInner --- but we don't want the abbreviation here either)

Wrapper<ADGroupInner> {
/**
* @return object Id.
*/
String objectId();

/**
* @return object type.
*/
String objectType();

/**
* @return group display name.
*/
String displayName();

/**
* @return security enabled field.
*/
Boolean securityEnabled();

This comment has been minimized.

Copy link
@martinsawicki

martinsawicki Sep 13, 2016

boolean


/**
* @return mail field.
*/
String mail();

/**************************************************************
* Fluent interfaces to provision a StorageAccount
**************************************************************/

/**
* Container interface for all the definitions that need to be implemented.
*/
interface Definition extends
DefinitionStages.Blank,
DefinitionStages.WithDisplayName,
DefinitionStages.WithMailNickname,
DefinitionStages.WithCreate {
}

/**
* Grouping of all the storage account definition stages.
*/
interface DefinitionStages {
/**
* The first stage of the storage account definition.
*/
interface Blank extends WithDisplayName {
}

interface WithDisplayName {
WithMailNickname withDisplayName(String displayName);
}

interface WithMailNickname {
WithCreate withMailNickname(String mailNickname);
}

/**
* A storage account definition with sufficient inputs to create a new
* storage account in the cloud, but exposing additional optional inputs to
* specify.
*/
interface WithCreate extends
Creatable<Group> {
}
}

/**
* Grouping of all the storage account update stages.
*/
interface UpdateStages {
}

/**
* The template for a storage account update operation, containing all the settings that can be modified.
*/
interface Update {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for
* license information.
*/

package com.microsoft.azure.management.graphrbac;

import com.microsoft.azure.CloudException;
import com.microsoft.azure.management.resources.fluentcore.collection.SupportsCreating;
import com.microsoft.azure.management.resources.fluentcore.collection.SupportsDeleting;
import com.microsoft.azure.management.resources.fluentcore.collection.SupportsListing;

import java.io.IOException;
import java.util.List;

/**
* Entry point to tenant management API.
*/
public interface Groups extends
SupportsCreating<Group.DefinitionStages.Blank>,
SupportsListing<Group>,
SupportsDeleting {
/**
* Gets the information about a user.
*
* @param objectId the unique object id
* @return an immutable representation of the resource
* @throws CloudException exceptions thrown from the cloud
* @throws IOException exceptions thrown from serialization/deserialization
*/
Group getByObjectId(String objectId) throws CloudException, IOException;

/**
* Gets the information about a user.
*
* @param displayNamePrefix the partial prefix of the display name to search
* @return an immutable representation of the resource
* @throws CloudException exceptions thrown from the cloud
* @throws IOException exceptions thrown from serialization/deserialization
*/
List<Group> searchByDisplayName(String displayNamePrefix) throws CloudException, IOException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,14 @@ protected ServicePrincipalImpl wrapModel(ServicePrincipalInner servicePrincipalI
public ServicePrincipalImpl getByObjectId(String objectId) throws CloudException, IOException {
return new ServicePrincipalImpl(innerCollection.get(objectId).getBody(), innerCollection);
}

@Override
public ServicePrincipal getByAppId(String appId) throws CloudException, IOException {
return null;
}

@Override
public ServicePrincipal getByServicePrincipalName(String spn) throws CloudException, IOException {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public void delete(String id) throws Exception {
}

@Override
public UserImpl define(String userPrincipalName) {
return wrapModel(userPrincipalName);
public UserImpl define(String name) {
return wrapModel(name);
}

@Override
Expand All @@ -59,7 +59,12 @@ protected UserImpl wrapModel(UserInner userInner) {
}

@Override
public UserImpl getByObjectId(String upnOrId) throws CloudException, IOException {
return new UserImpl(innerCollection.get(upnOrId).getBody(), innerCollection);
public UserImpl getByObjectId(String objectId) throws CloudException, IOException {
return new UserImpl(innerCollection.get(objectId).getBody(), innerCollection);
}

@Override
public UserImpl getByUserPrincipalName(String upn) throws CloudException, IOException {
return new UserImpl(innerCollection.get(upn).getBody(), innerCollection);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

package com.microsoft.azure.management.graphrbac;

import com.microsoft.azure.credentials.ApplicationTokenCredentials;
import com.microsoft.azure.AzureEnvironment;
import com.microsoft.azure.credentials.UserTokenCredentials;
import com.microsoft.azure.management.graphrbac.implementation.GraphRbacManager;
import okhttp3.logging.HttpLoggingInterceptor;

Expand All @@ -17,12 +18,21 @@ public abstract class GraphRbacManagementTestBase {
protected static GraphRbacManager graphRbacManager;

protected static void createClients() {
ApplicationTokenCredentials credentials = new ApplicationTokenCredentials(
System.getenv("client-id"),
// ApplicationTokenCredentials credentials = new ApplicationTokenCredentials(
// System.getenv("client-id"),
// System.getenv("domain"),
// System.getenv("secret"),
// "https://graph.windows.net",
// null);
UserTokenCredentials credentials = new UserTokenCredentials(
"1950a258-227b-4e31-a9cf-717495945fc2",
System.getenv("domain"),
System.getenv("secret"),
System.getenv("username"),
System.getenv("password"),
"https://graph.windows.net",
null);
"https://graph.windows.net",
AzureEnvironment.AZURE
);

graphRbacManager = GraphRbacManager
.configure()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for
* license information.
*/

package com.microsoft.azure.management.graphrbac;

import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;

import java.util.List;

public class GroupsTests extends GraphRbacManagementTestBase {
private static final String RG_NAME = "javacsmrg350";
private static final String APP_NAME = "app-javacsm350";

@BeforeClass
public static void setup() throws Exception {
createClients();
}

@AfterClass
public static void cleanup() throws Exception {
}

@Test
public void getServicePrincipal() throws Exception {
List<ServicePrincipal> servicePrincipals = graphRbacManager.servicePrincipals().list();
Assert.assertNotNull(servicePrincipals);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for
* license information.
*/

package com.microsoft.azure.management.graphrbac;

import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;

import java.util.List;

public class UsersTests extends GraphRbacManagementTestBase {
private static final String RG_NAME = "javacsmrg350";
private static final String APP_NAME = "app-javacsm350";

@BeforeClass
public static void setup() throws Exception {
createClients();
}

@AfterClass
public static void cleanup() throws Exception {
}

@Test
public void canCRUDUser() throws Exception {
//LIST
List<User> userList = graphRbacManager.users().list();
Assert.assertNotNull(userList);
User user = graphRbacManager.users().define("jeffrolfnlu@hotmail.com")
.withDisplayName("Test User 309")
.withPassword("Pa$$w0rd")
.withMailNickname("")
.create();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public ApplicationTokenCredentials(String clientId, String domain, String secret
} else {
this.environment = environment;
}
this.resourceEndpoint = this.environment.getTokenAudience();
this.resourceEndpoint = this.environment.getManagementEndpoint();
}

/**
Expand Down Expand Up @@ -155,7 +155,7 @@ public static ApplicationTokenCredentials fromFile(File credentialsFile) throws
Properties authSettings = new Properties();
authSettings.put(CredentialSettings.AUTH_URL.toString(), AzureEnvironment.AZURE.getAuthenticationEndpoint());
authSettings.put(CredentialSettings.BASE_URL.toString(), AzureEnvironment.AZURE.getBaseUrl());
authSettings.put(CredentialSettings.MANAGEMENT_URI.toString(), AzureEnvironment.AZURE.getTokenAudience());
authSettings.put(CredentialSettings.MANAGEMENT_URI.toString(), AzureEnvironment.AZURE.getManagementEndpoint());

// Load the credentials from the file
FileInputStream credentialsFileStream = new FileInputStream(credentialsFile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public UserTokenCredentials(String clientId, String domain, String username, Str
} else {
this.environment = environment;
}
this.resourceEndpoint = this.environment.getTokenAudience();
this.resourceEndpoint = this.environment.getManagementEndpoint();
}

/**
Expand Down
Loading

0 comments on commit fd4ce07

Please sign in to comment.