/*
 * Copyright 2013 - Elian ORIOU
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.vino;

import com.google.common.base.Charsets;
import restx.RestxRequest;
import restx.factory.Module;
import restx.factory.Provides;
import restx.security.Permission;
import restx.security.SignatureKey;
import restx.security.StdRestxSecurityManager;

import javax.inject.Named;

/**
 * User: walien
 * Date: 1/7/14
 * Time: 11:16 PM
 */

@Module(priority = -100)
public class AppModule {

    @Provides
    public SignatureKey signatureKey() {
        return new SignatureKey(
                "vino -4553657335605629125 1e6dcc7f-a28e-4511-8828-1fcad574eae4 vino"
                        .getBytes(Charsets.UTF_8));
    }

    @Provides
    @Named("app.name")
    public String appName() {
        return "vino";
    }

    @Provides
    @Named("mongo.db")
    public String jongoDbName() {
        return "vino";
    }

    @Provides
    @Named("restx.admin.password")
    public String restxAdminPassword() {
        return "vino";
    }

    @Provides
    @Named("StdRestxSecurityManager")
    public StdRestxSecurityManager permitsAllAlways() {
        return new StdRestxSecurityManager() {
            @Override
            public void check(RestxRequest request, Permission permission) {
                // Permit all
            }
        };
    }
}

@@ -659,26 +659,281 @@
 ort 
-restx.RestxRequest
+com.google.common.base.Optional;%0Aimport com.google.common.base.Predicates;%0Aimport com.google.common.collect.ImmutableList;%0Aimport com.mongodb.MongoClient;%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0Aimport restx.RestxRequest;%0Aimport restx.factory.AutoStartable
 ;%0Aim
@@ -1007,63 +1007,25 @@
 stx.
-security.Permission;%0Aimport restx.security.SignatureKey
+mongo.MongoModule
 ;%0Aim
@@ -1044,39 +1044,17 @@
 ecurity.
-StdRestxSecurityManager
+*
 ;%0A%0Aimpor
@@ -1074,16 +1074,48 @@
 t.Named;
+%0Aimport java.util.regex.Pattern;
 %0A%0A/**%0A *
@@ -1218,16 +1218,100 @@
 dule %7B%0A%0A
+    private static final Logger logger = LoggerFactory.getLogger(AppModule.class);%0A%0A
     @Pro
@@ -2168,10 +2168,932 @@
 ;%0A    %7D%0A
+%0A    @Provides%0A    public AutoStartable mongoConnectionLogger(final @Named(%22restx.server.id%22) Optional%3CString%3E serverId,%0A                                               final @Named(%22mongo.db%22) String dbName,%0A                                               final @Named(MongoModule.MONGO_CLIENT_NAME) MongoClient client) %7B%0A        return new AutoStartable() %7B%0A            @Override%0A            public void start() %7B%0A                logger.info(%22%7B%7D - connected to Mongo db '%7B%7D' @ %7B%7D%22, serverId.or(%22-%22), dbName, client.getAllAddress());%0A            %7D%0A        %7D;%0A    %7D%0A%0A    @Provides%0A    public CORSAuthorizer getCorsAuthorizer() %7B%0A        return new StdCORSAuthorizer.Builder()%0A                .setPathMatcher(Predicates.%3CCharSequence%3EalwaysTrue())%0A                .setPathMatcher(Predicates.contains(Pattern.compile(%22.*%22)))%0A                .setAllowedMethods(ImmutableList.of(%22GET%22, %22POST%22))%0A                .build();%0A    %7D%0A%0A
 %7D%0A

Add CORS support (due to cordova)