| package org.eclipse.osbp.authentication.ui.login; |
| |
| import org.apache.commons.mail.DefaultAuthenticator; |
| import org.apache.commons.mail.Email; |
| import org.apache.commons.mail.SimpleEmail; |
| import org.eclipse.osbp.preferences.ProductConfiguration; |
| import org.slf4j.Logger; |
| import org.slf4j.LoggerFactory; |
| |
| public class AuthenticationUiUtil { |
| |
| /** The Constant LOGGER. */ |
| private static final Logger LOGGER = LoggerFactory.getLogger(AuthenticationUiUtil.class); |
| public static final String PORTAL_ID = "1"; |
| |
| /** |
| * Try to authenticate with the credentials given!<br> |
| * {@link #setAuthenticated(boolean)} will explicit be called! |
| * |
| * @param portalId |
| * @param userName |
| * @param password |
| * @return true if the user was authenticated successful |
| */ |
| public static boolean checkPassword(String portalId, String userName, String password) { |
| try { |
| return InitializationListener.getUserAccessService().authenticate(portalId, userName, password); |
| } catch (Exception e) { |
| LOGGER.error(e.getLocalizedMessage()); |
| } |
| return false; |
| } |
| |
| public static Email getEmail() { |
| Email email = new SimpleEmail(); |
| email.setHostName(ProductConfiguration.getEmailServerIp()); |
| email.setSmtpPort(ProductConfiguration.getEmailSmtpPort()); |
| if (!ProductConfiguration.getAdminEmailUsername().isEmpty()) { |
| email.setAuthenticator(new DefaultAuthenticator(ProductConfiguration.getAdminEmailUsername(), ProductConfiguration |
| .getAdminEmailPassword())); |
| } |
| email.setSSLOnConnect(ProductConfiguration.isEmailUseSslOnConnect()); |
| return email; |
| } |
| |
| } |