IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Spring Web Java Discussion :

Problème avec @Preauthorize


Sujet :

Spring Web Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2009
    Messages
    26
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2009
    Messages : 26
    Par défaut Problème avec @Preauthorize
    Bonjour,

    je suis débutant avec Spring security et jusque là tout va bien ça marche nikel.

    Mon problème est le suivant je voudrais sécuriser mes méthodes dans mes servlets(j'utilise spring MVC) en fonction des accès utilisateurs, mais cela ne marche pas.
    Par contre les dans les jsp avec <sec:authorize access="hasRole('ACCESS_SCAT_19')"> ça marche nikel mais comme la plupart de mes pages ont des traitements lourds, je trouve dommage de charger tous mes infos pour ensuite ne pas les "utiliser".

    Voici ma config spring security :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    <?xml version="1.0" encoding="UTF-8"?>
     
    <beans:beans xmlns="http://www.springframework.org/schema/security"
    	xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                            http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd
                            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
                             http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
     
    	<global-method-security pre-post-annotations="enabled">
    	</global-method-security>
     
     
    	<http auto-config="true" use-expressions="true">
     
    		<!-- <intercept-url pattern="/secure/extreme/**" access="hasRole('ROLE_SUPERVISOR')"/> -->
    		<intercept-url pattern="/secure/**" access="hasRole('ROLE_ADMIN')" />
    		<intercept-url pattern="/**" access="isAuthenticated()" />
    		<intercept-url pattern="/login.do" filters="none" />
    		<intercept-url pattern="/logout.do" filters="none" />
    		<intercept-url pattern="/about.do" filters="none" />
    		<intercept-url pattern="/timeout.do" filters="none" />
    		<intercept-url pattern="/chart/**" filters="none" />
    		<intercept-url pattern="/css/**" filters="none" />
    		<intercept-url pattern="/img/**" filters="none" />
    		<intercept-url pattern="/js/**" filters="none" />
    		<access-denied-handler error-page="/login.do?access_denied=true" />
    		<form-login login-page="/login.do" default-target-url="/index.do"
    			always-use-default-target="true" authentication-failure-url="/login.do?login_error=true" />
     
    		<logout invalidate-session="true" logout-success-url="/login.do" />
    		<!-- Uncomment to enable X509 client authentication support <x509 /> -->
    		<!-- Uncomment to limit the number of sessions a user can have -->
    		<custom-filter position="CONCURRENT_SESSION_FILTER" ref="concurrencyFilter" />
    		<session-management
    			session-authentication-strategy-ref="max" />
    	</http>
     
     
    	<authentication-manager>
    		<authentication-provider ref="authenticationDao"
    			user-service-ref="authenticationDao" />
     
    	</authentication-manager>
     
    	<beans:bean id="authenticationDao"
    		class="server.DAO.hibernate.AuthentificationDaoImpl" />
     
    	<beans:bean id="concurrencyFilter"
    		class="org.springframework.security.web.session.ConcurrentSessionFilter">
    		<beans:property name="sessionRegistry" ref="sessionRegistry" />
    		<beans:property name="expiredUrl" value="/login.do?session_expired=true" />
    	</beans:bean>
     
    	<beans:bean id="max"
    		class="org.springframework.security.web.authentication.session.ConcurrentSessionControlStrategy">
    		<beans:constructor-arg name="sessionRegistry"
    			ref="sessionRegistry" />
    		<beans:property name="maximumSessions" value="2" />
    	</beans:bean>
     
    	<beans:bean id="sessionRegistry"
    		class="org.springframework.security.core.session.SessionRegistryImpl" />
     
    	</beans:beans>
    Un extrait de mon controleur(ACCESS_SCAT_19 correspond au droit utilisateur permettant d'afficher la page) :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    @RequestMapping(value = "/oraclehistorique.do", method = RequestMethod.GET)
    	@PreAuthorize("hasRole('ACCESS_SCAT_19')")
    	public ModelAndView oracleHistorique() {
    		ModelAndView mvn = new ModelAndView("oraclehistorique");
    		return mvn;
    	}
    Voila en espérant que vous pourrez m'aider et merci d'avance.

    Cordialement,
    Cleytus

  2. #2
    Membre Expert
    Homme Profil pro
    Inscrit en
    Septembre 2006
    Messages
    2 963
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations forums :
    Inscription : Septembre 2006
    Messages : 2 963
    Par défaut
    Votre controller est-il bien un bean managé par Spring ?

  3. #3
    Membre averti
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2009
    Messages
    26
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2009
    Messages : 26
    Par défaut
    Je suppose j'avoue que cette notion de bean est encore un peu floue à mes yeux.

    Mon controller est déclaré avec l'annotations @Controller et si ça peut aider le MVC_servlet.xml :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
    	xmlns:mvc="http://www.springframework.org/schema/mvc"
    	xsi:schemaLocation="
                http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
                http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
                http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
     
    	<context:annotation-config />
    	<context:component-scan base-package="web" />
     
    	<bean id="validator"
    		class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" />
    	<mvc:annotation-driven />
     
    	<bean id="viewResolver"
    		class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    		<property name="viewClass"
    			value="org.springframework.web.servlet.view.JstlView" />
    		<property name="prefix" value="/WEB-INF/jsp/" />
    		<property name="suffix" value=".jsp" />
    	</bean>
     
    </beans>

  4. #4
    Membre Expert
    Homme Profil pro
    Inscrit en
    Septembre 2006
    Messages
    2 963
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations forums :
    Inscription : Septembre 2006
    Messages : 2 963
    Par défaut
    je n'aperçois qu'un différence par rapport à un projet ici : avec use-expressions="true" on utilise hasAuthority au lieu de hasRole
    essayez toujours même si je ne vois pas a priori en quoi cela pourrait être un problème…

    sinon mettez un point d'arrêt dans votre code et regardez le stack trace pour vérifier la présence des méthodes d'interception, cela donnera au moins une piste de recherche.

  5. #5
    Membre averti
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2009
    Messages
    26
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2009
    Messages : 26
    Par défaut
    hasAuthority ne change malheureusement rien.

    Pour le point d'arret j'utilise le plugin jetty de maven et je n'ai aucune idée de comment faire.

  6. #6
    Membre averti
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2009
    Messages
    26
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2009
    Messages : 26
    Par défaut
    C'est bon j'ai résolu le problème. En fait il faut mettre le <global-method-security pre-post-annotations="enabled">
    </global-method-security>
    dans le MVC-servlet.xml de spring et non dans la config de spring security.C'est une question de visibilité(si j'ai bien compris sprint a deja initialisé les controllers quand le fichier de sécurité est exécuté)

    En tout cas merci quand même JeitEmgie

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. VC++ Direct3D8, problème avec LPD3DXFONT et LPD3DTEXTURE8
    Par Magus (Dave) dans le forum DirectX
    Réponses: 3
    Dernier message: 03/08/2002, 11h10
  2. Problème avec [b]struct[/b]
    Par Bouziane Abderraouf dans le forum CORBA
    Réponses: 2
    Dernier message: 17/07/2002, 10h25
  3. Problème avec le type 'Corba::Any_out'
    Par Steven dans le forum CORBA
    Réponses: 2
    Dernier message: 14/07/2002, 18h48
  4. Problème avec la mémoire virtuelle
    Par Anonymous dans le forum CORBA
    Réponses: 13
    Dernier message: 16/04/2002, 16h10

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo