|
|
|
@ -18,6 +18,8 @@ import org.gcube.common.encryption.StringEncrypter;
|
|
|
|
|
import org.gcube.common.portal.PortalContext;
|
|
|
|
|
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
|
|
|
|
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
|
|
|
|
|
import org.gcube.common.resources.gcore.ServiceEndpoint.Property;
|
|
|
|
|
import org.gcube.common.resources.gcore.utils.Group;
|
|
|
|
|
import org.gcube.common.scope.api.ScopeProvider;
|
|
|
|
|
import org.gcube.portal.databook.server.DBCassandraAstyanaxImpl;
|
|
|
|
|
import org.gcube.portal.databook.server.DatabookStore;
|
|
|
|
@ -33,15 +35,28 @@ import org.slf4j.LoggerFactory;
|
|
|
|
|
public class PortalSchedulerService extends HttpServlet {
|
|
|
|
|
|
|
|
|
|
private static final Logger _log = LoggerFactory.getLogger(PortalSchedulerService.class);
|
|
|
|
|
|
|
|
|
|
private static final String POP3_SERVER_NAME = "Pop3MailServer";
|
|
|
|
|
private static final String LDAP_SERVER_NAME = "LDAPServer";
|
|
|
|
|
private static final String LDAP_SERVER_FILTER_NAME = "filter";
|
|
|
|
|
private static final String LDAP_SERVER_PRINCPAL_NAME = "ldapPrincipal";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final int POP3_MINUTES_DELAY = 1;
|
|
|
|
|
private static final int LDAP_MINUTES_DELAY = 15;
|
|
|
|
|
|
|
|
|
|
private static DatabookStore store;
|
|
|
|
|
|
|
|
|
|
private static String portalName;
|
|
|
|
|
private static String host;
|
|
|
|
|
private static String user;
|
|
|
|
|
private static String password;
|
|
|
|
|
private String portalName;
|
|
|
|
|
private String pop3Server;
|
|
|
|
|
private String pop3user;
|
|
|
|
|
private String pop3password;
|
|
|
|
|
|
|
|
|
|
private String ldapUrl;
|
|
|
|
|
private String filter;
|
|
|
|
|
private String principal;
|
|
|
|
|
private String ldapPassword;
|
|
|
|
|
|
|
|
|
|
public void init() {
|
|
|
|
|
store = new DBCassandraAstyanaxImpl();
|
|
|
|
@ -66,16 +81,60 @@ public class PortalSchedulerService extends HttpServlet {
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
for (ServiceEndpoint res : list) {
|
|
|
|
|
AccessPoint found = res.profile().accessPoints().iterator().next();
|
|
|
|
|
host = found.address();
|
|
|
|
|
user = found.username();
|
|
|
|
|
String encrPassword = found.password();
|
|
|
|
|
Group<AccessPoint> apGroup = res.profile().accessPoints();
|
|
|
|
|
AccessPoint[] accessPoints = (AccessPoint[]) apGroup.toArray(new AccessPoint[apGroup.size()]);
|
|
|
|
|
for (int i = 0; i < accessPoints.length; i++) {
|
|
|
|
|
if (accessPoints[i].name().compareTo(POP3_SERVER_NAME) == 0) {
|
|
|
|
|
_log.info("Found credentials for " + POP3_SERVER_NAME);
|
|
|
|
|
AccessPoint found = accessPoints[i];
|
|
|
|
|
pop3Server = found.address();
|
|
|
|
|
pop3user = found.username();
|
|
|
|
|
String encrPassword = found.password();
|
|
|
|
|
try {
|
|
|
|
|
pop3password = StringEncrypter.getEncrypter().decrypt( encrPassword);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
_log.error("Something went wrong while decrypting password for " + POP3_SERVER_NAME);
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (accessPoints[i].name().compareTo(LDAP_SERVER_NAME) == 0) {
|
|
|
|
|
_log.info("Found credentials for " + LDAP_SERVER_NAME);
|
|
|
|
|
AccessPoint found = accessPoints[i];
|
|
|
|
|
ldapUrl = found.address();
|
|
|
|
|
String encrPassword = found.password();
|
|
|
|
|
try {
|
|
|
|
|
ldapPassword = StringEncrypter.getEncrypter().decrypt( encrPassword);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
_log.error("Something went wrong while decrypting password for " + LDAP_SERVER_NAME);
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
Group<Property> propGroup = found.properties();
|
|
|
|
|
Property[] props = (Property[]) propGroup.toArray(new Property[propGroup.size()]);
|
|
|
|
|
for (int j = 0; j < props.length; j++) {
|
|
|
|
|
_log.info("\tFound properties of " + LDAP_SERVER_NAME);
|
|
|
|
|
if (props[i].name().compareTo(LDAP_SERVER_FILTER_NAME) == 0) {
|
|
|
|
|
String encrValue = props[i].value();
|
|
|
|
|
try {
|
|
|
|
|
filter = StringEncrypter.getEncrypter().decrypt( encrValue);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
_log.error("Something went wrong while decrypting value for " + LDAP_SERVER_FILTER_NAME);
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (props[i].name().compareTo(LDAP_SERVER_PRINCPAL_NAME) == 0) {
|
|
|
|
|
String encrValue = props[i].value();
|
|
|
|
|
try {
|
|
|
|
|
principal = StringEncrypter.getEncrypter().decrypt( encrValue);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
_log.error("Something went wrong while decrypting value for " + LDAP_SERVER_PRINCPAL_NAME);
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
password = StringEncrypter.getEncrypter().decrypt( encrPassword);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -83,10 +142,10 @@ public class PortalSchedulerService extends HttpServlet {
|
|
|
|
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
|
|
|
|
|
|
|
|
|
ScheduledExecutorService ldapScheduler = Executors.newScheduledThreadPool(1);
|
|
|
|
|
ldapScheduler.scheduleAtFixedRate(new LDAPSync(), 0, LDAP_MINUTES_DELAY, TimeUnit.MINUTES);
|
|
|
|
|
ldapScheduler.scheduleAtFixedRate(new LDAPSync(ldapUrl, filter, principal, ldapPassword), 0, LDAP_MINUTES_DELAY, TimeUnit.MINUTES);
|
|
|
|
|
|
|
|
|
|
ScheduledExecutorService pop3Scheduler = Executors.newScheduledThreadPool(1);
|
|
|
|
|
pop3Scheduler.scheduleAtFixedRate(new PeriodicTask(store, portalName, host, user, password), 0, POP3_MINUTES_DELAY, TimeUnit.MINUTES);
|
|
|
|
|
pop3Scheduler.scheduleAtFixedRate(new PeriodicTask(store, portalName, pop3Server, pop3user, pop3password), 0, POP3_MINUTES_DELAY, TimeUnit.MINUTES);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String toReturn = "<DIV>Check Notification Email Started ... </DIV>";
|
|
|
|
|