@Test public void testGetUserInfo(){ suppress(constructor(DefaultOAuthTokenStoreImpl.class)); OAuth2TokenStore store = mock(DefaultOAuthTokenStoreImpl.class); AMIdentity id = PowerMockito.mock(AMIdentity.class); CoreToken token = mock(CoreToken.class); scopeImpl = new ScopeImpl(store, id); Set idAttribute = new HashSet<String>(); idAttribute.add("attributeValue"); Set scopeValue = new HashSet<String>(); scopeValue.add("email"); try { when(id.getAttribute(anyString())).thenReturn(idAttribute); } catch (Exception e){ } when(token.getUserID()).thenReturn("user"); when(token.getScope()).thenReturn(scopeValue); when(token.getRealm()).thenReturn("/"); Map<String, Object> returnValues = scopeImpl.getUserInfo(token); assert(returnValues.containsKey("sub") && returnValues.get("sub").equals("user")); assert(returnValues.containsKey("email") && returnValues.get("email").equals("attributeValue")); }
public Map<String,Object> getUserInfo(CoreToken token){ Set<String> scopes = token.getScope(); Map<String,Object> response = new HashMap<String, Object>(); AMIdentity id = null; if (this.id == null){ id = OAuth2Utils.getIdentity(token.getUserID(), token.getRealm()); } else { id = this.id; } response.put("sub", token.getUserID()); for(String scope: scopes){ Object attributes = scopeToUserUserProfileAttributes.get(scope); if (attributes == null){ OAuth2Utils.DEBUG.error("ScopeImpl.getUserInfo()::Invalid Scope in token scope="+ scope); } else if (attributes instanceof String){ Set<String> attr = null; try { attr = id.getAttribute((String)attributes); } catch (IdRepoException e) { OAuth2Utils.DEBUG.error("ScopeImpl.getUserInfo(): Unable to retrieve atrribute", e); } catch (SSOException e) { OAuth2Utils.DEBUG.error("ScopeImpl.getUserInfo(): Unable to retrieve atrribute", e); } if (attr != null && attr.size() == 1){ response.put(scope, attr.iterator().next()); } else if (attr != null && attr.size() > 1){ response.put(scope, attr); } else { OAuth2Utils.DEBUG.error("ScopeImpl.getUserInfo(): Got an empty result for scope=" + scope); } } else if (attributes instanceof Map){ if (attributes != null && !((Map<String,String>) attributes).isEmpty()){ for (Map.Entry<String, String> entry: ((Map<String, String>) attributes).entrySet()){ String attribute = null; attribute = (String)entry.getValue(); Set<String> attr = null; try { attr = id.getAttribute(attribute); } catch (IdRepoException e) { OAuth2Utils.DEBUG.error("ScopeImpl.getUserInfo(): Unable to retrieve atrribute", e); } catch (SSOException e) { OAuth2Utils.DEBUG.error("ScopeImpl.getUserInfo(): Unable to retrieve atrribute", e); } if (attr != null && attr.size() == 1){ response.put(entry.getKey(), attr.iterator().next()); } else if (attr != null && attr.size() > 1){ response.put(entry.getKey(), attr); } else { OAuth2Utils.DEBUG.error("ScopeImpl.getUserInfo(): Got an empty result for scope=" + scope); } } } } } return response; }
ScopeImpl implements Scope { public Map<String,Object> getUserInfo(CoreToken token){ Set<String> scopes = token.getScope(); Map<String,Object> response = new HashMap<String, Object>(); AMIdentity id = null; if (this.id == null){ id = OAuth2Utils.getIdentity(token.getUserID(), token.getRealm()); } else { id = this.id; } response.put("sub", token.getUserID()); for(String scope: scopes){ Object attributes = scopeToUserUserProfileAttributes.get(scope); if (attributes == null){ OAuth2Utils.DEBUG.error("ScopeImpl.getUserInfo()::Invalid Scope in token scope="+ scope); } else if (attributes instanceof String){ Set<String> attr = null; try { attr = id.getAttribute((String)attributes); } catch (IdRepoException e) { OAuth2Utils.DEBUG.error("ScopeImpl.getUserInfo(): Unable to retrieve atrribute", e); } catch (SSOException e) { OAuth2Utils.DEBUG.error("ScopeImpl.getUserInfo(): Unable to retrieve atrribute", e); } if (attr != null && attr.size() == 1){ response.put(scope, attr.iterator().next()); } else if (attr != null && attr.size() > 1){ response.put(scope, attr); } else { OAuth2Utils.DEBUG.error("ScopeImpl.getUserInfo(): Got an empty result for scope=" + scope); } } else if (attributes instanceof Map){ if (attributes != null && !((Map<String,String>) attributes).isEmpty()){ for (Map.Entry<String, String> entry: ((Map<String, String>) attributes).entrySet()){ String attribute = null; attribute = (String)entry.getValue(); Set<String> attr = null; try { attr = id.getAttribute(attribute); } catch (IdRepoException e) { OAuth2Utils.DEBUG.error("ScopeImpl.getUserInfo(): Unable to retrieve atrribute", e); } catch (SSOException e) { OAuth2Utils.DEBUG.error("ScopeImpl.getUserInfo(): Unable to retrieve atrribute", e); } if (attr != null && attr.size() == 1){ response.put(entry.getKey(), attr.iterator().next()); } else if (attr != null && attr.size() > 1){ response.put(entry.getKey(), attr); } else { OAuth2Utils.DEBUG.error("ScopeImpl.getUserInfo(): Got an empty result for scope=" + scope); } } } } } return response; } }
ScopeImpl implements Scope { public Map<String,Object> getUserInfo(CoreToken token){ Set<String> scopes = token.getScope(); Map<String,Object> response = new HashMap<String, Object>(); AMIdentity id = null; if (this.id == null){ id = OAuth2Utils.getIdentity(token.getUserID(), token.getRealm()); } else { id = this.id; } response.put("sub", token.getUserID()); for(String scope: scopes){ Object attributes = scopeToUserUserProfileAttributes.get(scope); if (attributes == null){ OAuth2Utils.DEBUG.error("ScopeImpl.getUserInfo()::Invalid Scope in token scope="+ scope); } else if (attributes instanceof String){ Set<String> attr = null; try { attr = id.getAttribute((String)attributes); } catch (IdRepoException e) { OAuth2Utils.DEBUG.error("ScopeImpl.getUserInfo(): Unable to retrieve atrribute", e); } catch (SSOException e) { OAuth2Utils.DEBUG.error("ScopeImpl.getUserInfo(): Unable to retrieve atrribute", e); } if (attr != null && attr.size() == 1){ response.put(scope, attr.iterator().next()); } else if (attr != null && attr.size() > 1){ response.put(scope, attr); } else { OAuth2Utils.DEBUG.error("ScopeImpl.getUserInfo(): Got an empty result for scope=" + scope); } } else if (attributes instanceof Map){ if (attributes != null && !((Map<String,String>) attributes).isEmpty()){ for (Map.Entry<String, String> entry: ((Map<String, String>) attributes).entrySet()){ String attribute = null; attribute = (String)entry.getValue(); Set<String> attr = null; try { attr = id.getAttribute(attribute); } catch (IdRepoException e) { OAuth2Utils.DEBUG.error("ScopeImpl.getUserInfo(): Unable to retrieve atrribute", e); } catch (SSOException e) { OAuth2Utils.DEBUG.error("ScopeImpl.getUserInfo(): Unable to retrieve atrribute", e); } if (attr != null && attr.size() == 1){ response.put(entry.getKey(), attr.iterator().next()); } else if (attr != null && attr.size() > 1){ response.put(entry.getKey(), attr); } else { OAuth2Utils.DEBUG.error("ScopeImpl.getUserInfo(): Got an empty result for scope=" + scope); } } } } } return response; } ScopeImpl();  ScopeImpl(OAuth2TokenStore store, AMIdentity id); }
ScopeImpl implements Scope { public Map<String,Object> getUserInfo(CoreToken token){ Set<String> scopes = token.getScope(); Map<String,Object> response = new HashMap<String, Object>(); AMIdentity id = null; if (this.id == null){ id = OAuth2Utils.getIdentity(token.getUserID(), token.getRealm()); } else { id = this.id; } response.put("sub", token.getUserID()); for(String scope: scopes){ Object attributes = scopeToUserUserProfileAttributes.get(scope); if (attributes == null){ OAuth2Utils.DEBUG.error("ScopeImpl.getUserInfo()::Invalid Scope in token scope="+ scope); } else if (attributes instanceof String){ Set<String> attr = null; try { attr = id.getAttribute((String)attributes); } catch (IdRepoException e) { OAuth2Utils.DEBUG.error("ScopeImpl.getUserInfo(): Unable to retrieve atrribute", e); } catch (SSOException e) { OAuth2Utils.DEBUG.error("ScopeImpl.getUserInfo(): Unable to retrieve atrribute", e); } if (attr != null && attr.size() == 1){ response.put(scope, attr.iterator().next()); } else if (attr != null && attr.size() > 1){ response.put(scope, attr); } else { OAuth2Utils.DEBUG.error("ScopeImpl.getUserInfo(): Got an empty result for scope=" + scope); } } else if (attributes instanceof Map){ if (attributes != null && !((Map<String,String>) attributes).isEmpty()){ for (Map.Entry<String, String> entry: ((Map<String, String>) attributes).entrySet()){ String attribute = null; attribute = (String)entry.getValue(); Set<String> attr = null; try { attr = id.getAttribute(attribute); } catch (IdRepoException e) { OAuth2Utils.DEBUG.error("ScopeImpl.getUserInfo(): Unable to retrieve atrribute", e); } catch (SSOException e) { OAuth2Utils.DEBUG.error("ScopeImpl.getUserInfo(): Unable to retrieve atrribute", e); } if (attr != null && attr.size() == 1){ response.put(entry.getKey(), attr.iterator().next()); } else if (attr != null && attr.size() > 1){ response.put(entry.getKey(), attr); } else { OAuth2Utils.DEBUG.error("ScopeImpl.getUserInfo(): Got an empty result for scope=" + scope); } } } } } return response; } ScopeImpl();  ScopeImpl(OAuth2TokenStore store, AMIdentity id); Set<String> scopeToPresentOnAuthorizationPage(Set<String> requestedScope, Set<String> availableScopes, Set<String> defaultScopes); Set<String> scopeRequestedForAccessToken(Set<String> requestedScope, Set<String> availableScopes, Set<String> defaultScopes); Set<String> scopeRequestedForRefreshToken(Set<String> requestedScope,
                                                     Set<String> availableScopes,
                                                     Set<String> allScopes,
                                                     Set<String> defaultScopes); Map<String, Object> evaluateScope(CoreToken token); Map<String, Object> extraDataToReturnForTokenEndpoint(Map<String, String> parameters, CoreToken token); Map<String, String> extraDataToReturnForAuthorizeEndpoint(Map<String, String> parameters, Map<String, CoreToken> tokens); Map<String,Object> getUserInfo(CoreToken token); }
ScopeImpl implements Scope { public Map<String,Object> getUserInfo(CoreToken token){ Set<String> scopes = token.getScope(); Map<String,Object> response = new HashMap<String, Object>(); AMIdentity id = null; if (this.id == null){ id = OAuth2Utils.getIdentity(token.getUserID(), token.getRealm()); } else { id = this.id; } response.put("sub", token.getUserID()); for(String scope: scopes){ Object attributes = scopeToUserUserProfileAttributes.get(scope); if (attributes == null){ OAuth2Utils.DEBUG.error("ScopeImpl.getUserInfo()::Invalid Scope in token scope="+ scope); } else if (attributes instanceof String){ Set<String> attr = null; try { attr = id.getAttribute((String)attributes); } catch (IdRepoException e) { OAuth2Utils.DEBUG.error("ScopeImpl.getUserInfo(): Unable to retrieve atrribute", e); } catch (SSOException e) { OAuth2Utils.DEBUG.error("ScopeImpl.getUserInfo(): Unable to retrieve atrribute", e); } if (attr != null && attr.size() == 1){ response.put(scope, attr.iterator().next()); } else if (attr != null && attr.size() > 1){ response.put(scope, attr); } else { OAuth2Utils.DEBUG.error("ScopeImpl.getUserInfo(): Got an empty result for scope=" + scope); } } else if (attributes instanceof Map){ if (attributes != null && !((Map<String,String>) attributes).isEmpty()){ for (Map.Entry<String, String> entry: ((Map<String, String>) attributes).entrySet()){ String attribute = null; attribute = (String)entry.getValue(); Set<String> attr = null; try { attr = id.getAttribute(attribute); } catch (IdRepoException e) { OAuth2Utils.DEBUG.error("ScopeImpl.getUserInfo(): Unable to retrieve atrribute", e); } catch (SSOException e) { OAuth2Utils.DEBUG.error("ScopeImpl.getUserInfo(): Unable to retrieve atrribute", e); } if (attr != null && attr.size() == 1){ response.put(entry.getKey(), attr.iterator().next()); } else if (attr != null && attr.size() > 1){ response.put(entry.getKey(), attr); } else { OAuth2Utils.DEBUG.error("ScopeImpl.getUserInfo(): Got an empty result for scope=" + scope); } } } } } return response; } ScopeImpl();  ScopeImpl(OAuth2TokenStore store, AMIdentity id); Set<String> scopeToPresentOnAuthorizationPage(Set<String> requestedScope, Set<String> availableScopes, Set<String> defaultScopes); Set<String> scopeRequestedForAccessToken(Set<String> requestedScope, Set<String> availableScopes, Set<String> defaultScopes); Set<String> scopeRequestedForRefreshToken(Set<String> requestedScope,
                                                     Set<String> availableScopes,
                                                     Set<String> allScopes,
                                                     Set<String> defaultScopes); Map<String, Object> evaluateScope(CoreToken token); Map<String, Object> extraDataToReturnForTokenEndpoint(Map<String, String> parameters, CoreToken token); Map<String, String> extraDataToReturnForAuthorizeEndpoint(Map<String, String> parameters, Map<String, CoreToken> tokens); Map<String,Object> getUserInfo(CoreToken token);  }