Hi Iurii,
FYI I have just published a blog post

http://blog.tirasa.net/add-rest-endpoints-to-apache-syncope-2.0.html

where I take the use case below as reference.

HTH
Regards.

On 28/11/2016 13:07, Francesco Chicchiriccò wrote:
On 28/11/2016 12:59, Iurii Smyrnov wrote:

Hi Francesco,
Thanks for your help, one more question, have I understood correctly - we should extend or add custom endpoint Syncope API (NotificationTask, NotificationServiceImpl etc.) because of your answer below ?

Not at all.
You need to add an extension to your project generated via archetype, which adds a REST service to the Syncope REST interface.

You extension will contain:

 1. a new JAX-RS annotated Java interface
2. a class implementing such interface and delegating the actual logic to another class 3. a logic class with actual implementation, e.g. finding user by e-mail and triggering the corresponding notification (which is assumed already available)

Unfortunately, there is no documentation around (yet) for such a task, but you can take a look at the Camel Provisioning extension:

1. https://github.com/apache/syncope/blob/2_0_X/ext/camel/rest-api/src/main/java/org/apache/syncope/common/rest/api/service/CamelRouteService.java 2. https://github.com/apache/syncope/blob/2_0_X/ext/camel/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/service/CamelRouteServiceImpl.java 3. https://github.com/apache/syncope/blob/2_0_X/ext/camel/logic/src/main/java/org/apache/syncope/core/logic/CamelRouteLogic.java

Regards.

My question was :
1. Does Syncope have workflow to request(find) userNames by user email and send this userNames to his email ?


Your answer:

I don't think there is something similar; essentially, you'd want to add a REST endpoint, say

GET /users/reminder?email=ilgro...@apache.org

which looks for an user with e-mail 'ilgro...@apache.org <mailto:ilgro...@apache.org>', gets his username ('fchicchiricco') and sends an e-mail to ilgro...@apache.org <mailto:ilgro...@apache.org> with 'fchicchiricco' in the body.

Correct? If so, you'll need to develop an extension for the purpose - from which you can leverage the existing Notification service.


Thanks,

Iurii Smyrnov

------------------------------------------------------------------------
*From:* Francesco Chicchiriccò <ilgro...@apache.org>
*Sent:* Monday, November 28, 2016 12:57:38 PM
*To:* user@syncope.apache.org
*Subject:* Re: Syncope notifications
On 28/11/2016 10:33, Iurii Smyrnov wrote:

Hi Francesco,

Thanks, that works, I've successfully created notification, but it still haven't sent email to the user - Should I call NotificationManager API to make it send emails ?


First of all, check if a notification task was created for the user below (with e-mail address y_smir...@ukr.net); you can do this either via the admin console (Realms > USER > click on the envelop icon on that user's row) or via REST:

GET /syncope/rest/tasks;type=NOTIFICATION?anyTypeKind=USER&entityKey=9fe21db4-4d12-42e0-a21d-b44d1242e01e

where '9fe21db4-4d12-42e0-a21d-b44d1242e01e' is that user's key.

If the notification task was created, there is probably something wrong in the e-mail configuration:

http://syncope.apache.org/docs/reference-guide.html#e-mail-configuration

For further investigation, as always take a look at the logs.

HTH
Regards.

1. I've successfully_created __notification _(request) :

{
"recipientAttrName":"emails",
"selfAsRecipient":false,
"sender":"send...@ukr.net",
"subject":"subject 2",
"template":"requestPasswordReset",
"traceLevel":"ALL",
"active":true,
"events": ["[LOGIC]:[UserLogic]:[]:[create]:[SUCCESS]"]
}

2. successfully _created user with email_ (y_smir...@ukr.net), but email haven't been sent to the user's mail:

{
"schemas" : ["urn:ietf:params:scim:schemas:core:2.0:User"],
    "userName":"userName",
    "name": {
        "familyName" : "1",
        "givenName" : "givenName-33",
        "middleName" : "middleName-33"
    },
    "emails": [{
        "value": "y_smir...@ukr.net"
    }],
      "ims": [
        {
          "value": "jopeeters36",
          "display": "jopeeters36",
          "type": "aim",
          "primary": false
        },
        {
          "value": "John",
          "display": "John",
          "type": "icq",
          "primary": false
        }
      ],
      "entitlements": [
        {
          "value": "maintenance",
          "display": "maintenance",
          "type": null,
          "primary": false
        },
        {
          "value": "support",
          "display": "support",
          "type": null,
          "primary": false
        }
      ]
}



Thanks,

Iurii Smyrnov

------------------------------------------------------------------------
*From:* Francesco Chicchiriccò <ilgro...@apache.org>
*Sent:* Friday, November 25, 2016 6:03:23 PM
*To:* user@syncope.apache.org
*Subject:* Re: Syncope notifications
On 25/11/2016 16:54, Iurii Smyrnov wrote:

Francesco,

 You've written "/you have posted no events for it/"

 So what is wrong with my request ?:


{
"recipientAttrName":"email",
"selfAsRecipient":false,
"sender":"sen...@ukr.net",
"subject":"subject 21",
"template":"requestPasswordReset",
"traceLevel":"ALL",
"active":true
}
Or you mean that I should call createTasks method from NotificationManagerImpl to create event manualy ? Or I should add some data to the request ?


PS.

Don't see envets field in the NotificationTO (request class in the create method of the NotificationServiceImpl )


You JSON payload is not valid because your are not passing anything in the "events" field; this would be correct, instead:

{
"recipientAttrName":"email",
"selfAsRecipient":false,
"sender":"sen...@ukr.net",
"subject":"subject 21",
"template":"requestPasswordReset",
"traceLevel":"ALL",
"active":true,
"events": ["create"]
}

Please also note that, in order to be meaningful for the NotificationManager, the string values in the events array must be in the format as generated by the admin console and described at

https://syncope.apache.org/docs/reference-guide.html#notification-events

Regards.

------------------------------------------------------------------------
*From:* Francesco Chicchiriccò <ilgro...@apache.org>
*Sent:* Friday, November 25, 2016 5:18:55 PM
*To:* user@syncope.apache.org
*Subject:* Re: Syncope notifications
Hi Iurii,
I have created this issue:

https://issues.apache.org/jira/browse/SYNCOPE-974

and I am also about to commit a fix.

FYI, the actual problem here is the misleading error message; your notification object is anyway invalid because you have posted no events for it (as the error message will correctly report after my fix).

Regards.

On 25/11/2016 13:32, Iurii Smyrnov wrote:

Hi Francesco,

Could you please take a look at the logs snippets (/*core-rest.log, *//*core-persistence.log*/) I've attached (I've set logging level to DEBUG and sent create notification request):


_Request_:

{
"recipientAttrName":"emails",
"selfAsRecipient":false,
"sender":"sen...@ukr.net",
"subject":"subject 21",
"template":"requestPasswordReset",
"traceLevel":"ALL",
"active":true
}


_Response_:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<syncope2:error xmlns:syncope2="http://syncope.apache.org/2.0";>
    <elements>
<element>InvalidStateException: The field "template" of instance "JPANotification[a96fff27-1b5d-4167-afff-271b5db1674f]" contained a null value; the metadata for this field specifies that nulls are illegal.</element>
    </elements>
    <status>500</status>
    <type>Unknown</type>
</syncope2:error>


Some thing wrong here:

at org.apache.syncope.core.persistence.jpa.dao.JPANotificationDAO.findAll(JPANotificationDAO.java:65) ~[syncope-core-persistence-jpa-2.0.1.jar:2.0.1]


Thanks,

Iurii Smyrnov

------------------------------------------------------------------------
*From:* Francesco Chicchiriccò <ilgro...@apache.org>
*Sent:* Thursday, November 24, 2016 3:58:34 PM
*To:* user@syncope.apache.org
*Subject:* Re: Syncope notifications
Hi,
you need to take a look at server logs to see what is actually happening: the Java statements below look generally fine, besides

notificationTO.setKey("111");

which is ignored, as keys are autogenerated.

I also suggest to use the admin console: first set the CXF logs at DEBUG or TRACE level, then create a notification and see what messages are exchanged.

HTH
Regards.

On 24/11/2016 14:46, Iurii Smyrnov wrote:

Hi Francesco,

Thanks for help, and yes we want to have REST endpoint - I've tried the NotificationService to create notification, but got strange error (see the log below), and before notification creation I've called 'read' method of the MailTemplateService and successfully got template entity with key = "requestPasswordReset" and set this key to the notification creation request (NotificationTO) (see code snippet below). Could you please take a look at it, is it a syncope bug :


33971 [qtp1620216417-18] INFO o.a.c.i.LoggingOutInterceptor - Outbound Message
---------------------------
ID: 2
Address: http://192.168.99.100:9080/syncope/rest/notifications
Http-Method: POST
Content-Type: application/json
Headers: {Content-Type=[application/json], Accept=[application/json], Authorization=[Basic YWRtaW46cGFzc3dvcmQ=]} Payload: {"key":"111","abouts":{},"recipientsFIQL":null,"recipientAttrName":"emails","selfAsRecipient":false,"recipientsProviderClassName":null,"sender":"sen...@ukr.net","subject":"subject 1","template":"requestPasswordReset","traceLevel":"ALL","active":true,"events":[],"staticRecipients":[]}
--------------------------------------
34017 [qtp1620216417-18] INFO o.a.c.i.LoggingInInterceptor - Inbound Message
----------------------------
ID: 2
Response-Code: 500
Encoding: UTF-8
Content-Type: application/json;charset=UTF-8
Headers: {connection=[close], content-type=[application/json;charset=UTF-8], Date=[Thu, 24 Nov 2016 13:25:21 GMT], Server=[Apache-Coyote/1.1], transfer-encoding=[chunked], X-Application-Error-Info=[Unknown:InvalidStateException: The field "template" of instance "JPANotification[5b5da1d2-bbf5-49f7-9da1-d2bbf519f746]" contained a null value; the metadata for this field specifies that nulls are illegal.], X-Syncope-Domain=[Master]} Payload: {"status":500,"type":"Unknown","elements":["InvalidStateException: The field \"template\" of instance \"JPANotification[5b5da1d2-bbf5-49f7-9da1-d2bbf519f746]\" contained a null value; the metadata for this field specifies that nulls are illegal."]}
--------------------------------------




MailTemplateTO mailTemplate = syncopeClient.getService(MailTemplateService.class).read("requestPasswordReset");


 NotificationTO notificationTO = new NotificationTO();
        notificationTO.setActive(true);
        notificationTO.setKey("111");
notificationTO.setRecipientAttrName("emails");
notificationTO.setSender("sen...@ukr.net");
notificationTO.setTemplate(mailTemplate.getKey());
notificationTO.setTraceLevel(TraceLevel.ALL);
notificationTO.setSubject("subject 1");

Response rep = syncopeClient.getService(NotificationService.class).create(notificationTO);


Thanks,

Iurii Smyrnov

------------------------------------------------------------------------
*From:* Francesco Chicchiriccò <ilgro...@apache.org>
*Sent:* Wednesday, November 23, 2016 3:08:52 PM
*To:* user@syncope.apache.org
*Subject:* Re: Syncope notifications
Hi Iurii,
first of all, have you already looked at

https://syncope.apache.org/docs/reference-guide.html#notifications

?

More replies below.
Regards.

On 23/11/2016 12:25, Iurii Smyrnov wrote:

Hi Syncope team,

Could you please help us, we've got few questions to you related to the Syncope built-in notification functionality:


1. Does Syncope have workflow to request(find) userNames by user email and send this userNames to his email ?


2. If no, is there a way to create a custom event (i.e. userName request), to associate it with a Notification (type email) and to initialize this event from outside of syncope (i.e. via Rest APIs) ?


I don't think there is something similar; essentially, you'd want to add a REST endpoint, say

GET /users/reminder?email=ilgro...@apache.org

which looks for an user with e-mail 'ilgro...@apache.org', gets his username ('fchicchiricco') and sends an e-mail to ilgro...@apache.org with 'fchicchiricco' in the body.

Correct? If so, you'll need to develop an extension for the purpose - from which you can leverage the existing Notification service.

3. Is there also a way to update syncope mail templates (requestPasswordReset and confirmPasswordReset) by using some REST APIs ?


You can update such templates (and create more, actually) via both Eclipse IDE plugin and admin console: both rely only on REST to communicate with the core, hence the answer is yes.

Take a look at the embedded Swagger UI (if extension is enabled) or REST reference available at

http://syncope.apache.org/rest/2.0/index.html

under /mailTemplates

--
Francesco Chicchiriccò

Tirasa - Open Source Excellence
http://www.tirasa.net/

Member at The Apache Software Foundation
Syncope, Cocoon, Olingo, CXF, OpenJPA, PonyMail
http://home.apache.org/~ilgrosso/

Reply via email to