@Override
 public Response redirectClientToGroup(String clientId) {
   ClientDetailsEntity clientDetails = clientDetailsManager.findByClientId(clientId);
   if (clientDetails == null) {
     return Response.status(Status.NOT_FOUND).build();
   }
   String groupOrcid = clientDetails.getGroupProfileId();
   URI groupUri;
   try {
     groupUri = new URI(jpa2JaxbAdapter.getOrcidIdBase(groupOrcid).getUri());
     return Response.seeOther(groupUri).build();
   } catch (URISyntaxException e) {
     LOGGER.error("Problem redirecting to group: {}", groupOrcid, e);
     return Response.serverError().build();
   }
 }
 @Test
 public void testValidCredentialsScopesForClientOnly() throws Exception {
   ClientDetailsEntity clientDetailsEntity = new ClientDetailsEntity();
   Set<ClientScopeEntity> scopes = new HashSet<ClientScopeEntity>(2);
   scopes.add(new ClientScopeEntity(ScopePathType.ORCID_PROFILE_CREATE.value()));
   clientDetailsEntity.setClientScopes(scopes);
   String orcid = "2875-8158-1475-6194";
   when(clientDetailsService.loadClientByClientId(orcid)).thenReturn(clientDetailsEntity);
   OrcidClientCredentialsChecker checker =
       new OrcidClientCredentialsChecker(clientDetailsService, oAuth2RequestFactory);
   Set<String> requestedScopes =
       new HashSet<String>(Arrays.asList(ScopePathType.READ_PUBLIC.value()));
   checker.validateCredentials(
       "client_credentials",
       new TokenRequest(
           Collections.<String, String>emptyMap(), orcid, requestedScopes, "client_credentials"));
 }
  private String extractAmenderName(OrcidProfile orcidProfile, String amenderId) {
    Delegation delegation = orcidProfile.getOrcidBio().getDelegation();
    if (delegation != null
        && delegation.getGivenPermissionTo() != null
        && !delegation.getGivenPermissionTo().getDelegationDetails().isEmpty()) {
      for (DelegationDetails delegationDetails :
          delegation.getGivenPermissionTo().getDelegationDetails()) {
        if (amenderId.equals(
            delegationDetails.getDelegateSummary().getOrcidIdentifier().getPath())) {
          return delegationDetails.getDelegateSummary().getCreditName().getContent();
        }
      }
    }

    ClientDetailsEntity clientDetailsEntity = clientDetailsEntityCacheManager.retrieve(amenderId);
    if (clientDetailsEntity != null) {
      return clientDetailsEntity.getClientName();
    }
    return "";
  }
Ejemplo n.º 4
0
 public void execute() throws IOException {
   List<ClientDetailsEntity> clientDetailsList = clientDetailsDao.getAll();
   for (ClientDetailsEntity clientDetailsEntity : clientDetailsList) {
     LOG.info("Checking client: {}", clientDetailsEntity.getId());
     if (PojoUtil.isEmpty(clientDetailsEntity.getGroupProfileId())) {
       LOG.info("Found orphan client: {}", clientDetailsEntity.getId());
       if (!dryRun) {
         // Remove the client
         LOG.info("Removing orphan client: {}", clientDetailsEntity.getId());
         clientDetailsDao.remove(clientDetailsEntity.getId());
       }
     }
   }
 }
  @Override
  @Transactional
  public void sendApiRecordCreationEmail(String toEmail, OrcidProfile createdProfile) {

    Source source = null;
    CustomEmailEntity customEmail = null;
    if (createdProfile.getOrcidHistory() != null
        && createdProfile.getOrcidHistory().getSource() != null) {
      if (!PojoUtil.isEmpty(createdProfile.getOrcidHistory().getSource().retrieveSourcePath())) {
        source = createdProfile.getOrcidHistory().getSource();
        customEmail =
            getCustomizedEmail(
                createdProfile.getOrcidHistory().getSource().retrieveSourcePath(), EmailType.CLAIM);
      }
    }

    String email =
        createdProfile.getOrcidBio().getContactDetails().retrievePrimaryEmail().getValue().trim();
    String emailName = deriveEmailFriendlyName(createdProfile);
    String orcid = createdProfile.getOrcidIdentifier().getPath();
    String verificationUrl = createClaimVerificationUrl(email, orcidUrlManager.getBaseUrl());

    String creatorName = "";
    if (source != null) {
      if (source.getSourceName() != null && source.getSourceName().getContent() != null) {
        creatorName = source.getSourceName().getContent();
      } else if (!PojoUtil.isEmpty(source.retrieveSourcePath())) {
        creatorName = source.retrieveSourcePath();
      }
    }

    String subject = null;
    String body = null;
    String htmlBody = null;
    String sender = null;

    if (customEmail != null) {
      // Get the customized sender if available
      sender =
          PojoUtil.isEmpty(customEmail.getSender())
              ? CLAIM_NOTIFY_ORCID_ORG
              : customEmail.getSender();
      // Get the customized subject is available
      subject =
          PojoUtil.isEmpty(customEmail.getSubject())
              ? getSubject("email.subject.api_record_creation", createdProfile)
              : customEmail.getSubject();
      // Replace the wildcards
      subject = subject.replace(WILDCARD_USER_NAME, emailName);
      subject = subject.replace(WILDCARD_MEMBER_NAME, creatorName);
      if (customEmail.isHtml()) {
        htmlBody = customEmail.getContent();
        htmlBody = htmlBody.replace(WILDCARD_USER_NAME, emailName);
        htmlBody = htmlBody.replace(WILDCARD_MEMBER_NAME, creatorName);
        htmlBody = htmlBody.replace(EmailConstants.WILDCARD_VERIFICATION_URL, verificationUrl);
        if (htmlBody.contains(WILDCARD_WEBSITE) || htmlBody.contains(WILDCARD_DESCRIPTION)) {
          ClientDetailsEntity clientDetails = customEmail.getClientDetailsEntity();
          htmlBody = htmlBody.replace(WILDCARD_WEBSITE, clientDetails.getClientWebsite());
          htmlBody = htmlBody.replace(WILDCARD_DESCRIPTION, clientDetails.getClientDescription());
        }
      } else {
        body = customEmail.getContent();
        body = body.replace(WILDCARD_USER_NAME, emailName);
        body = body.replace(WILDCARD_MEMBER_NAME, creatorName);
        body = body.replace(EmailConstants.WILDCARD_VERIFICATION_URL, verificationUrl);
        if (body.contains(WILDCARD_WEBSITE) || body.contains(WILDCARD_DESCRIPTION)) {
          ClientDetailsEntity clientDetails = customEmail.getClientDetailsEntity();
          body = body.replace(WILDCARD_WEBSITE, clientDetails.getClientWebsite());
          body = body.replace(WILDCARD_DESCRIPTION, clientDetails.getClientDescription());
        }
      }
    } else {
      subject = getSubject("email.subject.api_record_creation", createdProfile);
      // Create map of template params
      Map<String, Object> templateParams = new HashMap<String, Object>();
      templateParams.put("emailName", emailName);
      templateParams.put("orcid", orcid);
      templateParams.put("subject", subject);
      templateParams.put("creatorName", creatorName);
      templateParams.put("baseUri", orcidUrlManager.getBaseUrl());
      templateParams.put("baseUriHttp", orcidUrlManager.getBaseUriHttp());
      templateParams.put("verificationUrl", verificationUrl);

      addMessageParams(templateParams, createdProfile);
      // Generate body from template
      body = templateManager.processTemplate("api_record_creation_email.ftl", templateParams);
      htmlBody =
          templateManager.processTemplate("api_record_creation_email_html.ftl", templateParams);
    }

    // Send message
    if (apiRecordCreationEmailEnabled) {
      boolean isCustomEmail = customEmail != null ? true : false;
      // TODO: How to handle sender? we might have to register them on
      // mailgun
      if (isCustomEmail) {
        mailGunManager.sendEmail(sender, email, subject, body, htmlBody, isCustomEmail);
      } else {
        mailGunManager.sendEmail(CLAIM_NOTIFY_ORCID_ORG, email, subject, body, htmlBody);
      }
    } else {
      LOGGER.debug(
          "Not sending API record creation email, because option is disabled. Message would have been: {}",
          body);
    }
  }
Ejemplo n.º 6
0
  public static Client valueOf(ClientDetailsEntity clientDetails) {
    Client client = new Client();
    if (clientDetails != null) {
      client.setClientId(Text.valueOf(clientDetails.getClientId()));
      client.setDisplayName(Text.valueOf(clientDetails.getClientName()));
      client.setShortDescription(Text.valueOf(clientDetails.getClientDescription()));
      client.setWebsite(Text.valueOf(clientDetails.getClientWebsite()));
      client.redirectUris = new ArrayList<RedirectUri>();
      if (clientDetails.getClientRegisteredRedirectUris() != null) {
        for (ClientRedirectUriEntity rUri : clientDetails.getClientRegisteredRedirectUris()) {
          client.redirectUris.add(RedirectUri.valueOf(rUri));
        }
      }

      client.persistentTokenEnabled = new Checkbox();
      client.persistentTokenEnabled.setValue(clientDetails.isPersistentTokensEnabled());
      client.setType(Text.valueOf(clientDetails.getClientType().value()));

      if (clientDetails.isScoped()) client.setScopes(clientDetails.getScope());

      client.setMemberId(Text.valueOf(clientDetails.getGroupProfileId()));
    }
    return client;
  }