001/* 002 * The contents of this file are subject to the terms of the Common Development and 003 * Distribution License (the License). You may not use this file except in compliance with the 004 * License. 005 * 006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the 007 * specific language governing permission and limitations under the License. 008 * 009 * When distributing Covered Software, include this CDDL Header Notice in each file and include 010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL 011 * Header, with the fields enclosed by brackets [] replaced by your own identifying 012 * information: "Portions copyright [year] [name of copyright owner]". 013 * 014 * Copyright 2013-2015 ForgeRock AS. 015 */ 016 017package org.forgerock.json.jose.builders; 018 019import org.forgerock.json.jose.jwt.JwtClaimsSet; 020 021/** 022 * A base implementation for all JwtBuilders that provides the basis of the JWT builder methods. 023 * 024 * @since 2.0.0 025 */ 026public abstract class AbstractJwtBuilder implements JwtBuilder { 027 028 private JwtHeaderBuilder<?, ?> headerBuilder; 029 private JwtClaimsSet claimsSet; 030 031 /** 032 * Gets the JwtHeaderBuilder that this JwtBuilder will use to build the JWT's header parameters. 033 * 034 * @return The JwtHeaderBuilder instance. 035 */ 036 public abstract JwtHeaderBuilder<?, ?> headers(); 037 038 /** 039 * Sets the JwtHeaderBuilder that this JwtBuilder will use to build the JWT's header parameters. 040 * 041 * @param headerBuilder The JwtHeaderBuilder instance. 042 */ 043 void setJwtHeaderBuilder(JwtHeaderBuilder<?, ?> headerBuilder) { 044 this.headerBuilder = headerBuilder; 045 } 046 047 /** 048 * Gets the JwtHeaderBuilder that is used to build the JWT's header parameters. 049 * 050 * @return The JwtHeaderBuilder instance. 051 */ 052 JwtHeaderBuilder<?, ?> getHeaderBuilder() { 053 return headerBuilder; 054 } 055 056 /** 057 * Sets the JwtClaimsSet for this JwtBuilder. 058 * 059 * @param claimsSet The JwtClaimsSet containing the JWT's claims. 060 * @return This AbstractJwtBuilder. 061 */ 062 public AbstractJwtBuilder claims(JwtClaimsSet claimsSet) { 063 this.claimsSet = claimsSet; 064 return this; 065 } 066 067 /** 068 * Gets the JwtClaimsSet that has been set in this JwtBuilder. 069 * 070 * @return The JwtClaimsSet containing the JWT's claims. 071 */ 072 JwtClaimsSet getClaimsSet() { 073 return claimsSet; 074 } 075}