use of io.micronaut.core.annotation.NonNull in project micronaut-security by micronaut-projects.
the class X509AuthenticationFetcher method fetchAuthentication.
@Override
public Publisher<Authentication> fetchAuthentication(HttpRequest<?> request) {
return Mono.<Authentication>create(emitter -> {
Optional<Certificate> optionalCertificate = request.getCertificate();
if (optionalCertificate.isPresent()) {
Certificate certificate = optionalCertificate.get();
if (certificate instanceof X509Certificate) {
emitter.success(new Authentication() {
X509Certificate x509Certificate = ((X509Certificate) certificate);
@Override
public String getName() {
return x509Certificate.getIssuerX500Principal().getName();
}
@NonNull
@Override
public Map<String, Object> getAttributes() {
return Collections.emptyMap();
}
});
return;
}
}
emitter.success();
});
}
use of io.micronaut.core.annotation.NonNull in project micronaut-views by micronaut-projects.
the class SoySauceViewsRenderer method render.
/**
* @param viewName view name to be rendered
* @param data response body to render it with a view
* @param request HTTP request
* @return A writable where the view will be written to.
*/
@NonNull
@Override
public Writable render(@NonNull String viewName, @Nullable T data, @Nullable HttpRequest<?> request) {
ArgumentUtils.requireNonNull("viewName", viewName);
Map<String, Object> ijOverlay = new HashMap<>(1);
Map<String, Object> context = ViewUtils.modelOf(data);
final SoySauce.Renderer renderer = soySauce.newRenderer(new SoyTemplate() {
@Override
public String getTemplateName() {
return viewName;
}
@Override
public Map<String, SoyValueProvider> getParamsAsMap() {
return null;
}
});
renderer.setData(context);
if (injectNonce) {
Optional<Object> nonceObj = request != null ? request.getAttribute(CspFilter.NONCE_PROPERTY) : Optional.empty();
if (nonceObj.isPresent()) {
String nonceValue = ((String) nonceObj.get());
ijOverlay.put(INJECTED_NONCE_PROPERTY, nonceValue);
}
}
renderer.setIj(ijOverlay);
if (this.soyMicronautConfiguration.isRenamingEnabled() && this.namingMapProvider != null) {
SoyCssRenamingMap cssMap = this.namingMapProvider.cssRenamingMap();
SoyIdRenamingMap idMap = this.namingMapProvider.idRenamingMap();
if (cssMap != null) {
renderer.setCssRenamingMap(cssMap);
}
if (idMap != null) {
renderer.setXidRenamingMap(idMap);
}
}
try {
final AppendableToWritable target = new AppendableToWritable();
SoySauce.WriteContinuation state;
state = renderer.renderHtml(target);
while (state.result().type() != RenderResult.Type.DONE) {
switch(state.result().type()) {
// If it's done, do nothing.
case DONE:
break;
// Render engine is signalling that we are waiting on an async task.
case DETACH:
state.result().future().get();
state = state.continueRender();
break;
// Output buffer is full.
case LIMITED:
break;
default:
break;
}
}
return target;
} catch (IOException e) {
throw new ViewRenderingException("Error rendering Soy Sauce view [" + viewName + "]: " + e.getMessage(), e);
} catch (InterruptedException ixe) {
throw new ViewRenderingException("Interrupted while rendering Soy Sauce view [" + viewName + "]: " + ixe.getMessage(), ixe);
} catch (ExecutionException exe) {
throw new ViewRenderingException("Execution error while rendering Soy Sauce view [" + viewName + "]: " + exe.getMessage(), exe);
}
}
use of io.micronaut.core.annotation.NonNull in project micronaut-multitenancy by micronaut-projects.
the class SessionTenantResolver method resolveTenantIdentifier.
@Override
@NonNull
public Serializable resolveTenantIdentifier(@NonNull @NotNull HttpRequest<?> request) throws TenantNotFoundException {
if (this.attribute == null) {
throw new TenantNotFoundException("Tenant could not be resolved from HTTP Session, because session attribute name is not set");
}
Optional<Session> opt = request.getAttributes().get(HttpSessionFilter.SESSION_ATTRIBUTE, Session.class);
if (!opt.isPresent()) {
throw new TenantNotFoundException("Tenant could not be resolved from HTTP Session, if session not present");
}
Session session = opt.get();
Optional<Object> tenantId = session.get(attribute);
if (!tenantId.isPresent()) {
throw new TenantNotFoundException("Tenant could not be resolved from HTTP Session, if session attribute (" + attribute + ") not present");
}
if (!(tenantId.get() instanceof Serializable)) {
throw new TenantNotFoundException("Tenant was resolved from HTTP Session, but it is not serializable");
}
return (Serializable) tenantId.get();
}
use of io.micronaut.core.annotation.NonNull in project micronaut-views by micronaut-projects.
the class RockerViewsRenderer method render.
@NonNull
@Override
public Writable render(@NonNull String view, @Nullable T data, @Nullable HttpRequest<?> request) {
ArgumentUtils.requireNonNull("view", view);
Map<String, Object> context = ViewUtils.modelOf(data);
BindableRockerModel model = rockerConfiguration.isRelaxed() ? rockerEngine.template(view).relaxedBind(context) : rockerEngine.template(view).bind(context);
return new RockerWritable(model);
}
Aggregations