-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
80 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.oauth2.controllers; | ||
|
||
import java.util.UUID; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.security.access.prepost.PreAuthorize; | ||
import org.springframework.security.core.userdetails.UsernameNotFoundException; | ||
import org.springframework.web.bind.annotation.DeleteMapping; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import com.oauth2.entities.User; | ||
import com.oauth2.models.dto.auth.AuthUserRoleAndAuthoritiesDTO; | ||
import com.oauth2.services.IUserService; | ||
|
||
import io.swagger.annotations.Api; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@RequestMapping("/auth") | ||
@Api(tags="Authorities", description="This is about Authentication") | ||
@RestController | ||
@Slf4j | ||
public class AuthController { | ||
|
||
@Autowired | ||
private IUserService userService; | ||
|
||
@GetMapping(value = "/authorities/{uuid}", produces = MediaType.APPLICATION_JSON_VALUE) | ||
public ResponseEntity<AuthUserRoleAndAuthoritiesDTO> getAuthorities(@PathVariable String uuid){ | ||
try { | ||
UUID uuid_user = UUID.fromString(uuid.toString()); | ||
|
||
User user = userService.findByUuid(uuid_user) | ||
.orElseThrow(() -> new UsernameNotFoundException("Error -> hasPermission for UUID: " + uuid_user)); | ||
|
||
return ResponseEntity.ok(new AuthUserRoleAndAuthoritiesDTO(user)); | ||
} catch (IllegalArgumentException ie) { | ||
log.error("Error method getAuthorities in class AuthController: "+ie.getMessage()); | ||
return ResponseEntity.badRequest().build();//400 | ||
} | ||
catch (Exception ex) { | ||
log.error("Error method getAuthorities in class AuthController: "+ex.getMessage()); | ||
return ResponseEntity.badRequest().build();//400 | ||
} | ||
} | ||
|
||
@PreAuthorize("hasPermission(returnObject, {'user_create', 'user_update', 'abcd_create', 'abcd_read', 'user_read'})") | ||
@DeleteMapping("/test") | ||
public ResponseEntity<String> testAuthorities(){ | ||
System.out.print("I'm in the method!"); | ||
return ResponseEntity.ok(new String("OK -> Permission OK")); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,21 @@ | ||
package com.oauth2.controllers; | ||
|
||
import java.util.UUID; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.security.access.prepost.PreAuthorize; | ||
import org.springframework.security.core.userdetails.UsernameNotFoundException; | ||
import org.springframework.web.bind.annotation.DeleteMapping; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.ResponseBody; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import com.oauth2.entities.User; | ||
import com.oauth2.models.dto.auth.AuthUserRoleAndAuthoritiesDTO; | ||
import com.oauth2.services.IUserService; | ||
|
||
import io.swagger.annotations.Api; | ||
|
||
@RequestMapping("/") | ||
@Api(tags="Home - Test", description="Test Request") | ||
@Api(tags="Home - Test", description="Unrestricted request testing") | ||
@RestController | ||
public class HomeController { | ||
|
||
@Autowired | ||
private IUserService userService; | ||
|
||
@GetMapping() | ||
@ResponseBody | ||
public String home() { | ||
return "Hello World - Welcome API REST"; | ||
} | ||
|
||
@GetMapping(value = "authorities/{uuid}", produces = MediaType.APPLICATION_JSON_VALUE) | ||
public ResponseEntity<AuthUserRoleAndAuthoritiesDTO> getAuthorities(@PathVariable String uuid){ | ||
|
||
try { | ||
UUID uuid_user = UUID.fromString(uuid.toString()); | ||
|
||
User user = userService.findByUuid(uuid_user) | ||
.orElseThrow(() -> new UsernameNotFoundException("Error -> hasPermission for UUID: " + uuid_user)); | ||
|
||
AuthUserRoleAndAuthoritiesDTO dto = new AuthUserRoleAndAuthoritiesDTO(user); | ||
|
||
return ResponseEntity.ok(dto); | ||
} catch (Exception e) { | ||
return null; | ||
} | ||
|
||
|
||
} | ||
|
||
|
||
@PreAuthorize("hasPermission(returnObject, {'user_create', 'user_update', 'abcd_create', 'abcd_read', 'user_read'})") | ||
@DeleteMapping("/user") | ||
public ResponseEntity<String> update(){ | ||
System.out.print("I'm in the method!"); | ||
return ResponseEntity.ok(new String("OK -> Permission OK")); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,5 @@ public AuthRolesDTO(Role role) { | |
.map(AuthPermissionsDTO::new) | ||
.collect(Collectors.toList())); | ||
} | ||
|
||
|
||
} |
17 changes: 0 additions & 17 deletions
17
src/main/java/com/oauth2/repositories/IPermissionRepository.java
This file was deleted.
Oops, something went wrong.
13 changes: 0 additions & 13 deletions
13
src/main/java/com/oauth2/repositories/IRoleRepository.java
This file was deleted.
Oops, something went wrong.