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 Java Discussion :

401 full authentication is required to access this resource [Security]


Sujet :

Spring Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Janvier 2011
    Messages
    193
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Bénin

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Janvier 2011
    Messages : 193
    Par défaut 401 full authentication is required to access this resource
    Salut,
    je n'arrive pas à me connecter à mon application. je reçois un message 401 full authentication is required to access this resource à chaque essaie.

    Voici mes ressources :

    Application Properties :
    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
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    security.oauth2.resource.id: ed
     
    server:
      ssl:
        key-store-type: PKCS12
        key-store: classpath:server.p12
        key-store-password: ed19
        key-alias: edpi
        port: 8443
        key-password: edasta19
     
      security:
        require-ssl=true:
     
     
     
    spring:
     
      datasource:
        platform: mysql
        url: jdbc:mysql://localhost:3306/edas19?serverTimezone=UTC&useLegacyDatetimeCode=false
        username: root
        password:  '#L8#'
        tomcat:
          test-while-idle: true
          validation-query: SELECT 1
        initialization-mode: never
        sql-script-encoding: UTF-8
      jpa:
        show-sql: true
        generate-ddl: true
        open-in-view: false
        hibernate.ddl-auto: update
        properties:
          hibernate:
            dialect: org.hibernate.dialect.MySQL5Dialect
      jackson:
        mapper:
          default_view_inclusion: true
        serialization:
          indent_output: true
          write_dates_as_timestamps: false
        deserialization:
          fail_on_ignored_properties: false
          fail_on_unknown_properties: false
          accept_single_value_as_array: true
        default-property-inclusion: non_empty
        date-format: com.fasterxml.jackson.databind.util.ISO8601DateFormat #joda-date-time-format: yyyy-MM-dd HH:mm:ss
      mail:
        host: smtp.gmail.com
        port: 587
        username: edd@gmail.com
        password: '#l5#'
        properties:
          mail:
            transport.protocol: smtp
            smtp:
              auth: true
              starttls.enable: true
              timeout: 5000
              writetimeout: 5000
              connectiontimeout: 5000
            #debug: true
        #test-connection: true
    keystore:
      jwt:
        key-store: classpath:server.jks
        key-store-password: ed19
        key-pair-alias: edpi
        key-pair-password: ed19
        public-key: classpath:public.txt
      uuidd: ${random.uuid}
      password: edasta19
      value: ${random.value}
      upload-dir: /var/www/uploads
      purge:
        cron.expression: 0 0 5 * * ?
    AuthorizationServerConfig

    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
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
     
     
    @Configuration
    @EnableOAuth2Client
    @EnableAuthorizationServer
    public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter {
     
     
        @Value("${resource.id:edastapi}")
        private String RESSOURCE_ID;
     
        @Value("${keystore.jwt.key-pair-alias}")
        private String KEY_PAIR_ALIAS;
     
        @Value("${keystore.jwt.key-store-password}")
        private String KEY_STORE_PASS;
     
        @Value("${jwt.authorizedGrantTypes:password" +
                ",authorization_code" +
                ",refresh_token}")
        private String[] AUTHORIZED_GRANTYPES;
     
        private final static Integer RESOURCE_VALIDITY = 60*60;
     
        private final PasswordEncoder encoder;
     
        private final PersonneService service;
     
        private final AuthenticationManager manager;
     
     
        public AuthorizationServerConfig(
               PasswordEncoder encoder,
                                         PersonneService service,
                                         AuthenticationManager manager) {
           this.encoder = encoder;
            this.service = service;
            this.manager = manager;
        }
     
     
     
        @Bean
        public TokenStore tokenStore() {
     
            return new JwtTokenStore(
                    tokenEnhancer()
            );
     
        }
     
     
        @Bean
        public JwtAccessTokenConverter tokenEnhancer() {
     
            JwtAccessTokenConverter tokenConverter = new JwtAccessTokenConverter();
     
            KeyStoreKeyFactory factory = new KeyStoreKeyFactory(
     
                    new ClassPathResource("server.jks"), KEY_STORE_PASS.toCharArray()
            );
     
            tokenConverter.setKeyPair(factory.getKeyPair(KEY_PAIR_ALIAS));
     
            DefaultAccessTokenConverter converter = new DefaultAccessTokenConverter();
     
            DefaultUserAuthenticationConverter authConverter = new DefaultUserAuthenticationConverter();
     
            authConverter.setUserDetailsService(service);
     
            converter.setUserTokenConverter(authConverter);
     
            tokenConverter.setAccessTokenConverter(converter);
     
            return tokenConverter;
     
        }
     
        @Override
        public void configure(AuthorizationServerSecurityConfigurer security) throws Exception {
            security.tokenKeyAccess("permitAll()")
                    .checkTokenAccess("isAuthenticated()");//security.allowFormAuthenticationForClients();
        }
     
        @Override
        public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
            clients.inMemory()
                    .withClient("ed").resourceIds(RESSOURCE_ID)
                    .authorizedGrantTypes(AUTHORIZED_GRANTYPES)
                    .scopes("openid", "profile", "email", "read", "write")
                     .secret(encoder.encode("1234")).autoApprove(true)
    //                 .secret("secret").autoApprove(true)
     
                    .accessTokenValiditySeconds(RESOURCE_VALIDITY).refreshTokenValiditySeconds(2*RESOURCE_VALIDITY);
     
        }
     
        @Override
        public void configure(AuthorizationServerEndpointsConfigurer endpoints) {
     
            endpoints
                    .accessTokenConverter(tokenEnhancer())
                    .authenticationManager(manager).userDetailsService(service)
                    .tokenStore(tokenStore()).tokenServices(tokenServices());
     
        }
     
        @Bean @Primary
        public DefaultTokenServices tokenServices() {
     
            DefaultTokenServices services = new DefaultTokenServices();
            services.setTokenEnhancer(tokenEnhancer());
            services.setAuthenticationManager(manager);
            services.setSupportRefreshToken(true);
            services.setTokenStore(tokenStore());
            return services;
     
        }
     
    }
    SERVEUR DE RESSOURCES :

    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
     
    @Configuration
    @EnableResourceServer
    public class ResourceServerConfig extends ResourceServerConfigurerAdapter {
     
            @Autowired
            private ResourceServerTokenServices tokenServices;
     
            @Value("${security.oauth2.resource.id}")
            private String RESSOURCE_ID;
     
     
     
     
            @Override
            public void configure(ResourceServerSecurityConfigurer resources) {
                resources.resourceId(RESSOURCE_ID).tokenServices(tokenServices);;
            }
     
            @Override
            public void configure(HttpSecurity http) throws Exception {
                http
                       /* .cors().and().csrf().disable().httpBasic().disable().headers().frameOptions().disable().and().sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()
                        .authorizeRequests()
                        .antMatchers("/me").permitAll()
                        .anyRequest().authenticated().and()
                        .exceptionHandling().accessDeniedHandler(new OAuth2AccessDeniedHandler());
    */
                        .cors().and().csrf().disable().httpBasic().disable().headers().frameOptions().disable().and().sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()
                        .authorizeRequests().anyRequest().authenticated().and() //.antMatchers("/oauth/register", "/oauth/enable", "/operations/bondast", "/about").permitAll().antMatchers("/ross/**").access("hasRole('ADMIN') and hasRole('USER')").antMatchers("/admin/**").hasRole("ADMIN")
                        .exceptionHandling().accessDeniedHandler(new OAuth2AccessDeniedHandler());
     
            }
     
     
        }
    WebSecurity
    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
     
     
    @EnableWebSecurity
    @EnableGlobalMethodSecurity(prePostEnabled = true)
    public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
     
        @Autowired
        private PersonneService service;
     
     
       @Bean
        public static PasswordEncoder encoder() {
            return PasswordEncoderFactories.createDelegatingPasswordEncoder();
        }
     
     
     
        @Bean @Override
        protected AuthenticationManager authenticationManager() throws Exception {
            return super.authenticationManager();
        }
     
        @Override
        protected void configure(AuthenticationManagerBuilder auth) throws Exception {
           auth.userDetailsService(service).passwordEncoder(encoder());
        }
     
        @Override
        protected void configure(HttpSecurity http) throws Exception {
            super.configure(http);
            http.requiresChannel().anyRequest().requiresSecure();
        }
     
     
    }
    Je vous prie de m'aider SVP

  2. #2
    Rédacteur/Modérateur
    Avatar de andry.aime
    Homme Profil pro
    Inscrit en
    Septembre 2007
    Messages
    8 391
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Ile Maurice

    Informations forums :
    Inscription : Septembre 2007
    Messages : 8 391
    Par défaut
    Bonjour,

    Tu dois déclarer ta page de login et le laisser accessible au public pour se loguer dans la méthode configure de ton WebSecurityConfigurerAdapter

    A+.

  3. #3
    Membre confirmé
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Janvier 2011
    Messages
    193
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Bénin

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Janvier 2011
    Messages : 193
    Par défaut
    Merci pour l'apport.
    je note que j'ai accès à la page de connexion mais c'est en me connectant avec mon identifiant et mon mot de passe que j'ai le message 401.
    Je l'ai essayé avec mon projet angular et postman.
    Dans mes recherches, j'ai lu que la JWT n'arrive pas à décoder mon PassWordEncoder et que je ne dois pas l'utiliser avec la JWT.
    Merci

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

Discussions similaires

  1. [2.x] "Full Authentication Required" selon l'adresse IP dans l'url
    Par jejeman dans le forum Symfony
    Réponses: 2
    Dernier message: 13/02/2015, 21h13
  2. You do not have permission to access this document.
    Par loupanbagna dans le forum Apache
    Réponses: 3
    Dernier message: 13/12/2011, 14h17
  3. Réponses: 0
    Dernier message: 09/10/2010, 17h32
  4. Réponses: 0
    Dernier message: 09/10/2010, 17h20
  5. SMTP Authentication is not supported by this server!
    Par mikitoss dans le forum Programmation et administration système
    Réponses: 0
    Dernier message: 23/06/2009, 12h02

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