premek commented on a change in pull request #2906: URL: https://github.com/apache/netbeans/pull/2906#discussion_r617033108
########## File path: platform/keyring.impl/src/org/netbeans/modules/keyring/gnome/libsecret/GnomeLibSecretProvider.java ########## @@ -0,0 +1,146 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.netbeans.modules.keyring.gnome.libsecret; + +import com.sun.jna.Pointer; +import com.sun.jna.Structure; +import com.sun.jna.ptr.PointerByReference; +import java.text.MessageFormat; +import java.util.MissingResourceException; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.netbeans.modules.keyring.gnome.libsecret.Glib.GError; +import org.netbeans.modules.keyring.gnome.libsecret.LibSecret.SecretSchema; +import org.netbeans.modules.keyring.gnome.libsecret.LibSecret.SecretSchemaAttribute; +import org.netbeans.spi.keyring.KeyringProvider; +import org.openide.util.NbBundle; +import org.openide.util.lookup.ServiceProvider; + +@ServiceProvider(service = KeyringProvider.class, position = 150) +public class GnomeLibSecretProvider implements KeyringProvider { + + private static final Logger LOG = Logger.getLogger(GnomeLibSecretProvider.class.getName()); + private static final String KEY = "key"; // NOI18N + + private final String appName; + + public GnomeLibSecretProvider() { + appName = getAppName(); + } + + private SecretSchema getSchema() { + SecretSchema schema = new SecretSchema(); + schema.name = appName; + schema.flags = LibSecret.SECRET_SCHEMA_NONE; + schema.attributes[0] = new SecretSchemaAttribute(); + schema.attributes[0].name = KEY; + schema.attributes[0].type = LibSecret.SECRET_SCHEMA_ATTRIBUTE_STRING; + return schema; + } + + private String getAppName() { + try { + return MessageFormat.format( + NbBundle.getBundle("org.netbeans.core.windows.view.ui.Bundle").getString("CTL_MainWindow_Title_No_Project"), + "…"); + } catch (MissingResourceException x) { + return "NetBeans"; // NOI18N + } + } + + @Override + public boolean enabled() { + if (Boolean.getBoolean("netbeans.keyring.no.native")) { + LOG.fine("native keyring integration disabled"); + return false; + } + + try { + read("NoNeXiStEnT"); // NOI18N Review comment: This is based on how the current GnomeProvider worked. Attempting to read a secret would return the secret or null if it does not exist but it throws UnsatisfiedLinkError if the native library is not present. This is used to detect if the Provider will be used or not (enabled) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected] For further information about the NetBeans mailing lists, visit: https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
