All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.infusers.core.secrets.dto.OtherSecrets Maven / Gradle / Ivy

There is a newer version: 2025.03.0001
Show newest version
package com.infusers.core.secrets.dto;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Component
@ConfigurationProperties(prefix = "infusers.jwt")
@Data
@AllArgsConstructor
@NoArgsConstructor
public class OtherSecrets implements ISecrets {

	public static final int MIN_EXPIRY_HOURS = 2;
	public static final int MAX_EXPIRY_HOURS = 12;
	
	private String jwttokensecret;
	private String jwtTokenExpiryHours;
	
	public double getJwtTokenExpiryHoursNumber() {
		return Integer.parseInt(jwtTokenExpiryHours);
	}
	
	public String getJwtTokenExpiryHours() {
		return jwtTokenExpiryHours;
	}

	public void setJwtTokenExpiryHours(String jwtTokenExpiryHours) {
		this.jwtTokenExpiryHours = jwtTokenExpiryHours;
	}

	public String getJwttokensecret() {
		return jwttokensecret;
	}

	public void setJwttokensecret(String jwttokensecret) {
		this.jwttokensecret = jwttokensecret;
	}
	
    public boolean isValid() {
        return isValidField(jwttokensecret) && isValidField(jwtTokenExpiryHours) &&
               isValidJWTTokenExpiryHours(jwtTokenExpiryHours);
    }

    private boolean isValidField(String field) {
        return field != null && !field.isEmpty();
    }

    private boolean isValidJWTTokenExpiryHours(String expiryHours) {
        try {
            int intValue = Integer.parseInt(expiryHours);
            return intValue >= MIN_EXPIRY_HOURS && intValue <= MAX_EXPIRY_HOURS;
        } catch (NumberFormatException e) {
            return false; // Not a valid integer
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy