Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,59 +23,57 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<tomcat.port>9081</tomcat.port>
<tomcat.ip>127.0.0.1</tomcat.ip>
<file>readme</file>
<lombok.version>1.18.10</lombok.version>
<tomcat.ip>127.0.0.1</tomcat.ip>
<file>readme</file>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<lombok.version>1.18.36</lombok.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<version>3.4.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>3.4.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
<version>3.4.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>3.2.0</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<version>3.4.0</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>2.3.232</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>3.2.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-jwt</artifactId>
<version>1.0.7.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.security.oauth/spring-security-oauth2 -->
<dependency>
<groupId>org.springframework.security.oauth</groupId>
<artifactId>spring-security-oauth2</artifactId>
<version>2.1.0.RELEASE</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.10.8</version>
<version>2.18.2</version>
</dependency>

<dependency>
Expand All @@ -91,6 +89,7 @@
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>3.4.0</version>
<configuration>
<executable>true</executable>
<addResources>true</addResources>
Expand All @@ -107,6 +106,7 @@
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.45.1</version>
<extensions>true</extensions>

<configuration>
Expand Down Expand Up @@ -142,11 +142,11 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<version>3.13.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<annotationProcessorPaths>
<target>17</target>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
Expand All @@ -158,4 +158,4 @@
</plugins>
</build>

</project>
</project>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.nouhoun.springboot.jwt.integration.config;

import java.util.Arrays;

import java.util.Collections;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
Expand All @@ -12,24 +12,32 @@
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer;
import org.springframework.security.oauth2.provider.token.DefaultAccessTokenConverter;
import org.springframework.security.oauth2.provider.token.TokenEnhancer;
import org.springframework.security.oauth2.provider.token.TokenEnhancerChain;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
import org.springframework.security.oauth2.provider.token.store.JwtTokenStore;
import org.springframework.context.annotation.Bean;

import com.nouhoun.springboot.jwt.integration.config.CustomUserDetailsService;

/**
* Created by nydiarra on 06/05/17.
*/
* <p>
@Configuration
@EnableAuthorizationServer


public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter {

@Value("${security.jwt.client-id}")
private String clientId;

@Value("${security.jwt.client-secret}")
private String clientSecret;
private String clientSecret = "password";

@Value("${security.jwt.grant-type}")
private String grantType = "password";
private String grantType;

@Value("${security.jwt.scope-read}")
Expand All @@ -41,37 +49,59 @@ public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdap
@Value("${security.jwt.resource-ids}")
private String resourceIds;

@Autowired
private TokenStore tokenStore;


@Autowired
private JwtAccessTokenConverter accessTokenConverter;
private CustomUserDetailsService userDetailsService;

@Autowired
private AuthenticationManager authenticationManager;

@Autowired
private TokenStore tokenStore;

@Autowired
private PasswordEncoder passwordEncoder;

@Override
public void configure(ClientDetailsServiceConfigurer configurer) throws Exception {
configurer
.inMemory()
.withClient(clientId)
.secret(passwordEncoder.encode(clientSecret))
.withClient(clientId)
.secret(passwordEncoder.encode(clientSecret))
.authorizedGrantTypes(grantType)
.scopes(scopeRead, scopeWrite)
.resourceIds(resourceIds);
.scopes(scopeRead, scopeWrite);
// .resourceIds(resourceIds);
}

@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
TokenEnhancerChain enhancerChain = new TokenEnhancerChain();
enhancerChain.setTokenEnhancers(Arrays.asList(accessTokenConverter));
endpoints.tokenStore(tokenStore)
.accessTokenConverter(accessTokenConverter)
.accessTokenConverter(jwtAccessTokenConverter())
.tokenEnhancer(enhancerChain)
.authenticationManager(authenticationManager);
.userDetailsService(userDetailsService)
.authenticationManager(authenticationManager())
.pathMapping("/oauth/token", "/api/oauth/token");
}

}

// @Override
// public void configure(AuthorizationServerSecurityConfigurer security) throws Exception {
// security.tokenKeyAccess("isAuthenticated()")
// .checkTokenAccess("isAuthenticated()");
// }

// @Bean
// public AuthenticationManager authenticationManager() {
// return new AuthenticationManager();
// }
@Bean
public JwtAccessTokenConverter jwtAccessTokenConverter() {
JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
converter.setSigningKey("1234567890abcdef");
return converter;
DefaultAccessTokenConverter converter = new DefaultAccessTokenConverter();
converter.setUserTokenConverter(new UserAuthenticationConverter());
return converter;
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ protected void configure(HttpSecurity http) throws Exception {

@Bean
public JwtAccessTokenConverter accessTokenConverter() {
JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
converter.setSigningKey(signingKey);
JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
return converter;
}

Expand All @@ -78,4 +78,4 @@ public DefaultTokenServices tokenServices() {
defaultTokenServices.setSupportRefreshToken(true);
return defaultTokenServices;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException

return userDetails;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ public User findByUsername(String username) {

@Override
public List<User> findAllUsers() {
return (List<User>)userRepository.findAll();
return userRepository.findAll() instanceof List ? (List<User>) userRepository.findAll() : null;
}

@Override
public List<RandomCity> findAllRandomCities() {
return (List<RandomCity>)randomCityRepository.findAll();
return randomCityRepository.findAll() instanceof List ? (List<RandomCity>) randomCityRepository.findAll() : null;
}
}
}