001/*
002 * (C) Copyright 2018 Nuxeo (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     Florent Guillaume
018 */
019package org.nuxeo.ecm.jwt;
020
021import org.nuxeo.common.xmap.annotation.XNode;
022import org.nuxeo.common.xmap.annotation.XObject;
023
024/**
025 * Descriptor for the {@link JWTService}.
026 *
027 * @since 10.3
028 */
029@XObject(value = "configuration")
030public class JWTServiceConfigurationDescriptor {
031
032    public static final int DEFAULT_DEFAULT_TTL = 60 * 60; // 1h
033
034    @XNode("secret")
035    public String secret;
036
037    @XNode("defaultTTL")
038    public Integer defaultTTL;
039
040    public String getSecret() {
041        return secret;
042    }
043
044    public int getDefaultTTL() {
045        return defaultTTL == null ? DEFAULT_DEFAULT_TTL : defaultTTL.intValue();
046    }
047
048    /** Empty constructor, to get defaults. */
049    public JWTServiceConfigurationDescriptor() {
050    }
051
052    /** Copy constructor. */
053    public JWTServiceConfigurationDescriptor(JWTServiceConfigurationDescriptor other) {
054        this.secret = other.secret;
055        this.defaultTTL = other.defaultTTL;
056    }
057
058    /** Merge method. */
059    public void merge(JWTServiceConfigurationDescriptor other) {
060        if (other.secret != null) {
061            secret = other.secret;
062        }
063        if (other.defaultTTL != null) {
064            defaultTTL = other.defaultTTL;
065        }
066    }
067
068}