Merge pull request 'Feature/19186' (#2) from Feature/19186 into master
This commit is contained in:
commit
80ef562833
|
@ -1,6 +1,7 @@
|
|||
<ReleaseNotes>
|
||||
<Changeset component="org.gcube.dataanalysis.dataminer-pool-manager.2-7-0" date="2020-04-16">
|
||||
<Change>Updated to new Social Networking API [ticket #19081]</Change>
|
||||
<Change>Added application token for send notifications [ticket #19186]</Change>
|
||||
</Changeset>
|
||||
<Changeset component="org.gcube.dataanalysis.dataminer-pool-manager.2-6-0" date="2019-12-11">
|
||||
<Change>Updated to Git and Jenkins</Change>
|
||||
|
|
8
pom.xml
8
pom.xml
|
@ -12,7 +12,7 @@
|
|||
<groupId>org.gcube.dataanalysis</groupId>
|
||||
<artifactId>dataminer-pool-manager</artifactId>
|
||||
<packaging>war</packaging>
|
||||
<version>2.7.0</version>
|
||||
<version>2.7.0-SNAPSHOT</version>
|
||||
|
||||
<name>dataminer-pool-manager</name>
|
||||
<description>DataMiner Pool Manager is a service to support the integration of algorithms in D4Science Infrastructure</description>
|
||||
|
@ -56,6 +56,10 @@
|
|||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.gcube.core</groupId>
|
||||
<artifactId>common-encryption</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
|
@ -189,7 +193,7 @@
|
|||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
|
|
|
@ -12,6 +12,7 @@ import java.io.OutputStreamWriter;
|
|||
***REMOVED***
|
||||
import java.net.URLConnection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
***REMOVED***
|
||||
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
|
@ -21,7 +22,12 @@ import org.apache.http.util.EntityUtils;
|
|||
***REMOVED***
|
||||
import org.gcube.common.authorization.library.AuthorizationEntry;
|
||||
***REMOVED***
|
||||
import org.gcube.common.encryption.encrypter.StringEncrypter;
|
||||
import org.gcube.common.resources.gcore.GCoreEndpoint;
|
||||
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.dataanalysis.dataminer.poolmanager.clients.configuration.DMPMClientConfiguratorManager;
|
||||
import org.gcube.dataanalysis.dataminer.poolmanager.util.exception.EMailException;
|
||||
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
||||
|
@ -34,13 +40,17 @@ import org.json.JSONObject;
|
|||
|
||||
public class SendMail ***REMOVED***
|
||||
|
||||
private Logger logger = LoggerFactory.getLogger(SendMail.class);
|
||||
private final String WRITE_MESSAGE_ADDRESS_PATH = "2/messages/write-message?gcube-token=",
|
||||
USER_ROLES_ADDRESS_PATH = "2/users/get-usernames-by-role?role-name=DataMiner-Manager&gcube-token=",
|
||||
SOCIAL_SERVICE_QUERY_CONDITION = "$resource/Profile/ServiceName/text() eq 'SocialNetworking'",
|
||||
SOCIAL_SERVICE_URI = "jersey-servlet", JSON_MIME_TYPE = "application/json";
|
||||
private static final Logger logger = LoggerFactory.getLogger(SendMail.class);
|
||||
|
||||
private static final String WRITE_MESSAGE_ADDRESS_PATH = "2/messages/write-message?gcube-token=";
|
||||
private static final String USER_ROLES_ADDRESS_PATH = "2/users/get-usernames-by-role?role-name=DataMiner-Manager&gcube-token=";
|
||||
private static final String SOCIAL_SERVICE_QUERY_CONDITION = "$resource/Profile/ServiceName/text() eq 'SocialNetworking'";
|
||||
private static final String SOCIAL_SERVICE_URI = "jersey-servlet", JSON_MIME_TYPE = "application/json";
|
||||
private static final String DMPOOLMANAGER_SERVICE_QUERY_CONDITION = "$resource/Profile/Name/text() eq 'DMPoolManager'";
|
||||
|
||||
|
||||
private String socialServiceAddress;
|
||||
private String applicationToken;
|
||||
|
||||
public SendMail() ***REMOVED***
|
||||
|
||||
|
@ -51,6 +61,8 @@ public class SendMail ***REMOVED***
|
|||
logger.debug("Notification Subject: " + subject);
|
||||
logger.debug("Notification Body: " + body);
|
||||
|
||||
applicationToken = retrieveApplicationToken();
|
||||
|
||||
retrieveSocialService();
|
||||
|
||||
String postBody = createPostBody(subject, body);
|
||||
|
@ -93,6 +105,49 @@ public class SendMail ***REMOVED***
|
|||
|
||||
***REMOVED***
|
||||
|
||||
***REMOVED***
|
||||
|
||||
private String retrieveApplicationToken() throws EMailException ***REMOVED***
|
||||
try ***REMOVED***
|
||||
|
||||
SimpleQuery query = queryFor(ServiceEndpoint.class);
|
||||
query.addCondition(DMPOOLMANAGER_SERVICE_QUERY_CONDITION);
|
||||
DiscoveryClient<ServiceEndpoint> client = clientFor(ServiceEndpoint.class);
|
||||
List<ServiceEndpoint> resources = client.submit(query);
|
||||
if (resources.isEmpty()) ***REMOVED***
|
||||
logger.error("No services resource found on IS!");
|
||||
***REMOVED*** else ***REMOVED***
|
||||
logger.debug("Retrieved: " + resources.get(0));
|
||||
***REMOVED***
|
||||
|
||||
Group<AccessPoint> accessPoints = resources.get(0).profile().accessPoints();
|
||||
if (!accessPoints.isEmpty()) ***REMOVED***
|
||||
Iterator<AccessPoint> iterator = accessPoints.iterator();
|
||||
AccessPoint ap = iterator.next();
|
||||
Group<Property> props = ap.properties();
|
||||
if (!props.isEmpty()) ***REMOVED***
|
||||
Iterator<Property> iteratorProps = props.iterator();
|
||||
Property p = iteratorProps.next();
|
||||
String applicationToken = StringEncrypter.getEncrypter().decrypt(p.value());
|
||||
logger.debug("Application token found: " + applicationToken);
|
||||
return applicationToken;
|
||||
|
||||
***REMOVED*** else ***REMOVED***
|
||||
String error = "DMPoolManager application token not found in service resource on IS!";
|
||||
logger.error(error);
|
||||
throw new EMailException(error);
|
||||
***REMOVED***
|
||||
***REMOVED*** else ***REMOVED***
|
||||
String error = "DMPoolManager invalid service resource on IS!";
|
||||
logger.error(error);
|
||||
throw new EMailException(error);
|
||||
***REMOVED***
|
||||
|
||||
***REMOVED*** catch (Throwable e) ***REMOVED***
|
||||
logger.error("DMPoolManager application token not found: " + e.getLocalizedMessage(), e);
|
||||
throw new EMailException("DMPoolManager application token not found: " + e.getLocalizedMessage(), e);
|
||||
***REMOVED***
|
||||
|
||||
***REMOVED***
|
||||
|
||||
private void retrieveSocialService() throws EMailException ***REMOVED***
|
||||
|
@ -117,7 +172,6 @@ public class SendMail ***REMOVED***
|
|||
|
||||
***REMOVED***
|
||||
|
||||
|
||||
private String username(String token) throws ObjectNotFound, Exception ***REMOVED***
|
||||
AuthorizationEntry entry = authorizationService().get(token);
|
||||
logger.debug(entry.getClientInfo().getId());
|
||||
|
@ -136,7 +190,7 @@ public class SendMail ***REMOVED***
|
|||
|
||||
requestMessageBuilder.append(WRITE_MESSAGE_ADDRESS_PATH);
|
||||
logger.info("Execute Post Request: " + requestMessageBuilder.toString());
|
||||
requestMessageBuilder.append(SecurityTokenProvider.instance.get());
|
||||
requestMessageBuilder.append(applicationToken);
|
||||
String endpoint = requestMessageBuilder.toString();
|
||||
|
||||
***REMOVED*** Send the request
|
||||
|
@ -243,7 +297,8 @@ public class SendMail ***REMOVED***
|
|||
|
||||
requestMessageBuilder.append(USER_ROLES_ADDRESS_PATH);
|
||||
logger.info("Request Admins Url: " + requestMessageBuilder.toString());
|
||||
requestMessageBuilder.append(SecurityTokenProvider.instance.get());
|
||||
***REMOVED*** SecurityTokenProvider.instance.get()
|
||||
requestMessageBuilder.append(applicationToken);
|
||||
|
||||
String requestAdminsUrl = requestMessageBuilder.toString();
|
||||
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
package org.gcube.dataanalysis.dataminerpoolmanager;
|
||||
|
||||
import static org.gcube.resources.discovery.icclient.ICFactory.clientFor;
|
||||
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
|
||||
|
||||
import java.util.Iterator;
|
||||
***REMOVED***
|
||||
|
||||
***REMOVED***
|
||||
import org.gcube.common.encryption.encrypter.StringEncrypter;
|
||||
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;
|
||||
***REMOVED***
|
||||
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
||||
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
||||
|
||||
public class ApplicationTokenTest ***REMOVED***
|
||||
|
||||
private static final String DMPOOLMANAGER_SERVICE_QUERY_CONDITION = "$resource/Profile/Name/text() eq 'DMPoolManager'";
|
||||
|
||||
public static void main(String[] args) ***REMOVED***
|
||||
ScopeProvider.instance.set("/gcube/devsec/devVRE");
|
||||
SecurityTokenProvider.instance.set("xxxx-xxxx-xxx");
|
||||
|
||||
decryptToken();
|
||||
***REMOVED***
|
||||
|
||||
private static void decryptToken() ***REMOVED***
|
||||
try ***REMOVED***
|
||||
|
||||
SimpleQuery query = queryFor(ServiceEndpoint.class);
|
||||
query.addCondition(DMPOOLMANAGER_SERVICE_QUERY_CONDITION);
|
||||
DiscoveryClient<ServiceEndpoint> client = clientFor(ServiceEndpoint.class);
|
||||
List<ServiceEndpoint> resources = client.submit(query);
|
||||
if (resources.isEmpty()) ***REMOVED***
|
||||
System.out.println("No services resource found on IS!");
|
||||
|
||||
***REMOVED*** else ***REMOVED***
|
||||
System.out.println("Retrieved: " + resources.get(0));
|
||||
***REMOVED***
|
||||
|
||||
|
||||
Group<AccessPoint> accessPoints = resources.get(0).profile().accessPoints();
|
||||
if (!accessPoints.isEmpty()) ***REMOVED***
|
||||
Iterator<AccessPoint> iterator = accessPoints.iterator();
|
||||
AccessPoint ap = iterator.next();
|
||||
Group<Property> props = ap.properties();
|
||||
if (!props.isEmpty()) ***REMOVED***
|
||||
Iterator<Property> iteratorProps = props.iterator();
|
||||
Property p = iteratorProps.next();
|
||||
String applicationToken = StringEncrypter.getEncrypter().decrypt(p.value());
|
||||
System.out.println("Application token found: " + applicationToken);
|
||||
|
||||
***REMOVED*** else ***REMOVED***
|
||||
System.out.println("No application token found in service resource on IS!");
|
||||
***REMOVED***
|
||||
***REMOVED*** else ***REMOVED***
|
||||
System.out.println("Invalid service resource on IS!");
|
||||
|
||||
***REMOVED***
|
||||
|
||||
***REMOVED*** catch (Exception e) ***REMOVED***
|
||||
e.printStackTrace();
|
||||
***REMOVED***
|
||||
***REMOVED***
|
||||
|
||||
***REMOVED***
|
|
@ -0,0 +1 @@
|
|||
/devsec.gcubekey
|
Loading…
Reference in New Issue