本文整理汇总了Java中io.vertx.ext.web.RoutingContext.user方法的典型用法代码示例。如果您正苦于以下问题:Java RoutingContext.user方法的具体用法?Java RoutingContext.user怎么用?Java RoutingContext.user使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.vertx.ext.web.RoutingContext
的用法示例。
在下文中一共展示了RoutingContext.user方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handle
import io.vertx.ext.web.RoutingContext; //导入方法依赖的package包/类
@Override
public void handle(RoutingContext routingContext) {
VertxAsyncWebContext webContext = new VertxAsyncWebContext(routingContext, asynchronousComputationAdapter);
Pac4jUser pac4jUser = (Pac4jUser)routingContext.user();
if (pac4jUser != null) {
Map<String, CommonProfile> indirectProfiles = (Map)pac4jUser.pac4jUserProfiles().entrySet().stream().filter((e) -> {
String clientName = ((CommonProfile)e.getValue()).getClientName();
return ((AsyncClient)this.config.getClients().findClient(clientName)).isIndirect();
}).collect(Collectors.toMap((e) -> (String)e.getKey(), (e) -> (CommonProfile)e.getValue()));
if (!indirectProfiles.isEmpty()) {
pac4jUser.pac4jUserProfiles().clear();
pac4jUser.pac4jUserProfiles().putAll(indirectProfiles);
} else {
routingContext.clearUser();
}
}
securityLogic.perform(webContext, (ctx, parameters) -> {
LOG.info("Authorised to view resource " + routingContext.request().path());
routingContext.next();
return null;
}, clientNames, authorizerName, matcherName)
.whenComplete((result, failure) -> {
if (failure != null) {
vertx.runOnContext(v -> {
this.unexpectedFailure(routingContext, failure);
});
}
});
}
示例2: provideContext
import io.vertx.ext.web.RoutingContext; //导入方法依赖的package包/类
/**
* Provides vertx context of desired type if possible
*
* @param definition route definition
* @param type context type
* @param defaultValue default value if given
* @param context to extract value from
* @return found context or null if not found
*/
public static Object provideContext(RouteDefinition definition,
Class<?> type,
String defaultValue,
RoutingContext context) throws ContextException {
// vert.x context
if (type.isAssignableFrom(HttpServerResponse.class)) {
return context.response();
}
if (type.isAssignableFrom(HttpServerRequest.class)) {
return context.request();
}
if (type.isAssignableFrom(RoutingContext.class)) {
return context;
}
if (type.isAssignableFrom(Vertx.class)) {
return context.vertx();
}
if (type.isAssignableFrom(User.class)) {
return context.user();
}
// internal context
if (type.isAssignableFrom(RouteDefinition.class)) {
return definition;
}
// browse through context storage
if (context.data() != null && context.data().size() > 0) {
Object item = context.data().get(getContextKey(type));
if (item != null) { // found in storage ... return
return item;
}
}
if (defaultValue != null) {
// check if type has constructor that can be used with defaultValue ...
// and create Context type on the fly constructed with defaultValue
try {
return ClassFactory.constructType(type, defaultValue);
}
catch (ClassFactoryException e) {
throw new ContextException("Can't provide @Context of type: " + type + ". " + e.getMessage());
}
}
throw new ContextException("Can't provide @Context of type: " + type);
}
示例3: ingest
import io.vertx.ext.web.RoutingContext; //导入方法依赖的package包/类
@Override
public Epsilon<T> ingest(final RoutingContext context,
final Epsilon<T> income)
throws WebException {
Object returnValue = null;
final Class<?> paramType = income.getArgType();
if (is(Session.class, paramType)) {
// Session Object
returnValue = context.session();
} else if (is(HttpServerRequest.class, paramType)) {
// Request Object
returnValue = context.request();
} else if (is(HttpServerResponse.class, paramType)) {
// Response Object
returnValue = context.response();
} else if (is(Vertx.class, paramType)) {
// Vertx Object
returnValue = context.vertx();
} else if (is(EventBus.class, paramType)) {
// Eventbus Object
returnValue = context.vertx().eventBus();
} else if (is(User.class, paramType)) {
// User Objbect
returnValue = context.user();
} else if (is(Set.class, paramType)) {
// FileUpload
final Class<?> type = paramType.getComponentType();
if (is(FileUpload.class, type)) {
returnValue = context.fileUploads();
}
} else if (is(JsonArray.class, paramType)) {
// JsonArray
returnValue = context.getBodyAsJsonArray();
} else if (is(JsonObject.class, paramType)) {
// JsonObject
returnValue = context.getBodyAsJson();
} else if (is(Buffer.class, paramType)) {
// Buffer
returnValue = context.getBody();
}
return null == returnValue ? income.setValue(null) : income.setValue((T) returnValue);
}