Installation and operation manual


Push notification log

To obtain the logs concerning push notifications, you need to modify log4j.xml and add : 

<category name="org.ametys.plugins.mobileapp.PushNotificationManager" additivity="false">
    <priority value="debug"/>
    <appender-ref ref="notifications"/>
</category>

To log into a dedicated "notifications" file: 

<appender name="notifications" class="org.apache.log4j.rolling.RollingFileAppender">
    <param name="Encoding" value="UTF-8"/>
    <rollingPolicy class="org.apache.log4j.rolling.TimeBasedRollingPolicy">
        <param name="FileNamePattern" value="${ametys.home.dir}/logs/notifications-%d.log"/>
    </rollingPolicy>
    <layout class="org.apache.log4j.PatternLayout">
        <param name="ConversionPattern" value="%d %-5p [%c] (%t;%X{requestURI}) %m%n"/>
    </layout>
    <filter class="org.ametys.core.util.AmetysExceptionFilter"/>
</appender>

The logs will contain the notification tokens involved in the notification.

 

Extraction of push notification tokens by person

Push notification tokens are stored inAmetys user preferences. It is possible to extract tokens for each person. 

This script is used to obtain the connection ID of each person subscribed to the mobile app's push notifications: 

let population = "utilisateurs";
const UserPreferencesHelper = Ametys.serviceManager.lookup("org.ametys.plugins.mobileapp.UserPreferencesHelper");

printNotificationTokens("loginDeLUtilisateur");

function printNotificationTokens(login){
let user = org.ametys.core.user.UserIdentity.stringToUserIdentity(`${login}#${population}`);
Ametys.console.log(login+":"+UserPreferencesHelper.getNotificationTokens(user).toString());
}

Replace "loginDeLUtilisateur" with the user's login. You can add as many printNotificationTokens("loginDeLUtilisateur"); lines as you like to obtain the tokens for each of these people. 

Revoker a token (not to be confused with notification tokens)

When a user authenticates on the mobile app, a personal token dedicated to the mobile app is assigned. It is this token that then enables the user to authenticate via the mobile app. 

Tokens are stored in the database in the Authentication_Token table, and are encoded to prevent anyone reading the database from using the token.

mysql> desc Authentication_Token;
+---------------------+--------------+------+-----+---------+----------------+
| Field               | Type         | Null | Key | Default | Extra          |
+---------------------+--------------+------+-----+---------+----------------+
| id                  | int          | NO   | PRI | NULL    | auto_increment |
| login               | varchar(64)  | NO   |     | NULL    |                |
| population_id       | varchar(200) | NO   |     | NULL    |                |
| token               | varchar(128) | NO   |     | NULL    |                |
| salt                | varchar(64)  | NO   |     | NULL    |                |
| creation_date       | datetime     | YES  |     | NULL    |                |
| end_date            | datetime     | YES  |     | NULL    |                |
| last_update_date    | datetime     | YES  |     | NULL    |                |
| nb_uses_left        | int          | YES  |     | NULL    |                |
| auto_renew_duration | bigint       | YES  |     | NULL    |                |
| context             | varchar(200) | YES  |     | NULL    |                |
| type                | varchar(64)  | NO   |     | NULL    |                |
| token_comment       | longblob     | YES  |     | NULL    |                |
+---------------------+--------------+------+-----+---------+----------------+

All tokens created for the mobile application have the 'mobileapp' type.

To delete all a user's tokens from their mobile application login :

delete from Authentication_Token where type='mobileapp' and login='xxx';

You can force tokens to be deleted automatically using a script shell launched in a crontab, for example, based on the creation date, to delete all mobile app tokens older than 6 months.

delete from Authentication_Token where type='mobileapp' and creation_date < date_sub(now(), Interval 6 month);
Back to top

MobileApp