Add a license to an artifact

@param credential DbCredential
@param gavc String
@param licenseId String
@return Response
322556
@POST
    @Path("/{gavc}" + ServerAPI.GET_LICENSES)
    public Response addLicense(@Auth final DbCredential credential,
                               @PathParam("gavc") final String gavc,
                               @QueryParam(ServerAPI.LICENSE_ID_PARAM) final String licenseId){
        if(!credential.getRoles().contains(AvailableRoles.DATA_UPDATER) &&
                !credential.getRoles().contains(AvailableRoles.LICENSE_SETTER)){
            throw new WebApplicationException(Response.status(Response.Status.UNAUTHORIZED).build());
        }

        if(LOG.isInfoEnabled()) {
            LOG.info(String.format("Got a add license request [%s]", gavc));
        }

        if(licenseId == null){
            return Response.serverError().status(HttpStatus.NOT_ACCEPTABLE_406).build();
        }

        getArtifactHandler().addLicenseToArtifact(gavc, licenseId);
        cacheUtils.clear(CacheName.PROMOTION_REPORTS);

        return Response.ok("done").build();
    }
640679
public OvhCredential api_credential_credentialId_GET(Long credentialId) throws IOException {
		String qPath = "/me/api/credential/{credentialId}";
		StringBuilder sb = path(qPath, credentialId);
		String resp = exec(qPath, "GET", sb.toString(), null);
		return convertTo(resp, OvhCredential.class);
	}
889123
private void setCredential(Subject subject, WSPrincipal principal) throws CredentialException {
        String securityName = principal.getName();
        Hashtable<String, ?> customProperties = getUniqueIdHashtableFromSubject(subject);
        if (customProperties == null || customProperties.isEmpty()) {
            UserRegistryService urService = userRegistryServiceRef.getService();
            if (urService != null) {
                String urType = urService.getUserRegistryType();
                if ("WIM".equalsIgnoreCase(urType) || "LDAP".equalsIgnoreCase(urType)) {
                    try {
                        securityName = urService.getUserRegistry().getUserDisplayName(securityName);
                    } catch (Exception e) {
                        //do nothing
                    }
                }
            }
        }
        if (securityName == null || securityName.length() == 0) {
            securityName = principal.getName();
        }
        String accessId = principal.getAccessId();

        String customRealm = null;
        String realm = null;
        String uniqueName = null;

        if (customProperties != null) {
            customRealm = (String) customProperties.get(AttributeNameConstants.WSCREDENTIAL_REALM);
        }

        if (customRealm != null) {
            realm = customRealm;
            String[] parts = accessId.split(realm + "/");
            if (parts != null && parts.length == 2)
                uniqueName = parts[1];
        } else {
            realm = AccessIdUtil.getRealm(accessId);
            uniqueName = AccessIdUtil.getUniqueId(accessId);
        }
        if (AccessIdUtil.isServerAccessId(accessId)) {
            // Create a server WSCredential
            setCredential(null, subject, realm, securityName, uniqueName, null, accessId, null, null);
        } else {
            CredentialsService cs = credentialsServiceRef.getService();
            String unauthenticatedUserid = cs.getUnauthenticatedUserid();

            if (securityName != null && unauthenticatedUserid != null &&
                securityName.equals(unauthenticatedUserid)) {
                // Create an unauthenticated WSCredential
                setCredential(unauthenticatedUserid, subject, realm, securityName, uniqueName, null, null, null, null);
            } else if (AccessIdUtil.isUserAccessId(accessId)) {
                // Create a user WSCredential
                createUserWSCredential(subject, securityName, accessId, realm, uniqueName, unauthenticatedUserid);
            }
        }
    }
643589
public void verify() throws GlobusCredentialException {
        try {
            String caCertsLocation = "file:" + CoGProperties.getDefault().getCaCertLocations();
            String crlPattern = caCertsLocation + "/*.r*";
            String sigPolPattern = caCertsLocation + "/*.signing_policy";
            KeyStore keyStore = KeyStore.getInstance(GlobusProvider.KEYSTORE_TYPE, GlobusProvider.PROVIDER_NAME);
            CertStore crlStore = CertStore.getInstance(GlobusProvider.CERTSTORE_TYPE, new ResourceCertStoreParameters(null,crlPattern));
            ResourceSigningPolicyStore sigPolStore = new ResourceSigningPolicyStore(new ResourceSigningPolicyStoreParameters(sigPolPattern));
            keyStore.load(KeyStoreParametersFactory.createTrustStoreParameters(caCertsLocation));
            X509ProxyCertPathParameters parameters = new X509ProxyCertPathParameters(keyStore, crlStore, sigPolStore, false);
            X509ProxyCertPathValidator validator = new X509ProxyCertPathValidator();
            validator.engineValidate(CertificateUtil.getCertPath(this.cred.getCertificateChain()), parameters);
        } catch (Exception e) {
        	e.printStackTrace();
            throw new GlobusCredentialException(GlobusCredentialException.FAILURE, e.getMessage(), e);
        }
    }
32144
public X509Credential createCredential(X509Certificate[] certs, PrivateKey privateKey, int bits, int lifetime,
       GSIConstants.DelegationType delegType, X509ExtensionSet extSet, String cnValue) throws GeneralSecurityException {

        X509Certificate[] bcCerts = getX509CertificateObjectChain(certs);

        return createCredential(bcCerts, privateKey, bits, lifetime, decideProxyType(bcCerts[0], delegType), extSet, cnValue);
    }
691256
@GET
    @Produces({MediaType.APPLICATION_JSON})
    @Path("/{gavc}" + ServerAPI.GET_LICENSES)
    public Response getLicenses(@PathParam("gavc") final String gavc, @Context final UriInfo uriInfo){

        if(LOG.isInfoEnabled()) {
            LOG.info(String.format("Got a get artifact licenses request [%s]", gavc));
        }
        final LicenseListView view = new LicenseListView("Licenses of " + gavc);

        final FiltersHolder filters = new FiltersHolder();
        filters.init(uriInfo.getQueryParameters());

        final List<DbLicense> dbLicenses = getArtifactHandler().getArtifactLicenses(gavc,filters);
        for(final DbLicense license: dbLicenses){
            view.add(getModelMapper().getLicense(license));
        }

        return Response.ok(view).build();
    }
672919
private function fetch_license_by_key( $license_id, $license_key ) {
            $this->_logger->entrance();

            $api = $this->get_current_or_network_user_api_scope();

            $result = $api->get( "/licenses/{$license_id}.json?license_key=" . urlencode( $license_key ) );

            return $this->is_api_result_entity( $result ) ?
                new FS_Plugin_License( $result ) :
                $result;
        }
1343383
@Override
    public Account verify(Credential credential) {
        assertMechanism(AuthMechanism.CLIENT_CERT, AuthMechanism.KERBEROS);

        final AuthorizingCallbackHandler ach;
        final Principal user;
        if (credential instanceof X509CertificateCredential) {
            X509CertificateCredential certCred = (X509CertificateCredential) credential;

            ach = securityRealm.getAuthorizingCallbackHandler(AuthMechanism.CLIENT_CERT);
            user = certCred.getCertificate().getSubjectDN();
        } else if (credential instanceof GSSContextCredential) {
            GSSContextCredential gssCred = (GSSContextCredential) credential;
            try {
            user = new KerberosPrincipal(gssCred.getGssContext().getSrcName().toString());
            } catch (GSSException e) {
                // By this point this should not be able to happen.
                ROOT_LOGGER.debug("Unexpected authentication failure", e);
                return null;
            }
            ach = securityRealm.getAuthorizingCallbackHandler(AuthMechanism.KERBEROS);
        } else {
            return null;
        }

        try {
            ach.handle(new Callback[] { new AuthorizeCallback(user.getName(), user.getName()) });
        } catch (IOException e) {
            ROOT_LOGGER.debug("Unexpected authentication failure", e);
            return null;
        } catch (UnsupportedCallbackException e) {
            ROOT_LOGGER.debug("Unexpected authentication failure", e);
            return null;
        }

        Collection<Principal> userCol = Collections.singleton(user);
        SubjectUserInfo supplemental;
        try {
            supplemental = ach.createSubjectUserInfo(userCol);
        } catch (IOException e) {
            return null;
        }
        addInetPrincipal(supplemental.getSubject().getPrincipals());

        return new RealmIdentityAccount(supplemental.getSubject(), user);
    }
590396
public DruidQuerySignature asAggregateSignature(RowSignature sourceSignature)
  {
    return new DruidQuerySignature(
        sourceSignature,
        virtualColumnPrefix,
        virtualColumnsByExpression,
        virtualColumnsByName,
        true
    );
  }
1104511
public OvhApplication api_credential_credentialId_application_GET(Long credentialId) throws IOException {
		String qPath = "/me/api/credential/{credentialId}/application";
		StringBuilder sb = path(qPath, credentialId);
		String resp = exec(qPath, "GET", sb.toString(), null);
		return convertTo(resp, OvhApplication.class);
	}
652426
public void deleteArtifact(final String gavc, final String user, final String password) throws GrapesCommunicationException, AuthenticationException{
        final Client client = getClient(user, password);
        final WebResource resource = client.resource(serverURL).path(RequestUtils.getArtifactPath(gavc));
        final ClientResponse response = resource.delete(ClientResponse.class);

        client.destroy();
        if(ClientResponse.Status.OK.getStatusCode() != response.getStatus()){
            final String message = "Failed to DELETE artifact " + gavc;
            if(LOG.isErrorEnabled()) {
                LOG.error(String.format(HTTP_STATUS_TEMPLATE_MSG, message, response.getStatus()));
            }
            throw new GrapesCommunicationException(message, response.getStatus());
        }
    }
84285
@GET
    @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON})
    @Path("/{gavc}")
    public Response get(@PathParam("gavc") final String gavc){
        if(LOG.isInfoEnabled()) {
            LOG.info(String.format("Got a get artifact request [%s]", gavc));
        }

        final ArtifactView view = new ArtifactView();

        final DbArtifact dbArtifact = getArtifactHandler().getArtifact(gavc);
        view.setShouldNotBeUse(dbArtifact.getDoNotUse());

        final Artifact artifact = getModelMapper().getArtifact(dbArtifact);
        view.setArtifact(artifact);

        final DbOrganization dbOrganization = getArtifactHandler().getOrganization(dbArtifact);
        if(dbOrganization != null){
            final Organization organization = getModelMapper().getOrganization(dbOrganization);
            view.setOrganization(organization);
        }

        DbComment dbComment = getCommentHandler().getLatestComment(gavc, DbArtifact.class.getSimpleName());
        if(dbComment != null) {
            final Comment comment = getModelMapper().getComment(dbComment);
            view.setComment(comment);
        }

        return Response.ok(view).build();
    }
715062
@DELETE
    @Path("/{gavc}")
    public Response delete(@Auth final DbCredential credential, @PathParam("gavc") final String gavc){
        if(!credential.getRoles().contains(AvailableRoles.DATA_DELETER)){
            throw new WebApplicationException(Response.status(Response.Status.UNAUTHORIZED).build());
        }

        if(LOG.isInfoEnabled()) {
            LOG.info(String.format("Got a delete artifact request [%s]", gavc));
        }

        getArtifactHandler().deleteArtifact(gavc);

        return Response.ok().build();
    }
794098
public Account withSupportedLicenses(License... supportedLicenses) {
        java.util.ArrayList<String> supportedLicensesCopy = new java.util.ArrayList<String>(supportedLicenses.length);
        for (License value : supportedLicenses) {
            supportedLicensesCopy.add(value.toString());
        }
        if (getSupportedLicenses() == null) {
            setSupportedLicenses(supportedLicensesCopy);
        } else {
            getSupportedLicenses().addAll(supportedLicensesCopy);
        }
        return this;
    }
790410
public static Credential credential(
      AccessTokenProvider accessTokenProvider, Collection<String> scopes)
      throws IOException, GeneralSecurityException {
    return getCredentialFromAccessTokenProvider(accessTokenProvider, scopes);
  }
470675
public DbLicense getLicense(final String name) {
        final DbLicense license = repoHandler.getLicense(name);

        if (license == null) {
            throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND)
                    .entity("License " + name + " does not exist.").build());
        }

        return license;
    }
1285448
public DbArtifact getArtifact(final String gavc) {
        final DbArtifact artifact = repositoryHandler.getArtifact(gavc);

        if(artifact == null){
            throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND)
                    .entity("Artifact " + gavc + " does not exist.").build());
        }

        return artifact;
    }