Search in sources :

Example 21 with AuthorizationUrl

use of org.orcid.jaxb.model.notification.permission_rc4.AuthorizationUrl in project ORCID-Source by ORCID.

the class NotificationsTest method createPermissionNotificationWithBlankAuthorizationUri.

@Test
public void createPermissionNotificationWithBlankAuthorizationUri() 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("");
    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_rc4/" + 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"));
}
Also used : AuthorizationUrl(org.orcid.jaxb.model.notification.permission_rc4.AuthorizationUrl) ClientResponse(com.sun.jersey.api.client.ClientResponse) NotificationPermission(org.orcid.jaxb.model.notification.permission_rc4.NotificationPermission) Test(org.junit.Test)

Example 22 with AuthorizationUrl

use of org.orcid.jaxb.model.notification.permission_rc4.AuthorizationUrl in project ORCID-Source by ORCID.

the class NotificationsTest method createPermissionNotificationWithAbsentAuthorizationUriElement.

@Test
public void createPermissionNotificationWithAbsentAuthorizationUriElement() 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("");
    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_rc4/" + 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"));
}
Also used : AuthorizationUrl(org.orcid.jaxb.model.notification.permission_rc4.AuthorizationUrl) ClientResponse(com.sun.jersey.api.client.ClientResponse) NotificationPermission(org.orcid.jaxb.model.notification.permission_rc4.NotificationPermission) Test(org.junit.Test)

Example 23 with AuthorizationUrl

use of org.orcid.jaxb.model.notification.permission_rc4.AuthorizationUrl in project ORCID-Source by ORCID.

the class NotificationsTest method createPermissionNotificationWithUnencodedSpaceInAuthorizationPath.

@Test
public void createPermissionNotificationWithUnencodedSpaceInAuthorizationPath() 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(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());
}
Also used : AuthorizationUrl(org.orcid.jaxb.model.notification.permission_rc4.AuthorizationUrl) ClientResponse(com.sun.jersey.api.client.ClientResponse) NotificationPermission(org.orcid.jaxb.model.notification.permission_rc4.NotificationPermission) Test(org.junit.Test)

Example 24 with AuthorizationUrl

use of org.orcid.jaxb.model.notification.permission_rc4.AuthorizationUrl in project ORCID-Source by ORCID.

the class NotificationManagerImpl method sendAcknowledgeMessage.

@Override
public void sendAcknowledgeMessage(String userOrcid, String clientId) throws UnsupportedEncodingException {
    ProfileEntity profileEntity = profileEntityCacheManager.retrieve(userOrcid);
    ClientDetailsEntity clientDetails = clientDetailsEntityCacheManager.retrieve(clientId);
    Locale userLocale = (profileEntity.getLocale() == null || profileEntity.getLocale().value() == null) ? Locale.ENGLISH : LocaleUtils.toLocale(profileEntity.getLocale().value());
    String subject = getSubject("email.subject.institutional_sign_in", userLocale);
    String authorizationUrl = buildAuthorizationUrlForInstitutionalSignIn(clientDetails);
    // Create map of template params
    Map<String, Object> templateParams = new HashMap<String, Object>();
    templateParams.put("emailName", deriveEmailFriendlyName(profileEntity));
    templateParams.put("orcid", userOrcid);
    templateParams.put("baseUri", orcidUrlManager.getBaseUrl());
    templateParams.put("subject", subject);
    templateParams.put("clientName", clientDetails.getClientName());
    templateParams.put("authorization_url", authorizationUrl);
    addMessageParams(templateParams, userLocale);
    // Generate body from template
    String body = templateManager.processTemplate("authenticate_request_email.ftl", templateParams);
    // Generate html from template
    String html = templateManager.processTemplate("authenticate_request_email_html.ftl", templateParams);
    boolean notificationsEnabled = profileEntity.getEnableNotifications();
    if (notificationsEnabled) {
        NotificationInstitutionalConnection notification = new NotificationInstitutionalConnection();
        notification.setNotificationType(NotificationType.INSTITUTIONAL_CONNECTION);
        notification.setAuthorizationUrl(new AuthorizationUrl(authorizationUrl));
        NotificationInstitutionalConnectionEntity notificationEntity = (NotificationInstitutionalConnectionEntity) notificationAdapter.toNotificationEntity(notification);
        notificationEntity.setProfile(new ProfileEntity(userOrcid));
        notificationEntity.setClientSourceId(clientId);
        notificationEntity.setAuthenticationProviderId(clientDetails.getAuthenticationProviderId());
        notificationDao.persist(notificationEntity);
    } else {
        Emails emails = emailManager.getEmails(userOrcid, (profileEntity.getLastModified() == null ? System.currentTimeMillis() : profileEntity.getLastModified().getTime()));
        String primaryEmail = null;
        if (emails == null || emails.getEmails() == null) {
            throw new IllegalArgumentException("Unable to find primary email for: " + userOrcid);
        }
        for (org.orcid.jaxb.model.record_v2.Email email : emails.getEmails()) {
            if (email.isPrimary()) {
                primaryEmail = email.getEmail();
            }
        }
        mailGunManager.sendEmail(UPDATE_NOTIFY_ORCID_ORG, primaryEmail, subject, body, html);
    }
}
Also used : Locale(java.util.Locale) ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) NotificationInstitutionalConnection(org.orcid.model.notification.institutional_sign_in_v2.NotificationInstitutionalConnection) HashMap(java.util.HashMap) NotificationInstitutionalConnectionEntity(org.orcid.persistence.jpa.entities.NotificationInstitutionalConnectionEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) AuthorizationUrl(org.orcid.jaxb.model.notification.permission_v2.AuthorizationUrl) Emails(org.orcid.jaxb.model.record_v2.Emails)

Example 25 with AuthorizationUrl

use of org.orcid.jaxb.model.notification.permission_rc4.AuthorizationUrl in project ORCID-Source by ORCID.

the class NotificationsTest method createPermissionNotificationWithTrailingSpaceInAuthorizationUrl.

@Test
public void createPermissionNotificationWithTrailingSpaceInAuthorizationUrl() throws JSONException {
    NotificationPermission notification = unmarshallFromPath("/notification_2.1/samples/notification-permission-2.1.xml");
    notification.setPutCode(null);
    AuthorizationUrl authUrl = notification.getAuthorizationUrl();
    authUrl.setUri(authUrl.getUri() + "    ");
    String accessToken = oauthHelper.getClientCredentialsAccessToken(client1ClientId, client1ClientSecret, ScopePathType.PREMIUM_NOTIFICATION);
    ClientResponse response = notificationsClient_V2_1.addPermissionNotificationXml(testUser1OrcidId, notification, accessToken);
    assertNotNull(response);
    assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus());
    assertNull(response.getLocation());
}
Also used : AuthorizationUrl(org.orcid.jaxb.model.notification.permission_v2.AuthorizationUrl) ClientResponse(com.sun.jersey.api.client.ClientResponse) NotificationPermission(org.orcid.jaxb.model.notification.permission_v2.NotificationPermission) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)26 ClientResponse (com.sun.jersey.api.client.ClientResponse)24 AuthorizationUrl (org.orcid.jaxb.model.notification.permission_v2.AuthorizationUrl)13 NotificationPermission (org.orcid.jaxb.model.notification.permission_v2.NotificationPermission)11 AuthorizationUrl (org.orcid.jaxb.model.notification.permission_rc1.AuthorizationUrl)4 NotificationPermission (org.orcid.jaxb.model.notification.permission_rc1.NotificationPermission)4 AuthorizationUrl (org.orcid.jaxb.model.notification.permission_rc2.AuthorizationUrl)4 NotificationPermission (org.orcid.jaxb.model.notification.permission_rc2.NotificationPermission)4 AuthorizationUrl (org.orcid.jaxb.model.notification.permission_rc3.AuthorizationUrl)4 NotificationPermission (org.orcid.jaxb.model.notification.permission_rc3.NotificationPermission)4 AuthorizationUrl (org.orcid.jaxb.model.notification.permission_rc4.AuthorizationUrl)4 NotificationPermission (org.orcid.jaxb.model.notification.permission_rc4.NotificationPermission)4 Source (org.orcid.jaxb.model.common_v2.Source)2 SourceClientId (org.orcid.jaxb.model.common_v2.SourceClientId)2 NotificationAmended (org.orcid.jaxb.model.notification.amended_v2.NotificationAmended)2 NotificationCustom (org.orcid.jaxb.model.notification.custom_v2.NotificationCustom)2 Item (org.orcid.jaxb.model.notification.permission_v2.Item)2 Items (org.orcid.jaxb.model.notification.permission_v2.Items)2 NotificationInstitutionalConnection (org.orcid.model.notification.institutional_sign_in_v2.NotificationInstitutionalConnection)2 NotificationAddItemsEntity (org.orcid.persistence.jpa.entities.NotificationAddItemsEntity)2