<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Marcus Hert da Corégio on Medium]]></title>
        <description><![CDATA[Stories by Marcus Hert da Corégio on Medium]]></description>
        <link>https://medium.com/@marcusdacoregio?source=rss-5cfb26e8714b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Kej79GPfr6g94sCscHXU7g.jpeg</url>
            <title>Stories by Marcus Hert da Corégio on Medium</title>
            <link>https://medium.com/@marcusdacoregio?source=rss-5cfb26e8714b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 03:54:46 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@marcusdacoregio/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Microservices with Spring Boot and Spring Cloud.]]></title>
            <link>https://itnext.io/microservices-with-spring-boot-and-spring-cloud-441e3dabc67d?source=rss-5cfb26e8714b------2</link>
            <guid isPermaLink="false">https://medium.com/p/441e3dabc67d</guid>
            <category><![CDATA[spring-cloud]]></category>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[oauth2]]></category>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Marcus Hert da Corégio]]></dc:creator>
            <pubDate>Tue, 07 May 2019 01:52:58 GMT</pubDate>
            <atom:updated>2020-04-14T22:23:10.414Z</atom:updated>
            <content:encoded><![CDATA[<h3>Microservices with Spring Boot and Spring Cloud. From config server to OAuth2 server (without inMemory things) — Part 3</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/791/1*fCKQ5BcIvBf0fLQxl7BjNg.png" /></figure><p>Okay, here we are. We have built an auth service who is responsible to authenticate and authorize our users and clients in a microservices architecture.</p><p>Now we will build the account service, this guy is responsible to create the users and will hold the business logic for this because we won’t put the business logic on the service responsible for the authentication/authorization. We may want to send account activation email or SMS, do other processing, so we will separate this logic.<br>In this third part, we will learn how to create and config a resource server with Spring Boot and Spring Cloud.</p><h4>Creating the account-service project</h4><p>As usual, we will use <a href="https://start.spring.io/">Spring Initializr</a> to generate the project for us, create it like the image below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/985/1*tI7KvAH7XIhayjvhwzbTIA.png" /><figcaption>Generating the account-service project</figcaption></figure><h4>Adding the application’s configuration files</h4><p>Rename the application.properties file to bootstrap.yml and add the following configuration:</p><pre>spring:<br>  application:<br>    name: account-service<br>  cloud:<br>    config:<br>      uri: http://localhost:8888<br>      fail-fast: true<br>      password: 1234<br>      username: user<br>  main:<br>    allow-bean-definition-overriding: true #i dont remember why but i think there is a bug with spring cloud and OAuth2ClientContext</pre><p>In the config service application, create the account-service.yml file to hold the configuration for auth service.</p><pre>security:<br>  oauth2:<br>    client:<br>      clientId: account-service<br>      clientSecret: 1234<br>      accessTokenUri: http://localhost:8081/uaa/oauth/token<br>      grant-type: client_credentials<br>      scope: server<br><br>server:<br>  servlet:<br>    context-path: /accounts<br>  port: 8082<br><br>feign:<br>  hystrix:<br>    enabled: true</pre><p>If you don’t know why these files are being created, I recommend you to read this <a href="https://itnext.io/microservices-with-spring-boot-and-spring-cloud-16d2c056ba12">article’s first part.</a></p><p>Open the file /resources/shared/application.yml in the config service project and add the following information:</p><pre><em>#This configuration file will hold common configs to be shared among all files<br></em>eureka:<br>  instance:<br>    prefer-ip-address: false<br>  client:<br>    serviceUrl:<br>      defaultZone: http://localhost:8761/eureka/<br><br>security:<br>  oauth2:<br>    resource:<br>      user-info-uri: http://localhost:8080/uaa/user/current<br>      token-info-uri: <a href="http://auth-service/uaa/oauth/check_token">http://</a>localhost:8080<a href="http://auth-service/uaa/oauth/check_token">/uaa/oauth/check_token</a> <strong>#add this information</strong></pre><p>This URL will provide us our UserDetails implementation from auth service in our resource servers.</p><h4>Adding annotations</h4><p>Our main class from account-service will be like this:</p><pre>@SpringBootApplication<br>@EnableDiscoveryClient<br>@EnableOAuth2Sso<br>@EnableFeignClients<br>@EnableGlobalMethodSecurity(prePostEnabled = true)<br>public class AccountServiceApplication {<br>    public static void main(String[] args) {<br>        SpringApplication.<em>run</em>(AccountServiceApplication.class, args);<br>    }<br>}</pre><p>The @EnableOAuth2Sso will enable configuration for an OAuth2 client in a web application that uses Spring Security and wants to use the Authorization Code Grant from our auth-service and create a WebSecurityConfigurerAdapter with all paths secured. And the @EnableFeignClients scans for interfaces that declare they as feign clients.</p><h4>Configuring the resource server</h4><p>Create a class named ResourceServerConfig with the following content:</p><pre>@Configuration<br>@EnableResourceServer<br>public class ResourceServerConfig extends ResourceServerConfigurerAdapter {<br><br>    private final ResourceServerProperties sso;<br><br>    private final OAuth2ClientContext oAuth2ClientContext;<br><br>    @Autowired<br>    public ResourceServerConfig(ResourceServerProperties sso, OAuth2ClientContext oAuth2ClientContext) {<br>        this.sso = sso;<br>        this.oAuth2ClientContext = oAuth2ClientContext;<br>    }<br><br>    @Bean<br>    @ConfigurationProperties(prefix = &quot;security.oauth2.client&quot;)<br>    public ClientCredentialsResourceDetails clientCredentialsResourceDetails() {<br>        return new ClientCredentialsResourceDetails();<br>    }<br><br>    @Bean<br>    public RequestInterceptor oauth2FeignRequestInterceptor() {<br>        return new OAuth2FeignRequestInterceptor(oAuth2ClientContext, clientCredentialsResourceDetails());<br>    }<br><br>    @Bean<br>    public OAuth2RestOperations restTemplate(OAuth2ClientContext oauth2ClientContext) {<br>        return new OAuth2RestTemplate(clientCredentialsResourceDetails(), oauth2ClientContext);<br>    }<br><br>    @Bean<br>    @Primary<br>    public ResourceServerTokenServices resourceServerTokenServices() {<br>        return new UserInfoTokenServices(sso.getUserInfoUri(), sso.getClientId());<br>    }<br><br>    @Override<br>    public void configure(HttpSecurity http) throws Exception {<br>        http.authorizeRequests()<br>                .antMatchers(HttpMethod.<em>POST</em>, &quot;/&quot;).permitAll()<br>                .antMatchers(HttpMethod.<em>OPTIONS</em>, &quot;/&quot;).permitAll()<br>                .anyRequest().authenticated();<br>    }<br>}</pre><p>In this class, we are configuring our resource server to permit any POST request to /accounts/ path, because who wants to create a new account is not logged in. And any other request needs to be authenticated.<br>Also, we are configuring the Feign to use an <a href="https://docs.spring.io/spring-security/oauth/apidocs/org/springframework/security/oauth2/client/OAuth2RestTemplate.html">OAuh2RestTemplate</a> to make authenticated requests.</p><h4>Inserting account service client details in auth service</h4><p>As we are creating another microservice, we need to register it as a client for our auth service.<br>Open the InitialValuesChangeLog class on the auth service project and add another ChangeSet .</p><pre>@ChangeSet(order = &quot;003&quot;, id = &quot;insertAccountServiceClientDetails&quot;, author = &quot;Marcus Hert Da Corégio&quot;)<br>public void insertAccountServiceClientDetails(MongoTemplate mongoTemplate) {<br>    AuthClientDetails accountServiceClientDetails = new AuthClientDetails();<br>    accountServiceClientDetails.setClientId(&quot;account-service&quot;);<br>    accountServiceClientDetails.setClientSecret(&quot;$2a$10$fWNTd3H.u7G/aNROVQSifebOkZ2xzU5nUPOCI2Ld42M8E25/ljJqK&quot;);<br>    accountServiceClientDetails.setScopes(&quot;server&quot;);<br>    accountServiceClientDetails.setGrantTypes(&quot;refresh_token,client_credentials&quot;);<br><br>    mongoTemplate.save(accountServiceClientDetails);<br>}</pre><p>It’s almost the same as the <strong>browser </strong>client but has a different <a href="https://oauth.net/2/scope/">scope</a> and <a href="https://oauth.net/2/grant-types/">grant types</a>.</p><h4>Creating the users endpoint in auth service</h4><p>Here, I will list to you the changes that need to be made on auth service. I will not put the code here because it will become too messy, instead, I’ll attach the links for the class in the repository.</p><ul><li><a href="https://github.com/marcusdacoregio/oauth2-spring-boot/blob/master/auth-service/src/main/java/com/marcusdacoregio/authservice/AuthServiceApplication.java">Add the </a><a href="https://github.com/marcusdacoregio/oauth2-spring-boot/blob/master/auth-service/src/main/java/com/marcusdacoregio/authservice/AuthServiceApplication.java">@EnableResourceServer annotation on auth service main class</a>.</li><li>Create the <a href="https://github.com/marcusdacoregio/oauth2-spring-boot/blob/master/auth-service/src/main/java/com/marcusdacoregio/authservice/service/UserService.java">UserService interface</a> and its <a href="https://github.com/marcusdacoregio/oauth2-spring-boot/blob/master/auth-service/src/main/java/com/marcusdacoregio/authservice/service/UserServiceImpl.java">implementation</a>.</li><li>Create the <a href="https://en.wikipedia.org/wiki/Data_transfer_object">DTO</a> for <a href="https://github.com/marcusdacoregio/oauth2-spring-boot/blob/master/auth-service/src/main/java/com/marcusdacoregio/authservice/dto/UserRegistrationDto.java">user registration</a> and <a href="https://github.com/marcusdacoregio/oauth2-spring-boot/blob/master/auth-service/src/main/java/com/marcusdacoregio/authservice/dto/UserDto.java">returned user</a>.</li><li>Create the <a href="https://github.com/marcusdacoregio/oauth2-spring-boot/blob/master/auth-service/src/main/java/com/marcusdacoregio/authservice/controller/UserController.java">UserController</a> for handling HTTP requests.</li></ul><p>With this is hand, we can move to account service. If you have any questions about this, feel free to ask me in the comments section.</p><h4>Creating the Feign client</h4><p>The question now is how do we make a request to auth service from account service? For this we have <a href="https://spring.io/projects/spring-cloud-openfeign">Feign</a> which is a Java to HTTP client binder, it makes easy to create interfaces for communication between our services.</p><p>Let’s start creating the AuthServiceFeignClient interface.</p><pre>import com.marcusdacoregio.accountservice.dto.UserDto;<br>import com.marcusdacoregio.accountservice.dto.UserRegistrationDto;<br>import org.springframework.cloud.openfeign.FeignClient;<br>import org.springframework.web.bind.annotation.PostMapping;<br>import org.springframework.web.bind.annotation.RequestBody;<br><br>@FeignClient(name = &quot;auth-service&quot;)<br>public interface AuthServiceFeignClient {<br><br>    @PostMapping(value = &quot;/uaa/user&quot;)<br>    UserDto createUser(@RequestBody UserRegistrationDto user);<br><br>}</pre><p>The @FeignClient is an annotation for interfaces declaring that a REST client with that interface should be created. The name that we passed as value is the name of the microservice registered on our registry service, this way we don’t need to use the IP address which we won’t know in a microservices environment.</p><p>I’ve copied the DTOs from auth service, but you can create a submodule auth service, place the DTOs inside it, and add as a dependency on account service.</p><p>Now let’s create the AccountService interface and its implementation.</p><pre>public interface AccountService {<br><br>    <em>/**<br>     * Invokes Auth Service user creation<br>     *<br>     * </em><strong><em>@param </em></strong><em>user<br>     * </em><strong><em>@return </em></strong><em>created account<br>     */<br>    </em>UserDto create(UserRegistrationDto user);<br>}</pre><pre>@Service<br>public class AccountServiceImpl implements AccountService {<br><br>    private final AuthServiceFeignClient authServiceFeignClient;<br><br>    public AccountServiceImpl(AuthServiceFeignClient authServiceFeignClient) {<br>        this.authServiceFeignClient = authServiceFeignClient;<br>    }<br><br>    @Override<br>    public UserDto create(UserRegistrationDto user) {<br>        return authServiceFeignClient.createUser(user);<br>    }<br>}</pre><p>And our controller to handle the requests:</p><pre>@RestController<br>public class AccountController {<br><br>    private final AccountService accountService;<br><br>    public AccountController(AccountService accountService) {<br>        this.accountService = accountService;<br>    }<br><br>    @PostMapping<br>    public UserDto createNewAccount(@RequestBody UserRegistrationDto user) {<br>        return accountService.create(user);<br>    }<br><br>}</pre><h4>Testing what we did</h4><p>Okay, open <a href="https://www.getpostman.com/">Postman</a> and let’s make a request to test if things are working.</p><p>Create a POST request to http://localhost:8080/accounts/ with username and password body:</p><h3>pay attention in this request because it has an additional slash in the end of the URI <a href="http://localhost:8080/accounts/"><em>http://localhost:8080/accounts</em><strong><em>/</em></strong></a></h3><p>If you try to do a POST request in the context-path without the slash, like <strong>/uaa</strong> or <strong>/accounts</strong> it will fail and the error message will not be very clear (I still didn’t figure out why). Thanks to <a href="https://gist.github.com/CallMeHeisenberg">George</a> who warned me about this!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/791/1*SUZ1nV27i4gfsjhFW5qTiQ.png" /></figure><p>Everything is working fine. If you try to create a new user with the same username you will receive an ugly response message, like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/794/1*4dn1wFnl12ilE5zfKexEqg.png" /></figure><p>This is because our exception being throw on auth service is not mapped to a <a href="https://www.baeldung.com/spring-response-entity">ResponseEntity</a> or so, and Feign doesn’t know what to do with an exception thrown by another service. We can achieve this using the <a href="https://spring.io/blog/2013/11/01/exception-handling-in-spring-mvc">@ExceptionHandler</a> annotation. I’ll let this as homework for you :D.</p><p>You can request a token with this user created to see if this is working and get an access token. If you don’t know how to do this, check the <a href="https://itnext.io/microservices-with-spring-boot-and-spring-cloud-20f689b17fc7">second part</a> of this article.</p><p>You can also make a GET request to http://localhost:8080/uaa/user/current with the Authorization header like this: <em>Bearer your_access_token.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/869/1*fXXumafyq5PZoQ0ZFCVX5A.png" /></figure><h4>Conclusion</h4><p>Feel free to share any questions with me, I think I didn’t forget anything. The code is available on <a href="https://github.com/marcusdacoregio/oauth2-spring-boot">GitHub</a>. Check also the <a href="https://itnext.io/microservices-with-spring-boot-and-spring-cloud-16d2c056ba12">first</a> and <a href="https://itnext.io/microservices-with-spring-boot-and-spring-cloud-20f689b17fc7">second part</a> of this article.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=441e3dabc67d" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/microservices-with-spring-boot-and-spring-cloud-441e3dabc67d">Microservices with Spring Boot and Spring Cloud.</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Microservices with Spring Boot and Spring Cloud.]]></title>
            <link>https://itnext.io/microservices-with-spring-boot-and-spring-cloud-20f689b17fc7?source=rss-5cfb26e8714b------2</link>
            <guid isPermaLink="false">https://medium.com/p/20f689b17fc7</guid>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[oauth2]]></category>
            <category><![CDATA[spring-cloud]]></category>
            <dc:creator><![CDATA[Marcus Hert da Corégio]]></dc:creator>
            <pubDate>Thu, 18 Apr 2019 00:01:05 GMT</pubDate>
            <atom:updated>2019-05-07T01:54:32.234Z</atom:updated>
            <content:encoded><![CDATA[<h3>Microservices with Spring Boot and Spring Cloud. From config server to OAuth2 server (without inMemory things) — Part 2</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/791/1*kCLh49Ywl5TVKNKNbJcb2Q.png" /></figure><p>Hello everyone, in this second part we will build the auth service. This is the guy we are looking for in this guide.<br>The first part is available <a href="https://itnext.io/microservices-with-spring-boot-and-spring-cloud-16d2c056ba12">here</a>.</p><p>We will not use those <strong><em>inMemory </em></strong>configurations, the auth service will be built on top of a MongoDB and will be able to create users, authenticate them, store their tokens/refresh tokens and revoke it if needed.</p><p>Remember that the code is available on <a href="https://github.com/marcusdacoregio/oauth2-spring-boot">GitHub</a>.</p><h3>Creating the Auth Service</h3><p>Let’s start creating the auth-service, we will use <a href="https://start.spring.io/">Spring Initializr</a> to create the maven project. Generate it like the image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/971/1*H02YtUzsCugGLh4ifpSpTQ.png" /></figure><h4>Adding annotations</h4><p>Import the generated project in your favorite IDE. <br>Open AuthServiceApplication class to add some annotations. Start with the @EnableResourceServer annotation, it will enable a Spring Security filter that authenticates requests via an incoming OAuth2 token.</p><p>The next one is @EnableDiscoveryClient which we already know, it will enable the discovery client implementation to let our auth service register in Registry Service.</p><p>The last one is @EnableGlobalMethodSecurity which enables Spring Security global method security. Set the prePostEnabled field from the annotation to true to enable Spring Security’s pre post annotations, we will use them later.</p><pre>@SpringBootApplication<br>@EnableResourceServer<br>@EnableDiscoveryClient<br>@EnableGlobalMethodSecurity(prePostEnabled = true)<br>public class AuthServiceApplication {<br>    public static void main(String[] args) {<br>        SpringApplication.<em>run</em>(AuthServiceApplication.class, args);<br>    }<br>}</pre><h4>Adding the application’s configuration files</h4><p>Rename the application.properties file to bootstrap.yml and add the following configuration:</p><pre><strong>spring</strong>:<br>  <strong>application</strong>:<br>    <strong>name</strong>: auth-service<br>  <strong>cloud</strong>:<br>    <strong>config</strong>:<br>      <strong>uri</strong>: http://localhost:8888<br>      <strong>fail-fast</strong>: true<strong><br>      password</strong>: 1234<br>      <strong>username</strong>: user</pre><p>In the config service application, create the auth-service.yml file to hold the configuration for auth service.</p><pre><strong>spring</strong>:<br>  <strong>data</strong>:<br>    <strong>mongodb</strong>:<br>      <strong>host</strong>: localhost<br>      <strong>port</strong>: 27017<br>      <strong>username</strong>: oauth-user<br>      <strong>password</strong>: password<br>      <strong>database</strong>: oauth-db</pre><pre><strong>server</strong>:<br>  <strong>servlet</strong>:<br>    <strong>context-path</strong>: /uaa<br>  <strong>port</strong>: 8081</pre><p>If you don’t know why these files are being created, I recommend you to read this <a href="https://itnext.io/microservices-with-spring-boot-and-spring-cloud-16d2c056ba12">article’s first part.</a></p><h4>Creating the domain entities and its DAO</h4><p>Let’s start creating the <strong>authorities enum.</strong></p><pre>import org.springframework.security.core.GrantedAuthority;<br><br>public enum Authorities implements GrantedAuthority {<br>    <em>ROLE_USER</em>;<br><br>    @Override<br>    public String getAuthority() {<br>        return name();<br>    }<br>}</pre><p>This enum is responsible to define the authorities of our auth service and it implements the GrantedAuthority interface which represents an authority granted to an <a href="https://docs.spring.io/spring-security/site/docs/4.2.11.RELEASE/apidocs/org/springframework/security/core/Authentication.html">Authentication</a> object.</p><p>Now create the <strong>User </strong>entity to represent our user.</p><pre>@Document<br>public class User implements UserDetails {<br>    @Id<br>    private String id;<br><br>    @Indexed(unique = true)<br>    private String username;<br><br>    private String password;<br><br>    private boolean activated;<br><br>    private String activationKey;<br><br>    private String resetPasswordKey;<br><br>    private Set&lt;Authorities&gt; authorities = new HashSet&lt;&gt;();</pre><pre>    ...getters and setters<br>}</pre><p>I omitted the getters and setters for the sake of simplicity, but you can check them <a href="https://github.com/marcusdacoregio/oauth2-spring-boot/blob/master/auth-service/src/main/java/com/marcusdacoregio/authservice/domain/User.java">here</a>. The User class implements the UserDetails interface who provides core user information to be encapsulated into Authentication objects. The @Document , @Id and @Indexed annotations are used by Mongo, I’ll not enter in details here, but you can ask in the comments section.</p><p>Create the <strong>UserRepository </strong>to be our DAO.</p><pre>import com.marcusdacoregio.authservice.domain.User;<br>import org.springframework.data.mongodb.repository.MongoRepository;<br>import org.springframework.stereotype.Repository;<br><br>import java.util.Optional;<br><br>@Repository<br>public interface UserRepository extends MongoRepository&lt;User, String&gt; {<br>    Optional&lt;User&gt; findByUsername(String username);<br>}</pre><p>And now our custom implementation of the UserDetailsService , it is a core interface which loads user-specific data. It is used throughout the spring framework as a user DAO and is the strategy used by the DaoAuthenticationProvider. You can read more about it in the <a href="https://docs.spring.io/spring-security/site/docs/5.1.5.RELEASE/api/org/springframework/security/core/userdetails/UserDetailsService.html">official documentation</a>.</p><pre>@Service<br>public class CustomUserDetailsService implements UserDetailsService {<br><br>    private final UserRepository userRepository;<br><br>    public CustomUserDetailsService(UserRepository userRepository) {<br>        this.userRepository = userRepository;<br>    }<br><br>    @Override<br>    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {<br>        return userRepository.findByUsername(username)<br>                .orElseThrow(() -&gt; new UsernameNotFoundException(&quot;Username &quot; + username + &quot; not found&quot;));<br>    }<br><br>}</pre><p>Ok, until here we created some needed classes to deal with our users.</p><p>Now we will create the classes to deal with our clients, which are the resource servers whose wants to use the authentication. Let’s start the class who represents the detail of an authorization client.</p><pre>@Document<br>public class AuthClientDetails implements ClientDetails {<br>    private static final long <em>serialVersionUID </em>= 1L;<br><br>    @Id<br>    private String id;<br><br>    private String clientId;<br><br>    private String clientSecret;<br><br>    private String grantTypes;<br><br>    private String scopes;<br><br>    private String resources;<br><br>    private String redirectUris;<br><br>    private Integer accessTokenValidity;<br><br>    private Integer refreshTokenValidity;<br><br>    private String additionalInformation;</pre><pre>    ...getters and setters<br>}</pre><p>You can check the details for the getters and setters from this class <a href="https://github.com/marcusdacoregio/oauth2-spring-boot/blob/master/auth-service/src/main/java/com/marcusdacoregio/authservice/domain/AuthClientDetails.java">here</a>. It’d be nice to check out the <a href="https://docs.spring.io/spring-security/oauth/apidocs/org/springframework/security/oauth2/provider/ClientDetails.html">documentation</a> for ClientDetails .</p><p>The next class is AuthClientRepository to be our DAO for AuthClientDetails.</p><pre>@Repository<br>public interface AuthClientRepository extends MongoRepository&lt;AuthClientDetails, String&gt; {</pre><pre>    Optional&lt;AuthClientDetails&gt; findByClientId(String clientId);</pre><pre>}</pre><p>Now the class AuthClientDetailsService , it implements the <a href="https://docs.spring.io/spring-security/oauth/apidocs/org/springframework/security/oauth2/provider/ClientDetailsService.html"><strong>ClientDetailsService</strong></a><strong> </strong>which is a service interface to provide the details about an OAuth2 client.</p><pre>@Service<br>public class AuthClientDetailsService implements ClientDetailsService {<br>    private final AuthClientRepository authClientRepository;<br><br>    public AuthClientDetailsService(AuthClientRepository authClientRepository) {<br>        this.authClientRepository = authClientRepository;<br>    }<br><br>    @Override<br>    public ClientDetails loadClientByClientId(String clientId) {<br>        return authClientRepository.findByClientId(clientId).orElseThrow(IllegalArgumentException::new);<br>    }<br>}</pre><p>In the next section, we will start to configure security and OAuth2 in Spring.</p><h4>Configuring security and OAuth2 in Spring</h4><p>Starting with the WebSecurityConfig class, it will extend the WebSecurityConfigurerAdapter abstract class.</p><p>On it, we are defining some security things and our AuthenticationManager to make use of the CustomUserDetailsService we have created before.</p><pre>@Configuration<br>public class WebSecurityConfig extends WebSecurityConfigurerAdapter {<br><br>    @Autowired<br>    private CustomUserDetailsService userDetailsService;<br><br>    @Override<br>    protected void configure(HttpSecurity http) throws Exception {<br>        // @formatter:off<br>        http<br>                .authorizeRequests().anyRequest().authenticated()<br>                .antMatchers(&quot;/oauth/**&quot;).permitAll()<br>                .and()<br>                .csrf().disable();<br>        // @formatter:on<br>    }<br><br>    @Override<br>    protected void configure(AuthenticationManagerBuilder auth) throws Exception {<br>        auth.userDetailsService(userDetailsService)<br>                .passwordEncoder(passwordEncoder());<br>    }<br><br>    @Override<br>    @Bean<br>    public AuthenticationManager authenticationManagerBean() throws Exception {<br>        return super.authenticationManagerBean();<br>    }<br><br>    @Bean<br>    public PasswordEncoder passwordEncoder() {<br>        return new BCryptPasswordEncoder();<br>    }<br><br>}</pre><p>We configured the Spring Security to authorize any request that is authenticated, but allow any request on <strong><em>/oauth/**</em></strong> endpoint to be allowed even without authentication.<br>We did set our CustomUserDetailsService to be used by the <a href="https://docs.spring.io/spring-security/site/docs/5.1.5.RELEASE/api/org/springframework/security/authentication/AuthenticationManager.html"><strong>AuthenticationManager</strong></a><strong> </strong>and defined the password encoder to use the implementation from <a href="https://docs.spring.io/spring-security/site/docs/5.1.5.RELEASE/api/org/springframework/security/crypto/bcrypt/BCryptPasswordEncoder.html"><strong>BCryptPasswordEncoder</strong></a>.</p><p>Now create the OAuth2AuthorizationCofig who act as a strategy for configuring an OAuth2 Authorization Server.</p><pre>@Configuration<br>@EnableAuthorizationServer<br>public class OAuth2AuthorizationConfig extends AuthorizationServerConfigurerAdapter {<br><br>    @Autowired<br>    @Qualifier(&quot;authenticationManagerBean&quot;)<br>    private AuthenticationManager authenticationManager;<br><br>    @Autowired<br>    private CustomUserDetailsService userDetailsService;<br><br>    @Autowired<br>    private AuthClientDetailsService authClientDetailsService;<br><br>    @Autowired<br>    private PasswordEncoder encoder;<br><br>    @Override<br>    public void configure(ClientDetailsServiceConfigurer clients) throws Exception {<br>        clients.withClientDetails(authClientDetailsService);<br>    }<br><br>    @Bean<br>    public TokenStore tokenStore() {<br>        return new MongoTokenStore();<br>    }<br><br>    @Override<br>    public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {<br>        endpoints<br>                .tokenStore(tokenStore())<br>                .authenticationManager(authenticationManager)<br>                .userDetailsService(userDetailsService);<br>    }<br><br>    @Override<br>    public void configure(AuthorizationServerSecurityConfigurer oauthServer) throws Exception {<br>        oauthServer<br>                .tokenKeyAccess(&quot;permitAll()&quot;)<br>                .checkTokenAccess(&quot;isAuthenticated()&quot;)<br>                .passwordEncoder(encoder)<br>                .allowFormAuthenticationForClients();<br>    }<br><br>}</pre><p>The @EnableAuthorizationServer enables an <a href="https://docs.spring.io/spring-security/oauth/apidocs/org/springframework/security/oauth2/provider/endpoint/AuthorizationEndpoint.html"><strong>AuthorizationEndpoint</strong></a> and a <a href="https://docs.spring.io/spring-security/oauth/apidocs/org/springframework/security/oauth2/provider/endpoint/TokenEndpoint.html"><strong>TokenEndpoint</strong></a> exposing endpoints to be used to authentication and authorization.</p><p>We defined our AuthClientDetailsService implementation to be used, as well a custom <a href="https://docs.spring.io/spring-security/oauth/apidocs/org/springframework/security/oauth2/provider/token/TokenStore.html"><strong>TokenStore</strong></a><strong> </strong>implementation to make use of MongoDB to store the generated tokens. I want you to check the implementation of <a href="https://github.com/marcusdacoregio/oauth2-spring-boot/blob/master/auth-service/src/main/java/com/marcusdacoregio/authservice/config/mongodb/MongoTokenStore.java"><strong>MongoTokenStore </strong>here</a>, as well as <a href="https://github.com/marcusdacoregio/oauth2-spring-boot/blob/master/auth-service/src/main/java/com/marcusdacoregio/authservice/config/mongodb/MongoConfig.java">MongoConfig</a> and <a href="https://github.com/marcusdacoregio/oauth2-spring-boot/blob/master/auth-service/src/main/java/com/marcusdacoregio/authservice/config/mongodb/MongoProperties.java">MongoProperties</a>, I won’t put them here because it will become messy.</p><p>I have created the <a href="https://github.com/marcusdacoregio/oauth2-spring-boot/blob/master/auth-service/src/main/java/com/marcusdacoregio/authservice/config/mongodb/MongoBeeConfig.java">MongoBeeConfig</a> class to insert some initial data in our Mongo database, it uses the <a href="https://github.com/mongobee/mongobee">Mongobee</a> library which is a MongoDB data migration tool for Java, like Flyway or Liquibase for relational databases. We will create this initial data after.</p><h4>Using Docker to provide us a Mongo database</h4><p>Okay, until now we configured our MongoDB but we don’t have installed it yet. Instead of installing and configuring it we will use a <a href="https://github.com/marcusdacoregio/oauth2-spring-boot/blob/master/docker-compose.yml"><strong><em>docker-compose</em></strong></a> file to provide it for us.</p><pre>mongo-oauth:<br>  image: mongo:4.0.4<br>  restart: always<br>  environment:<br>    MONGO_INITDB_ROOT_USERNAME: root<br>    MONGO_INITDB_ROOT_PASSWORD: example<br>    MONGO_INITDB_DATABASE: oauth-db<br>    MONGODB_USER: oauth-user<br>    MONGODB_DATABASE: oauth-db<br>    MONGODB_PASS: password<br>  log_opt:<br>    max-size: &quot;10m&quot;<br>    max-file: &quot;10&quot;<br>  ports:<br>    - 27017:27017<br>  volumes:<br>    - ./mongo-init/init-mongo.sh:/docker-entrypoint-initdb.d/init-mongo.sh<br><br>mongo-express-oauth:<br>  image: mongo-express:0.49<br>  restart: always<br>  ports:<br>    - 10081:8081<br>  environment:<br>    ME_CONFIG_MONGODB_ADMINUSERNAME: root<br>    ME_CONFIG_MONGODB_ADMINPASSWORD: example<br>    ME_CONFIG_MONGODB_SERVER: mongo-oauth<br>    ME_CONFIG_MONGODB_PORT: 27017<br>  links:<br>    - mongo-oauth</pre><p>You need to have Docker installed (<a href="https://medium.com/@yannmjl/what-is-docker-in-simple-english-a24e8136b90b">don’t know what is Docker?</a>). Create a file <strong><em>docker-compose.yml</em></strong> somewhere, and in this same place, you need to have a folder called <strong><em>mongo-init</em></strong> with a file named <strong><em>init-mongo.sh</em></strong> inside it. You can copy the content from <strong><em>init-mongo.sh</em></strong> <a href="https://github.com/marcusdacoregio/oauth2-spring-boot/blob/master/mongo-init/init-mongo.sh">here</a>, it is used to create the database and user defined in the environment variables from <strong><em>docker-compose.yml.</em></strong></p><p>Once you have all in place, run the command docker-compose up --build in your preferred terminal to create and start the MongoDB container.</p><h4>Creating the very first client of our auth service</h4><p>We need now to have one client to retrieve the access tokens from our users. Let’s create him with <strong>password</strong> and <strong>refresh token</strong> <a href="https://oauth.net/2/grant-types/">grant types</a>.<br>Create a <strong>ChangeLog</strong> from <strong>Mongobee</strong> to insert this client upon application start. Create a class named InitialValuesChangeLog with the following content:</p><pre>@ChangeLog<br>public class InitialValuesChangeLog {</pre><pre>    @ChangeSet(order = &quot;001&quot;, id = &quot;insertBrowserClientDetails&quot;, author = &quot;Marcus Hert Da Corégio&quot;)<br>    public void insertBrowserClientDetails(MongoTemplate mongoTemplate) {<br>        AuthClientDetails browserClientDetails = new AuthClientDetails();<br>        browserClientDetails.setClientId(&quot;browser&quot;);<br>        browserClientDetails.setClientSecret(&quot;$2a$10$fWNTd3H.u7G/aNROVQSifebOkZ2xzU5nUPOCI2Ld42M8E25/ljJqK&quot;);<br>        browserClientDetails.setScopes(&quot;ui&quot;);<br>        browserClientDetails.setGrantTypes(&quot;refresh_token,password&quot;);<br><br>        mongoTemplate.save(browserClientDetails);<br>    }</pre><pre>}</pre><p>In it, we are creating a new <strong>AuthClientDetails</strong> on our MongoDB with a secret, scope and grant types to be able to get an access token based on user credentials.<br>That client secret is a hash generated from <strong>BCryptPasswordEncoder</strong> for the value <strong>1234</strong>.</p><p>Let’s create another @ChangeSet to create a <strong>User</strong> for us to be able to authenticate him with the same password we used before for <strong>browser client</strong>. I won’t create an endpoint now because this will be the content of the article’s next part :).</p><pre>@ChangeSet(order = &quot;002&quot;, id = &quot;insertUserToTestAuthentication&quot;, author = &quot;Marcus Hert Da Corégio&quot;)<br>public void insertUserToTestAuthentication(MongoTemplate mongoTemplate) {<br>    Set&lt;Authorities&gt; authorities = new HashSet&lt;&gt;();<br>    authorities.add(Authorities.<em>ROLE_USER</em>);<br><br>    User user = new User();<br>    user.setActivated(true);<br>    user.setAuthorities(authorities);<br>    user.setPassword(&quot;$2a$10$fWNTd3H.u7G/aNROVQSifebOkZ2xzU5nUPOCI2Ld42M8E25/ljJqK&quot;);<br>    user.setUsername(&quot;randomuser&quot;);<br><br>    mongoTemplate.save(user);<br>}</pre><h4>Testing what we did until now</h4><p>Ok, now we will do some requests to see if what we did is working :D. I recommend you to use <a href="https://www.getpostman.com/">Postman</a> to make the HTTP requests. Run the config, registry, gateway and auth services respectively.</p><p>Open Postman and let’s do a POST request to <a href="http://localhost:8080/uaa/oauth/token">http://localhost:8080/uaa/oauth/token</a> to retrieve an access token for our <strong>randomuser </strong>and <strong>browser </strong>client.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1011/1*mamLDi6gRhW15xiR3kVumQ.png" /><figcaption>Authorization details for the request</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YJl3QbQmdsr2b71ZW3pAJw.png" /><figcaption>Request body details for the request</figcaption></figure><p>Sending this request, I received the following response body:</p><pre>{<br>    &quot;access_token&quot;: &quot;38f1a0ac-a762-4b2a-af51-45a26d97e2bd&quot;,<br>    &quot;token_type&quot;: &quot;bearer&quot;,<br>    &quot;refresh_token&quot;: &quot;fad35f6f-84e8-4c37-abc5-73c77018f885&quot;,<br>    &quot;expires_in&quot;: 43199,<br>    &quot;scope&quot;: &quot;ui&quot;<br>}</pre><p>That’s it, we have accomplished what we were looking for. The authentication is finally working, you can check the generated tokens on MongoDB via Mongo Express at <a href="http://localhost:10081/">http://localhost:10081</a>.</p><p>Let me know if you made this works too, I hope so!</p><h4>What we will do in the third part</h4><p>The next thing we gonna do is to create an account service, this application will manage our users, authenticate with our auth service and so on.</p><p>Check the third part <a href="https://medium.com/@marcusdacoregio/microservices-with-spring-boot-and-spring-cloud-441e3dabc67d">here</a>.</p><p>I hope you guys like it, feel free to share with me any questions.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=20f689b17fc7" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/microservices-with-spring-boot-and-spring-cloud-20f689b17fc7">Microservices with Spring Boot and Spring Cloud.</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Microservices with Spring Boot and Spring Cloud.]]></title>
            <link>https://itnext.io/microservices-with-spring-boot-and-spring-cloud-16d2c056ba12?source=rss-5cfb26e8714b------2</link>
            <guid isPermaLink="false">https://medium.com/p/16d2c056ba12</guid>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[spring-cloud]]></category>
            <category><![CDATA[oauth2]]></category>
            <dc:creator><![CDATA[Marcus Hert da Corégio]]></dc:creator>
            <pubDate>Thu, 11 Apr 2019 22:00:05 GMT</pubDate>
            <atom:updated>2019-05-07T01:55:12.325Z</atom:updated>
            <content:encoded><![CDATA[<h3>Microservices with Spring Boot and Spring Cloud. From config server to OAuth2 server (without inMemory things) — Part 1</h3><p>In this guide, we will build a working app who will create users and authenticate/authorize users and clients in a microservices architecture using Spring Boot, Spring Cloud, and MongoDB.<br>I won’t use the <strong>inMemory </strong>configuration that we always see in the most guides.</p><p>This guide will be composed of 3 parts:<br>First part: Creating the config, registry and gateway services;<br><a href="https://itnext.io/microservices-with-spring-boot-and-spring-cloud-20f689b17fc7">Second part</a>: Create the auth service, the one who will authenticate the users;<br><a href="https://medium.com/@marcusdacoregio/microservices-with-spring-boot-and-spring-cloud-441e3dabc67d">Third part</a>: Create the account service, the one who will register new users;</p><p>I’ll assume you already have some familiarity with microservices and Spring Boot.</p><h3>Creating the Config Service</h3><p>The config application will be responsible to serve the spring configuration to every service. With it, you can centralize your configuration files and separate them by the environment that you are working, like dev, QA or production. <a href="https://cloud.spring.io/spring-cloud-config/multi/multi__spring_cloud_config_server.html">Here</a> is a more detailed explanation of the config server.</p><p>I’ll use the <a href="https://start.spring.io/">Spring Initializr</a> to generate the project, and it will be available in the <a href="https://github.com/marcusdacoregio/oauth2-spring-boot">GitHub repo</a>. The configuration will be like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/973/1*QlOuWF9ygNy5PI3GFBO0eQ.png" /><figcaption>Generating the config-service</figcaption></figure><p>We will need to add the annotation @EnableConfigServer in ConfigServerApplication class.</p><pre>@SpringBootApplication<br>@EnableConfigServer<br>public class ConfigServerApplication {<br>    public static void main(String[] args) {<br>        SpringApplication.<em>run</em>(ConfigServerApplication.class, args);<br>    }<br>}</pre><p>This annotation tells Spring that this application will act as a config server.</p><p>Now we will rename the application.properties file to application.yml and add these configurations to it:</p><pre><strong>spring</strong>:<br>  <strong>cloud</strong>:<br>    <strong>config</strong>:<br>      <strong>server</strong>:<br>        <strong>native</strong>:<br>          <strong>search-locations</strong>: classpath:/shared <em>#tells spring where to locate the config files<br>  </em><strong>profiles</strong>:<br>    <strong>active</strong>: native <em>#we are using native because the config server uses a git repo by default<br>  </em><strong>security</strong>:<br>    <strong>user</strong>:<br>      <strong>password</strong>: 1234 <em>#the password which apps will use to access its configurations<br><br></em><strong>server</strong>:<br>  <strong>port</strong>: 8888 <em>#the port where the config-server will be acessible</em></pre><p>Create the folder shared inside the resources folder. Create another application.yml in the folder you have just created with this content:</p><pre><em>#This configuration file will hold common configs to be shared among all files<br></em><strong>eureka</strong>:<br>  <strong>instance</strong>:<br>    <strong>prefer-ip-address</strong>: false<br>  <strong>client</strong>:<br>    <strong>serviceUrl</strong>:<br>      <strong>defaultZone</strong>: <a href="http://localhost:8761/eureka/">http://localhost:8761/eureka/</a> #where our registry server is located<br><br><strong>security</strong>:<br>  <strong>oauth2</strong>:<br>    <strong>resource</strong>:<br>      <strong>user-info-uri</strong>: <a href="http://auth-service/uaa/users/current">http://auth-service/uaa/users/current</a> #which uri will be used to find the user</pre><p>Let’s run the application and access <a href="http://localhost:8888/actuator/health">http://localhost:8888/actuator/health</a>. You should see a message like this:</p><p>{“status”:”UP”}</p><h3>Creating the Registry Service</h3><p>Now we will build the registry service using the Netflix Eureka. This service is responsible for the registration and discovery of the many services we should build. This way we don’t need to know the IP address of each service we create, we just know their names and the discovery do the rest.</p><p>Let’s generate the project using the <a href="https://start.spring.io/">Spring Initializr</a>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/876/1*FXIZeq3iVDomkPr0TtOf-A.png" /><figcaption>Generating the registry-service</figcaption></figure><p>Open the RegistryServiceApplication class and add the @EnableEurekaServer annotation, like this:</p><pre>@SpringBootApplication<br>@EnableEurekaServer<br>public class RegistryServiceApplication {<br>    public static void main(String[] args) {<br>        SpringApplication.<em>run</em>(RegistryServiceApplication.class, args);<br>    }<br>}</pre><p>This annotation tells Spring to activate the Eureka Server related configuration.</p><p>Delete the file application.properties and create one called bootstrap.yml in the resources folder, with this content:</p><pre><em>#This file is the entrypoint for spring to know where to look for the configuration file and hold the initial configuration<br><br></em><strong>spring</strong>:<br>  <strong>application</strong>:<br>    <strong>name</strong>: registry-service <em>#name of the application<br>  </em><strong>cloud</strong>:<br>    <strong>config</strong>:<br>      <strong>uri</strong>: http://localhost:8888 <em>#where the config-service is running<br>      </em><strong>fail-fast</strong>: true <em>#the service will not run if it can&#39;t reach the config-service<br>      </em><strong>password</strong>: 1234 <em>#password of the config-service<br>      </em><strong>username</strong>: user <em>#username of the config-service<br><br></em><strong>eureka</strong>:<br>  <strong>instance</strong>:<br>    <strong>prefer-ip-address</strong>: true <em>#when the application registers with eureka, it uses its IP address rather than its hostname<br>  </em><strong>client</strong>:<br>    <strong>registerWithEureka</strong>: false <em>#tells the built-in eureka client to not register itself with eureka, because we should act as a server<br>    </em><strong>fetchRegistry</strong>: false</pre><p>We told registry service to look at <a href="http://localhost:8888/">http://localhost:8888</a> to find its configuration, so we need to create a configuration file for it on config service.</p><p>In the config-service/resources/shared folder, let’s create a file named registry-service.yml with the following content:</p><pre><strong>server</strong>:<br>  <strong>port</strong>: 8761 <em>#the default port used for eureka servers</em></pre><p>Now run the config-service and the registry-service, and access <a href="http://localhost:8761/">http://localhost:8761/</a>. You should see a page like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5QcE0QEmPBujG_uqjmsj_Q.png" /><figcaption>View of Eureka dashboard</figcaption></figure><p>There is where you will find the services registered with the Eureka Server.</p><p>When looking for its configuration, the services will search for the configuration with the same name defined in spring.application.name property in the bootstrap.yml file. You can even access <a href="http://localhost:8888/registry-service/default">http://localhost:8888/registry-service/default</a>, authenticate with user as the username and 1234 as the password to see the configuration.</p><h3>Creating the Gateway Service</h3><p>Now we will build the gateway service using the <a href="https://cloud.spring.io/spring-cloud-netflix/multi/multi__router_and_filter_zuul.html">Spring Netflix Zuul</a>. This service is responsible to map the incoming requests to specific microservices, it can act as a load balancer too.</p><p>Let’s generate the project using the <a href="https://start.spring.io/">Spring Initializr</a>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/878/1*T2OxQwFI7NelxCbGYeBoyA.png" /><figcaption>Generating the gateway-service</figcaption></figure><p>We need to add two annotations to our main class GatewayServiceApplication :</p><pre>@SpringBootApplication<br>@EnableDiscoveryClient<br>@EnableZuulProxy<br>public class GatewayServiceApplication {<br>    public static void main(String[] args) {<br>        SpringApplication.<em>run</em>(GatewayServiceApplication.class, args);<br>    }<br>}</pre><p>@EnableDiscoveryClient tells Spring to enable the discovery client implementation.</p><p>@EnableZuulProxy sets up a Zuul Server so it can forward requests to other services. This services can be configured manually through configuration or via Discovery (Eureka) Server.</p><p>Create the bootstrap.yml file in the place of application.properties with this content, almost the same as the registry service:</p><pre><strong>spring</strong>:<br>  <strong>application</strong>:<br>    <strong>name</strong>: gateway-service<br>  <strong>cloud</strong>:<br>    <strong>config</strong>:<br>      <strong>uri</strong>: http://localhost:8888<br>      <strong>fail-fast</strong>: true<br>      <strong>password</strong>: 1234<br>      <strong>username</strong>: user</pre><p>Now we need to create the configuration file for gateway-service.</p><p>In the config-service/resources/shared folder, let’s create a file named gateway-service.yml with the following content:</p><pre><strong>zuul</strong>:<br>  <strong>ignoredServices</strong>: &#39;*&#39;<br>  <strong>host</strong>:<br>    <strong>connect-timeout-millis</strong>: 20000<br>    <strong>socket-timeout-millis</strong>: 20000<br><br>  <strong>routes</strong>:<br>    <strong>auth-service</strong>:<br>      <strong>path</strong>: /uaa/** <em>#path that will be intercepted<br>      </em><strong>url</strong>: auth-service <em>#which url the request will e mapped to<br>      </em><strong>stripPrefix</strong>: false <em>#if zuul should replace the &quot;/uaa/&quot; segment<br>      </em><strong>sensitiveHeaders</strong>:<br><br>    <strong>account-service</strong>:<br>      <strong>path</strong>: /accounts/**<br>      <strong>serviceId</strong>: account-service<br>      <strong>stripPrefix</strong>: false<br>      <strong>sensitiveHeaders</strong>:<br><br><strong>server</strong>:<br>  <strong>port</strong>: 8080</pre><p>I let some configurations that we will need later in this guide.</p><p>Now, you can run your gateway service application and access <a href="http://localhost:8761/">http://localhost:8761/</a> to see if the service is registered in Eureka Server. You should see something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2g-NXWBLH9cc6DyhiYKomQ.png" /><figcaption>View of the Eureka Server with Gateway Service instance running</figcaption></figure><p>And that’s it, we are done with the first part of this guide. We have created the basics of our microservices architecture.</p><p>In the second part, we will create the auth service, the one which will do the authentication and authorization of users and clients. I’m looking forward to hearing from you guys any questions. Let me know if this guide did help you.</p><p>Remember that the code is available on <a href="https://github.com/marcusdacoregio/oauth2-spring-boot">GitHub</a>.</p><p>The second part is available <a href="https://medium.com/@marcusdacoregio/microservices-with-spring-boot-and-spring-cloud-20f689b17fc7">here</a>.<br>The third part is coming soon.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=16d2c056ba12" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/microservices-with-spring-boot-and-spring-cloud-16d2c056ba12">Microservices with Spring Boot and Spring Cloud.</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>