no message

This commit is contained in:
annabakouli 2017-12-19 11:02:25 +02:00
parent 3e5e550cee
commit 8bec0a6cf0
5 changed files with 35 additions and 7 deletions

View File

@ -1,6 +1,8 @@
package eu.eudat.configurations; package eu.eudat.configurations;
import eu.eudat.handlers.PrincipalArgumentResolver; import eu.eudat.handlers.PrincipalArgumentResolver;
import eu.eudat.services.AuthenticationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodArgumentResolver; import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
@ -13,9 +15,10 @@ import java.util.List;
@Configuration @Configuration
public class WebMVCConfiguration extends WebMvcConfigurerAdapter { public class WebMVCConfiguration extends WebMvcConfigurerAdapter {
@Autowired
AuthenticationService authenticationService;
@Override @Override
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) { public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
argumentResolvers.add(new PrincipalArgumentResolver()); argumentResolvers.add(new PrincipalArgumentResolver(this.authenticationService));
} }
} }

View File

@ -24,7 +24,7 @@ public class DashBoardController {
@Autowired private ProjectDao projectDao; @Autowired private ProjectDao projectDao;
@RequestMapping(method = RequestMethod.GET, value = { "/dashboard/getStatistics" }, produces="application/json") @RequestMapping(method = RequestMethod.GET, value = { "/dashboard/getStatistics" }, produces="application/json")
public ResponseItem<DashBoardStatistics> getStatistics(){ public ResponseItem<DashBoardStatistics> getStatistics(Principal principal){
try { try {
DashBoardStatistics statistics = new DashBoardManager().getStatistics(datasetDao, dMPDao, projectDao); DashBoardStatistics statistics = new DashBoardManager().getStatistics(datasetDao, dMPDao, projectDao);
return new ResponseItem<DashBoardStatistics>().status(HttpStatus.OK).payload(statistics); return new ResponseItem<DashBoardStatistics>().status(HttpStatus.OK).payload(statistics);

View File

@ -5,6 +5,7 @@ import eu.eudat.models.helpers.responses.ResponseItem;
import eu.eudat.models.login.LoginInfo; import eu.eudat.models.login.LoginInfo;
import eu.eudat.models.security.Principal; import eu.eudat.models.security.Principal;
import eu.eudat.security.CustomAuthenticationProvider; import eu.eudat.security.CustomAuthenticationProvider;
import eu.eudat.services.AuthenticationService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -14,12 +15,14 @@ import org.springframework.web.bind.annotation.*;
*/ */
@RestController @RestController
@CrossOrigin @CrossOrigin
@RequestMapping(value = "/login") @RequestMapping(value = "/auth")
public class Login { public class Login {
@Autowired @Autowired
private CustomAuthenticationProvider customAuthenticationProvider; private CustomAuthenticationProvider customAuthenticationProvider;
@Autowired
private AuthenticationService authenticationService;
@RequestMapping(method = RequestMethod.POST, value = { "/externallogin" }, consumes = "application/json", produces="application/json") @RequestMapping(method = RequestMethod.POST, value = { "/externallogin" }, consumes = "application/json", produces="application/json")
public @ResponseBody ResponseItem<Principal> googleLogin(@RequestBody LoginInfo credentials) { public @ResponseBody ResponseItem<Principal> googleLogin(@RequestBody LoginInfo credentials) {
try { try {
@ -30,4 +33,27 @@ public class Login {
return new ResponseItem<Principal>().status(HttpStatus.BAD_REQUEST).message(ex.getMessage()); return new ResponseItem<Principal>().status(HttpStatus.BAD_REQUEST).message(ex.getMessage());
} }
} }
@RequestMapping(method = RequestMethod.POST, value = { "/me" }, consumes = "application/json", produces="application/json")
public @ResponseBody ResponseItem<Principal> authMe(Principal principal) {
try {
return new ResponseItem<Principal>().payload(this.authenticationService.Touch(principal.getToken())).status(HttpStatus.OK);
} catch (Exception ex) {
ex.printStackTrace();
return new ResponseItem<Principal>().status(HttpStatus.BAD_REQUEST).message(ex.getMessage());
}
}
@RequestMapping(method = RequestMethod.POST, value = { "/logout" }, consumes = "application/json", produces="application/json")
public @ResponseBody ResponseItem<Principal> logout(Principal principal) {
try {
this.authenticationService.Logout(principal.getToken());
return new ResponseItem<Principal>().status(HttpStatus.OK);
} catch (Exception ex) {
ex.printStackTrace();
return new ResponseItem<Principal>().status(HttpStatus.BAD_REQUEST).message(ex.getMessage());
}
}
} }

View File

@ -40,8 +40,7 @@ public final class PrincipalArgumentResolver implements HandlerMethodArgumentRes
return principal; return principal;
} }
@Autowired public PrincipalArgumentResolver(AuthenticationService authenticationService){
private void PrincipalArgumentResolver(AuthenticationService authenticationService){
this.authenticationService = authenticationService; this.authenticationService = authenticationService;
} }

View File

@ -24,7 +24,7 @@ export class AuthService {
public router: Router public router: Router
) { ) {
this.actionUrl = HostConfiguration.Server + 'login/'; this.actionUrl = HostConfiguration.Server + 'auth/';
this.headers = new HttpHeaders(); this.headers = new HttpHeaders();
this.headers = this.headers.set('Content-Type', 'application/json'); this.headers = this.headers.set('Content-Type', 'application/json');