use of org.orcid.core.oauth.OrcidOauth2UserAuthentication in project ORCID-Source by ORCID.
the class DefaultPermissionCheckerTest method testCheckUserPermissionsAuthenticationScopesOrcidAndOrcidMessage.
@Test
@Rollback
@Transactional
public void testCheckUserPermissionsAuthenticationScopesOrcidAndOrcidMessage() throws Exception {
Set<String> resourceIds = new HashSet<String>(Arrays.asList("orcid"));
HashSet<GrantedAuthority> grantedAuthorities = new HashSet<GrantedAuthority>(Arrays.asList(new SimpleGrantedAuthority("ROLE_CLIENT")));
AuthorizationRequest request = new AuthorizationRequest("4444-4444-4444-4441", Arrays.asList("/orcid-bio/external-identifiers/create"));
request.setAuthorities(grantedAuthorities);
request.setResourceIds(resourceIds);
ProfileEntity entity = profileEntityManager.findByOrcid("4444-4444-4444-4446");
OrcidOauth2UserAuthentication oauth2UserAuthentication = new OrcidOauth2UserAuthentication(entity, true);
OAuth2Authentication oAuth2Authentication = new OrcidOAuth2Authentication(request, oauth2UserAuthentication, "made-up-token");
ScopePathType requiredScope = ScopePathType.ORCID_BIO_EXTERNAL_IDENTIFIERS_CREATE;
OrcidMessage orcidMessage = getOrcidMessage();
String messageOrcid = orcidMessage.getOrcidProfile().getOrcidIdentifier().getPath();
defaultPermissionChecker.checkPermissions(oAuth2Authentication, requiredScope, messageOrcid, orcidMessage);
}
use of org.orcid.core.oauth.OrcidOauth2UserAuthentication in project ORCID-Source by ORCID.
the class OrcidTokenStoreServiceTest method testGetAccessToken.
@Test
@Transactional
public void testGetAccessToken() throws Exception {
String clientId = "4444-4444-4444-4441";
Map<String, String> parameters = new HashMap<String, String>();
parameters.put("client_id", clientId);
parameters.put("state", "read");
parameters.put("scope", "/orcid-profile/write");
parameters.put("redirect_uri", "http://www.google.com/");
parameters.put("response_type", "bearer");
OAuth2Request request = new OAuth2Request(Collections.<String, String>emptyMap(), clientId, Collections.<GrantedAuthority>emptyList(), true, new HashSet<String>(Arrays.asList("/orcid-profile/read-limited")), Collections.<String>emptySet(), null, Collections.<String>emptySet(), Collections.<String, Serializable>emptyMap());
ProfileEntity profileEntity = profileEntityManager.findByOrcid("4444-4444-4444-4444");
OrcidOauth2UserAuthentication userAuthentication = new OrcidOauth2UserAuthentication(profileEntity, true);
OAuth2Authentication authentication = new OAuth2Authentication(request, userAuthentication);
DefaultOAuth2AccessToken token = new DefaultOAuth2AccessToken("4444-4444-4444-4441");
token.setExpiration(new Date());
token.setScope(OAuth2Utils.parseParameterList("/orcid-profile/read,/orcid-profile/write"));
token.setTokenType("bearer");
token.setRefreshToken(new DefaultExpiringOAuth2RefreshToken("a-refresh-token", new Date()));
orcidTokenStoreService.storeAccessToken(token, authentication);
OAuth2AccessToken accessToken = orcidTokenStoreService.getAccessToken(authentication);
assertNotNull(accessToken);
}
Aggregations