Request for classic confinement highlighterpdf

There seems to be a problem with java and printing in strict mode.
Printing is a key feature of my app.
Even though I have cups-control in my plugs it will not work in strict confinement.
Everything works in classic.
Following symlinks is a minor casualty of the strict environment.
Looking back through the files there seems to be an issue with java and cups-control for some time.
So I make a request for you to allow me classic confinement so I can publish my app.

Here is my scanlog

= AppArmor =
Time: May 9 18:17:48
Log: apparmor=“DENIED” operation=“connect” profile=“snap.highlighterpdf.highlighterpdf” name="/run/cups/cups.sock" pid=20475 comm=“AWT-EventQueue-” requested_mask=“wr” denied_mask=“wr” fsuid=1000 ouid=0
File: /run/cups/cups.sock (write)

The cups-control interface is not automatically connected when a snap is installed - you need to manually connect it first:
sudo snap connect highlighterpdf:cups-control

This connection must be by console? or you can use the store gui for permissions?

Yes you can also use the snap-store / ubuntu-software GUI for this (and even the Settings application in Ubuntu 20.04 etc) for managing snap permissions. If you feel printing is a critical function for this snap and that most users would expect printing to work automatically you can always request auto-connection of cups-control instead. In that case, you can reuse this request and just change the title and add a new comment to this effect.

sorry I am such a newb

But I use

sudo snap connect highlighterpdf:cups-control

already and it still does not work

Can you please post the contents of the snapcraft.yaml for this snap? I suspect that you have:

apps:
  highlighterpdf:
   plugs:
     - cups-control

But from the AppArmor denial listed in your first post the process which causes the denial is not highlighterpdf but AWT-EventQueue - so instead you should plug the cups-control interface at the top-level of the snapcraft.yaml - ie define a top-level plugs entry as:

plugs:
  - cups-control
apps:
  highlighterpdf:
    ...

This way the cups-control interface is available to all binaries / processes launched by the snap, not just the highlighterpdf process.

Hi here is my Yaml:

name: highlighterpdf
title: HighlighterPdf
version: 1.0.2
summary: Highiight the text in a Pdf.
description:
        HighlighterPdf  is a free and open source software application that you can use to 
        highlight text in your pdf document. You can select text in a colour of your choice        
        and then save it.
confinement: strict
grade: stable


base: core18
           
apps:
 highlighterpdf:
   extensions: [gnome-3-28]
   command: java -jar $SNAP/highlighterpdf.jar
   environment:
         JAVA_HOME: $SNAP/usr/lib/jvm/java-11-openjdk-amd64
         PATH: $JAVA_HOME/bin:$PATH
   plugs:
      - home
      - network
      - cups-control
      
      
   
parts:
  highlighterpdf:
       source: https://github.com/gerry136/highlighterpdf.git
       plugin: dump

       build-packages:
           - openjdk-11-jdk
           
       
       stage-packages:
           - unzip
           - openjdk-11-jdk
           - lpr

When I try to put in plugs as you suggested I get
"
Issues while validating snapcraft.yaml: The ‘plugs’ property does not match the required schema: ‘-cups-control’ is not of type ‘object’ "

   plugs:
      - home
      - network
      - cups-control

your indendation for all the plugs is broken, it needs to be an even number of spaces (2 or 4) not 3 … i.e.

    plugs:
      - home
      - network
      - cups-control

your toplevel “highlighterpdf:” in the “apps:” section is also wrong (1 space) … you are giving the yaml parser a hard time here …

thanks for your answer Ogra
I have changed the Yaml as follows;

name: highlighterpdf
title: HighlighterPdf
version: 1.0.2
summary: Highiight the text in a Pdf.
description:
        HighlighterPdf  is a free and open source software application that you can use to 
        highlight text in your pdf document. You can select text in a colour of your choice        
        and then save it.
confinement: strict
grade: stable


base: core18

    plugs:
        - cups-control    
         
           
apps:
  highlighterpdf:
   extensions: [gnome-3-28]
   command: java -jar $SNAP/highlighterpdf.jar
   environment:
         JAVA_HOME: $SNAP/usr/lib/jvm/java-11-openjdk-amd64
         PATH: $JAVA_HOME/bin:$PATH

    plugs:
        - home
        - network
        - cups-control

      
   
parts:
  highlighterpdf:
       source: https://github.com/gerry136/highlighterpdf.git
       plugin: dump

       build-packages:
           - openjdk-11-jdk
           
       
       stage-packages:
           - unzip
           - openjdk-11-jdk
           - lpr
now I am getting the error message:
" Issues while validating snapcraft.yaml: mapping values are not allowed in this context on line 15, column 10"

now you only have one space here …

  highlighterpdf:
   extensions: [gnome-3-28]
   command: java -jar $SNAP/highlighterpdf.jar
   environment:

just try to generally stick to two spaces everywhere, that makes it easily readable too …

ok determined to get this right:

name: highlighterpdf
title: HighlighterPdf
version: 1.0.2
summary: Highiight the text in a Pdf.
description:
        HighlighterPdf  is a free and open source software application that you can use to 
        highlight text in your pdf document. You can select text in a colour of your choice        
        and then save it.
confinement: strict
grade: stable

plugs:
    - cups-control  

base: core18

      
         
           
apps:
  highlighterpdf:
    extensions: [gnome-3-28]
    command: java -jar $SNAP/highlighterpdf.jar
    environment:
        JAVA_HOME: $SNAP/usr/lib/jvm/java-11-openjdk-amd64
        PATH: $JAVA_HOME/bin:$PATH

    plugs:
        - home
        - network
        

      
   
parts:
  highlighterpdf:
       source: https://github.com/gerry136/highlighterpdf.git
       plugin: dump

       build-packages:
           - openjdk-11-jdk
           
       
       stage-packages:
           - unzip
           - openjdk-11-jdk
           - lpr

When I try to build it I am getting:

Issues while validating snapcraft.yaml: The ‘plugs’ property does not match the required schema: [‘cups-control’] is not of type ‘object’

and when I change the indentation I get
“Issues while validating snapcraft.yaml: mapping values are not allowed in this context on line 12, column 10”

name: highlighterpdf
title: HighlighterPdf
version: 1.0.2
summary: Highiight the text in a Pdf.
description:
  HighlighterPdf  is a free and open source software application that you can use to 
  highlight text in your pdf document. You can select text in a colour of your choice        
  and then save it.
confinement: strict
grade: stable  
base: core18

apps:
  highlighterpdf:
    extensions: [gnome-3-28]
    command: java -jar $SNAP/highlighterpdf.jar
    environment:
      JAVA_HOME: $SNAP/usr/lib/jvm/java-11-openjdk-amd64
      PATH: $JAVA_HOME/bin:$PATH
    plugs:
      - home
      - network
      - cups-control

parts:
  highlighterpdf:
    source: https://github.com/gerry136/highlighterpdf.git
    plugin: dump
    build-packages:
      - openjdk-11-jdk
    stage-packages:
      - unzip
      - openjdk-11-jdk
      - lpr

ok I have put plugs: cups control where suggested:

grade: stable

base: core18

plugs: cups-control      
apps:

but I am getting
Issues while validating snapcraft.yaml: The ‘plugs’ property does not match the required schema: ‘cups-control’ is not of type ‘object’

please just copy-paste the file i pasted above and start working off that …

it builds and runs fine here …

also drop the whole build-package block it isnt needed and makes the build just pointlessly longer (downloading java on teh build host without using it)…

ok thanks for your help ogra.

now when I put plugs in the place advised by alexmurray I get:

Issues while validating snapcraft.yaml: The ‘plugs’ property does not match the required schema: [‘cups-control’] is not of type ‘object’

the file should work fine as is without modifying it

it does but it suffers from the original problem that it can not print in strict mode. that is why alexmurray came up with the solution of putting cups-control above apps.

so before we spend another week on this, i spent my lunch break on fixing it for you (note that i’m working on a hidpi display and the app was unreadable, thus i had to add he launcher/wrapper to set proper scaling values) …

snap/snapcraft.yaml:

name: highlighterpdf
title: HighlighterPdf
version: 1.0.2
summary: Highiight the text in a Pdf.
description:
  HighlighterPdf  is a free and open source software application that you can use to 
  highlight text in your pdf document. You can select text in a colour of your choice        
  and then save it.
confinement: strict
grade: stable  
base: core18

plugs:
  gtk-2-engines:
    interface: content
    target: $SNAP/lib/gtk-2.0
    default-provider: gtk2-common-themes
  gtk-3-themes:
    default-provider: gtk-common-themes:gtk-3-themes
    interface: content
    target: $SNAP/data-dir/themes
  sound-themes:
    default-provider: gtk-common-themes:sound-themes
    interface: content
    target: $SNAP/data-dir/sounds
  gnome-3-28-1804:
    default-provider: gnome-3-28-1804:gnome-3-28-1804
    interface: content
    target: $SNAP/gnome-platform
  icon-themes:
    default-provider: gtk-common-themes:icon-themes
    interface: content
    target: $SNAP/data-dir/icons

layout:
  /usr/bin/lpr:
    bind-file: $SNAP/usr/bin/lpr

apps:
  highlighterpdf:
    extensions: [gnome-3-28]
    command: desktop-launch launcher
    environment:
      JAVA_HOME: $SNAP/usr/lib/jvm/java-11-openjdk-amd64
      PATH: $JAVA_HOME/bin:$PATH
    plugs:
      - avahi-control
      - home
      - network
      - network-bind
      - cups-control

parts:
  highlighterpdf:
    source: https://github.com/gerry136/highlighterpdf.git
    plugin: dump
    stage-packages:
      - cups-bsd # for /usr/bin/lpr
      - unzip
      - openjdk-11-jdk
      - x11-xserver-utils # for xrdb
  launcher:
    source: .
    plugin: dump
    organize:
      launcher: bin/launcher

launcher (put it in the toplevel dir of your source tree, dont forget to make it executable):

#! /bin/sh

# scale according to dpi
DPI="$(xrdb -query 2>/dev/null| grep dpi | sed 's/^.*\t//;s/\..*$//')"
if [ -n "$DPI" ]; then
  if [ "$DPI" -le 96 ]; then
          SCALE=""
  elif [ "$DPI" -le 120 ]; then
          SCALE="-Dsun.java2d.uiScale=1.25"
  elif [ "$DPI" -le 144 ]; then
          SCALE="-Dsun.java2d.uiScale=1.5"
  elif [ "$DPI" -le 192 ]; then
          SCALE="-Dsun.java2d.uiScale=2"
  elif [ "$DPI" -le 240 ]; then
          SCALE="-Dsun.java2d.uiScale=2.5"
  elif [ "$DPI" -le 288 ]; then
          SCALE="-Dsun.java2d.uiScale=3"
  elif [ "$DPI" -le 384 ]; then
          SCALE="-Dsun.java2d.uiScale=4"
  fi
fi

exec java $SCALE -jar $SNAP/highlighterpdf.jar

make sure to connect the avahi-control and cups-control interfaces after installing the snap … it prints fine for me on a networked priner in my house…

Thank you so much Ogra I do appreiciate all the help you have given me.