forbid spaces in login field, see #16
This commit is contained in:
parent
f0d30ec6ed
commit
0e57c57ccc
@ -1,5 +1,5 @@
|
||||
plugins {
|
||||
id 'org.springframework.boot' version '3.2.3'
|
||||
id 'org.springframework.boot' version '3.2.4'
|
||||
id "io.spring.dependency-management" version "1.1.4"
|
||||
id 'java'
|
||||
id 'war'
|
||||
@ -8,7 +8,7 @@ plugins {
|
||||
}
|
||||
|
||||
group = 'de.jottyfan.camporganizer'
|
||||
version = '0.8.0'
|
||||
version = '0.8.1'
|
||||
|
||||
description = """CampOrganizer2"""
|
||||
|
||||
@ -35,9 +35,8 @@ war {
|
||||
"Implementation-Timestamp": new Date())
|
||||
}
|
||||
}
|
||||
baseName = project.name
|
||||
version = version
|
||||
archiveName = 'CampOrganizer2.war'
|
||||
archiveFileName = 'CampOrganizer2.war'
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@ -1,5 +1,5 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
1
settings.gradle
Normal file
1
settings.gradle
Normal file
@ -0,0 +1 @@
|
||||
rootProject.name = 'CampOrganizer2'
|
@ -14,6 +14,7 @@ import de.jottyfan.camporganizer.db.jooq.enums.EnumSex;
|
||||
import de.jottyfan.camporganizer.module.registration.validate.AlreadyRegisteredCheck;
|
||||
import de.jottyfan.camporganizer.module.registration.validate.TeacherAgeCheck;
|
||||
import de.jottyfan.camporganizer.module.registration.validate.UnusedUsername;
|
||||
import de.jottyfan.camporganizer.module.registration.validate.ValidUsername;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -23,6 +24,7 @@ import de.jottyfan.camporganizer.module.registration.validate.UnusedUsername;
|
||||
@UnusedUsername(field = "login", message = "Dieses Login ist leider bereits vergeben. Bitte wähle ein anderes.")
|
||||
@TeacherAgeCheck(field = "birthDate", fkCamp = "fkCamp", campRole = "campRole", message = "Als Mitarbeiter bist Du leider zu jung für diese Freizeit.")
|
||||
@AlreadyRegisteredCheck(field = "forename", surname = "surname", birthDate = "birthDate", fkCamp = "fkCamp", message = "Diese Anmeldung wurde bereits vorgenommen. Wenn Du sie in Deinem Profil nicht sehen kannst, wurde sie vielleicht von jemand Anderem durchgeführt. In Absprache mit der Freizeitleitung kannst Du die Anmeldung von einem Administrator Deinem Konto zuordnen lassen.")
|
||||
@ValidUsername(field = "login", message = "Bitte überprüfe das Feld Login. Dort sind Leerzeichen nicht erlaubt.")
|
||||
public class RegistrationBean implements Serializable {
|
||||
//TODO: registration completeness annotation; in case of registerInKeycloak == true, force login, password, kcForename, kcSurname and kcEmail not to be blank
|
||||
private static final long serialVersionUID = 2L;
|
||||
|
@ -0,0 +1,29 @@
|
||||
package de.jottyfan.camporganizer.module.registration.validate;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import jakarta.validation.Constraint;
|
||||
import jakarta.validation.Payload;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author jotty
|
||||
*
|
||||
*/
|
||||
@Target({ ElementType.TYPE })
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Constraint(validatedBy = ValidUsernameValidator.class)
|
||||
@Documented
|
||||
public @interface ValidUsername {
|
||||
String message() default "username is invalid";
|
||||
|
||||
String field();
|
||||
|
||||
Class<?>[] groups() default {};
|
||||
|
||||
Class<? extends Payload>[] payload() default {};
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package de.jottyfan.camporganizer.module.registration.validate;
|
||||
|
||||
import org.springframework.beans.BeanWrapperImpl;
|
||||
|
||||
import jakarta.validation.ConstraintValidator;
|
||||
import jakarta.validation.ConstraintValidatorContext;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author jotty
|
||||
*
|
||||
*/
|
||||
public class ValidUsernameValidator implements ConstraintValidator<ValidUsername, Object> {
|
||||
|
||||
private String field;
|
||||
private String message;
|
||||
|
||||
public void initialize(ValidUsername vu) {
|
||||
this.field = vu.field();
|
||||
this.message = vu.message();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(Object value, ConstraintValidatorContext context) {
|
||||
Object login = new BeanWrapperImpl(value).getPropertyValue(field);
|
||||
String loginString = String.valueOf(login);
|
||||
Boolean result = login != null && !loginString.isBlank() && !loginString.contains(" ");
|
||||
if (!result) {
|
||||
context.buildConstraintViolationWithTemplate(message).addPropertyNode(field).addConstraintViolation()
|
||||
.disableDefaultConstraintViolation();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
package de.jottyfan.camporganizer.module.registration;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.keycloak.admin.client.resource.UsersResource;
|
||||
import org.keycloak.representations.idm.UserRepresentation;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author jotty
|
||||
*
|
||||
*/
|
||||
public class TestKeycloakRepository {
|
||||
|
||||
/**
|
||||
* test registration
|
||||
*/
|
||||
@Test
|
||||
public void testRegister() {
|
||||
KeycloakRepository repository = new KeycloakRepository();
|
||||
UserRepresentation user = repository.getUserRepresentation("Hans", "Dampf", "hans", "password", "hans@dampf.org");
|
||||
UsersResource resource = repository.getUsersResource("http://localhost:8080", "ow", "owadmin", "password", "biblecamp");
|
||||
assertTrue(repository.register(resource, user));
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user