Browse Source

Consolidate login/logout process

Julio 7 years ago
parent
commit
688539d5d0

+ 2 - 1
config/packages/framework.yaml

@@ -22,4 +22,5 @@ framework:
     fragments:       ~
     http_method_override: true
     assets: ~
-    annotations: true
+    annotations: true
+    translator: ~

+ 2 - 2
config/packages/hwi_oauth.yaml

@@ -1,7 +1,7 @@
 hwi_oauth:
     connect:
         account_connector: chamilo_user_provider
-    firewall_names: [secured_area]
+    firewall_names: [admin]
     resource_owners:
         github:
             type:                github
@@ -38,4 +38,4 @@ hwi_oauth:
             github: githubId
             google: googleId
             facebook: facebookId
-            my_custom_provider: customId
+            my_custom_provider: customId

+ 18 - 35
config/packages/security.yaml

@@ -52,51 +52,34 @@ security:
         dev:
             pattern: ^/(_(profiler|wdt)|css|images|js)/
             security: false
-
         admin:
-            pattern:            /admin(.*)
+            pattern:            .*
             context:            user
             form_login:
                 provider:       fos_userbundle
-                login_path:     /admin/login
-                use_forward:    false
-                check_path:     /admin/login_check
-                failure_path:   null
-            logout:
-                path:           /admin/logout
-                target:         /admin/login
-            anonymous:          true
-        secured_area:
-            pattern: .*
-            context: user
-            form_login:
-                provider: fos_userbundle
                 csrf_token_generator: security.csrf.token_manager
-                login_path:     /login
+                login_path:     /administration/login
                 use_forward:    false
-                check_path:     /login_check
-                failure_path:   null
+                check_path:     /administration/login_check
                 success_handler: chamilo_core.listener.login_success_handler
-                remember_me: true
+                failure_path:   null
             remember_me:
                 secret:   '%secret%'
                 lifetime: 604800 # 1 week in seconds
                 path:     /
             logout:
-                path:   /logout
-                target: /
-                success_handler: chamilo_core.listener.logout_success_handler
-                invalidate_session: false
-#                handlers: ['sonata.page.cms_manager_selector']
-            anonymous: true
+                path:           /administration/logout
+                target:         /
+            anonymous:          true
+
             oauth:
-                resource_owners:
-                    facebook:        "/login/check-facebook"
-                    google:          "/login/check-google"
-                    github:          "/login/check-github"
-                login_path:        /login
-                failure_path:      /connect
-                use_forward:       false
-                oauth_user_provider:
-                    service: chamilo_user_provider
-            switch_user: false
+              resource_owners:
+                  facebook:        "/administration/login/check-facebook"
+                  google:          "/administration/login/check-google"
+                  github:          "/administration/login/check-github"
+              login_path:        /administration/login
+              check_path:     /administration/login_check
+              failure_path:      /administration/connect
+              use_forward:       false
+              oauth_user_provider:
+                  service: chamilo_user_provider

+ 3 - 3
config/routing.yaml

@@ -9,10 +9,10 @@
 #    type: annotation
 
 logout:
-    path: /logout
+    path: /administration/logout
 
 sonata_user_admin_security_logout:
-    path: /logout
+    path: /administration/logout
 
 _admin:
     resource: routing/sonata_admin.yaml
@@ -55,4 +55,4 @@ _admin:
 #app_settings:
 #    resource: |
 #        alias: app.settings
-#    type: sylius.resource_api
+#    type: sylius.resource_api

+ 56 - 0
public/.htaccess

@@ -0,0 +1,56 @@
+# Use the front controller as index file. It serves as a fallback solution when
+# every other rewrite/redirect fails (e.g. in an aliased environment without
+# mod_rewrite). Additionally, this reduces the matching process for the
+# start page (path "/") because otherwise Apache will apply the rewriting rules
+# to each configured DirectoryIndex file (e.g. index.php, index.html, index.pl).
+DirectoryIndex index.php
+
+<IfModule mod_rewrite.c>
+    RewriteEngine On
+
+    # Determine the RewriteBase automatically and set it as environment variable.
+    # If you are using Apache aliases to do mass virtual hosting or installed the
+    # project in a subdirectory, the base path will be prepended to allow proper
+    # resolution of the app.php file and to redirect to the correct URI. It will
+    # work in environments without path prefix as well, providing a safe, one-size
+    # fits all solution. But as you do not need it in this case, you can comment
+    # the following 2 lines to eliminate the overhead.
+    RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
+    RewriteRule ^(.*) - [E=BASE:%1]
+
+    # Redirect to URI without front controller to prevent duplicate content
+    # (with and without `/app.php`). Only do this redirect on the initial
+    # rewrite by Apache and not on subsequent cycles. Otherwise we would get an
+    # endless redirect loop (request -> rewrite to front controller ->
+    # redirect -> request -> ...).
+    # So in case you get a "too many redirects" error or you always get redirected
+    # to the start page because your Apache does not expose the REDIRECT_STATUS
+    # environment variable, you have 2 choices:
+    # - disable this feature by commenting the following 2 lines or
+    # - use Apache >= 2.3.9 and replace all L flags by END flags and remove the
+    #   following RewriteCond (best solution)
+    RewriteCond %{ENV:REDIRECT_STATUS} ^$
+    RewriteRule ^index\.php(/(.*)|$) %{ENV:BASE}/$2 [R=302,L]
+
+    # If the requested filename exists, simply serve it.
+    # We only want to let Apache serve files and not directories.
+    RewriteCond %{REQUEST_FILENAME} -f
+    RewriteRule .? - [L]
+
+    # Rewrite all other queries to the front controller.
+    RewriteRule .? %{ENV:BASE}/index.php [L]
+</IfModule>
+
+<IfModule !mod_rewrite.c>
+    <IfModule mod_alias.c>
+        # When mod_rewrite is not available, we instruct a temporary redirect of
+        # the start page to the front controller explicitly so that the website
+        # and the generated links can still be used.
+        RedirectMatch 302 ^/$ /index.php/
+        # RedirectTemp cannot be used instead
+    </IfModule>
+</IfModule>
+
+
+
+

+ 2 - 2
src/ThemeBundle/Resources/views/Sidebar/login.html.twig

@@ -1,6 +1,6 @@
 {{ locale_switcher(null, null, 'ChamiloCoreBundle:Admin:switcher_links.html.twig') }}
 
-<form class="form-horizontal" action="{{ path("fos_user_security_check") }}" method="post" name="formLogin" id="formLogin">
+<form class="form-horizontal" action="{{ path("sonata_user_admin_security_check") }}" method="post" name="formLogin" id="formLogin">
     <input type="hidden" name="_csrf_token" value="{{ csrf_token('authenticate') }}"/>
     <fieldset>
         <div class="input-group">
@@ -33,4 +33,4 @@
     </fieldset>
     <input name="_qf__formLogin" type="hidden" value="">
 </form>
-{{ mopa_bootstrap_menu('ChamiloCoreBundle:LeftMenuBuilder:loginMenu', {'automenu': 'pills', 'stacked':true}) }}
+{{ mopa_bootstrap_menu('ChamiloCoreBundle:LeftMenuBuilder:loginMenu', {'automenu': 'pills', 'stacked':true}) }}

+ 1 - 1
src/UserBundle/Resources/views/Security/base_login.html.twig

@@ -17,7 +17,7 @@
                         {% endblock %}
 
                         {% block sonata_user_login_form %}
-                            <form action="{{ path("fos_user_security_check") }}"
+                            <form action="{{ path("sonata_user_admin_security_check") }}"
                                   method="post" role="form"
                                   class="form-horizontal">
                                 <input type="hidden" name="_csrf_token"

+ 1 - 1
src/UserBundle/Resources/views/Security/login.html.twig

@@ -9,7 +9,7 @@
         {% endblock %}
         <div class="login-box-body">
             {% block sonata_user_login_form %}
-                <form action="{{ path("fos_user_security_check") }}" method="post" role="form">
+                <form action="{{ path("sonata_user_admin_security_check") }}" method="post" role="form">
                     <input type="hidden" name="_csrf_token" value="{{ csrf_token }}"/>
 
                     <div class="form-group has-feedback">