use of org.springframework.security.oauth2.provider.OAuth2Request in project ORCID-Source by ORCID.
the class T2OrcidApiServiceDelegatorImpl method setSponsorFromAuthentication.
public void setSponsorFromAuthentication(OrcidProfile profile) {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (profile.getOrcidHistory() == null) {
OrcidHistory orcidHistory = new OrcidHistory();
orcidHistory.setCreationMethod(CreationMethod.API);
profile.setOrcidHistory(orcidHistory);
}
profile.getOrcidHistory().setSubmissionDate(new SubmissionDate(DateUtils.convertToXMLGregorianCalendar(new Date())));
if (OAuth2Authentication.class.isAssignableFrom(authentication.getClass())) {
OAuth2Request authorizationRequest = ((OAuth2Authentication) authentication).getOAuth2Request();
Source sponsor = new Source();
String sponsorId = authorizationRequest.getClientId();
ClientDetailsEntity clientDetails = clientDetailsManager.findByClientId(sponsorId);
if (clientDetails != null) {
sponsor.setSourceName(new SourceName(clientDetails.getClientName()));
if (OrcidStringUtils.isClientId(sponsorId)) {
sponsor.setSourceClientId(new SourceClientId(sponsorId));
} else {
sponsor.setSourceOrcid(new SourceOrcid(sponsorId));
}
}
profile.getOrcidHistory().setSource(sponsor);
}
}
use of org.springframework.security.oauth2.provider.OAuth2Request in project ORCID-Source by ORCID.
the class OrcidRandomValueTokenServicesTest method testReissuedAccessTokenHasUpdatedExpiration.
@Test
public void testReissuedAccessTokenHasUpdatedExpiration() throws InterruptedException {
Date earliestExpiry = oneHoursTime();
Map<String, String> authorizationParameters = new HashMap<>();
String clientId = "4444-4444-4444-4441";
authorizationParameters.put(OAuth2Utils.CLIENT_ID, clientId);
authorizationParameters.put(OAuth2Utils.SCOPE, "/orcid-works/create");
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());
ClientDetailsEntity clientDetails = clientDetailsManager.findByClientId(clientId);
Authentication userAuthentication = new OrcidOauth2ClientAuthentication(clientDetails);
OAuth2Authentication authentication = new OAuth2Authentication(request, userAuthentication);
OAuth2AccessToken oauth2AccessToken = tokenServices.createAccessToken(authentication);
Date latestExpiry = oneHoursTime();
assertNotNull(oauth2AccessToken);
assertFalse(oauth2AccessToken.getExpiration().before(earliestExpiry));
assertFalse(oauth2AccessToken.getExpiration().after(latestExpiry));
Thread.sleep(1000);
earliestExpiry = oneHoursTime();
OAuth2AccessToken reissuedOauth2AccessToken = tokenServices.createAccessToken(authentication);
latestExpiry = oneHoursTime();
assertNotNull(reissuedOauth2AccessToken);
assertFalse(reissuedOauth2AccessToken.getExpiration().before(earliestExpiry));
assertFalse(reissuedOauth2AccessToken.getExpiration().after(latestExpiry));
}
use of org.springframework.security.oauth2.provider.OAuth2Request in project ORCID-Source by ORCID.
the class OrcidRandomValueTokenServicesTest method testCreateAddWorkAccessToken.
@Test
public void testCreateAddWorkAccessToken() {
Date earliestExpiry = oneHoursTime();
Map<String, String> authorizationParameters = new HashMap<>();
String clientId = "4444-4444-4444-4441";
authorizationParameters.put(OAuth2Utils.CLIENT_ID, clientId);
authorizationParameters.put(OAuth2Utils.SCOPE, "/orcid-works/create");
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());
ClientDetailsEntity clientDetails = clientDetailsManager.findByClientId(clientId);
Authentication userAuthentication = new OrcidOauth2ClientAuthentication(clientDetails);
OAuth2Authentication authentication = new OAuth2Authentication(request, userAuthentication);
OAuth2AccessToken oauth2AccessToken = tokenServices.createAccessToken(authentication);
Date latestExpiry = oneHoursTime();
assertNotNull(oauth2AccessToken);
assertFalse(oauth2AccessToken.getExpiration().before(earliestExpiry));
assertFalse(oauth2AccessToken.getExpiration().after(latestExpiry));
}
use of org.springframework.security.oauth2.provider.OAuth2Request in project ORCID-Source by ORCID.
the class OrcidTokenStoreServiceTest method testReadAuthentication.
@Test
@Transactional
public void testReadAuthentication() throws Exception {
OAuth2Authentication oAuth2Authentication = orcidTokenStoreService.readAuthentication("persistent-token-2");
assertNotNull(oAuth2Authentication);
OAuth2Request oAuth2Request = oAuth2Authentication.getOAuth2Request();
assertNotNull(oAuth2Request);
Object principal = oAuth2Authentication.getPrincipal();
assertNotNull(principal);
assertTrue(!oAuth2Authentication.isClientOnly());
}
use of org.springframework.security.oauth2.provider.OAuth2Request in project ORCID-Source by ORCID.
the class OrcidSecurityManagerImpl method isNonClientCredentialScope.
private boolean isNonClientCredentialScope(OAuth2Authentication oAuth2Authentication) {
OAuth2Request authorizationRequest = oAuth2Authentication.getOAuth2Request();
Set<String> requestedScopes = ScopePathType.getCombinedScopesFromStringsAsStrings(authorizationRequest.getScope());
for (String scopeName : requestedScopes) {
ScopePathType scopePathType = ScopePathType.fromValue(scopeName);
if (!scopePathType.isClientCreditalScope()) {
return true;
}
}
return false;
}
Aggregations