This repository has been archived by the owner on Aug 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 460
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Spring Social support for Microsoft Graph (#121)
- Loading branch information
1 parent
3be5eec
commit 3d92eb6
Showing
35 changed files
with
1,964 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
...boot-autoconfigure/src/test/java/com/microsoft/azure/autoconfigure/msgraph/Constants.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/** | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See LICENSE in the project root for | ||
* license information. | ||
*/ | ||
package com.microsoft.azure.autoconfigure.msgraph; | ||
|
||
public class Constants { | ||
public static final String APP_ID_PROPERTY = "spring.social.microsoft.app-id"; | ||
public static final String APP_ID = "123456789-acb1-4d0b-a13b-1a70ac85d8bf"; | ||
public static final String APP_SECRET_PROPERTY = "spring.social.microsoft.app-secret"; | ||
public static final String APP_SECRET = "1234mAocWmbvawgg4hyRTZ8"; | ||
} |
51 changes: 51 additions & 0 deletions
51
...c/test/java/com/microsoft/azure/autoconfigure/msgraph/MicrosoftAutoConfigurationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/** | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See LICENSE in the project root for | ||
* license information. | ||
*/ | ||
|
||
package com.microsoft.azure.autoconfigure.msgraph; | ||
|
||
import com.microsoft.azure.msgraph.api.Microsoft; | ||
import org.assertj.core.api.Assertions; | ||
import org.junit.Test; | ||
import org.springframework.boot.autoconfigure.social.SocialWebAutoConfiguration; | ||
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; | ||
|
||
import static org.assertj.core.api.Java6Assertions.assertThat; | ||
|
||
public class MicrosoftAutoConfigurationTest { | ||
@Test | ||
public void canAutowire() { | ||
System.setProperty(Constants.APP_ID_PROPERTY, Constants.APP_ID); | ||
System.setProperty(Constants.APP_SECRET_PROPERTY, Constants.APP_SECRET); | ||
|
||
try (AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext()) { | ||
context.register(MicrosoftAutoConfiguration.class); | ||
context.register(SocialWebAutoConfiguration.class); | ||
context.refresh(); | ||
Assertions.assertThat(context.getBean(Microsoft.class)).isNotNull(); | ||
} | ||
|
||
System.clearProperty(Constants.APP_ID_PROPERTY); | ||
System.clearProperty(Constants.APP_SECRET_PROPERTY); | ||
} | ||
|
||
@Test | ||
public void cannotAutowire() { | ||
try (AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext()) { | ||
context.register(MicrosoftAutoConfiguration.class); | ||
context.register(SocialWebAutoConfiguration.class); | ||
context.refresh(); | ||
|
||
Microsoft microsoft = null; | ||
try { | ||
microsoft = context.getBean(Microsoft.class); | ||
} catch (Exception e) { | ||
assertThat(e.getMessage()).contains("No qualifying bean of type 'com.microsoft.azure." + | ||
"msgraph.api.Microsoft' available"); | ||
} | ||
assertThat(microsoft).isNull(); | ||
} | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...gure/src/test/java/com/microsoft/azure/autoconfigure/msgraph/MicrosoftPropertiesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See LICENSE in the project root for | ||
* license information. | ||
*/ | ||
|
||
package com.microsoft.azure.autoconfigure.msgraph; | ||
|
||
import org.junit.Test; | ||
import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||
import org.springframework.context.annotation.AnnotationConfigApplicationContext; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class MicrosoftPropertiesTest { | ||
@Test | ||
public void canSetProperties() { | ||
System.setProperty(Constants.APP_ID_PROPERTY, Constants.APP_ID); | ||
System.setProperty(Constants.APP_SECRET_PROPERTY, Constants.APP_SECRET); | ||
|
||
try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext()) { | ||
context.register(Config.class); | ||
context.refresh(); | ||
final MicrosoftProperties properties = context.getBean(MicrosoftProperties.class); | ||
|
||
assertThat(properties.getAppId()).isEqualTo(Constants.APP_ID); | ||
assertThat(properties.getAppSecret()).isEqualTo(Constants.APP_SECRET); | ||
} | ||
|
||
System.clearProperty(Constants.APP_ID_PROPERTY); | ||
System.clearProperty(Constants.APP_SECRET_PROPERTY); | ||
} | ||
|
||
@Configuration | ||
@EnableConfigurationProperties(MicrosoftProperties.class) | ||
static class Config { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
...aph-spring-social-starter-sample/src/main/java/sample/microsoft/graph/custom/Contact.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See LICENSE in the project root for | ||
* license information. | ||
*/ | ||
|
||
package sample.microsoft.graph.custom; | ||
|
||
// Please be noted this is not a complete representation of the JSON object returned by Microsoft Graph. | ||
public class Contact { | ||
|
||
private String displayName; | ||
private String mobilePhone; | ||
|
||
/** | ||
* The Display Name. | ||
*/ | ||
public String getDisplayName() { | ||
return displayName; | ||
} | ||
|
||
public void setDisplayName(String displayName) { | ||
this.displayName = displayName; | ||
} | ||
|
||
/** | ||
* The Mobile Phone. | ||
*/ | ||
public String getMobilePhone() { | ||
return mobilePhone; | ||
} | ||
|
||
public void setMobilePhone(String mobilePhone) { | ||
this.mobilePhone = mobilePhone; | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...ph-spring-social-starter-sample/src/main/java/sample/microsoft/graph/custom/Contacts.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See LICENSE in the project root for | ||
* license information. | ||
*/ | ||
|
||
package sample.microsoft.graph.custom; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
public class Contacts { | ||
@JsonProperty("value") | ||
private java.util.List<Contact> contacts; | ||
|
||
@JsonProperty("@odata.nextLink") | ||
private String nextLink; | ||
|
||
public java.util.List<Contact> getContacts() { | ||
return contacts; | ||
} | ||
|
||
public void setContacts(java.util.List<Contact> contacts) { | ||
this.contacts = contacts; | ||
} | ||
|
||
/** | ||
* The url to the next page of this collection, or null | ||
*/ | ||
public String getNextLink() { | ||
return nextLink; | ||
} | ||
|
||
public void setNextLink(String nextLink) { | ||
this.nextLink = nextLink; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
...h/microsoft-graph-spring-social-starter-sample/src/main/resources/templates/contacts.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<html> | ||
<head> | ||
<title>Hello Microsoft Graph</title> | ||
</head> | ||
<body> | ||
<table> | ||
<tr> | ||
<th>Name</th> | ||
<th>Phone</th> | ||
</tr> | ||
<tr th:each="contact : ${contacts}"> | ||
<td th:text="${contact.getDisplayName()}"/> | ||
<td th:text="${contact.getMobilePhone()}"/> | ||
</tr> | ||
</table> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...spring-social-microsoft-graph/src/main/java/com/microsoft/azure/msgraph/api/BodyType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See LICENSE in the project root for | ||
* license information. | ||
*/ | ||
|
||
package com.microsoft.azure.msgraph.api; | ||
|
||
/** | ||
* The Enum Body Type. | ||
*/ | ||
public enum BodyType { | ||
/** | ||
* text | ||
*/ | ||
text, | ||
/** | ||
* html | ||
*/ | ||
html, | ||
/** | ||
* For BodyType values that were not expected from the service | ||
*/ | ||
unexpectedValue | ||
} |
17 changes: 17 additions & 0 deletions
17
...ocial-microsoft-graph/src/main/java/com/microsoft/azure/msgraph/api/CustomOperations.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See LICENSE in the project root for | ||
* license information. | ||
*/ | ||
|
||
package com.microsoft.azure.msgraph.api; | ||
|
||
import org.springframework.web.client.RestTemplate; | ||
|
||
import java.net.URI; | ||
|
||
public interface CustomOperations { | ||
public RestTemplate getRestTemplate(); | ||
|
||
public URI getGraphAPIURI(String relativePath); | ||
} |
Oops, something went wrong.