Skip to content

Instantly share code, notes, and snippets.

@MrMjauh
MrMjauh / elastic-migration.py
Last active September 29, 2021 03:43
Migrate between elastic env
#
# Only tested on Kibana 7.1.1 management
#
import argparse
import json
import uuid
from elasticsearch import Elasticsearch
@MrMjauh
MrMjauh / Assets.cs
Created November 25, 2019 22:19
Asset
public class Transform
{
private ulong instanceId = ulong.MaxValue;
public Transform(ulong InstanceId)
{
this.instanceId = InstanceId;
}
public Transform()
{
@MrMjauh
MrMjauh / AuthTest.java
Last active July 2, 2019 23:16
AuthTest
@ExtendWith(SpringExtension.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ActiveProfiles("prod")
public class AuthTest {
@MockBean
private IUserService userService;
@MockBean
@MrMjauh
MrMjauh / Controller.java
Created June 30, 2019 21:16
Controller
@RestController
@RequestMapping("/user")
public class UserController {
private IUserService userService;
@Autowired
public UserController(IUserService userService) {
this.userService = userService;
}
@MrMjauh
MrMjauh / MetaAnnotations.java
Created June 30, 2019 21:09
MetaAnnotations
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@PreAuthorize("hasAuthority('" + SecurityResource.Role.ADMIN + "')")
public @interface AccessAdmin {
}
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@PreAuthorize("hasAnyAuthority('" + SecurityResource.Role.ADMIN + "','" + SecurityResource.Role.USER + "')")
@MrMjauh
MrMjauh / TokenAuthenticationFilter.java
Created June 30, 2019 21:04
TokenAuthenticationFilter.java
public class TokenAuthenticationFilter extends OncePerRequestFilter {
private ITokenService tokenService;
public TokenAuthenticationFilter(ITokenService tokenService) {
Assert.notNull(tokenService, "Can not be null");
this.tokenService = tokenService;
}
@MrMjauh
MrMjauh / Persistance.java
Created June 30, 2019 20:50
Persitance classes conneted to mongodb
@Data
@NoArgsConstructor
@Document(collection = "user")
public class User extends BaseEntity {
@Field("email")
@Indexed(unique = true)
private String email;
@Field("token")
@MrMjauh
MrMjauh / Webconfig.java
Last active June 27, 2019 22:02
Deny all
package com.codecamos.timetracking.config;
import javax.servlet.http.HttpServletResponse;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
@MrMjauh
MrMjauh / ExcpetionHandlingBundle.java
Last active June 28, 2019 11:25
Excpetion Handling
package com.codecamos.timetracking.config;
@ControllerAdvice
public class RestResponseEntityExceptionHandler extends ResponseEntityExceptionHandler {
private Environment env;
private static final Logger logger = LogManager.getLogger(RestResponseEntityExceptionHandler.class);
public static final HttpStatus DEFAULT_STATUS_CODE = HttpStatus.BAD_REQUEST;
@MrMjauh
MrMjauh / Resource.java
Last active July 10, 2019 08:31
Resource file
package com.codecamos.timetracking.config;
public final class Resource {
private Resource() { }
/**
* @param activeProfiles The current active profiles this application was started with, {@link Profile} for available profiles
* @return returns true if we are in dev or stage
*/