Skip to content
This repository has been archived by the owner on Dec 4, 2023. It is now read-only.

Java build corrections #83

Merged
merged 14 commits into from
Aug 12, 2019
21 changes: 21 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# EditorConfig is awesome: http://EditorConfig.org
# File take from the VSCode repo at:
# https://github.com/Microsoft/vscode/blob/master/.editorconfig

# top-most EditorConfig file
root = true

# Tab indentation
[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false

[*.xml]
indent_size = 2
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ Thumbs.db

# reduced pom files should not be included
dependency-reduced-pom.xml
/.vs/ProjectSettings.json
/.vs/slnx.sqlite
/.vs/VSWorkspaceState.json
*.factorypath
.vscode/settings.json
pom.xml.versionsBackup
3 changes: 0 additions & 3 deletions .vscode/settings.json

This file was deleted.

17 changes: 13 additions & 4 deletions libraries/bot-connector/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,19 @@
<aggregate>true</aggregate>
</configuration>
</plugin>
</plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

</profile>
Expand Down Expand Up @@ -249,11 +261,8 @@
</archive>
</configuration>
</plugin>


</plugins>
</build>
</profile>
</profiles>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import com.microsoft.rest.ServiceFuture;
import com.microsoft.rest.ServiceResponse;
import java.io.InputStream;
import java.io.IOException;
import rx.Observable;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import com.microsoft.rest.ServiceCallback;
import com.microsoft.rest.ServiceFuture;
import com.microsoft.rest.ServiceResponse;
import java.io.IOException;
import java.util.List;
import rx.Observable;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@
package com.microsoft.bot.connector.authentication;

import com.microsoft.aad.adal4j.AuthenticationException;
import com.microsoft.bot.connector.authentication.JwtTokenExtractor;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

import static com.microsoft.bot.connector.authentication.AuthenticationConstants.*;

public class ChannelValidation {
/**
* TO BOT FROM CHANNEL: Token validation parameters when connecting to a bot
Expand All @@ -27,9 +24,9 @@ public class ChannelValidation {
*/
public static CompletableFuture<ClaimsIdentity> authenticateToken(String authHeader, CredentialProvider credentials, String channelId) throws ExecutionException, InterruptedException, AuthenticationException {
JwtTokenExtractor tokenExtractor = new JwtTokenExtractor(
ToBotFromChannelTokenValidationParameters,
ToBotFromChannelOpenIdMetadataUrl,
AllowedSigningAlgorithms);
ToBotFromChannelTokenValidationParameters,
AuthenticationConstants.ToBotFromChannelOpenIdMetadataUrl,
AuthenticationConstants.AllowedSigningAlgorithms);

ClaimsIdentity identity = tokenExtractor.getIdentityAsync(authHeader, channelId).get();
if (identity == null) {
Expand All @@ -48,13 +45,13 @@ public static CompletableFuture<ClaimsIdentity> authenticateToken(String authHea
// Async validation.

// Look for the "aud" claim, but only if issued from the Bot Framework
if (!identity.getIssuer().equalsIgnoreCase(ToBotFromChannelTokenIssuer)) {
if (!identity.getIssuer().equalsIgnoreCase(AuthenticationConstants.ToBotFromChannelTokenIssuer)) {
throw new AuthenticationException("Token Not Authenticated");
}

// The AppId from the claim in the token must match the AppId specified by the developer. Note that
// the Bot Framework uses the Audience claim ("aud") to pass the AppID.
String appIdFromClaim = identity.claims().get(AudienceClaim);
String appIdFromClaim = identity.claims().get(AuthenticationConstants.AudienceClaim);
if (appIdFromClaim == null || appIdFromClaim.isEmpty()) {
// Claim is present, but doesn't have a value. Not Authorized.
throw new AuthenticationException("Token Not Authenticated");
Expand All @@ -79,14 +76,14 @@ public static CompletableFuture<ClaimsIdentity> authenticateToken(String authHea
public static CompletableFuture<ClaimsIdentity> authenticateToken(String authHeader,CredentialProvider credentials, String channelId, String serviceUrl) throws ExecutionException, InterruptedException, AuthenticationException {
ClaimsIdentity identity = ChannelValidation.authenticateToken(authHeader, credentials, channelId).get();

if (!identity.claims().containsKey(ServiceUrlClaim)) {
if (!identity.claims().containsKey(AuthenticationConstants.ServiceUrlClaim)) {
// Claim must be present. Not Authorized.
throw new AuthenticationException(String.format("'%s' claim is required on Channel Token.", ServiceUrlClaim));
throw new AuthenticationException(String.format("'%s' claim is required on Channel Token.", AuthenticationConstants.ServiceUrlClaim));
}

if (!serviceUrl.equalsIgnoreCase(identity.claims().get(ServiceUrlClaim))) {
if (!serviceUrl.equalsIgnoreCase(identity.claims().get(AuthenticationConstants.ServiceUrlClaim))) {
// Claim must match. Not Authorized.
throw new AuthenticationException(String.format("'%s' claim does not match service url provided (%s).", ServiceUrlClaim, serviceUrl));
throw new AuthenticationException(String.format("'%s' claim does not match service url provided (%s).", AuthenticationConstants.ServiceUrlClaim, serviceUrl));
}

return CompletableFuture.completedFuture(identity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public CompletableFuture<Boolean> isValidAppIdAsync(String appId) {

@Override
public CompletableFuture<String> getAppPasswordAsync(String appId) {
return CompletableFuture.completedFuture((this.appId.equals(appId) ? this.appPassword : null));
return CompletableFuture.completedFuture(this.appId.equals(appId) ? this.appPassword : null);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@
import com.auth0.jwt.JWT;
import com.auth0.jwt.interfaces.DecodedJWT;
import com.microsoft.aad.adal4j.AuthenticationException;
import com.microsoft.bot.connector.authentication.JwtTokenExtractor;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

import static com.microsoft.bot.connector.authentication.AuthenticationConstants.*;

/**
* Validates and Examines JWT tokens from the Bot Framework Emulator
*/
Expand Down Expand Up @@ -78,8 +75,8 @@ public static CompletableFuture<Boolean> isTokenFromEmulator(String authHeader)
public static CompletableFuture<ClaimsIdentity> authenticateToken(String authHeader, CredentialProvider credentials, String channelId) throws ExecutionException, InterruptedException, AuthenticationException {
JwtTokenExtractor tokenExtractor = new JwtTokenExtractor(
ToBotFromEmulatorTokenValidationParameters,
ToBotFromEmulatorOpenIdMetadataUrl,
AllowedSigningAlgorithms);
AuthenticationConstants.ToBotFromEmulatorOpenIdMetadataUrl,
AuthenticationConstants.AllowedSigningAlgorithms);

ClaimsIdentity identity = tokenExtractor.getIdentityAsync(authHeader, channelId).get();
if (identity == null) {
Expand All @@ -96,32 +93,32 @@ public static CompletableFuture<ClaimsIdentity> authenticateToken(String authHea
// what we're looking for. Note that in a multi-tenant bot, this value
// comes from developer code that may be reaching out to a service, hence the
// Async validation.
if (!identity.claims().containsKey(VersionClaim)) {
throw new AuthenticationException(String.format("'%s' claim is required on Emulator Tokens.", VersionClaim));
if (!identity.claims().containsKey(AuthenticationConstants.VersionClaim)) {
throw new AuthenticationException(String.format("'%s' claim is required on Emulator Tokens.", AuthenticationConstants.VersionClaim));
}

String tokenVersion = identity.claims().get(VersionClaim);
String tokenVersion = identity.claims().get(AuthenticationConstants.VersionClaim);
String appId = "";

// The Emulator, depending on Version, sends the AppId via either the
// appid claim (Version 1) or the Authorized Party claim (Version 2).
if (tokenVersion.isEmpty() || tokenVersion.equalsIgnoreCase("1.0")) {
// either no Version or a version of "1.0" means we should look for
// the claim in the "appid" claim.
if (!identity.claims().containsKey(AppIdClaim)) {
if (!identity.claims().containsKey(AuthenticationConstants.AppIdClaim)) {
// No claim around AppID. Not Authorized.
throw new AuthenticationException(String.format("'%s' claim is required on Emulator Token version '1.0'.", AppIdClaim));
throw new AuthenticationException(String.format("'%s' claim is required on Emulator Token version '1.0'.", AuthenticationConstants.AppIdClaim));
}

appId = identity.claims().get(AppIdClaim);
appId = identity.claims().get(AuthenticationConstants.AppIdClaim);
} else if (tokenVersion.equalsIgnoreCase("2.0")) {
// Emulator, "2.0" puts the AppId in the "azp" claim.
if (!identity.claims().containsKey(AuthorizedParty)) {
if (!identity.claims().containsKey(AuthenticationConstants.AuthorizedParty)) {
// No claim around AppID. Not Authorized.
throw new AuthenticationException(String.format("'%s' claim is required on Emulator Token version '2.0'.", AuthorizedParty));
throw new AuthenticationException(String.format("'%s' claim is required on Emulator Token version '2.0'.", AuthenticationConstants.AuthorizedParty));
}

appId = identity.claims().get(AuthorizedParty);
appId = identity.claims().get(AuthenticationConstants.AuthorizedParty);
} else {
// Unknown Version. Not Authorized.
throw new AuthenticationException(String.format("Unknown Emulator Token version '%s'.", tokenVersion));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
import com.auth0.jwt.interfaces.DecodedJWT;
import com.auth0.jwt.interfaces.Verification;
import com.microsoft.aad.adal4j.AuthenticationException;
import com.microsoft.bot.connector.authentication.ClaimsIdentity;
import com.microsoft.bot.connector.authentication.ClaimsIdentityImpl;
import com.microsoft.bot.connector.authentication.TokenValidationParameters;
import org.apache.commons.lang3.StringUtils;

import java.util.HashMap;
Expand All @@ -20,7 +17,6 @@
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.function.Function;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@

package com.microsoft.bot.connector.authentication;

import com.auth0.jwt.interfaces.Claim;
import com.microsoft.aad.adal4j.AuthenticationException;
import com.microsoft.bot.connector.authentication.MicrosoftAppCredentials;
import com.microsoft.bot.connector.authentication.ClaimsIdentityImpl;
import com.microsoft.bot.connector.authentication.EmulatorValidation;
import com.microsoft.bot.schema.models.Activity;

import java.util.concurrent.CompletableFuture;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ public class MicrosoftAppCredentials implements ServiceClientCredentials {

private String currentToken = null;
private long expiredTime = 0;
private static final Object cacheSync = new Object();
//private static final Object cacheSync = new Object();
protected static final HashMap<String, OAuthResponse> cache = new HashMap<String, OAuthResponse>();

public final String OAuthEndpoint = AuthenticationConstants.ToChannelFromBotLoginUrl;
public final String OAuthScope = AuthenticationConstants.ToChannelFromBotOAuthScope;
public final String OAuthEndpoint = ToChannelFromBotLoginUrl;
public final String OAuthScope = ToChannelFromBotOAuthScope;


public String getTokenCacheKey() {
Expand Down Expand Up @@ -83,7 +83,7 @@ public String getToken(Request request) throws IOException {
}


private boolean ShouldSetToken(String url) {
protected boolean ShouldSetToken(String url) {
if (isTrustedServiceUrl(url)) {
return true;
}
Expand Down Expand Up @@ -121,6 +121,8 @@ public static void trustServiceUrl(String serviceUrl, LocalDateTime expirationTi
URL url = new URL(serviceUrl);
trustServiceUrl(url, expirationTime);
} catch (MalformedURLException e) {
//TODO: What's missing here?
e.printStackTrace();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

package com.microsoft.bot.connector.authentication;

import com.microsoft.bot.connector.authentication.MicrosoftAppCredentials;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ protected URI MakeUri(String uri, HashMap<String, String> queryStrings) throws U
throw new RuntimeException(e);
}
})
.collect(joining("&", (uri.endsWith("?") ? uri : uri + "?"), ""));
.collect(joining("&", uri.endsWith("?") ? uri : uri + "?", ""));
return new URI(newUri);


Expand Down Expand Up @@ -177,8 +177,6 @@ public CompletableFuture<Boolean> SignOutUserAsync(String userId, String connect
}

return CompletableFuture.supplyAsync(() -> {
String invocationId = null;

// Construct URL
HashMap<String, String> qstrings = new HashMap<>();
qstrings.put("userId", userId);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.microsoft.bot.connector.authentication;


import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.joda.time.DateTime;
Expand Down Expand Up @@ -43,6 +42,6 @@ public OAuthResponse withExpirationTime(DateTime expirationTime) {
}

@JsonAnySetter
private HashMap<String, String> properties;
public HashMap<String, String> properties;

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@
import com.microsoft.azure.AzureServiceClient;
import com.microsoft.bot.connector.Attachments;
import com.microsoft.bot.connector.ConnectorClient;
import com.microsoft.bot.connector.Conversations;
import com.microsoft.rest.credentials.ServiceClientCredentials;
import com.microsoft.rest.RestClient;
import com.microsoft.rest.retry.RetryStrategy;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import java.util.stream.Stream;

/**
* Initializes a new instance of the ConnectorClientImpl class.
Expand Down
18 changes: 14 additions & 4 deletions libraries/botbuilder-schema/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>RELEASE</version>
<version>2.10.3</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>RELEASE</version>
<version>3.9</version>
<scope>compile</scope>
</dependency>
</dependencies>
Expand Down Expand Up @@ -125,6 +125,18 @@
<aggregate>true</aggregate>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand Down Expand Up @@ -197,10 +209,8 @@
</execution>
</executions>
</plugin>

</plugins>
</build>
</profile>
</profiles>

</project>
Loading