/** * Get public credential for the specified type. * * @param credential credential type's class * @param <T> credential type * @return optional of public credential of the type defined */ public <T> Optional<T> publicCredential(Class<T> credential) { return publicCredentials.getInstance(credential); }
/** * Get private credential for the specified type. * * @param credential credential type's class * @param <T> credential type * @return optional of private credential of the type defined */ public <T> Optional<T> privateCredential(Class<T> credential) { return privateCredentials.getInstance(credential); }
/** * Get an instance of a custom object configuring this endpoint. * * @param clazz class the instance is bound under (only explicit binding is supported) * @param <U> type of the configuration * @return instance of the custom object if present */ public <U> Optional<U> instance(Class<U> clazz) { return customObjects.getInstance(clazz); }
/** * Get a token of a specific class. * By default the String.class is supported - and returns the token content. * Other instances may be available from authentication provider (e.g. Jwt). * * @param tokenClass class we want to get * @param <U> type of the class * @return instance of the token if present */ public <U> Optional<U> getTokenInstance(Class<U> tokenClass) { return tokens.getInstance(tokenClass); }
/** * Allows a programmatic client to send custom security provider specific parameters to the provider. * Definition of such properties must be documented on the provider. * The Security is not aware of such properties. * * @param <T> Type of the provider specific object * @param clazz Class we want to get * @return class to value mapping * @see Builder#customObject(Class, Object) */ public <T> Optional<? extends T> customObject(Class<? extends T> clazz) { return customObjects.getInstance(clazz); }
/** * Will add all principals and credentials from another subject to this subject, will not replace {@link #principals()}. * * @param another the other subject to combine with this subject * @return a new subject that is a combination of this subject and the other subject, this subject is more significant */ public Subject combine(Subject another) { Builder builder = Subject.builder() .addPrincipal(this.principal); // add this subject principals.forEach(builder::addPrincipal); privateCredentials.keys().forEach(key -> builder.addPrivateCredential(key, privateCredentials.getInstance(key))); publicCredentials.keys().forEach(key -> builder.addPublicCredential(key, publicCredentials.getInstance(key))); grants.forEach(builder::addGrant); attributes.abacAttributeNames().forEach(key -> builder.addAttribute(key, attributes.abacAttribute(key))); // add the other subject another.principals.forEach(builder::addPrincipal); another.privateCredentials.keys() .forEach(key -> builder.addPrivateCredential(key, another.privateCredentials.getInstance(key))); another.publicCredentials.keys() .forEach(key -> builder.addPublicCredential(key, another.publicCredentials.getInstance(key))); another.grants.forEach(builder::addGrant); another.attributes.abacAttributeNames().forEach(key -> builder.addAttribute(key, another.attributes.abacAttribute(key))); return builder.build(); }
/** * Get a token of a specific class. * By default the String.class is supported - and returns the token content. * Other instances may be available from authentication provider (e.g. Jwt). * * @param tokenClass class we want to get * @param <U> type of the class * @return instance of the token if present */ public <U> Optional<U> getTokenInstance(Class<U> tokenClass) { return tokens.getInstance(tokenClass); }
/** * Get a token of a specific class. * By default the String.class is supported - and returns the token content. * Other instances may be available from authentication provider (e.g. Jwt). * * @param tokenClass class we want to get * @param <U> type of the class * @return instance of the token if present */ public <U> Optional<U> getTokenInstance(Class<U> tokenClass) { return tokens.getInstance(tokenClass); }
/** * Allows a programmatic client to send custom security provider specific parameters to the provider. * Definition of such properties must be documented on the provider. * The Security is not aware of such properties. * * @param <T> Type of the provider specific object * @param clazz Class we want to get * @return class to value mapping * @see Builder#customObject(Class, Object) */ public <T> Optional<? extends T> customObject(Class<? extends T> clazz) { return customObjects.getInstance(clazz); }
/** * Allows a programmatic client to send custom security provider specific parameters to the provider. * Definition of such properties must be documented on the provider. * The Security is not aware of such properties. * * @param <T> Type of the provider specific object * @param clazz Class we want to get * @return class to value mapping * @see Builder#customObject(Class, Object) */ public <T> Optional<? extends T> getCustomObject(Class<? extends T> clazz) { return customObjects.getInstance(clazz); }