access modifiers and constructors fix
This commit is contained in:
parent
44bcc24110
commit
15a4c526b4
@ -9,12 +9,11 @@ import org.springframework.data.jpa.repository.Query;
|
|||||||
import org.springframework.data.repository.query.Param;
|
import org.springframework.data.repository.query.Param;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
//if result could be null, should we wrapped in optional
|
|
||||||
@Repository
|
@Repository
|
||||||
public interface UserRepository extends JpaRepository<User, Long> {
|
public interface UserRepository extends JpaRepository<User, Long> {
|
||||||
@Query("FROM User WHERE email = ?1")
|
@Query("FROM User WHERE email = ?1")
|
||||||
Optional<User> getByAuthority(@Param("authority") String authority);
|
Optional<User> getByAuthority(@Param("authority") String authority);
|
||||||
|
|
||||||
@Query("FROM User WHERE token = ?1")
|
@Query("FROM User WHERE token = ?1")
|
||||||
User getByToken(@Param("token") String token);
|
Optional<User> getByToken(@Param("token") String token);
|
||||||
}
|
}
|
@ -1,5 +1,6 @@
|
|||||||
package com.plannaplan.services;
|
package com.plannaplan.services;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import com.plannaplan.entities.User;
|
import com.plannaplan.entities.User;
|
||||||
@ -38,7 +39,7 @@ public class UserService {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public User getByToken(String token) {
|
public Optional<User> getByToken(String token) {
|
||||||
return this.repo.getByToken(token);
|
return this.repo.getByToken(token);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ public class TokenController {
|
|||||||
|
|
||||||
@GetMapping("/token")
|
@GetMapping("/token")
|
||||||
public ResponseEntity<String> getToken(@RequestParam("ticket") final String ticket) {
|
public ResponseEntity<String> getToken(@RequestParam("ticket") final String ticket) {
|
||||||
CasValidator validator = new CasValidator(SERVICE_URL, ticket);
|
final CasValidator validator = new CasValidator(SERVICE_URL, ticket);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String authority = validator.validate();
|
String authority = validator.validate();
|
||||||
|
@ -31,19 +31,11 @@ public class AuthenticationProvider extends AbstractUserDetailsAuthenticationPro
|
|||||||
protected UserDetails retrieveUser(String username, UsernamePasswordAuthenticationToken authentication)
|
protected UserDetails retrieveUser(String username, UsernamePasswordAuthenticationToken authentication)
|
||||||
throws AuthenticationException {
|
throws AuthenticationException {
|
||||||
|
|
||||||
String token = authentication.getCredentials().toString();
|
final String token = authentication.getCredentials().toString();
|
||||||
|
User user = this.userService.getByToken(token)
|
||||||
User user = this.userService.getByToken(token);
|
.orElseThrow(() -> new UsernameNotFoundException("Cannot find user with given authority"));
|
||||||
|
|
||||||
if (user == null) {
|
|
||||||
throw new UsernameNotFoundException("Cannot find user with authentication token=" + token);
|
|
||||||
}
|
|
||||||
|
|
||||||
UserDetails response = new UserDetails() {
|
UserDetails response = new UserDetails() {
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user