Skip to content

Instantly share code, notes, and snippets.

PublicClientApplication app = PublicClientApplication.builder("YOUR_CLIENT_ID")
.authority("https://login.microsoftonline.com/YOUR_TENANT_ID")
.build();
RefreshTokenParameters parameters = RefreshTokenParameters.builder(
Collections.singleton("YOUR_SCOPE"),
"YOUR_REFRESH_TOKEN")
.build();
Future<IAuthenticationResult> future = app.acquireToken(parameters);
POST http://yourserver.com/your-endpoint
Content-Type: multipart/form-data; boundary=boundarystring
--boundarystring
Content-Disposition: form-data; name="file"; filename="sample.txt"
Content-Type: text/plain
< ./path-to-your-file/sample.txt
--boundarystring--
try (OutputStream os = enc.getDataStream(fs)) {
os.write(inputExcel);
}
// Convert the POIFSFileSystem to a byte array
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
fs.writeFilesystem(baos);
return baos.toByteArray();
}
public static byte[] passwordProtectExcel(byte[] inputExcel) throws IOException, GeneralSecurityException {
// Convert the input byte array to a Workbook
XSSFWorkbook workbook = new XSSFWorkbook(new ByteArrayInputStream(inputExcel));
// Prepare to encrypt the workbook
POIFSFileSystem fs = new POIFSFileSystem();
EncryptionInfo info = new EncryptionInfo(EncryptionMode.agile);
Encryptor enc = info.getEncryptor();
enc.confirmPassword("password"); // Set the password here
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<outputDirectory>${project.build.directory}/modified</outputDirectory>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
@Configuration
@EnableSwagger2
public class SpringFoxConfig {
public static final String AUTHORIZATION_HEADER = "Authorization";
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.ignoredParameterTypes(AuthenticationPrincipal.class, DespaniPrincipal.class)
@Bean(name = "piTaskExecutor")
@Primary
public Executor piTaskExecutor() {
log.debug("Creating Async Task Executor");
final ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(4);
executor.setMaxPoolSize(10);
executor.setQueueCapacity(5);
executor.setAllowCoreThreadTimeOut(false);
executor.setThreadNamePrefix("PiExecutor-");
public static String getURL(HttpServletRequest curRequest) {
if(curRequest ==null) {
return "https://treespond.com/";
}
String scheme = curRequest.getScheme(); // http
String serverName = curRequest .getServerName(); // hostname.com
int serverPort = curRequest .getServerPort(); // 80
List<MyObject> largeList = /* your large list */;
List<MyObject> smallList = /* your small list */;
Collections.sort(largeList, Comparator.comparing(MyObject::getTicker));
List<MyObject> matchingObjects = smallList.stream()
.filter(item -> Collections.binarySearch(largeList, item, Comparator.comparing(MyObject::getTicker)) >= 0)
.collect(Collectors.toList());
public class JWTAuthenticationEntryPoint implements AuthenticationEntryPoint {
@Override
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception)
throws IOException, ServletException {
response.setStatus(403);
response.setContentType(MediaType. APPLICATION_JSON_VALUE);
String message;
if (exception.getCause() != null) {