public static Optional<AuthenticationType> getAuthenticationType(ApplicationLink applink) { if (applink != null) { Object authMethod = applink.getProperty(JwtConstants.AppLinks.AUTH_METHOD_PROPERTY_NAME); if (AuthenticationType.JWT.toString().equals(authMethod)) { return Optional.of(AuthenticationType.JWT); } else if (AuthenticationType.NONE.toString().equals(authMethod)) { return Optional.of(AuthenticationType.NONE); } else if (authMethod != null) { log.warn("Unknown authType encountered: " + authMethod); return Optional.of(AuthenticationType.NONE); } } return Optional.empty(); } }
@Override public Optional<String> getUserKey(@Nonnull final String addonKey) { // Although we can return username based only on addon key using usernameForAddon mapping // We want to be sure that addon actually exist. // Note: We had to move a bit of logic here to check if an addon has an authentication type JWT // This has to be done as userKey is not stored in the DB but a derived value. // We will be pushing for Crowd to create an API to get add-on users for a given key, or return no user return getAddonWithCaching(addonKey) .flatMap(addon -> addon.getAuthType().equals(AuthenticationType.JWT.toString()) ? Optional.of(ConnectAddonUserUtil.usernameForAddon(addon.getAddonKey())) : Optional.empty()); }
if (settings.getAuth().equals(AuthenticationType.JWT.toString())) { if (!secret.isPresent()) { // If auth is JWT but no shared secret errors.add(logErrorAndReturnMessage("add-on '%s' reported having no shared secret, but the auth type is JWT", addonKey));
@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; }); }