// Path: stickypunch-common/src/main/java/com/comandante/stickypunch/api/model/WebPushStore.java
// public interface WebPushStore {
// 
//     void updateWebPushUser(WebPushUser webPushUser) throws Exception;
// 
//     Optional<WebPushUser> getWebPushUserMostRecentlyUpdatedByDeviceToken(String deviceToken);
// 
//     Optional<WebPushUser> getWebPushUsersByUserId(String userId);
// 
//     Optional<WebPushUser> getWebPushUsersByUserIdAndDeviceToken(String userId, String deviceToken);
// 
//     Optional<List<WebPushUser>> getWebPushUsers();
// 
// }
// 
// Path: stickypunch-common/src/main/java/com/comandante/stickypunch/api/model/WebPushStoreAuth.java
// public interface WebPushStoreAuth {
// 
//     public boolean authUserId(String userId, Optional<String> deviceToken);
// 
// }
// 
// Path: stickypunch-common/src/main/java/com/comandante/stickypunch/api/model/WebPushUser.java
// public class WebPushUser {
//     private Optional<String> deviceToken;
//     private Optional<String> websitePushId;
//     private Optional<String> userId;
//     private Optional<Boolean> isActive;
//     private Optional<Long> isActiveTimestamp;
// 
//     public WebPushUser(Optional<String> deviceToken,
//                        Optional<String> websitePushId,
//                        Optional<String> userId,
//                        Optional<Boolean> active,
//                        Optional<Long> isActiveTimestamp) {
//         this.deviceToken = deviceToken;
//         this.websitePushId = websitePushId;
//         this.userId = userId;
//         this.isActive = active;
//         this.isActiveTimestamp = isActiveTimestamp;
//     }
// 
//     public Optional<String> getDeviceToken() {
//         return deviceToken;
//     }
// 
//     public Optional<String> getWebsitePushId() {
//         return websitePushId;
//     }
// 
//     public Optional<String> getUserId() {
//         return userId;
//     }
// 
//     public Optional<Boolean> getActive() {
//         return isActive;
//     }
// 
//     public Optional<Long> getActiveTimestamp() {
//         return isActiveTimestamp;
//     }
// 
//     public void setActiveTimestamp(Long activeTimestamp) {
//         isActiveTimestamp = Optional.of(activeTimestamp);
//     }
// 
//     public void setDeviceToken(String deviceToken) {
//         this.deviceToken = Optional.of(deviceToken);
//     }
// 
//     public void setWebsitePushId(String websitePushId) {
//         this.websitePushId = Optional.of(websitePushId);
//     }
// 
//     public void setUserId(String userId) {
//         this.userId = Optional.of(userId);
//     }
// 
//     public void setActive(Boolean active) {
//         isActive = Optional.of(active);
//     }
// }


import com.google.common.base.Optional;
import com.comandante.stickypunch.api.model.WebPushStore;
import com.comandante.stickypunch.api.model.WebPushStoreAuth;
import com.comandante.stickypunch.api.model.WebPushUser;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
package com.comandante.stickypunch.http;


public class WebPushUserIdAuth implements WebPushStoreAuth {

    private static final Logger log = LogManager.getLogger(WebPushUserIdAuth.class);

    private final WebPushStore webPushStore;
    private final HttpConfiguration httpConfiguration;

    public WebPushUserIdAuth(WebPushStore webPushStore, HttpConfiguration configuration) {
        this.webPushStore = webPushStore;
        this.httpConfiguration = configuration;
    }

    @Override
    public boolean authUserId(String userId, Optional<String> deviceToken) {
        if (!httpConfiguration.isStrictAuth) {
            return true;
        }
        Optional<WebPushUser> webPushUser = Optional.absent();
        if (deviceToken.isPresent()) {
            webPushUser = webPushStore.getWebPushUsersByUserIdAndDeviceToken(userId, deviceToken.get());
        } else {
            webPushUser = webPushStore.getWebPushUsersByUserId(userId);
        }
        if (webPushUser.isPresent() && webPushUser.get().getUserId().isPresent()) {
// Path: stickypunch-common/src/main/java/com/comandante/stickypunch/api/model/WebPushStore.java
// public interface WebPushStore {
// 
//     void updateWebPushUser(WebPushUser webPushUser) throws Exception;
// 
//     Optional<WebPushUser> getWebPushUserMostRecentlyUpdatedByDeviceToken(String deviceToken);
// 
//     Optional<WebPushUser> getWebPushUsersByUserId(String userId);
// 
//     Optional<WebPushUser> getWebPushUsersByUserIdAndDeviceToken(String userId, String deviceToken);
// 
//     Optional<List<WebPushUser>> getWebPushUsers();
// 
// }
// 
// Path: stickypunch-common/src/main/java/com/comandante/stickypunch/api/model/WebPushStoreAuth.java
// public interface WebPushStoreAuth {
// 
//     public boolean authUserId(String userId, Optional<String> deviceToken);
// 
// }
// 
// Path: stickypunch-common/src/main/java/com/comandante/stickypunch/api/model/WebPushUser.java
// public class WebPushUser {
//     private Optional<String> deviceToken;
//     private Optional<String> websitePushId;
//     private Optional<String> userId;
//     private Optional<Boolean> isActive;
//     private Optional<Long> isActiveTimestamp;
// 
//     public WebPushUser(Optional<String> deviceToken,
//                        Optional<String> websitePushId,
//                        Optional<String> userId,
//                        Optional<Boolean> active,
//                        Optional<Long> isActiveTimestamp) {
//         this.deviceToken = deviceToken;
//         this.websitePushId = websitePushId;
//         this.userId = userId;
//         this.isActive = active;
//         this.isActiveTimestamp = isActiveTimestamp;
//     }
// 
//     public Optional<String> getDeviceToken() {
//         return deviceToken;
//     }
// 
//     public Optional<String> getWebsitePushId() {
//         return websitePushId;
//     }
// 
//     public Optional<String> getUserId() {
//         return userId;
//     }
// 
//     public Optional<Boolean> getActive() {
//         return isActive;
//     }
// 
//     public Optional<Long> getActiveTimestamp() {
//         return isActiveTimestamp;
//     }
// 
//     public void setActiveTimestamp(Long activeTimestamp) {
//         isActiveTimestamp = Optional.of(activeTimestamp);
//     }
// 
//     public void setDeviceToken(String deviceToken) {
//         this.deviceToken = Optional.of(deviceToken);
//     }
// 
//     public void setWebsitePushId(String websitePushId) {
//         this.websitePushId = Optional.of(websitePushId);
//     }
// 
//     public void setUserId(String userId) {
//         this.userId = Optional.of(userId);
//     }
// 
//     public void setActive(Boolean active) {
//         isActive = Optional.of(active);
//     }
// }


// Path: stickypunch-http/src/main/java/com/comandante/stickypunch/http/WebPushUserIdAuth.java
import com.google.common.base.Optional;
import com.comandante.stickypunch.api.model.WebPushStore;
import com.comandante.stickypunch.api.model.WebPushStoreAuth;
import com.comandante.stickypunch.api.model.WebPushUser;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;

package com.comandante.stickypunch.http;


public class WebPushUserIdAuth implements WebPushStoreAuth {

    private static final Logger log = LogManager.getLogger(WebPushUserIdAuth.class);

    private final WebPushStore webPushStore;
    private final HttpConfiguration httpConfiguration;

    public WebPushUserIdAuth(WebPushStore webPushStore, HttpConfiguration configuration) {
        this.webPushStore = webPushStore;
        this.httpConfiguration = configuration;
    }

    @Override
    public boolean authUserId(String userId, Optional<String> deviceToken) {
        if (!httpConfiguration.isStrictAuth) {
            return true;
        }
        Optional<WebPushUser> webPushUser = Optional.absent();
        if (deviceToken.isPresent()) {
            webPushUser = webPushStore.getWebPushUsersByUserIdAndDeviceToken(userId, deviceToken.get());
        } else {
            webPushUser = webPushStore.getWebPushUsersByUserId(userId);
        }
        if (webPushUser.isPresent() && webPushUser.get().getUserId().isPresent()) {
            if (webPushUser.get().getUserId().get().equals(userId)) {