Token metamodel implemented
This commit is contained in:
@ -20,6 +20,7 @@ import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import de.stklcode.jvault.connector.exception.*;
|
||||
import de.stklcode.jvault.connector.model.AuthBackend;
|
||||
import de.stklcode.jvault.connector.model.Token;
|
||||
import de.stklcode.jvault.connector.model.response.*;
|
||||
import de.stklcode.jvault.connector.model.response.embedded.AuthMethod;
|
||||
import org.apache.http.HttpResponse;
|
||||
@ -338,6 +339,12 @@ public class HTTPVaultConnector implements VaultConnector {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TokenResponse createToken(final Token token) throws VaultConnectorException {
|
||||
/* TODO */
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Execute HTTP request using POST method.
|
||||
|
@ -18,6 +18,7 @@ package de.stklcode.jvault.connector;
|
||||
|
||||
import de.stklcode.jvault.connector.exception.VaultConnectorException;
|
||||
import de.stklcode.jvault.connector.model.AuthBackend;
|
||||
import de.stklcode.jvault.connector.model.Token;
|
||||
import de.stklcode.jvault.connector.model.response.*;
|
||||
|
||||
import java.util.List;
|
||||
@ -208,4 +209,13 @@ public interface VaultConnector {
|
||||
* @return Renewed lease
|
||||
*/
|
||||
VaultResponse renew(final String leaseID, final Integer seconds);
|
||||
|
||||
/**
|
||||
* Create a new token.
|
||||
*
|
||||
* @param token the token
|
||||
* @return the result response
|
||||
* @throws VaultConnectorException on error
|
||||
*/
|
||||
TokenResponse createToken(final Token token) throws VaultConnectorException;
|
||||
}
|
||||
|
117
src/main/java/de/stklcode/jvault/connector/model/Token.java
Normal file
117
src/main/java/de/stklcode/jvault/connector/model/Token.java
Normal file
@ -0,0 +1,117 @@
|
||||
/*
|
||||
* Copyright 2016 Stefan Kalscheuer
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package de.stklcode.jvault.connector.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Vault Token metamodel.
|
||||
*
|
||||
* @author Stefan Kalscheuer
|
||||
* @since 0.4.0
|
||||
*/
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class Token {
|
||||
@JsonProperty("id")
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
private String id;
|
||||
|
||||
@JsonProperty("display_name")
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
private String displayName;
|
||||
|
||||
@JsonProperty("no_parent")
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
private Boolean noParent;
|
||||
|
||||
@JsonProperty("no_default_policy")
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
private Boolean noDefaultPolicy;
|
||||
|
||||
@JsonProperty("ttl")
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
private Integer ttl;
|
||||
|
||||
@JsonProperty("num_uses")
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
private Integer numUses;
|
||||
|
||||
@JsonProperty("policies")
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
private List<String> policies;
|
||||
|
||||
@JsonProperty("meta")
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
private Map<String, String> meta;
|
||||
|
||||
@JsonProperty("renewable")
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
private Boolean renewable;
|
||||
|
||||
public Token(String id, String displayName, Boolean noParent, Boolean noDefaultPolicy, Integer ttl, Integer numUses, List<String> policies, Map<String, String> meta, Boolean renewable) {
|
||||
this.id = id;
|
||||
this.displayName = displayName;
|
||||
this.ttl = ttl;
|
||||
this.numUses = numUses;
|
||||
this.noParent = noParent;
|
||||
this.noDefaultPolicy = noDefaultPolicy;
|
||||
this.policies = policies;
|
||||
this.meta = meta;
|
||||
this.renewable = renewable;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getDisplayName() {
|
||||
return displayName;
|
||||
}
|
||||
|
||||
public Boolean getNoParent() {
|
||||
return noParent;
|
||||
}
|
||||
|
||||
public Boolean getNoDefaultPolicy() {
|
||||
return noDefaultPolicy;
|
||||
}
|
||||
|
||||
public Integer getTtl() {
|
||||
return ttl;
|
||||
}
|
||||
|
||||
public Integer getNumUses() {
|
||||
return numUses;
|
||||
}
|
||||
|
||||
public List<String> getPolicies() {
|
||||
return policies;
|
||||
}
|
||||
|
||||
public Map<String, String> getMeta() {
|
||||
return meta;
|
||||
}
|
||||
|
||||
public Boolean isRenewable() {
|
||||
return renewable;
|
||||
}
|
||||
}
|
@ -0,0 +1,247 @@
|
||||
/*
|
||||
* Copyright 2016 Stefan Kalscheuer
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package de.stklcode.jvault.connector.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* A builder for vault tokens.
|
||||
*
|
||||
* @author Stefan Kalscheuer
|
||||
* @since 0.4.0
|
||||
*/
|
||||
public class TokenBuilder {
|
||||
private String id;
|
||||
private String displayName;
|
||||
private Boolean noParent;
|
||||
private Boolean noDefaultPolicy;
|
||||
private Integer ttl;
|
||||
private Integer numUses;
|
||||
private List<String> policies;
|
||||
private Map<String, String> meta;
|
||||
private Boolean renewable;
|
||||
|
||||
/**
|
||||
* Add token ID (optional)
|
||||
*
|
||||
* @param id the ID
|
||||
* @return self
|
||||
*/
|
||||
public TokenBuilder withId(final String id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add display name
|
||||
*
|
||||
* @param displayName the display name
|
||||
* @return self
|
||||
*/
|
||||
public TokenBuilder withDisplayName(final String displayName) {
|
||||
this.displayName = displayName;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set desired time to live.
|
||||
* @param ttl the ttl
|
||||
* @return self
|
||||
*/
|
||||
public TokenBuilder withTtl(final Integer ttl) {
|
||||
this.ttl = ttl;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set desired number of uses.
|
||||
* @param numUses the number of uses
|
||||
* @return self
|
||||
*/
|
||||
public TokenBuilder withNumUses(final Integer numUses) {
|
||||
this.numUses = numUses;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set TRUE if the token should be created without parent
|
||||
*
|
||||
* @param noParent if TRUE, token is created as orphan
|
||||
* @return self
|
||||
*/
|
||||
public TokenBuilder withNoParent(final boolean noParent) {
|
||||
this.noParent = noParent;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create token without parent.
|
||||
* Convenience method for withNoParent()
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public TokenBuilder asOrphan() {
|
||||
return withNoParent(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create token with parent.
|
||||
* Convenience method for withNoParent()
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public TokenBuilder withParent() {
|
||||
return withNoParent(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set TRUE if the default policy should not be part of this token.
|
||||
*
|
||||
* @param noDefaultPolicy if TRUE, default policy is not attached
|
||||
* @return self
|
||||
*/
|
||||
public TokenBuilder withNoDefaultPolicy(final boolean noDefaultPolicy) {
|
||||
this.noDefaultPolicy = noDefaultPolicy;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attach default policy to token.
|
||||
* Convenience method for withNoDefaultPolicy()
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public TokenBuilder withDefaultPolicy() {
|
||||
return withNoDefaultPolicy(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Do not attach default policy to token.
|
||||
* Convenience method for withNoDefaultPolicy()
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public TokenBuilder withoutDefaultPolicy() {
|
||||
return withNoDefaultPolicy(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add given policies
|
||||
*
|
||||
* @param policies the policies
|
||||
* @return self
|
||||
*/
|
||||
public TokenBuilder withPolicies(final List<String> policies) {
|
||||
if (this.policies == null)
|
||||
this.policies = new ArrayList<>();
|
||||
this.policies.addAll(policies);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a single policy.
|
||||
*
|
||||
* @param policy the policy
|
||||
* @return self
|
||||
*/
|
||||
public TokenBuilder withPolicy(final String policy) {
|
||||
if (this.policies == null)
|
||||
this.policies = new ArrayList<>();
|
||||
policies.add(policy);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add meta data.
|
||||
*
|
||||
* @param meta the metadata
|
||||
* @return self
|
||||
*/
|
||||
public TokenBuilder withMeta(final Map<String, String> meta) {
|
||||
if (this.meta == null)
|
||||
this.meta = new HashMap<>();
|
||||
this.meta.putAll(meta);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add meta data.
|
||||
*
|
||||
* @param key the key
|
||||
* @param value the value
|
||||
* @return self
|
||||
*/
|
||||
public TokenBuilder withMeta(final String key, final String value) {
|
||||
if (this.meta == null)
|
||||
this.meta = new HashMap<>();
|
||||
this.meta.put(key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set if token is renewable.
|
||||
*
|
||||
* @param renewable TRUE, if renewable
|
||||
* @return self
|
||||
*/
|
||||
public TokenBuilder withRenewable(final Boolean renewable) {
|
||||
this.renewable = renewable;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set token to be renewable.
|
||||
* Convenience method for withRenewable()
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public TokenBuilder renewable() {
|
||||
return withRenewable(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set token to be not renewable.
|
||||
* Convenience method for withRenewable()
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public TokenBuilder notRenewable() {
|
||||
return withRenewable(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the token based on given parameters.
|
||||
*
|
||||
* @return the token
|
||||
*/
|
||||
public Token build() {
|
||||
return new Token(id,
|
||||
displayName,
|
||||
noParent,
|
||||
noDefaultPolicy,
|
||||
ttl,
|
||||
numUses,
|
||||
policies,
|
||||
meta,
|
||||
renewable);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user