use of org.orcid.jaxb.model.notification.permission_rc3.AuthorizationUrl in project ORCID-Source by ORCID.
the class NotificationValidationManagerImpl method validateNotificationPermission.
@Override
public void validateNotificationPermission(NotificationPermission notification) {
AuthorizationUrl authorizationUrl = notification.getAuthorizationUrl();
String uriString = authorizationUrl.getUri();
if (StringUtils.isNotBlank(uriString)) {
try {
new URI(uriString);
} catch (URISyntaxException e) {
throw new OrcidValidationException("Bad authorization uri", e);
}
}
externalIDValidator.validateNotificationItems(notification.getItems());
}
use of org.orcid.jaxb.model.notification.permission_rc3.AuthorizationUrl in project ORCID-Source by ORCID.
the class NotificationsTest method createPermissionNotificationWithBlankAuthorizationUri.
@Test
public void createPermissionNotificationWithBlankAuthorizationUri() throws JSONException {
NotificationPermission notification = unmarshallFromPath("/notification_2.0_rc3/samples/notification-permission-2.0_rc3.xml");
notification.setPutCode(null);
AuthorizationUrl authUrl = notification.getAuthorizationUrl();
authUrl.setUri("");
String accessToken = oauthHelper.getClientCredentialsAccessToken(client1ClientId, client1ClientSecret, ScopePathType.PREMIUM_NOTIFICATION);
ClientResponse postResponse = notificationsClient.addPermissionNotificationXml(testUser1OrcidId, notification, accessToken);
assertNotNull(postResponse);
assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
String locationPath = postResponse.getLocation().getPath();
assertTrue("Location header path should match pattern, but was " + locationPath, locationPath.matches(".*/v2.0_rc3/" + testUser1OrcidId + "/notification-permission/\\d+"));
String putCodeString = locationPath.substring(locationPath.lastIndexOf('/') + 1);
Long putCode = Long.valueOf(putCodeString);
ClientResponse viewResponse = notificationsClient.viewPermissionNotificationXml(testUser1OrcidId, putCode, accessToken);
assertEquals(Response.Status.OK.getStatusCode(), viewResponse.getStatus());
NotificationPermission retrievedNotification = viewResponse.getEntity(NotificationPermission.class);
assertNotNull(retrievedNotification);
assertTrue(retrievedNotification.getAuthorizationUrl().getPath().endsWith(authUrl.getPath()));
assertFalse(retrievedNotification.getAuthorizationUrl().getPath().startsWith("http"));
assertTrue(retrievedNotification.getAuthorizationUrl().getUri().startsWith("http"));
}
use of org.orcid.jaxb.model.notification.permission_rc3.AuthorizationUrl in project ORCID-Source by ORCID.
the class NotificationsTest method createPermissionNotificationWithUnencodedSpaceInAuthorizationPath.
@Test
public void createPermissionNotificationWithUnencodedSpaceInAuthorizationPath() throws JSONException {
NotificationPermission notification = unmarshallFromPath("/notification_2.0_rc3/samples/notification-permission-2.0_rc3.xml");
notification.setPutCode(null);
AuthorizationUrl authUrl = notification.getAuthorizationUrl();
authUrl.setUri(null);
authUrl.setPath("/oauth/authorize?client_id=0000-0003-4223-0632&response_type=code&scope=/read-limited /activities/update&redirect_uri=https://developers.google.com/oauthplayground");
String accessToken = oauthHelper.getClientCredentialsAccessToken(client1ClientId, client1ClientSecret, ScopePathType.PREMIUM_NOTIFICATION);
ClientResponse response = notificationsClient.addPermissionNotificationXml(testUser1OrcidId, notification, accessToken);
assertNotNull(response);
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus());
assertNull(response.getLocation());
}
use of org.orcid.jaxb.model.notification.permission_rc3.AuthorizationUrl in project ORCID-Source by ORCID.
the class NotificationsTest method createPermissionNotificationWithTrailingSpaceInAuthorizationUrl.
@Test
public void createPermissionNotificationWithTrailingSpaceInAuthorizationUrl() throws JSONException {
NotificationPermission notification = unmarshallFromPath("/notification_2.0_rc4/samples/notification-permission-2.0_rc4.xml");
notification.setPutCode(null);
AuthorizationUrl authUrl = notification.getAuthorizationUrl();
authUrl.setUri(authUrl.getUri() + " ");
String accessToken = oauthHelper.getClientCredentialsAccessToken(client1ClientId, client1ClientSecret, ScopePathType.PREMIUM_NOTIFICATION);
ClientResponse response = notificationsClient.addPermissionNotificationXml(testUser1OrcidId, notification, accessToken);
assertNotNull(response);
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus());
assertNull(response.getLocation());
}
use of org.orcid.jaxb.model.notification.permission_rc3.AuthorizationUrl in project ORCID-Source by ORCID.
the class NotificationsTest method createPermissionNotificationWithUnencodedSpaceInAuthorizationPath.
@Test
public void createPermissionNotificationWithUnencodedSpaceInAuthorizationPath() throws JSONException {
NotificationPermission notification = unmarshallFromPath("/notification_2.0_rc2/samples/notification-permission-2.0_rc2.xml");
notification.setPutCode(null);
AuthorizationUrl authUrl = notification.getAuthorizationUrl();
authUrl.setUri(null);
authUrl.setPath("/oauth/authorize?client_id=0000-0003-4223-0632&response_type=code&scope=/read-limited /activities/update&redirect_uri=https://developers.google.com/oauthplayground");
String accessToken = oauthHelper.getClientCredentialsAccessToken(client1ClientId, client1ClientSecret, ScopePathType.PREMIUM_NOTIFICATION);
ClientResponse response = notificationsClient.addPermissionNotificationXml(testUser1OrcidId, notification, accessToken);
assertNotNull(response);
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus());
assertNull(response.getLocation());
}
Aggregations