I want to make a client make REST calls to a jhipster generated webapp. And i seem to mis a bit of information to do it.
what i found is in the application.yml i need to enable the cors options. so i uncommented the following:
jhipster:
cors: #By default CORS are not enabled. Uncomment to enable.
allowed-origins: "*"
allowed-methods: GET, PUT, POST, DELETE, OPTIONS
allowed-headers: "*"
exposed-headers:
allow-credentials: true
max-age: 1800
Which should make REST calls possible.
I think i also need to enable this, but i'm not sure:
security:
basic:
enabled: true
I would expect that i could make a call like this:
import com.fasterxml.jackson.databind.ObjectMapper;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter;
....
Client client = Client.create();
client.addFilter(new HTTPBasicAuthFilter("admin", "admin"));
WebResource webResource = client.resource("http://localhost:8080/api/example");
But i get a 401. So Am i missing something?
here my .yo-rc.json file:
{
"generator-jhipster": {
"jhipsterVersion": "3.0.0",
"baseName": "tinybotsWeb",
"packageName": "nl.tinybots.web",
"packageFolder": "nl/tinybots/web",
"serverPort": "8080",
"authenticationType": "session",
"hibernateCache": "ehcache",
"clusteredHttpSession": "no",
"websocket": "no",
"databaseType": "sql",
"devDatabaseType": "mysql",
"prodDatabaseType": "mysql",
"searchEngine": "elasticsearch",
"buildTool": "maven",
"enableSocialSignIn": true,
"rememberMeKey": "6799bca03613c99e29cd3c1bb7ac878157250d87",
"useSass": false,
"applicationType": "monolith",
"testFrameworks": [
"gatling",
"cucumber",
"protractor"
],
"enableTranslation": true,
"nativeLanguage": "nl",
"languages": [
"nl",
"en",
"de"
]
}
}
i added the following to the SecuryConfiguration:
http
.csrf()
.ignoringAntMatchers("/basicAuthApi/**")
...
.and()
.authorizeRequests()
.antMatchers("/basicAuthApi/**")
.hasAuthority(AuthoritiesConstants.BASIC_AUTH).and().httpBasic()
...
And now i can make the request.
My question now is: is the how i should do it? is this secure? what is this doing?:
security:
basic:
enabled: true