Skip to content

Commit

Permalink
custom user info token services
Browse files Browse the repository at this point in the history
  • Loading branch information
sqshq committed Mar 27, 2016
1 parent 428eaa9 commit 5e260b5
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.piggymetrics.account.service;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.piggymetrics.account.client.AuthServiceClient;
import com.piggymetrics.account.client.StatisticsServiceClient;
import com.piggymetrics.account.domain.Account;
Expand Down Expand Up @@ -88,10 +89,11 @@ public void saveChanges(String name, Account update) {

log.debug("account {} changes has been saved", name);

try {
statisticsClient.updateStatistics(name, account);
} catch (Exception e) {
log.error("error during statistics update", e);
}
updateStatistics(name, account);
}

@HystrixCommand
private void updateStatistics(String name, Account account) {
statisticsClient.updateStatistics(name, account);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@
import org.springframework.security.oauth2.provider.OAuth2Request;
import org.springframework.security.oauth2.provider.token.ResourceServerTokenServices;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;

/**
* Extended implementation of {@link org.springframework.boot.autoconfigure.security.oauth2.resource.UserInfoTokenServices}
Expand Down Expand Up @@ -99,10 +96,10 @@ private OAuth2Request getRequest(Map<String, Object> map) {
Map<String, Object> request = (Map<String, Object>) map.get("oauth2Request");

String clientId = (String) request.get("clientId");
Set<String> scope = request.containsKey("scope") ?
(Set<String>) map.get("scope") : Collections.<String>emptySet();
Set<String> scope = new LinkedHashSet<>(request.containsKey("scope") ?
(Collection<String>) request.get("scope") : Collections.<String>emptySet());

return new OAuth2Request(null, clientId, null, true, scope,
return new OAuth2Request(null, clientId, null, true, new HashSet<>(scope),
null, null, null, null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,16 +146,4 @@ public void shouldFailWhenNoAccountsExistedWithGivenName() {
when(accountService.findByName("test")).thenReturn(null);
accountService.saveChanges("test", update);
}

@Test
public void shouldNotFailOnStatisticsClientException() {
final Account update = new Account();
update.setIncomes(Arrays.asList(new Item()));
update.setExpenses(Arrays.asList(new Item()));

when(accountService.findByName("test")).thenReturn(new Account());
doThrow(RuntimeException.class).when(statisticsClient).updateStatistics(any(), any());

accountService.saveChanges("test", update);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@
import org.springframework.security.oauth2.provider.OAuth2Request;
import org.springframework.security.oauth2.provider.token.ResourceServerTokenServices;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;

/**
* Extended implementation of {@link org.springframework.boot.autoconfigure.security.oauth2.resource.UserInfoTokenServices}
Expand Down Expand Up @@ -99,10 +96,10 @@ private OAuth2Request getRequest(Map<String, Object> map) {
Map<String, Object> request = (Map<String, Object>) map.get("oauth2Request");

String clientId = (String) request.get("clientId");
Set<String> scope = request.containsKey("scope") ?
(Set<String>) map.get("scope") : Collections.<String>emptySet();
Set<String> scope = new LinkedHashSet<>(request.containsKey("scope") ?
(Collection<String>) request.get("scope") : Collections.<String>emptySet());

return new OAuth2Request(null, clientId, null, true, scope,
return new OAuth2Request(null, clientId, null, true, new HashSet<>(scope),
null, null, null, null);
}

Expand Down

0 comments on commit 5e260b5

Please sign in to comment.