Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code formatting applied to most files #417

Merged
merged 3 commits into from
Jul 26, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,75 +24,75 @@ public class AcquireTokenInteractiveIT extends SeleniumTest {
private Config cfg;

@Test(dataProvider = "environments", dataProviderClass = EnvironmentsProvider.class)
public void acquireTokenInteractive_ManagedUser(String environment){
public void acquireTokenInteractive_ManagedUser(String environment) {
cfg = new Config(environment);

User user = labUserProvider.getDefaultUser(cfg.azureEnvironment);
assertAcquireTokenAAD(user);
}

@Test()
public void acquireTokenInteractive_ADFSv2019_OnPrem(){
public void acquireTokenInteractive_ADFSv2019_OnPrem() {
User user = labUserProvider.getOnPremAdfsUser(FederationProvider.ADFS_2019);
assertAcquireTokenADFS2019(user);
}

@Test(dataProvider = "environments", dataProviderClass = EnvironmentsProvider.class)
public void acquireTokenInteractive_ADFSv2019_Federated(String environment){
public void acquireTokenInteractive_ADFSv2019_Federated(String environment) {
cfg = new Config(environment);

User user = labUserProvider.getFederatedAdfsUser(cfg.azureEnvironment, FederationProvider.ADFS_2019);
assertAcquireTokenAAD(user);
}

@Test(dataProvider = "environments", dataProviderClass = EnvironmentsProvider.class)
public void acquireTokenInteractive_ADFSv4_Federated(String environment){
public void acquireTokenInteractive_ADFSv4_Federated(String environment) {
cfg = new Config(environment);

User user = labUserProvider.getFederatedAdfsUser(cfg.azureEnvironment, FederationProvider.ADFS_4);
assertAcquireTokenAAD(user);
}

@Test(dataProvider = "environments", dataProviderClass = EnvironmentsProvider.class)
public void acquireTokenInteractive_ADFSv3_Federated(String environment){
public void acquireTokenInteractive_ADFSv3_Federated(String environment) {
cfg = new Config(environment);

User user = labUserProvider.getFederatedAdfsUser(cfg.azureEnvironment, FederationProvider.ADFS_3);
assertAcquireTokenAAD(user);
}

@Test(dataProvider = "environments", dataProviderClass = EnvironmentsProvider.class)
public void acquireTokenInteractive_ADFSv2_Federated(String environment){
public void acquireTokenInteractive_ADFSv2_Federated(String environment) {
cfg = new Config(environment);

User user = labUserProvider.getFederatedAdfsUser(cfg.azureEnvironment, FederationProvider.ADFS_2);
assertAcquireTokenAAD(user);
}

@Test(dataProvider = "environments", dataProviderClass = EnvironmentsProvider.class)
public void acquireTokenWithAuthorizationCode_B2C_Local(String environment){
public void acquireTokenWithAuthorizationCode_B2C_Local(String environment) {
cfg = new Config(environment);

User user = labUserProvider.getB2cUser(cfg.azureEnvironment, B2CProvider.LOCAL);
assertAcquireTokenB2C(user);
}

@Test
public void acquireTokenInteractive_ManagedUser_InstanceAware(){
public void acquireTokenInteractive_ManagedUser_InstanceAware() {
cfg = new Config(AzureEnvironment.AZURE);

User user = labUserProvider.getDefaultUser(AzureEnvironment.AZURE_US_GOVERNMENT);
assertAcquireTokenInstanceAware(user);
}

private void assertAcquireTokenAAD(User user){
private void assertAcquireTokenAAD(User user) {
PublicClientApplication pca;
try {
pca = PublicClientApplication.builder(
user.getAppId()).
authority(cfg.organizationsAuthority()).
build();
} catch(MalformedURLException ex){
} catch (MalformedURLException ex) {
throw new RuntimeException(ex.getMessage());
}

Expand All @@ -107,14 +107,14 @@ private void assertAcquireTokenAAD(User user){
Assert.assertEquals(user.getUpn(), result.account().username());
}

private void assertAcquireTokenADFS2019(User user){
private void assertAcquireTokenADFS2019(User user) {
PublicClientApplication pca;
try {
pca = PublicClientApplication.builder(
TestConstants.ADFS_APP_ID).
authority(TestConstants.ADFS_AUTHORITY).
build();
} catch(MalformedURLException ex){
} catch (MalformedURLException ex) {
throw new RuntimeException(ex.getMessage());
}

Expand All @@ -126,15 +126,15 @@ private void assertAcquireTokenADFS2019(User user){
Assert.assertEquals(user.getUpn(), result.account().username());
}

private void assertAcquireTokenB2C(User user){
private void assertAcquireTokenB2C(User user) {

PublicClientApplication pca;
try {
pca = PublicClientApplication.builder(
user.getAppId()).
b2cAuthority(TestConstants.B2C_AUTHORITY_SIGN_IN).
build();
} catch(MalformedURLException ex){
} catch (MalformedURLException ex) {
throw new RuntimeException(ex.getMessage());
}

Expand Down Expand Up @@ -189,10 +189,12 @@ public void acquireTokensInHomeAndGuestClouds(String homeCloud, String homeCloud

ITokenCacheAccessAspect persistenceAspect = new ITokenCacheAccessAspect() {
String data;

@Override
public void beforeCacheAccess(ITokenCacheAccessContext iTokenCacheAccessContext) {
iTokenCacheAccessContext.tokenCache().deserialize(data);
}

@Override
public void afterCacheAccess(ITokenCacheAccessContext iTokenCacheAccessContext) {
data = iTokenCacheAccessContext.tokenCache().serialize();
Expand All @@ -218,7 +220,7 @@ public void afterCacheAccess(ITokenCacheAccessContext iTokenCacheAccessContext)
private IAuthenticationResult acquireTokenInteractive(
User user,
PublicClientApplication pca,
String scope){
String scope) {

IAuthenticationResult result;
try {
Expand All @@ -238,7 +240,7 @@ private IAuthenticationResult acquireTokenInteractive(

result = pca.acquireToken(parameters).get();

} catch(Exception e){
} catch (Exception e) {
LOG.error("Error acquiring token with authCode: " + e.getMessage());
throw new RuntimeException("Error acquiring token with authCode: " + e.getMessage());
}
Expand All @@ -248,7 +250,7 @@ private IAuthenticationResult acquireTokenInteractive(
private IAuthenticationResult acquireTokenInteractive_instanceAware(
User user,
PublicClientApplication pca,
String scope){
String scope) {

IAuthenticationResult result;
try {
Expand All @@ -268,7 +270,7 @@ private IAuthenticationResult acquireTokenInteractive_instanceAware(

result = pca.acquireToken(parameters).get();

} catch(Exception e){
} catch (Exception e) {
LOG.error("Error acquiring token with authCode: " + e.getMessage());
throw new RuntimeException("Error acquiring token with authCode: " + e.getMessage());
}
Expand All @@ -280,12 +282,12 @@ class SeleniumOpenBrowserAction implements OpenBrowserAction {
private User user;
private PublicClientApplication pca;

SeleniumOpenBrowserAction(User user, PublicClientApplication pca){
SeleniumOpenBrowserAction(User user, PublicClientApplication pca) {
this.user = user;
this.pca = pca;
}

public void openBrowser(URL url){
public void openBrowser(URL url) {
seleniumDriver.navigate().to(url);
runSeleniumAutomatedLogin(user, pca);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class AcquireTokenSilentIT {
private Config cfg;

@BeforeClass
public void setUp(){
public void setUp() {
labUserProvider = LabUserProvider.getInstance();
}

Expand Down Expand Up @@ -109,13 +109,13 @@ public void acquireTokenSilent_MultipleAccountsInCache_UseCorrectAccount(String
}

@Test(dataProvider = "environments", dataProviderClass = EnvironmentsProvider.class)
public void acquireTokenSilent_ADFS2019(String environment) throws Exception{
public void acquireTokenSilent_ADFS2019(String environment) throws Exception {
cfg = new Config(environment);

UserQueryParameters query = new UserQueryParameters();
query.parameters.put(UserQueryParameters.AZURE_ENVIRONMENT, cfg.azureEnvironment);
query.parameters.put(UserQueryParameters.FEDERATION_PROVIDER, FederationProvider.ADFS_2019);
query.parameters.put(UserQueryParameters.USER_TYPE, UserType.FEDERATED);
query.parameters.put(UserQueryParameters.FEDERATION_PROVIDER, FederationProvider.ADFS_2019);
query.parameters.put(UserQueryParameters.USER_TYPE, UserType.FEDERATED);

User user = labUserProvider.getLabUser(query);

Expand All @@ -140,7 +140,7 @@ public void acquireTokenSilent_ADFS2019(String environment) throws Exception{

// Commented out due to unclear B2C behavior causing occasional errors
//@Test
public void acquireTokenSilent_B2C() throws Exception{
public void acquireTokenSilent_B2C() throws Exception {
UserQueryParameters query = new UserQueryParameters();
query.parameters.put(UserQueryParameters.USER_TYPE, UserType.B2C);
query.parameters.put(UserQueryParameters.B2C_PROVIDER, B2CProvider.LOCAL);
Expand All @@ -162,7 +162,6 @@ public void acquireTokenSilent_B2C() throws Exception{
}



@Test
public void acquireTokenSilent_usingCommonAuthority_returnCachedAt() throws Exception {
acquireTokenSilent_returnCachedTokens(cfg.organizationsAuthority());
Expand All @@ -174,7 +173,7 @@ public void acquireTokenSilent_usingTenantSpecificAuthority_returnCachedAt() thr
}

@Test(dataProvider = "environments", dataProviderClass = EnvironmentsProvider.class)
public void acquireTokenSilent_ConfidentialClient_acquireTokenSilent(String environment) throws Exception{
public void acquireTokenSilent_ConfidentialClient_acquireTokenSilent(String environment) throws Exception {
cfg = new Config(environment);

IConfidentialClientApplication cca = getConfidentialClientApplications();
Expand Down Expand Up @@ -221,7 +220,7 @@ public void acquireTokenSilent_ConfidentialClient_acquireTokenSilentDifferentSco
}

@Test(dataProvider = "environments", dataProviderClass = EnvironmentsProvider.class)
public void acquireTokenSilent_WithRefreshOn(String environment) throws Exception{
public void acquireTokenSilent_WithRefreshOn(String environment) throws Exception {
cfg = new Config(environment);

User user = labUserProvider.getDefaultUser(cfg.azureEnvironment);
Expand Down Expand Up @@ -295,7 +294,7 @@ public void acquireTokenSilent_TenantAsParameter(String environment) throws Exce
assertTokensAreNotEqual(result, resultWithTenantParam);
}

private IConfidentialClientApplication getConfidentialClientApplications() throws Exception{
private IConfidentialClientApplication getConfidentialClientApplications() throws Exception {
String clientId = cfg.appProvider.getOboAppId();
String password = cfg.appProvider.getOboAppPassword();

Expand All @@ -304,8 +303,8 @@ private IConfidentialClientApplication getConfidentialClientApplications() throw
return ConfidentialClientApplication.builder(
clientId, credential).
//authority(MICROSOFT_AUTHORITY)
authority(cfg.tenantSpecificAuthority()).
build();
authority(cfg.tenantSpecificAuthority()).
build();
}

private void acquireTokenSilent_returnCachedTokens(String authority) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ApacheHttpClientAdapter implements IHttpClient {

private final CloseableHttpClient httpClient;

ApacheHttpClientAdapter(){
ApacheHttpClientAdapter() {
this.httpClient = HttpClients.createDefault();
}

Expand All @@ -38,31 +38,31 @@ public IHttpResponse send(HttpRequest httpRequest) throws Exception {
}


private HttpRequestBase buildApacheRequestFromMsalRequest(HttpRequest httpRequest){
private HttpRequestBase buildApacheRequestFromMsalRequest(HttpRequest httpRequest) {

if(httpRequest.httpMethod() == HttpMethod.GET){
if (httpRequest.httpMethod() == HttpMethod.GET) {
return builGetRequest(httpRequest);
} else if(httpRequest.httpMethod() == HttpMethod.POST){
} else if (httpRequest.httpMethod() == HttpMethod.POST) {
return buildPostRequest(httpRequest);
} else {
throw new IllegalArgumentException("HttpRequest method should be either GET or POST");
}
}

private HttpGet builGetRequest(HttpRequest httpRequest){
private HttpGet builGetRequest(HttpRequest httpRequest) {
HttpGet httpGet = new HttpGet(httpRequest.url().toString());

for(Map.Entry<String, String> entry: httpRequest.headers().entrySet()){
for (Map.Entry<String, String> entry : httpRequest.headers().entrySet()) {
httpGet.setHeader(entry.getKey(), entry.getValue());
}

return httpGet;
}

private HttpPost buildPostRequest(HttpRequest httpRequest){
private HttpPost buildPostRequest(HttpRequest httpRequest) {

HttpPost httpPost = new HttpPost(httpRequest.url().toString());
for(Map.Entry<String, String> entry: httpRequest.headers().entrySet()){
for (Map.Entry<String, String> entry : httpRequest.headers().entrySet()) {
httpPost.setHeader(entry.getKey(), entry.getValue());
}

Expand All @@ -81,7 +81,7 @@ private IHttpResponse buildMsalResponseFromApacheResponse(CloseableHttpResponse
((HttpResponse) httpResponse).statusCode(apacheResponse.getStatusLine().getStatusCode());

Map<String, List<String>> headers = new HashMap<>();
for(Header header: apacheResponse.getAllHeaders()){
for (Header header : apacheResponse.getAllHeaders()) {
headers.put(header.getName(), Collections.singletonList(header.getValue()));
}
((HttpResponse) httpResponse).addHeaders(headers);
Expand Down
Loading