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
#!/bin/bash | |
mkfifo pipe | |
APP_NAME="xxx" | |
GRADLE_OR_MAVEN="gradle" | |
JAR_NAME="xxx-0.0.1-SNAPSHOT.jar" | |
# Set to 0 for standard startup | |
# Only for Java 21+ and Spring Boot 3.3 | |
# - Set to 1 to use fast startup with the new JAR format |
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
/* | |
implementation("com.google.apis:google-api-services-forms:v1-rev20220307-1.32.1") | |
implementation("com.google.apis:google-api-services-drive:v3-rev20220214-1.32.1") | |
implementation ("com.google.api-client:google-api-client-jackson2:1.28.1") | |
implementation("com.google.auth:google-auth-library-oauth2-http:1.5.3") | |
*/ | |
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport; | |
import com.google.api.client.json.JsonFactory; | |
import com.google.api.client.json.jackson2.JacksonFactory; |
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
import com.google.api.services.forms.v1.model.ListFormResponsesResponse; | |
import java.io.IOException; | |
private static void readResponses(String formId, String token) throws IOException { | |
ListFormResponsesResponse response = formsService.forms().responses().list(formId).setOauthToken(token).execute(); | |
System.out.println(response.toPrettyString()); | |
} |
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
import com.google.api.services.drive.model.Permission; | |
import com.google.api.services.drive.model.PermissionList; | |
import java.io.IOException; | |
import java.security.GeneralSecurityException; | |
public boolean publishForm(String formId, String token) throws GeneralSecurityException, IOException { | |
PermissionList list = driveService.permissions().list(formId).setOauthToken(token).execute(); |
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
private static void main_chapter3() { | |
//0- access token, from the previous chapter | |
String token = getAccessToken(); | |
//1- create a new form | |
String formId = createNewForm(token); | |
//2- transform it into a quiz | |
transformInQuiz(formId,token); |
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
import com.google.api.services.forms.v1.FormsScopes; | |
import com.google.auth.oauth2.GoogleCredentials; | |
import java.io.IOException; | |
import java.util.Objects; | |
public static String getAccessToken() throws IOException { | |
GoogleCredentials credential = GoogleCredentials.fromStream(Objects.requireNonNull( | |
Main.class.getResourceAsStream("cred.json"))).createScoped(FormsScopes.all()); | |
return credential.getAccessToken() != null ? |
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
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport; | |
import com.google.api.client.json.JsonFactory; | |
import com.google.api.client.json.jackson2.JacksonFactory; | |
import com.google.api.services.drive.Drive; | |
import com.google.api.services.forms.v1.Forms; | |
import java.io.IOException; | |
import java.security.GeneralSecurityException; | |
public class Boilerplate { |
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
@Configuration | |
@AutoConfigureAfter(RedisAutoConfiguration.class) | |
public class CacheConfig { | |
public final static String BLACKLIST_CACHE_NAME = "jwt-black-list"; | |
@Value("${jwt.duration:0}") | |
private int tokenDuration; | |
@Value("${spring.redis.host:localhost}") | |
private String redisHost; |
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
@Service | |
public class BlackListingService { | |
@CachePut(CacheConfig.BLACKLIST_CACHE_NAME) | |
public String blackListJwt(String jwt) { | |
return jwt; | |
} | |
@Cacheable(value = CacheConfig.BLACKLIST_CACHE_NAME, unless = "#result == null") | |
public String getJwtBlackList(String jwt) { |
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
@RestController | |
@RequestMapping("/logout") | |
public class LogoutController { | |
@Autowired | |
private BlackListingService blackListingService; | |
@Autowired | |
private UserRequestScopedBean userRequestScopedBean; |
NewerOlder