Pseudow
Pseudow
JCHJava Community | Help. Code. Learn.
Created by Pseudow on 5/6/2025 in #java-help
Spring Redis
Hi, I am currently using Spring Boot with Redis and I am using the Caching annotations. Do you know why the first time I hit the endpoint Spring will still make a call to my db even though the data is already in my Redis? After that it will take data from Redis.
8 replies
JCHJava Community | Help. Code. Learn.
Created by Pseudow on 8/10/2024 in #java-help
Kotlin coroutine
Hi do you know how do I proceed to have my coroutines run on different threads? I have tried this to speed up:
val threadPoolExecutor: ExecutorService = Executors.newFixedThreadPool(3)
val coroutineDispatcher: CoroutineDispatcher = this.threadPoolExecutor.asCoroutineDispatcher()

withContext(coroutineDispatcher) {
dependencies.forEach { dependency ->
val resolver = resolvers.first { resolver -> resolver.accept(dependency) }

launch { resolver.resolve(dependency) }
}
}
val threadPoolExecutor: ExecutorService = Executors.newFixedThreadPool(3)
val coroutineDispatcher: CoroutineDispatcher = this.threadPoolExecutor.asCoroutineDispatcher()

withContext(coroutineDispatcher) {
dependencies.forEach { dependency ->
val resolver = resolvers.first { resolver -> resolver.accept(dependency) }

launch { resolver.resolve(dependency) }
}
}
but it tourned out it was less fast than concurrent only?
6 replies
JCHJava Community | Help. Code. Learn.
Created by Pseudow on 4/21/2024 in #java-help
Protobuf Proto source set not added
No description
4 replies
JCHJava Community | Help. Code. Learn.
Created by Pseudow on 4/20/2024 in #java-help
hasAuthority Spring doesn't work
Hi I have replaced the default permission evaluator but now it just makes the hasAuthority not working (I am using the same example as the ones on google but it doesn't work with me)
@Bean
fun expressionHandler(@Autowired permissionEvaluator: CustomPermissionEvaluator,
@Autowired roleHierarchy: RoleHierarchy): MethodSecurityExpressionHandler {
val handler = DefaultMethodSecurityExpressionHandler()
handler.setPermissionEvaluator(permissionEvaluator)
handler.setRoleHierarchy(roleHierarchy)

return handler
}
@Bean
fun expressionHandler(@Autowired permissionEvaluator: CustomPermissionEvaluator,
@Autowired roleHierarchy: RoleHierarchy): MethodSecurityExpressionHandler {
val handler = DefaultMethodSecurityExpressionHandler()
handler.setPermissionEvaluator(permissionEvaluator)
handler.setRoleHierarchy(roleHierarchy)

return handler
}
Here is my error Property or field 'hasAuthority' cannot be found on object of type 'org.springframework.security.access.expression.method.MethodSecurityExpressionRoot' - maybe not public or not valid?
6 replies
JCHJava Community | Help. Code. Learn.
Created by Pseudow on 4/19/2024 in #java-help
Ktor Login Bearer Token
How can I make a login step using credentials to retrieve my bearer tokens with Ktor because in the inialization of my client I can't access the client itself?
5 replies
JCHJava Community | Help. Code. Learn.
Created by Pseudow on 4/17/2024 in #java-help
Spring admin authorization
Is it possible to give all authorization to administrators without having to create all existing permissions to add them to the role?
4 replies
JCHJava Community | Help. Code. Learn.
Created by Pseudow on 4/14/2024 in #java-help
Spring Context Holder
How spring context holder works? Does the current user is stored in the client or something like this? Because basically if I made an API should I rely on a JWT or just the context holder is enough?
4 replies
JCHJava Community | Help. Code. Learn.
Created by Pseudow on 3/30/2024 in #java-help
Spring Password Encoder Argon2
Hi I just went into the spring argon2 password encoder and I saw this:
public String encode(CharSequence rawPassword) {
byte[] salt = this.saltGenerator.generateKey();
byte[] hash = new byte[this.hashLength];
Argon2Parameters params = (new Argon2Parameters.Builder(2)).withSalt(salt).withParallelism(this.parallelism).withMemoryAsKB(this.memory).withIterations(this.iterations).build();
Argon2BytesGenerator generator = new Argon2BytesGenerator();
generator.init(params);
generator.generateBytes(rawPassword.toString().toCharArray(), hash);
return Argon2EncodingUtils.encode(hash, params);
}
public String encode(CharSequence rawPassword) {
byte[] salt = this.saltGenerator.generateKey();
byte[] hash = new byte[this.hashLength];
Argon2Parameters params = (new Argon2Parameters.Builder(2)).withSalt(salt).withParallelism(this.parallelism).withMemoryAsKB(this.memory).withIterations(this.iterations).build();
Argon2BytesGenerator generator = new Argon2BytesGenerator();
generator.init(params);
generator.generateBytes(rawPassword.toString().toCharArray(), hash);
return Argon2EncodingUtils.encode(hash, params);
}
spring encode my password with all the params to decode it, so should I rewrite my own password encoder or anything like this?
4 replies
JCHJava Community | Help. Code. Learn.
Created by Pseudow on 3/9/2024 in #java-help
Kotlin Serialization Spring Integration
Hi I encountered a problem, I am currently trying to create unit test in order to test my API responses but I just found out that even by specifying that I want spring to use kotlin serialization to serialize controller responses it doesn't not work. Here is my configuration:
@Configuration
class WebSerializationConfiguration: WebMvcConfigurer {
private val converter = KotlinSerializationJsonHttpMessageConverter(DEFAULT_JSON)

override fun configureMessageConverters(converters: MutableList<HttpMessageConverter<*>>) {
converters.add(this.converter)
}
}
@Configuration
class WebSerializationConfiguration: WebMvcConfigurer {
private val converter = KotlinSerializationJsonHttpMessageConverter(DEFAULT_JSON)

override fun configureMessageConverters(converters: MutableList<HttpMessageConverter<*>>) {
converters.add(this.converter)
}
}
I even tried to just remove the json from my dependency:
implementation("org.springframework.boot:spring-boot-starter-web") {
exclude("org.springframework.boot:spring-boot-starter-json")
}
implementation("org.springframework.boot:spring-boot-starter-web") {
exclude("org.springframework.boot:spring-boot-starter-json")
}
But it doesn't work and I get a weird serializable
5 replies
JCHJava Community | Help. Code. Learn.
Created by Pseudow on 3/9/2024 in #java-help
Kotlin Serialization
Hi guys do you know why do I get an error from my kotlin code?
@Serializable(with = DefinitionExceptionSerializer::class)
sealed class DefinitionException(
val id: String,
override val message: String
): Exception(message)

@Serializable
class InvitationAlreadySentException(val expire: Instant): DefinitionException(
"${Invitation.ENTITY_NAME}-already-sent",
"Invite already pending, you will be able to try again in ${expire.epochSecond - Instant.now().epochSecond}"
)
@Serializable(with = DefinitionExceptionSerializer::class)
sealed class DefinitionException(
val id: String,
override val message: String
): Exception(message)

@Serializable
class InvitationAlreadySentException(val expire: Instant): DefinitionException(
"${Invitation.ENTITY_NAME}-already-sent",
"Invite already pending, you will be able to try again in ${expire.epochSecond - Instant.now().epochSecond}"
)
I get this error from the class InvitationAlreadySentException Impossible to make this class serializable because its parent is not serializable and does not have exactly one constructor without parameters
4 replies
JCHJava Community | Help. Code. Learn.
Created by Pseudow on 3/1/2024 in #java-help
Spring Security Mock MVC Test
Hi I am trying to use Spring to test my controller but here is the definition of my test class:
@SpringBootTest(
webEnvironment = SpringBootTest.WebEnvironment.MOCK,
classes = [ProfileController::class]
)
@AutoConfigureMockMvc(addFilters = false)
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@TestMethodOrder(MethodOrderer.OrderAnnotation::class)
@ActiveProfiles("test", REST_API_PROFILE_NAME)
@DisplayName("Profile Controller Test")
class ProfileControllerTest
@SpringBootTest(
webEnvironment = SpringBootTest.WebEnvironment.MOCK,
classes = [ProfileController::class]
)
@AutoConfigureMockMvc(addFilters = false)
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@TestMethodOrder(MethodOrderer.OrderAnnotation::class)
@ActiveProfiles("test", REST_API_PROFILE_NAME)
@DisplayName("Profile Controller Test")
class ProfileControllerTest
In the SpringBootTest#classes method I specified my controller but when I run it, Spring doesn't automatically create all needed beans for example ProfileService or ProfileDao
4 replies
JCHJava Community | Help. Code. Learn.
Created by Pseudow on 2/22/2024 in #java-help
Snowflake x Spring
Hi I am planning on using Snowflake algorithm to generate ids, but I wanted to know more about it so basically there are three ways of customizing it with the timestamp bits, the generator bits and sequence bits. The addition of all those bits have to equal 63 bits but what is the best way to make it work with my spring application? Each backend instance would have an unique generator id? Because if for example there are two backends that receives one request at the same time to send a message for example with the same generator id it could potentially create two same ids?
7 replies
JCHJava Community | Help. Code. Learn.
Created by Pseudow on 2/3/2024 in #java-help
Spring Security
Hi is it possible to modify how spring security deals with passwords? Actually I would like my password to stay only in my database and never retrieve it just checking if for the account the password matches. But everywhere including in UserDetails I have to give access to the password to Spring.
45 replies