diff --git a/app/AppKernel.php b/app/AppKernel.php index f5064b9..1716e6f 100644 --- a/app/AppKernel.php +++ b/app/AppKernel.php @@ -20,6 +20,7 @@ class AppKernel extends Kernel new JMS\DiExtraBundle\JMSDiExtraBundle($this), new JMS\SecurityExtraBundle\JMSSecurityExtraBundle(), new KekRozsak\FrontBundle\KekRozsakFrontBundle(), + new KekRozsak\SecurityBundle\KekRozsakSecurityBundle(), ); if (in_array($this->getEnvironment(), array('dev', 'test'))) { diff --git a/app/config/routing.yml b/app/config/routing.yml index 5c7e0b0..c525b24 100644 --- a/app/config/routing.yml +++ b/app/config/routing.yml @@ -1,3 +1,7 @@ +KekRozsakSecurityBundle: + resource: "@KekRozsakSecurityBundle/Resources/config/routing.yml" + prefix: / + KekRozsakFrontBundle: resource: "@KekRozsakFrontBundle/Resources/config/routing.yml" prefix: / diff --git a/app/config/security.yml b/app/config/security.yml index e01c1c2..86c9e6a 100644 --- a/app/config/security.yml +++ b/app/config/security.yml @@ -5,17 +5,18 @@ jms_security_extra: security: encoders: Symfony\Component\Security\Core\User\User: plaintext + KekRozsak\FrontBundle\Entity\User: + id: kek_rozsak_security.encoder.crypt role_hierarchy: ROLE_ADMIN: ROLE_USER ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH] providers: - in_memory: - memory: - users: - user: { password: userpass, roles: [ 'ROLE_USER' ] } - admin: { password: adminpass, roles: [ 'ROLE_ADMIN' ] } + user_db: + entity: + class: KekRozsak\FrontBundle\Entity\User + property: username firewalls: dev: @@ -23,21 +24,23 @@ security: security: false login: - pattern: ^/demo/secured/login$ + pattern: ^/login$ security: false - secured_area: - pattern: ^/demo/secured/ + members: + pattern: ^/ form_login: - check_path: /demo/secured/login_check - login_path: /demo/secured/login + check_path: /login_check + login_path: /login logout: - path: /demo/secured/logout - target: /demo/ - #anonymous: ~ - #http_basic: - # realm: "Secured Demo Area" + path: /logout + target: / + anonymous: ~ access_control: + - { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY } + - { path: ^/$, roles: IS_AUTHENTICATED_ANONYMOUSLY } + - { path: ^/cikk/, roles: IS_AUTHENTICATED_ANONYMOUSLY } + - { path: ^/, roles: [ IS_AUTHENTICATED_FULLY, IS_AUTHENTICATED_REMEMBERED ] } #- { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY, requires_channel: https } #- { path: ^/_internal/secure, roles: IS_AUTHENTICATED_ANONYMOUSLY, ip: 127.0.0.1 } diff --git a/src/KekRozsak/FrontBundle/Controller/DefaultController.php b/src/KekRozsak/FrontBundle/Controller/DefaultController.php index dbfc1db..29f2de0 100644 --- a/src/KekRozsak/FrontBundle/Controller/DefaultController.php +++ b/src/KekRozsak/FrontBundle/Controller/DefaultController.php @@ -26,4 +26,9 @@ class DefaultController extends Controller 'article' => $article )); } + + public function forumMainAction() + { + return $this->forward('KekRozsakFrontBundle:Default:homepage'); + } } diff --git a/src/KekRozsak/FrontBundle/Entity/Role.php b/src/KekRozsak/FrontBundle/Entity/Role.php index 22317ea..12e4a47 100644 --- a/src/KekRozsak/FrontBundle/Entity/Role.php +++ b/src/KekRozsak/FrontBundle/Entity/Role.php @@ -3,11 +3,12 @@ namespace KekRozsak\FrontBundle\Entity; use Doctrine\ORM\Mapping as ORM; +use Symfony\Component\Security\Core\Role\RoleInterface; /** * KekRozsak\FrontBundle\Entity\Role */ -class Role +class Role implements RoleInterface { /** * @var integer $id @@ -136,4 +137,9 @@ class Role { return $this->included_roles; } -} \ No newline at end of file + + public function getRole() + { + return $this->name; + } +} diff --git a/src/KekRozsak/FrontBundle/Entity/User.php b/src/KekRozsak/FrontBundle/Entity/User.php index 5680b4a..f91b995 100644 --- a/src/KekRozsak/FrontBundle/Entity/User.php +++ b/src/KekRozsak/FrontBundle/Entity/User.php @@ -3,11 +3,12 @@ namespace KekRozsak\FrontBundle\Entity; use Doctrine\ORM\Mapping as ORM; +use Symfony\Component\Security\Core\User\UserInterface; /** * KekRozsak\FrontBundle\Entity\User */ -class User +class User implements UserInterface { /** * @var integer $id @@ -188,6 +189,15 @@ class User */ public function getRoles() { - return $this->roles; + return $this->roles->toArray(); } -} \ No newline at end of file + + public function eraseCredentials() + { + } + + public function getSalt() + { + return $this->password; + } +} diff --git a/src/KekRozsak/FrontBundle/Resources/config/routing.yml b/src/KekRozsak/FrontBundle/Resources/config/routing.yml index cc32995..d2d3f15 100644 --- a/src/KekRozsak/FrontBundle/Resources/config/routing.yml +++ b/src/KekRozsak/FrontBundle/Resources/config/routing.yml @@ -7,3 +7,8 @@ KekRozsakFrontBundle_article: pattern: /cikk/{articleSlug} defaults: _controller: KekRozsakFrontBundle:Default:article + +KekRozsakFrontBundle_forum_main: + pattern: /forum + defaults: + _controller: KekRozsakFrontBundle:Default:forumMain diff --git a/src/KekRozsak/SecurityBundle/Controller/DefaultController.php b/src/KekRozsak/SecurityBundle/Controller/DefaultController.php new file mode 100644 index 0000000..684c9d4 --- /dev/null +++ b/src/KekRozsak/SecurityBundle/Controller/DefaultController.php @@ -0,0 +1,30 @@ +getRequest(); + $session = $request->getSession(); + + if ($request->attributes->has(SecurityContext::AUTHENTICATION_ERROR)) + { + $error = $request->attributes->get(SecurityContext::AUTHENTICATION_ERROR); + } + else + { + $error = $session->get(SecurityContext::AUTHENTICATION_ERROR); + $session->remove(SecurityContext::AUTHENTICATION_ERROR); + } + + return $this->render('KekRozsakSecurityBundle:Default:login.html.twig', array( + 'last_username' => $session->get(SecurityContext::LAST_USERNAME), + 'error' => $error, + )); + } +} diff --git a/src/KekRozsak/SecurityBundle/DependencyInjection/Configuration.php b/src/KekRozsak/SecurityBundle/DependencyInjection/Configuration.php new file mode 100644 index 0000000..6daa422 --- /dev/null +++ b/src/KekRozsak/SecurityBundle/DependencyInjection/Configuration.php @@ -0,0 +1,29 @@ +root('kek_rozsak_security'); + + // Here you should define the parameters that are allowed to + // configure your bundle. See the documentation linked above for + // more information on that topic. + + return $treeBuilder; + } +} diff --git a/src/KekRozsak/SecurityBundle/DependencyInjection/KekRozsakSecurityExtension.php b/src/KekRozsak/SecurityBundle/DependencyInjection/KekRozsakSecurityExtension.php new file mode 100644 index 0000000..19f4cf0 --- /dev/null +++ b/src/KekRozsak/SecurityBundle/DependencyInjection/KekRozsakSecurityExtension.php @@ -0,0 +1,28 @@ +processConfiguration($configuration, $configs); + + $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); + $loader->load('services.yml'); + } +} diff --git a/src/KekRozsak/SecurityBundle/KekRozsakSecurityBundle.php b/src/KekRozsak/SecurityBundle/KekRozsakSecurityBundle.php new file mode 100644 index 0000000..26a4099 --- /dev/null +++ b/src/KekRozsak/SecurityBundle/KekRozsakSecurityBundle.php @@ -0,0 +1,9 @@ +{{ error.message }} +{% endif %} + +
+ + + +
+{% endblock content %} diff --git a/src/KekRozsak/SecurityBundle/Service/CryptEncoder.php b/src/KekRozsak/SecurityBundle/Service/CryptEncoder.php new file mode 100644 index 0000000..e2b5f7a --- /dev/null +++ b/src/KekRozsak/SecurityBundle/Service/CryptEncoder.php @@ -0,0 +1,18 @@ +request('GET', '/hello/Fabien'); + + $this->assertTrue($crawler->filter('html:contains("Hello Fabien")')->count() > 0); + } +}