io.github.cdelmas.spike.vertx.infrastructure.auth.MyUser.java Source code

Java tutorial

Introduction

Here is the source code for io.github.cdelmas.spike.vertx.infrastructure.auth.MyUser.java

Source

/*
   Copyright 2015 Cyril Delmas
    
   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at
    
   http://www.apache.org/licenses/LICENSE-2.0
    
   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/
package io.github.cdelmas.spike.vertx.infrastructure.auth;

import io.vertx.core.AsyncResult;
import io.vertx.core.Future;
import io.vertx.core.Handler;
import io.vertx.core.json.JsonObject;
import io.vertx.ext.auth.AbstractUser;
import io.vertx.ext.auth.AuthProvider;

public class MyUser extends AbstractUser {

    private AuthProvider authProvider;
    private final long id;
    private final String name;
    private final String token;

    public MyUser(long id, String name, String token) {
        this.id = id;
        this.name = name;
        this.token = token;
    }

    @Override
    protected void doIsPermitted(String permission, Handler<AsyncResult<Boolean>> resultHandler) {
        resultHandler.handle(Future.failedFuture("Not implemented yet"));
    }

    @Override
    public JsonObject principal() {
        return new JsonObject().put("id", id).put("name", name).put("token", token);
    }

    @Override
    public void setAuthProvider(AuthProvider authProvider) {
        this.authProvider = authProvider;
    }

    public String getName() {
        return name;
    }

    public String getToken() {
        return token;
    }
}