43 lines
1.4 KiB
Java
43 lines
1.4 KiB
Java
package enseirb.myinpulse.api;
|
|
|
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
import org.springframework.security.core.context.SecurityContextHolder;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import javax.management.relation.RoleNotFoundException;
|
|
import java.security.Principal;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
@SpringBootApplication
|
|
@RestController
|
|
public class GetUserInfo {
|
|
// TODO: understand how to get data
|
|
@GetMapping("/getUserInfo")
|
|
public Object user(Principal principal) {
|
|
System.out.println("GetUserInfo + " + principal);
|
|
System.out.println(SecurityContextHolder.getContext().getAuthentication());
|
|
return SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
|
}
|
|
|
|
@CrossOrigin(methods = {RequestMethod.GET, RequestMethod.OPTIONS})
|
|
@GetMapping("/unauth/random")
|
|
public boolean rand(@RequestHeader("Authorization") String token) throws RoleNotFoundException {
|
|
System.err.println(token);
|
|
System.err.println("HELLO");
|
|
return Math.random() > 0.5;
|
|
}
|
|
|
|
@GetMapping("/admin/random")
|
|
public boolean rand2() {
|
|
return Math.random() > 0.5;
|
|
}
|
|
|
|
@GetMapping("/entrepreneur/random")
|
|
public boolean rand3() {
|
|
return Math.random() > 0.5;
|
|
}
|
|
}
|