package com.mailserver.config; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; /** * «Sign in with Jambotron»: JAMBOTRON_URL (https://jambotron.com) + SERVICE_TOKEN (the same token Jambotron uses for * the service API — here it proves to Jambotron that the code is exchanged by this mail server). Both set — people log * in through Jambotron, web password login only for the built-in administrator. */ @Component public class JambotronSso { private final String url; private final String token; private final String publicUrl; public JambotronSso(@Value("${mailserver.jambotron.url:}") String url, @Value("${mailserver.service-token:}") String token, @Value("${mailserver.public-url:}") String publicUrl, @Value("${mailserver.smtp.hostname:localhost}") String hostname) { this.url = url.isBlank() ? null : url.trim().replaceAll("/+$", ""); this.token = token.isBlank() ? null : token.trim(); this.publicUrl = publicUrl.isBlank() ? "https://" + hostname : publicUrl.trim().replaceAll("/+$", ""); } public boolean enabled() { return url != null && token != null; } public String url() { return url; } public String token() { return token; } /** Where Jambotron sends the browser back: https://mail.jambocheck.com/api/oauth/callback */ public String callback() { return publicUrl + "/api/oauth/callback"; } }