Java源码示例:io.vertx.ext.auth.jwt.JWTOptions

示例1
private JwtAuth(final Vertx vertx,
                final String keystorePath,
                final String keystorePass,
                final List<String> audience) {
    this.jwtAuth = JWTAuth.create(vertx, new JsonObject().put("keyStore", new JsonObject()
            .put("path", keystorePath)
            .put("type", "jceks")
            .put("password", keystorePass)));
    this.jwtOptions = new JWTOptions()
            .setAudience(audience)
            .setAlgorithm("RS256")
            .setExpiresInSeconds(Duration.of(365, DAYS).getSeconds());
    this.audience = audience;
}
 
示例2
@NoAuthFilter
@Produces("text/plain")
@GET
@Path("token")
public Single<Response> token(@HeaderParam("login") String username, 
		@HeaderParam("password") String password,
		@Context JWTAuth jwt,
		@Context AuthProvider auth){
	
	JsonObject creds = new JsonObject()
			.put("username", username)
			.put("password", password);
	return fiber(() -> {
		User user;
		try {
			user = await(auth.rxAuthenticate(creds));
		}catch(VertxException x) {
			return Response.status(Status.FORBIDDEN).build();
		}
		
		boolean canCreate = await(user.rxIsAuthorised("create"));
		boolean canUpdate = await(user.rxIsAuthorised("update"));
		boolean canDelete = await(user.rxIsAuthorised("delete"));
		JsonArray permissions = new JsonArray();
		if(canCreate)
			permissions.add("create");
		if(canUpdate)
			permissions.add("update");
		if(canDelete)
			permissions.add("delete");
		
        String jwtToken = jwt.generateToken(
        		new JsonObject()
        		.put("username", username)
        		.put("permissions", permissions),
                new JWTOptions()
                  .setSubject("Wiki API")
                  .setIssuer("Vert.x"));
        return Response.ok(jwtToken).build();
	});
}
 
示例3
@NoAuthFilter
@Produces("text/plain")
@GET
@Path("token")
public Single<Response> token(@HeaderParam("login") String username, 
		@HeaderParam("password") String password,
		@Context JWTAuth jwt,
		@Context AuthProvider auth){
	
	JsonObject creds = new JsonObject()
			.put("username", username)
			.put("password", password);
	return fiber(() -> {
		User user;
		try {
			user = await(auth.rxAuthenticate(creds));
		}catch(VertxException x) {
			return Response.status(Status.FORBIDDEN).build();
		}
		
		boolean canCreate = await(user.rxIsAuthorised("create"));
		boolean canUpdate = await(user.rxIsAuthorised("update"));
		boolean canDelete = await(user.rxIsAuthorised("delete"));
		JsonArray permissions = new JsonArray();
		if(canCreate)
			permissions.add("create");
		if(canUpdate)
			permissions.add("update");
		if(canDelete)
			permissions.add("delete");
		
        String jwtToken = jwt.generateToken(
        		new JsonObject()
        		.put("username", username)
        		.put("permissions", permissions),
                new JWTOptions()
                  .setSubject("Wiki API")
                  .setIssuer("Vert.x"));
        return Response.ok(jwtToken).build();
	});
}