Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
trismegisto-services
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Mauro Paolo Josue Zuñiga Mallqui
trismegisto-services
Commits
69efc884
Commit
69efc884
authored
Dec 20, 2023
by
Mauro Paolo Josue Zuñiga Mallqui
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[ADD] JWT WITH SPRING SECURITY ADDED
parent
b8ffb757
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
25 additions
and
54 deletions
+25
-54
AppApi.java
src/main/java/web/multitask/app/api/AppApi.java
+10
-1
SecurityConfig.java
src/main/java/web/multitask/app/config/SecurityConfig.java
+3
-2
ERole.java
src/main/java/web/multitask/app/model/ERole.java
+0
-8
Role.java
src/main/java/web/multitask/app/model/Role.java
+9
-15
HeaderAuthenticationProvider.java
.../multitask/app/provider/HeaderAuthenticationProvider.java
+0
-26
application.properties
src/main/resources/application.properties
+3
-2
app.war
target/app.war
+0
-0
No files found.
src/main/java/web/multitask/app/api/AppApi.java
View file @
69efc884
...
...
@@ -5,6 +5,7 @@ import org.json.JSONObject;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.*
;
import
web.multitask.app.mysql.ProcedureMysql
;
import
web.multitask.app.repository.UserRespository
;
@RestController
@CrossOrigin
(
"*"
)
...
...
@@ -12,9 +13,11 @@ import web.multitask.app.mysql.ProcedureMysql;
public
class
AppApi
{
final
ProcedureMysql
procedureMysql
;
final
UserRespository
userRepo
;
public
AppApi
(
ProcedureMysql
procedureMysql
)
{
public
AppApi
(
ProcedureMysql
procedureMysql
,
UserRespository
userRepo
)
{
this
.
procedureMysql
=
procedureMysql
;
this
.
userRepo
=
userRepo
;
}
@PostMapping
(
"/procedure"
)
...
...
@@ -34,4 +37,9 @@ public class AppApi {
}
}
@GetMapping
(
"/users"
)
public
String
getUsers
(){
return
new
JSONObject
().
put
(
"data"
,
userRepo
.
findAll
()).
put
(
"message"
,
"Success"
).
put
(
"status"
,
true
).
toString
();
}
}
\ No newline at end of file
src/main/java/web/multitask/app/config/SecurityConfig.java
View file @
69efc884
...
...
@@ -49,8 +49,9 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
http
.
cors
(
AbstractHttpConfigurer:
:
disable
).
csrf
(
AbstractHttpConfigurer:
:
disable
)
.
authorizeHttpRequests
(
authorizeRequests
->
authorizeRequests
.
antMatchers
(
"/test/admin"
).
hasRole
(
"ADMIN"
)
.
antMatchers
(
"/test/user"
).
hasRole
(
"USER"
)
authorizeRequests
->
authorizeRequests
.
antMatchers
(
"/test/admin"
).
hasAuthority
(
"ADMIN"
)
.
antMatchers
(
"/test/user"
).
hasAuthority
(
"USER"
)
.
antMatchers
(
HttpMethod
.
GET
,
"/**"
).
permitAll
()
.
antMatchers
(
HttpMethod
.
POST
,
"/**"
).
permitAll
()
.
anyRequest
()
...
...
src/main/java/web/multitask/app/model/ERole.java
deleted
100644 → 0
View file @
b8ffb757
package
web
.
multitask
.
app
.
model
;
public
enum
ERole
{
ROLE_USER
,
ROLE_MODERATOR
,
ROLE_ADMIN
}
\ No newline at end of file
src/main/java/web/multitask/app/model/Role.java
View file @
69efc884
package
web
.
multitask
.
app
.
model
;
;
import
lombok.Getter
;
import
lombok.NoArgsConstructor
;
import
lombok.NonNull
;
import
lombok.Setter
;
import
javax.persistence.*
;
@Getter
@Setter
@Entity
@Table
(
name
=
"roles"
)
@Getter
public
class
Role
{
@NonNull
@Id
@GeneratedValue
(
strategy
=
GenerationType
.
IDENTITY
)
private
Integer
id
;
@Enumerated
(
EnumType
.
STRING
)
@Column
(
length
=
20
)
private
ERole
name
;
public
Role
()
{
}
@GeneratedValue
(
strategy
=
GenerationType
.
AUTO
)
private
int
id
;
@NonNull
private
String
descripcion
;
public
Role
(
ERole
name
)
{
this
.
name
=
name
;
}
}
\ No newline at end of file
src/main/java/web/multitask/app/provider/HeaderAuthenticationProvider.java
deleted
100644 → 0
View file @
b8ffb757
package
web
.
multitask
.
app
.
provider
;
import
org.springframework.security.authentication.AuthenticationProvider
;
import
org.springframework.security.authentication.UsernamePasswordAuthenticationToken
;
import
org.springframework.security.core.Authentication
;
import
org.springframework.security.core.AuthenticationException
;
import
java.util.ArrayList
;
import
org.springframework.stereotype.Component
;
@Component
public
class
HeaderAuthenticationProvider
implements
AuthenticationProvider
{
@Override
public
Authentication
authenticate
(
Authentication
authentication
)
throws
AuthenticationException
{
String
name
=
authentication
.
getName
();
String
password
=
authentication
.
getCredentials
().
toString
();
return
new
UsernamePasswordAuthenticationToken
(
name
,
password
,
new
ArrayList
<>());
}
@Override
public
boolean
supports
(
Class
<?>
authentication
)
{
return
authentication
.
equals
(
UsernamePasswordAuthenticationToken
.
class
);
}
}
\ No newline at end of file
src/main/resources/application.properties
View file @
69efc884
...
...
@@ -4,7 +4,7 @@ spring.datasource.password=asd123
spring.datasource.driverClassName
=
com.mysql.cj.jdbc.Driver
server.port
=
8080
server.address
=
0.0.0.0
spring.jpa.show-sql
=
true
app.jwtSecret
=
9a4f2c8d3b7a1e6f45c8a0b3f267d8b1d4e6f3c8a9d2b5f8e3a9c8b5f6v8a3d9
spring.jpa.hibernate.ddl-auto
=
update
spring.security.filter.order
=
1
\ No newline at end of file
target/app.war
View file @
69efc884
No preview for this file type
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment