/** * Add a token instance (such as JWT instance). May contain more than one instance (e.g. for JWT, we may send both * SignedJwt and Jwt). * Object is registered under the class it provides through {@link Object#getClass()}. * * @param token instance * @return updated builder instance */ public Builder addToken(Object token) { this.tokens.putInstance(token); return this; }
/** * Add a public credential to this subject to be bound under its class. * * @param instance instance of the credential, the class it will be bound to is obtained through {@link Object#getClass() * instance.getClass()} * @return updated builder instance */ public Builder addPublicCredential(Object instance) { publicCredentials.putInstance(instance); return this; }
/** * Add a private credential to this subject. * Only one instance of a type may be added to a subject. * * @param className class of the credential (e.g. X509 certificate) * @param instance instance of the credential * @return updated builder instance */ public Builder addPrivateCredential(Class<?> className, Object instance) { privateCredentials.putInstance(className, instance); return this; }
/** * Add a private credential to this subject to be bound under its class. * * @param instance instance of the credential, the class it will be bound to is obtained through {@link Object#getClass() * instance.getClass()} * @return updated builder instance */ public Builder addPrivateCredential(Object instance) { privateCredentials.putInstance(instance); return this; }
/** * Add a public credential to this subject. * Only one instance of a type may be added to a subject. * * @param className class of the credential (e.g. X509 certificate) * @param instance instance of the credential * @return updated builder instance */ public Builder addPublicCredential(Class<?> className, Object instance) { publicCredentials.putInstance(className, instance); return this; }
/** * Set or replace a custom object. This object will be provided to security provider. * Objects are stored by class, so we can have multiple objects of different classes * (e.g. when using multiple authorizers/authenticators). Class of object is defined by security provider. * * @param objectClass Class of object as expected by security provider * @param anObject Custom object to propagate to security provider * @param <U> Type of the custom object to be stored. The object instance is available ONLY under this class * @param <V> Type of instance (must be descendant of U) * @return updated Builder instance */ public <U, V extends U> Builder customObject(Class<U> objectClass, V anObject) { this.customObjects.putInstance(objectClass, anObject); return this; }
/** * Add a token instance (such as JWT instance). May contain more than one instance (e.g. for JWT, we may send both * SignedJwt and Jwt). * * @param tokenClass class we want to register the instance under * @param tokenInstance instance * @param <T> type of instance * @param <U> type of class to register instance by * @return updated builder instance */ public <T, U extends T> Builder addToken(Class<T> tokenClass, U tokenInstance) { tokens.putInstance(tokenClass, tokenInstance); return this; }
/** * Set or replace a custom object. This object will be provided to security provider. * Objects are stored by class, so we can have multiple objects of different classes * (e.g. when using multiple outbound providers). Class of object is defined by security provider. * * @param objectClass Class of object as expected by security provider * @param anObject Custom object to be used by outbound security provider * @param <U> Class of the custom object to be stored. The object instance is available ONLY under this class * @param <V> Implementation of the class * @return updated Builder instance */ public <U, V extends U> Builder customObject(Class<U> objectClass, V anObject) { customObjects.putInstance(objectClass, anObject); return this; }
/** * Put an instance with implicit class mapping into this store. Please use {@link #putInstance(Class, Object)} when * feasible as it provides more explicit mapping. * This is a helper method for instances obtained by other means or where we are sure of the class of the instance. * * @param instance instance to map to its class (obtained through {@link Object#getClass()} * @param <U> Type of this instance * @return existing value for the class of this instance */ @SuppressWarnings("unchecked") public <U extends T> Optional<U> putInstance(U instance) { return putInstance((Class<? extends U>) instance.getClass(), instance); }
/** * Create a new instance based on explicit instances. * This method creates a MUTABLE instance (contrary to such methods on java collections). * * @param instances instances to add to the new store * @param <T> type of the store * @return new store with instances inserted as when calling {@link #putInstance(Object)} for each of them */ @SafeVarargs public static <T> ClassToInstanceStore<T> create(T... instances) { ClassToInstanceStore<T> result = new ClassToInstanceStore<>(); for (T instance : instances) { result.putInstance(instance); } return result; }
/** * Register a custom object for security request(s). * This creates a hard dependency on a specific security provider, so use with care. * * @param object An object expected by security provider * @return updated builder instance */ Builder customObject(Object object) { OptionalHelper.from(customObjects) .ifPresentOrElse(store -> store.putInstance(object), () -> { ClassToInstanceStore<Object> ctis = new ClassToInstanceStore<>(); ctis.putInstance(object); customObjects = Optional.of(ctis); }); return this; }
/** * Add a token instance (such as JWT instance). May contain more than one instance (e.g. for JWT, we may send both * SignedJwt and Jwt). * Object is registered under the class it provides through {@link Object#getClass()}. * * @param token instance * @return updated builder instance */ public Builder addToken(Object token) { this.tokens.putInstance(token); return this; }
/** * Add a token instance (such as JWT instance). May contain more than one instance (e.g. for JWT, we may send both * SignedJwt and Jwt). * Object is registered under the class it provides through {@link Object#getClass()}. * * @param token instance * @return updated builder instance */ public Builder addToken(Object token) { this.tokens.putInstance(token); return this; }
/** * Add a token instance (such as JWT instance). May contain more than one instance (e.g. for JWT, we may send both * SignedJwt and Jwt). * * @param tokenClass class we want to register the instance under * @param tokenInstance instance * @param <T> type of instance * @param <U> type of class to register instance by * @return updated builder instance */ public <T, U extends T> Builder addToken(Class<T> tokenClass, U tokenInstance) { tokens.putInstance(tokenClass, tokenInstance); return this; }
/** * Set or replace a custom object. This object will be provided to security provider. * Objects are stored by class, so we can have multiple objects of different classes * (e.g. when using multiple outbound providers). Class of object is defined by security provider. * * @param objectClass Class of object as expected by security provider * @param anObject Custom object to be used by outbound security provider * @param <U> Class of the custom object to be stored. The object instance is available ONLY under this class * @param <V> Implementation of the class * @return updated Builder instance */ public <U, V extends U> Builder customObject(Class<U> objectClass, V anObject) { customObjects.putInstance(objectClass, anObject); return this; }
/** * Add a token instance (such as JWT instance). May contain more than one instance (e.g. for JWT, we may send both * SignedJwt and Jwt). * * @param tokenClass class we want to register the instance under * @param tokenInstance instance * @param <T> type of instance * @param <U> type of class to register instance by * @return updated builder instance */ public <T, U extends T> Builder addToken(Class<T> tokenClass, U tokenInstance) { tokens.putInstance(tokenClass, tokenInstance); return this; }
/** * Set or replace a custom object. This object will be provided to security provider. * Objects are stored by class, so we can have multiple objects of different classes * (e.g. when using multiple outbound providers). Class of object is defined by security provider. * * @param objectClass Class of object as expected by security provider * @param anObject Custom object to be used by outbound security provider * @param <U> Class of the custom object to be stored. The object instance is available ONLY under this class * @param <V> Implementation of the class * @return updated Builder instance */ public <U, V extends U> Builder customObject(Class<U> objectClass, V anObject) { customObjects.putInstance(objectClass, anObject); return this; }
/** * Register a custom object for security request(s). * This creates a hard dependency on a specific security provider, so use with care. * * @param object An object expected by security provider * @return updated builder instance */ Builder customObject(Object object) { OptionalHelper.from(customObjects) .ifPresentOrElse(store -> store.putInstance(object), () -> { ClassToInstanceStore<Object> ctis = new ClassToInstanceStore<>(); ctis.putInstance(object); customObjects = Optional.of(ctis); }); return this; }