diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/config/SpringFoxConfig.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/config/SpringFoxConfig.java index 2fdab4e..971a7fb 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/config/SpringFoxConfig.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/config/SpringFoxConfig.java @@ -1,6 +1,5 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.config; - import java.util.List; import java.util.function.Predicate; import org.springframework.context.annotation.Bean; @@ -75,7 +74,8 @@ public class SpringFoxConfig { .or(PathSelectors.regex("/sensor.*")::apply) .or(PathSelectors.regex("/smartPlug.*")::apply) .or(PathSelectors.regex("/switch.*")::apply) - .or(PathSelectors.regex("/motionSensor.*")::apply); + .or(PathSelectors.regex("/motionSensor.*")::apply) + .or(PathSelectors.regex("/auth/profile.*")::apply); } /** diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/AuthenticationController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/AuthenticationController.java index d26eed4..ad48da2 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/AuthenticationController.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/AuthenticationController.java @@ -6,6 +6,7 @@ import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.JWTResponse; import ch.usi.inf.sa4.sanmarinoes.smarthut.error.UnauthorizedException; import ch.usi.inf.sa4.sanmarinoes.smarthut.error.UserNotFoundException; import ch.usi.inf.sa4.sanmarinoes.smarthut.models.*; +import java.security.Principal; import javax.validation.Valid; import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.authentication.BadCredentialsException; @@ -69,6 +70,11 @@ public class AuthenticationController { return new JWTResponse(token); } + @GetMapping("/profile") + public User profile(final Principal principal) { + return userRepository.findByUsername(principal.getName()); + } + private void authenticate(String username, String password) throws UnauthorizedException { try { authenticationManager.authenticate( diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/User.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/User.java index dc6766d..60aad17 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/User.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/User.java @@ -1,5 +1,6 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models; +import ch.usi.inf.sa4.sanmarinoes.smarthut.config.GsonExclude; import io.swagger.annotations.ApiModelProperty; import java.util.Objects; import javax.persistence.*; @@ -24,6 +25,7 @@ public class User { /** A properly salted way to store the password */ @Column(nullable = false) + @GsonExclude private String password; /** @@ -34,7 +36,7 @@ public class User { private String email; @Column(nullable = false) - @ApiModelProperty(hidden = true) + @GsonExclude private Boolean isEnabled = false; public Long getId() {