-



Download 8,6 Mb.
Pdf ko'rish
bet6/37
Sana18.01.2022
Hajmi8,6 Mb.
#383795
1   2   3   4   5   6   7   8   9   ...   37
Bog'liq
Designing Applications with Spring Boot 2.2 and React JS Step-by-step guide to design and develop intuitive full stack web applications by Dinesh Rajput (z-lib.org)

TYPE
PASSWORD = “password”;
   static final String AUTHORIZATION
CODE = “authorization
code”;
   static final String REFRESH
TOKEN = “refresh
token”;
   static final String IMPLICIT = “implicit”;
   static final String SCOPE_READ = “read”;
   static final String SCOPE_WRITE = “write”;
   static final String TRUST = “trust”;
   static final int ACCESS
TOKEN
VALIDITY_SECONDS = 1
60
60;
   static final int FREFRESH
TOKEN
VALIDITY_SECONDS = 6
60
60;
   private String privateKey = “111dinesh000”;


   @Autowired
   private AuthenticationManager authenticationManager;
   @Autowired
   BCryptPasswordEncoder encoder;
   @Bean
   public JwtAccessTokenConverter tokenEnhancer() {
   JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
   converter.setSigningKey(privateKey);
   return converter;
   }
   @Bean
   public JwtTokenStore tokenStore() {
   return new JwtTokenStore(tokenEnhancer());
   }
   @Override
   public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
   endpoints.authenticationManager(authenticationManager).tokenStore(tokenStore())
   .accessTokenConverter(tokenEnhancer());
   }
   @Override
   public void configure(AuthorizationServerSecurityConfigurer security) throws Exception {
   security.tokenKeyAccess(“permitAll()”).checkTokenAccess(“isAuthenticated()”).
passwordEncoder(encoder);
   }
   @Override
   public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
   clients.inMemory()
   .withClient(CLIEN_ID)
   .secret(CLIENT_SECRET)
   .authorizedGrantTypes(GRANT
TYPE
PASSWORD, AUTHORIZATION
CODE, REFRESH
TOKEN, IMPLICIT )
   .scopes(SCOPE
READ, SCOPE
WRITE, TRUST)
   .accessTokenValiditySeconds(ACCESS
TOKEN
VALIDITY_SECONDS)
   .refreshTokenValiditySeconds(FREFRESH
TOKEN
VALIDITY_SECONDS);
   }
}


In the preceding authorization server configuration, we are using the JwtAccessTokenConverter and JwtTokenStore beans. These classes are
helper classes used to provide JWT tokens based on the OAuth authentication information. We also added a private key to make the JWT token
more robust. In this example, we are using the JwtTokenStore beans but Spring Security also provides you InMemoryTokenStore and
JdbcTokenStore.
We override the configure(ClientDetailsServiceConfigurer clients) method. This method takes a ClientDetailsServiceConfigurer object as an
argument. The ClientDetailsServiceConfigurer class is a configurer class that defines the client details service. In our example, we used the
inMemory() method client details service implementation. Spring Security also provides the jdbc() method for the client details service
implementation instead of the inMemory() client details implementation.
The AuthorizationServerSecurityConfigurer class is another configurer class that defines the security constraints on the token endpoint.
The authorization server configuration class also configured the AuthorizationServerEndpointsConfigurer class and that defines the authorization
and token endpoints and the token services.
Here, we are not going to discuss each file of the authorization server application. All the other files are very similar to the ones we used in the
previous examples. You can find the whole source code of the authorization server application from GitHub ( https://github.com/dineshonjava/bpb-
spring-boot-reactjs ).
Let’s create the resource server configuration files.
Implementing the resource server with Spring Boot Security
We will implement a Prodos Resource Server application to provide the protected resource EndPoints using the access token. Let’s see the
following project structure for the Resource Server application:
Figure 5.15: The resource server project structure
Let’s discuss the resource server configuration files.
Resource server configuration
The following class will provide the configuration to the resource server application:
package com.dineshonjava.prodos.security.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;


import org.springframework.security.oauth2.config.annotation.web.configuration.
EnableResourceServer;
import org.springframework.security.oauth2.config.annotation.web.configuration.
ResourceServerConfigurerAdapter;
import org.springframework.security.oauth2.config.annotation.web.configurers.
ResourceServerSecurityConfigurer;
import org.springframework.security.oauth2.provider.error.OAuth2AccessDeniedHandler;
@Configuration
@EnableResourceServer
public class ResourceServerConfig extends ResourceServerConfigurerAdapter{
   private static final String RESOURCE

Download 8,6 Mb.

Do'stlaringiz bilan baham:
1   2   3   4   5   6   7   8   9   ...   37




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish