Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
INB
eTRANSAFE
pretox-rest-api
Commits
e24606cc
Commit
e24606cc
authored
Oct 07, 2021
by
Javi Corvi
Browse files
development
parent
38d6aeab
Pipeline
#24992
passed with stage
in 4 minutes and 22 seconds
Changes
8
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
pom.xml
View file @
e24606cc
...
...
@@ -51,7 +51,10 @@
<artifactId>
spring-boot-devtools
</artifactId>
<optional>
true
</optional>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-security
</artifactId>
</dependency>
<!-- <dependency>
<groupId>org.springframework.boot</groupId>
...
...
src/main/java/es/bsc/inb/ades/rest/api/controllers/DocumentController.java
View file @
e24606cc
package
es.bsc.inb.ades.rest.api.controllers
;
import
java.security.Principal
;
import
java.util.List
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -7,6 +8,7 @@ import org.springframework.http.HttpHeaders;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.MediaType
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.ui.Model
;
import
org.springframework.web.bind.annotation.CrossOrigin
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestMapping
;
...
...
@@ -23,6 +25,11 @@ public class DocumentController {
@Autowired
public
DocumentService
documentService
;
@RequestMapping
(
"/api/v1/basicauth"
)
public
String
validateLogin
(
Model
model
,
Principal
principal
)
{
return
"login correct"
;
}
@RequestMapping
(
"/documents/"
)
public
List
<
Document
>
findAll
()
{
return
documentService
.
findAll
();
...
...
src/main/java/es/bsc/inb/ades/rest/api/security/WebController.java
View file @
e24606cc
...
...
@@ -9,9 +9,9 @@ import java.security.Principal;
@Controller
public
class
WebController
{
@RequestMapping
(
"/"
)
@RequestMapping
(
"/
api/v1/nada
"
)
public
String
index
(
Model
model
,
Principal
principal
)
{
return
"
index
"
;
return
"
login correct
"
;
}
@GetMapping
(
"/greeting"
)
public
String
greeting
(
@RequestParam
(
name
=
"name"
,
required
=
false
,
defaultValue
=
"World"
)
String
name
,
Model
model
)
{
...
...
src/main/java/es/bsc/inb/ades/rest/api/security/basic/inmemory/AuthenticationBean.java
0 → 100644
View file @
e24606cc
package
es.bsc.inb.ades.rest.api.security.basic.inmemory
;
public
class
AuthenticationBean
{
private
String
message
;
public
AuthenticationBean
(
String
message
)
{
this
.
message
=
message
;
}
public
String
getMessage
()
{
return
message
;
}
public
void
setMessage
(
String
message
)
{
this
.
message
=
message
;
}
@Override
public
String
toString
()
{
return
String
.
format
(
"HelloWorldBean [message=%s]"
,
message
);
}
}
src/main/java/es/bsc/inb/ades/rest/api/security/basic/inmemory/BasicAuthenticationController.java
0 → 100644
View file @
e24606cc
package
es.bsc.inb.ades.rest.api.security.basic.inmemory
;
import
org.springframework.web.bind.annotation.CrossOrigin
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RestController
;
//Controller
@CrossOrigin
(
origins
={
"http://localhost:3000"
,
"http://localhost:4200"
,
"http://localhost:8081"
})
@RestController
public
class
BasicAuthenticationController
{
@GetMapping
(
path
=
"/basicauth"
)
public
AuthenticationBean
helloWorldBean
()
{
//throw new RuntimeException("Some Error has Happened! Contact Support at ***-***");
return
new
AuthenticationBean
(
"You are authenticated"
);
}
}
src/main/java/es/bsc/inb/ades/rest/api/security/basic/inmemory/SecurityConfig.java
0 → 100644
View file @
e24606cc
package
es.bsc.inb.ades.rest.api.security.basic.inmemory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.http.HttpMethod
;
import
org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder
;
import
org.springframework.security.config.annotation.web.builders.HttpSecurity
;
import
org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter
;
@Configuration
public
class
SecurityConfig
extends
WebSecurityConfigurerAdapter
{
@Override
protected
void
configure
(
HttpSecurity
http
)
throws
Exception
{
http
.
csrf
().
disable
().
authorizeRequests
().
antMatchers
(
HttpMethod
.
OPTIONS
,
"/**"
).
permitAll
().
anyRequest
().
authenticated
()
.
and
().
httpBasic
();
}
@Autowired
public
void
configureGlobal
(
AuthenticationManagerBuilder
auth
)
throws
Exception
{
auth
.
inMemoryAuthentication
().
withUser
(
"admin"
).
password
(
"{noop}password"
).
roles
(
"USER"
);
}
}
src/main/resources/application-prod.properties
View file @
e24606cc
spring.application.name
=
ades_rest_api
#Spring Boot Port
server.port
=
${SERVER_PORT}
#ADES Database
spring.data.mongodb.uri
=
${MONGO_URI}/etransafe
#PRETOX Database
spring.data.mongodb.uri
=
${MONGO_URI}
src/main/resources/application.properties
View file @
e24606cc
...
...
@@ -3,7 +3,8 @@ spring.application.name =ades_rest_api
#server.port = ${SERVER_PORT}
server.port
=
8090
#ADES Database
spring.data.mongodb.uri
=
mongodb://localhost:27017/etransafe
#spring.data.mongodb.uri=mongodb://localhost:27017/etransafe
spring.data.mongodb.uri
=
mongodb://etransafe_rw:etransafe_rw2019!@mdb-login.bsc.es:27017/etransafe
#development enviroment
#docker run -d -p 27017-27019:27017-27019 -v /home/javi/eTRANSAFE_DATA/mongo-data-dev://data/db --name mongodb mongo:4.0.4
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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