001package org.apache.archiva.redback.rest.api.model.v2; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * Unless required by applicable law or agreed to in writing, 014 * software distributed under the License is distributed on an 015 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 016 * KIND, either express or implied. See the License for the 017 * specific language governing permissions and limitations 018 * under the License. 019 */ 020 021import io.swagger.v3.oas.annotations.media.Schema; 022 023import javax.xml.bind.annotation.XmlElement; 024import javax.xml.bind.annotation.XmlRootElement; 025import java.io.Serializable; 026 027/** 028 * @author Martin Stockhammer <martin_s@apache.org> 029 */ 030@XmlRootElement(name="refreshToken") 031@Schema(name="Request Token Data", description = "Schema used for requesting a Bearer token.") 032public class TokenRequest implements Serializable 033{ 034 private static final long serialVersionUID = -2420082541650525792L; 035 GrantType grantType = GrantType.NONE; 036 String clientId; 037 String clientSecret; 038 String code; 039 String scope = ""; 040 String state = ""; 041 String userId; 042 String password; 043 String redirectUri; 044 045 public TokenRequest() { 046 047 } 048 049 public TokenRequest( String userId, String password ) 050 { 051 this.userId = userId; 052 this.password = password; 053 } 054 055 public TokenRequest( String userId, String password, String scope ) 056 { 057 this.userId = userId; 058 this.password = password; 059 this.scope = scope; 060 } 061 062 public TokenRequest( String userId, String password, GrantType grantType ) 063 { 064 this.userId = userId; 065 this.password = password; 066 this.grantType = grantType; 067 } 068 069 @XmlElement(name = "grant_type", required = true ) 070 @Schema( 071 name = "grant_type", 072 description = "The grant type. Currently only 'authorization_code' is supported.", 073 allowableValues = {"authorization_code","access_token"}, 074 defaultValue = "authorization_code", 075 example = "authorization_code") 076 public GrantType getGrantType( ) 077 { 078 return grantType; 079 } 080 081 public void setGrantType( GrantType grantType ) 082 { 083 this.grantType = grantType; 084 } 085 086 @XmlElement(name="client_id", nillable = true) 087 @Schema( 088 name = "client_id", 089 description = "The client identifier.") 090 public String getClientId( ) 091 { 092 return clientId; 093 } 094 095 public void setClientId( String clientId ) 096 { 097 this.clientId = clientId; 098 } 099 100 @XmlElement(name="client_secret", nillable = true) 101 @Schema( 102 name = "client_secret", 103 description = "The client application secret.") 104 public String getClientSecret( ) 105 { 106 return clientSecret; 107 } 108 109 public void setClientSecret( String clientSecret ) 110 { 111 this.clientSecret = clientSecret; 112 } 113 114 @XmlElement(name="scope", nillable = true) 115 public String getScope( ) 116 { 117 return scope; 118 } 119 120 public void setScope( String scope ) 121 { 122 this.scope = scope; 123 } 124 125 @XmlElement(name="user_id", required = true ) 126 @Schema(name="user_id", description = "The user identifier.") 127 public String getUserId( ) 128 { 129 return userId; 130 } 131 132 public void setUserId( String userId ) 133 { 134 this.userId = userId; 135 } 136 137 @XmlElement(name="password", required = true ) 138 @Schema(description = "The user password") 139 public String getPassword( ) 140 { 141 return password; 142 } 143 144 public void setPassword( String password ) 145 { 146 this.password = password; 147 } 148 149 @XmlElement(name="code" ) 150 public String getCode( ) 151 { 152 return code; 153 } 154 155 public void setCode( String code ) 156 { 157 this.code = code; 158 } 159 160 @XmlElement(name="redirect_uri" ) 161 @Schema( 162 name = "redirect_uri", 163 description = "The URL to redirect to.") 164 public String getRedirectUri( ) 165 { 166 return redirectUri; 167 } 168 169 public void setRedirectUri( String redirectUri ) 170 { 171 this.redirectUri = redirectUri; 172 } 173 174 @XmlElement(name="state" ) 175 public String getState( ) 176 { 177 return state; 178 } 179 180 public void setState( String state ) 181 { 182 this.state = state; 183 } 184 185 186 @Override 187 public String toString( ) 188 { 189 final StringBuilder sb = new StringBuilder( "TokenRequest{" ); 190 sb.append( "grantType=" ).append( grantType ); 191 sb.append( ", clientId='" ).append( clientId ).append( '\'' ); 192 sb.append( ", clientSecret='" ).append( clientSecret ).append( '\'' ); 193 sb.append( ", code='" ).append( code ).append( '\'' ); 194 sb.append( ", scope='" ).append( scope ).append( '\'' ); 195 sb.append( ", state='" ).append( state ).append( '\'' ); 196 sb.append( ", userId='" ).append( userId ).append( '\'' ); 197 sb.append( ", password='*******'" ); 198 sb.append( ", redirectUri='" ).append( redirectUri ).append( '\'' ); 199 sb.append( '}' ); 200 return sb.toString( ); 201 } 202}