Skip to content

Commit 5af5a12

Browse files
authored
Merge pull request #32 from MetheaX/dev
Re-Engineer
2 parents 58ac7a0 + 7f02bc5 commit 5af5a12

298 files changed

Lines changed: 1183 additions & 39303 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 13 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22
Methea is a framework providing authentication and access management for your `Spring Boot Application`
33
with minimum configuration. No need to deal with users and permission stuffs.
44

5-
Methea also provide UI components which is build on top of [FreeMarker](https://freemarker.apache.org/) to increase your development speed.
5+
Methea also provide [UI Management Tool](https://github.com/MetheaX/methea-management) which is allows you to control & configure your system.
66

77
Methea build on top of following frameworks:
88
1. [Spring Boot](https://spring.io/projects/spring-boot)
99
2. [JWT](https://jwt.io/)
10-
3. [FreeMarker](https://freemarker.apache.org/)
11-
4. [CoreUI](https://coreui.io/)
1210

1311
# Building from sources
1412

@@ -22,60 +20,28 @@ How to build
2220
Support with `Spring Boot 2.2.2.Release` and later version of Spring Boot.
2321

2422
# Usages
25-
26-
### I. Integration as web application
27-
28-
1. Adding dependency to spring boot application
29-
30-
<dependency>
31-
<groupId>io.methea</groupId>
32-
<artifactId>web-ui</artifactId>
33-
<version>0.0.1-SNAPSHOT</version>
34-
</dependency>
35-
36-
2. Adding spring-boot components scan
37-
38-
@SpringBootApplication(scanBasePackages = {"io.methea", "your-reverse-domain"})
39-
@EnableJpaRepositories(basePackages = {"io.methea", "your-reverse-domain"})
40-
@EntityScan(basePackages = {"io.methea", "your-reverse-domain"})
41-
public class MetheaHostApplication {
42-
public static void main(String[] args) {
43-
SpringApplication.run(MetheaHostApplication.class, args);
44-
}
45-
}
46-
3. In resources config environment properties
47-
- create file `environment.properties` with the configuration
48-
49-
methea.client.freemarker.templates=your-template-path
50-
51-
4. Config datasource of your choice
52-
* Please note that currently, we testing only with [PostgreSQL](https://www.postgresql.org/)
53-
5. Sample project
54-
* Still have doubt here is our [sample project](https://github.com/MetheaX/Methea-Sample-Project)
55-
### II. Integration as webservice application
23+
### I. Integration into webservice application
5624
1. Adding dependency to your spring boot application
5725

5826
<dependency>
59-
<groupId>io.methea</groupId>
27+
<groupId>io.github.metheax</groupId>
6028
<artifactId>api</artifactId>
6129
<version>0.0.1-SNAPSHOT</version>
6230
</dependency>
31+
32+
2. Config datasource of your choice
33+
* Please note that currently, we're testing only with [PostgreSQL](https://www.postgresql.org/)
6334

64-
2. Adding spring-boot components scan
35+
3. Adding spring-boot components scan
6536

66-
@SpringBootApplication(scanBasePackages = {"io.methea", "your-reverse-domain"})
67-
@EnableJpaRepositories(basePackages = {"io.methea", "your-reverse-domain"})
68-
@EntityScan(basePackages = {"io.methea", "your-reverse-domain"})
37+
@SpringBootApplication(scanBasePackages = {"io.github.metheax", "your-reverse-domain"})
38+
@EnableJpaRepositories(basePackages = {"io.github.metheax", "your-reverse-domain"})
39+
@EntityScan(basePackages = {"io.github.metheax", "your-reverse-domain"})
6940
public class MetheaHostApplication {
7041
public static void main(String[] args) {
7142
SpringApplication.run(WebServiceApplication.class, args);
7243
}
73-
}
74-
3. Deployment methea web management (Optional)
44+
}`
7545

76-
Methea web management allow you to manage users, permission, roles, groups, URI... in webservice application.
77-
* Default login credential for web management
78-
79-
`username: admin`
80-
81-
`password: admin`
46+
4. Sample project
47+
* Still have doubt on how to integrate, here is our [sample project](https://github.com/MetheaX/Methea-Sample-Webservice)

api/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
55
<parent>
66
<artifactId>methea</artifactId>
7-
<groupId>io.methea</groupId>
7+
<groupId>io.github.metheax</groupId>
88
<version>0.0.1-SNAPSHOT</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
@@ -19,7 +19,7 @@
1919

2020
<dependencies>
2121
<dependency>
22-
<groupId>io.methea</groupId>
22+
<groupId>io.github.metheax</groupId>
2323
<artifactId>methea-core</artifactId>
2424
<version>0.0.1-SNAPSHOT</version>
2525
</dependency>

api/src/main/java/io/methea/api/auth/AuthenticationController.java renamed to api/src/main/java/io/github/metheax/api/auth/AuthenticationController.java

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
package io.methea.api.auth;
1+
package io.github.metheax.api.auth;
22

3-
import io.methea.api.domain.RefreshTokenPayload;
4-
import io.methea.api.domain.RequestTokenPayload;
5-
import io.methea.api.domain.RevokeTokenPayload;
6-
import io.methea.api.domain.Token;
7-
import io.methea.api.service.MetheaAuthenticationService;
8-
import io.methea.constant.MConstant;
3+
import io.github.metheax.api.domain.RefreshTokenPayload;
4+
import io.github.metheax.api.domain.RequestTokenPayload;
5+
import io.github.metheax.api.domain.Token;
6+
import io.github.metheax.api.service.MetheaAuthenticationService;
7+
import io.github.metheax.api.domain.RevokeTokenPayload;
8+
import io.github.metheax.constant.MetheaConstant;
99
import org.slf4j.Logger;
1010
import org.slf4j.LoggerFactory;
1111
import org.springframework.context.annotation.Scope;
@@ -14,7 +14,6 @@
1414
import org.springframework.http.MediaType;
1515
import org.springframework.http.ResponseEntity;
1616
import org.springframework.util.ObjectUtils;
17-
import org.springframework.web.bind.annotation.GetMapping;
1817
import org.springframework.web.bind.annotation.PostMapping;
1918
import org.springframework.web.bind.annotation.RequestBody;
2019
import org.springframework.web.bind.annotation.RestController;
@@ -26,14 +25,13 @@
2625
import java.util.Map;
2726

2827
/**
29-
* Author : DKSilverX
28+
* Author : Kuylim Tith
3029
* Date : 08/08/2020
3130
*/
3231
@RestController
3332
@Scope(value = WebApplicationContext.SCOPE_REQUEST, proxyMode = ScopedProxyMode.TARGET_CLASS)
3433
public class AuthenticationController {
3534
private static final Logger log = LoggerFactory.getLogger(AuthenticationController.class);
36-
private static final String UNAUTHORIZED_ACCESS_URL = "/unauthorized-access";
3735
private static final String GET_ACCESS_TOKEN_URL = "/auth/token";
3836
private static final String VERIFY_REFRESH_TOKEN = "/auth/refresh/token";
3937
private static final String REVOKE_ACCESS_TOKEN_URL = "/auth/token/revoke";
@@ -45,29 +43,20 @@ public AuthenticationController(MetheaAuthenticationService authenticationServic
4543
this.authenticationService = authenticationService;
4644
}
4745

48-
@GetMapping(value = UNAUTHORIZED_ACCESS_URL, produces = MediaType.APPLICATION_JSON_VALUE)
49-
public ResponseEntity<Map<String, Object>> unauthorizedAccess() {
50-
Map<String, Object> map = new HashMap<>();
51-
map.put(MConstant.JSON_MESSAGE, "Unauthorized Access!!");
52-
map.put(MConstant.JSON_STATUS, 401);
53-
54-
return new ResponseEntity<>(map, HttpStatus.OK);
55-
}
56-
5746
@PostMapping(value = GET_ACCESS_TOKEN_URL, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
5847
public ResponseEntity<Map<String, Object>> generateTokenFromUser(@RequestBody RequestTokenPayload client, HttpServletRequest req) {
5948
Map<String, Object> map = new HashMap<>();
6049
try {
6150
Token token = authenticationService.generateTokenFromUser(client, req);
6251

6352
if (ObjectUtils.isEmpty(token)) {
64-
map.put(MConstant.JSON_MESSAGE, "Invalid account!!");
65-
map.put(MConstant.JSON_STATUS, 400);
53+
map.put(MetheaConstant.JSON_MESSAGE, "Invalid account!!");
54+
map.put(MetheaConstant.JSON_STATUS, 400);
6655
return new ResponseEntity<>(map, HttpStatus.OK);
6756
}
6857
map.put("token", token);
69-
map.put(MConstant.JSON_MESSAGE, "Access token generated!!!");
70-
map.put(MConstant.JSON_STATUS, 200);
58+
map.put(MetheaConstant.JSON_MESSAGE, "Access token generated!!!");
59+
map.put(MetheaConstant.JSON_STATUS, 200);
7160
} catch (Exception ex) {
7261
log.error("=========> Generate access token from user error: ", ex);
7362
}
@@ -82,13 +71,13 @@ public ResponseEntity<Map<String, Object>> generateTokenFromRefreshToken(@Reques
8271
try {
8372
Token token = authenticationService.generateTokenFromRefreshToken(payload, req);
8473
if (ObjectUtils.isEmpty(token)) {
85-
map.put(MConstant.JSON_MESSAGE, "Invalid refresh token!!");
86-
map.put(MConstant.JSON_STATUS, 400);
74+
map.put(MetheaConstant.JSON_MESSAGE, "Invalid refresh token!!");
75+
map.put(MetheaConstant.JSON_STATUS, 400);
8776
return new ResponseEntity<>(map, HttpStatus.OK);
8877
}
8978
map.put("token", token);
90-
map.put(MConstant.JSON_MESSAGE, "Access token generated!!!");
91-
map.put(MConstant.JSON_STATUS, 200);
79+
map.put(MetheaConstant.JSON_MESSAGE, "Access token generated!!!");
80+
map.put(MetheaConstant.JSON_STATUS, 200);
9281
} catch (Exception ex) {
9382
log.error("=========> Generate access token from refresh token error: ", ex);
9483
}
@@ -103,12 +92,12 @@ public ResponseEntity<Map<String, Object>> revokeAccessToken(@RequestBody Revoke
10392

10493
try {
10594
authenticationService.revokeAccessToken(payload, request);
106-
map.put(MConstant.JSON_MESSAGE, "Access token revoked!!!");
107-
map.put(MConstant.JSON_STATUS, 200);
95+
map.put(MetheaConstant.JSON_MESSAGE, "Access token revoked!!!");
96+
map.put(MetheaConstant.JSON_STATUS, 200);
10897
} catch (Exception ex) {
10998
log.error("=========> revokeAccessToken error: ", ex);
110-
map.put(MConstant.JSON_MESSAGE, "Failed to revoke access token!!");
111-
map.put(MConstant.JSON_STATUS, 400);
99+
map.put(MetheaConstant.JSON_MESSAGE, "Failed to revoke access token!!");
100+
map.put(MetheaConstant.JSON_STATUS, 400);
112101
}
113102

114103
return new ResponseEntity<>(map, HttpStatus.OK);

api/src/main/java/io/methea/api/config/security/SecurityConstants.java renamed to api/src/main/java/io/github/metheax/api/config/security/SecurityConstants.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
package io.methea.api.config.security;
1+
package io.github.metheax.api.config.security;
22

33
/**
4-
* Author : DKSilverX
4+
* Author : Kuylim Tith
55
* Date : 13/04/2020
66
*/
77
public class SecurityConstants {

api/src/main/java/io/methea/api/config/security/WebSecurity.java renamed to api/src/main/java/io/github/metheax/api/config/security/WebSecurity.java

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
1-
package io.methea.api.config.security;
1+
package io.github.metheax.api.config.security;
22

3-
import io.methea.api.service.MetheaAuthenticationService;
4-
import io.methea.constant.MConstant;
5-
import io.methea.repository.configuration.permission.WhiteURIPermissionRepository;
6-
import io.methea.repository.webservice.system.SystemCertificateRepository;
3+
import io.github.metheax.api.service.MetheaAuthenticationService;
4+
import io.github.metheax.repository.WhiteURIPermissionRepository;
5+
import io.github.metheax.repository.SystemCertificateRepository;
6+
import io.github.metheax.utils.auth.MetheaPasswordEncoder;
77
import org.springframework.context.annotation.Bean;
8-
import org.springframework.core.env.Environment;
98
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
109
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
1110
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
1211
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
1312
import org.springframework.security.config.http.SessionCreationPolicy;
14-
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
15-
import org.springframework.util.ObjectUtils;
1613
import org.springframework.web.cors.CorsConfiguration;
1714
import org.springframework.web.cors.CorsConfigurationSource;
1815
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
@@ -22,38 +19,36 @@
2219
import java.util.Collections;
2320

2421
/**
25-
* Author : DKSilverX
22+
* Author : Kuylim Tith
2623
* Date : 18/06/2020
2724
*/
2825
@EnableWebSecurity
2926
public class WebSecurity extends WebSecurityConfigurerAdapter {
3027

3128
private final MetheaAuthenticationService metheaAuthenticationService;
32-
private final BCryptPasswordEncoder bCryptPasswordEncoder;
29+
private final MetheaPasswordEncoder encoder;
3330
private final SystemCertificateRepository certificateRepository;
3431
private final WhiteURIPermissionRepository whiteURIPermissionRepository;
35-
private final Environment env;
3632

3733
@Inject
38-
public WebSecurity(MetheaAuthenticationService service, BCryptPasswordEncoder bCryptPasswordEncoder,
34+
public WebSecurity(MetheaAuthenticationService service, MetheaPasswordEncoder encoder,
3935
SystemCertificateRepository certificateRepository,
40-
WhiteURIPermissionRepository whiteURIPermissionRepository, Environment env) {
41-
this.bCryptPasswordEncoder = bCryptPasswordEncoder;
36+
WhiteURIPermissionRepository whiteURIPermissionRepository) {
37+
this.encoder = encoder;
4238
this.certificateRepository = certificateRepository;
4339
this.metheaAuthenticationService = service;
4440
this.whiteURIPermissionRepository = whiteURIPermissionRepository;
45-
this.env = env;
4641
}
4742

4843
@Override
4944
public void configure(AuthenticationManagerBuilder authenticationManagerBuilder) throws Exception {
50-
authenticationManagerBuilder.userDetailsService(metheaAuthenticationService).passwordEncoder(bCryptPasswordEncoder);
45+
authenticationManagerBuilder.userDetailsService(metheaAuthenticationService).passwordEncoder(encoder);
5146
}
5247

5348
@Override
5449
public void configure(HttpSecurity httpSecurity) throws Exception {
5550
httpSecurity.cors().and().csrf().disable().authorizeRequests()
56-
.antMatchers("/auth/**", "/unauthorized-access").permitAll()
51+
.antMatchers("/auth/**").permitAll()
5752
.antMatchers("/**").authenticated().and()
5853
.addFilter(new WebServiceAuthorizationFilter(metheaAuthenticationService, authenticationManager(),
5954
certificateRepository, whiteURIPermissionRepository))
@@ -67,8 +62,7 @@ CorsConfigurationSource corsConfigurationSource() {
6762
configuration.setAllowedOrigins(Collections.singletonList("*"));
6863
configuration.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "OPTION", "DELETE"));
6964
configuration.setAllowedHeaders(Arrays.asList("Content-Type", "Access-Control-Allow-Headers", "x-requested-with",
70-
ObjectUtils.isEmpty(env.getProperty(MConstant.CLIENT_REQUEST_HEADER_KEY)) ? SecurityConstants.HEADER_STRING
71-
: env.getProperty(MConstant.CLIENT_REQUEST_HEADER_KEY)));
65+
SecurityConstants.HEADER_STRING));
7266
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
7367
source.registerCorsConfiguration("/**", configuration);
7468
return source;

0 commit comments

Comments
 (0)