/** * Supplies an accessor for remote plugin operations but always creates a new one. Instances are still only meant * to be used for the current operation and should not be cached across operations. * * This method is useful for when the display url is known but the application link has not yet been created * * @param addon The addon bean * @param displayUrl The display url * @return An accessor for a remote plugin */ private RemotablePluginAccessor create(ConnectAddonBean addon, Supplier<URI> displayUrl) { return create(addon.getKey(), addon.getName(), displayUrl); }
public JwtSigningRemotablePluginAccessor(ConnectAddonBean addon, Supplier<URI> baseUrlSupplier, JwtJsonBuilderFactory jwtBuilderFactory, JwtService jwtService, ConsumerService consumerService, HttpContentRetriever httpContentRetriever, ConnectAddonInformationProvider connectAddonInformationProvider) { super(addon.getKey(), addon.getName(), baseUrlSupplier, httpContentRetriever); this.consumerService = consumerService; this.jwtEncoder = new JwtEncoder(jwtBuilderFactory, jwtService); this.authorizationGenerator = new JwtAuthorizationGenerator(jwtService, jwtBuilderFactory, this::requireSharedSecret, consumerService, URI.create(addon.getBaseUrl())); this.connectAddonInformationProvider = connectAddonInformationProvider; }
private void rollBackToPreviousVersion(String pluginKey, AddonSettings previousSettings, PluginState targetState, Optional<AuthenticationType> maybePreviousAuthType, Optional<String> maybePreviousPublicKeyOrSharedSecret, String baseUrl, Exception e) throws ConnectAddonInstallException { log.error("An exception occurred while installing the plugin '[" + pluginKey + "]. Restoring previous version...", e); ConnectAddonBean previousAddon = connectAddonBeanFactory.fromJson(previousSettings.getDescriptor()); String addonUserKey = this.connectUserService.getOrCreateAddonUserName(pluginKey, previousAddon.getName()); addonRegistry.storeAddonSettings(pluginKey, previousSettings); connectApplinkManager.createAppLink(previousAddon, baseUrl, maybePreviousAuthType.get(), maybePreviousPublicKeyOrSharedSecret.orElse(""), addonUserKey); setAddonState(targetState, pluginKey); }
private String provisionAddonUserAndScopes(ConnectAddonBean addon, Optional<String> maybePreviousDescriptor) throws PluginInstallException, ConnectAddonInstallException { final Set<ScopeName> newScopes = addon.getScopes(); final Set<ScopeName> previousScopes = maybePreviousDescriptor .map(desc -> connectAddonBeanFactory.fromJson(desc).getScopes()) .orElse(ImmutableSet.of()); try { return connectUserService.provisionAddonUserWithScopes(addon, previousScopes, newScopes); } catch (ConnectAddonInitException e) { throw new ConnectAddonInstallException(e.getMessage(), e, e.getI18nKey(), addon.getName()); } } }
public String getAbsoluteUrl(ConnectAddonBean addon, String url) { try { return getAbsoluteUrl(addon.getKey(), url); } catch (URISyntaxException e) { throw new PluginParseException("Malformed url declared by '" + addon.getName() + "' (" + addon.getKey() + "): " + url, e); } } }
private void enableAddonUser(ConnectAddonBean addon) throws ConnectAddonInitException { String userKey = connectUserService.getOrCreateAddonUserName(addon.getKey(), addon.getName()); ApplicationLink applicationLink = connectApplinkManager.getAppLink(addon.getKey()); if (null != applicationLink) { applicationLink.putProperty(JwtConstants.AppLinks.ADD_ON_USER_KEY_PROPERTY_NAME, userKey); } else { log.error("Unable to set the ApplicationLink user key property for add-on '{}' because the add-on has no ApplicationLink!", addon.getKey()); } }
private String provisionAddonUserAndScopes(ConnectAddonBean addon, String previousDescriptor) throws PluginInstallException, ConnectAddonInstallException { Set<ScopeName> previousScopes = Sets.newHashSet(); Set<ScopeName> newScopes = addon.getScopes(); if (StringUtils.isNotBlank(previousDescriptor)) { ConnectAddonBean previousAddon = connectAddonBeanFactory.fromJson(previousDescriptor); previousScopes = previousAddon.getScopes(); } try { return connectUserService.provisionAddonUserWithScopes(addon, previousScopes, newScopes); } catch (ConnectAddonInitException e) { throw new ConnectAddonInstallException(e.getMessage(), e, e.getI18nKey(), addon.getName()); } } }
@Override public void createAppLink(final ConnectAddonBean addon, final String baseUrl, final AuthenticationType authType, final String publicKey, final String addonUserKey) { transactionTemplate.execute((TransactionCallback<Void>) () -> { String pluginKey = addon.getKey(); URI baseUri = URI.create(baseUrl); final ApplicationId expectedApplicationId = ApplicationIdUtil.generate(baseUri); final RemotePluginContainerApplicationType applicationType = typeAccessor.getApplicationType(RemotePluginContainerApplicationType.class); deleteOldAppLinks(pluginKey, expectedApplicationId); final ApplicationLinkDetails details = ApplicationLinkDetails.builder() .displayUrl(baseUri) .isPrimary(false) .name(addon.getName() != null ? addon.getName() : addon.getKey()) .rpcUrl(baseUri) .build(); log.info("Creating an application link for Connect add-on with key '{}'", pluginKey); ApplicationLink link = applicationLinkService.addApplicationLink(expectedApplicationId, applicationType, details); link.putProperty(PLUGIN_KEY_PROPERTY, pluginKey); link.putProperty(JwtConstants.AppLinks.ADD_ON_USER_KEY_PROPERTY_NAME, addonUserKey); link.putProperty("IS_ACTIVITY_ITEM_PROVIDER", Boolean.FALSE.toString()); link.putProperty("system", Boolean.TRUE.toString()); link.putProperty(JwtConstants.AppLinks.AUTH_METHOD_PROPERTY_NAME, authType.toString()); if (authType == AuthenticationType.JWT) { link.putProperty(JwtConstants.AppLinks.SHARED_SECRET_PROPERTY_NAME, publicKey); } return null; }); }
/** * Creates a {@link Plugin} for the given add-on descriptor. * * @param addon the descriptor of the add-on * @param state the enablement state of the add-on * @return the plugin */ public Plugin create(ConnectAddonBean addon, PluginState state) { ConnectAddonPlugin plugin = new ConnectAddonPlugin(beanToModuleRegistrar.getRegisteredDescriptorsForAddon(addon.getKey())); plugin.setKey(addon.getKey()); plugin.setName(addon.getName()); plugin.setPluginsVersion(3); plugin.setPluginState(state); plugin.setPluginInformation(createPluginInfo(addon)); return plugin; }