Skip to content

Instantly share code, notes, and snippets.

View Enigo's full-sized avatar

Ruslan S. Enigo

View GitHub Profile
@Enigo
Enigo / 11.cs
Last active February 23, 2021 22:39
public class OrientationSetter : MonoBehaviour
{
private static IEnumerator SetupInitialOrientation()
{
if (PlayerPrefsUtils.HasOrientation())
{
if (PlayerPrefsUtils.IsPortrait())
{
SetupPortraitOrientation();
if (Screen.orientation != ScreenOrientation.Portrait)
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.1</version>
<relativePath/>
</parent>
@RestController
@RequestMapping(path = "/zoo")
public class ZooController {
@PostMapping(path = "/add", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public String addAnimal(@RequestBody String payload) {
return "OK from post addAnimal";
}
@GetMapping(path = "/all")
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-oauth2-client</artifactId>
</dependency>
@EnableConfigurationProperties(OneLoginConfigs.class)
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@Configuration
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
private final OneLoginConfigs oneLoginConfigs;
@Override
public void configure(final HttpSecurity http) throws Exception {
http.authorizeRequests()
@Setter
@Getter
@ConfigurationProperties(prefix = "onelogin")
public class OneLoginConfigs {
private String clientId;
private String clientSecret;
}
---
onelogin:
client-id: id
client-secret: secret
@RequiredArgsConstructor
public enum Role implements GrantedAuthority {
ADMIN(Code.ADMIN),
USER(Code.USER);
private final String authority;
@Override
public String getAuthority() {
return authority;
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
private static final String GROUPS = "groups";
@Override
public void configure(final HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/", "/login**", "/oauth2/authorization/**").permitAll()
.antMatchers("/zoo/add/**").access("hasRole('ADMIN')")
.antMatchers("/zoo/all/**").access("hasAnyRole('ADMIN, USER')")
.anyRequest().authenticated()
@RestController
@RequestMapping(path = "/zoo")
public class ZooController {
@Secured(Role.Code.ADMIN)
@PostMapping(path = "/add", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public String addAnimal(@RequestBody String payload) {
return "OK from post addAnimal";
}