2021-03-11 13:38:35 -08:00
|
|
|
package react.graphql;
|
2021-01-22 15:44:00 -08:00
|
|
|
|
|
|
|
import com.typesafe.config.Config;
|
|
|
|
import play.mvc.Http;
|
|
|
|
import com.linkedin.datahub.graphql.QueryContext;
|
|
|
|
|
2021-03-11 13:38:35 -08:00
|
|
|
import static react.auth.AuthUtils.*;
|
2021-01-22 15:44:00 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Provides session context to components of the GraphQL Engine at runtime.
|
|
|
|
*/
|
|
|
|
public class PlayQueryContext implements QueryContext {
|
|
|
|
|
2021-03-11 13:38:35 -08:00
|
|
|
private final Http.Context _context;
|
2021-01-22 15:44:00 -08:00
|
|
|
private final Config _appConfig;
|
|
|
|
|
2021-03-11 13:38:35 -08:00
|
|
|
public PlayQueryContext(Http.Context context) {
|
|
|
|
this(context, null);
|
2021-01-22 15:44:00 -08:00
|
|
|
}
|
|
|
|
|
2021-03-11 13:38:35 -08:00
|
|
|
public PlayQueryContext(Http.Context context, Config appConfig) {
|
|
|
|
_context = context;
|
2021-01-22 15:44:00 -08:00
|
|
|
_appConfig = appConfig;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if the current user is authenticated, false otherwise.
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public boolean isAuthenticated() {
|
2021-03-11 13:38:35 -08:00
|
|
|
return _context.session().containsKey(ACTOR);
|
2021-01-22 15:44:00 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the currently logged in user string
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public String getActor() {
|
2021-03-11 13:38:35 -08:00
|
|
|
return _context.session().get(ACTOR);
|
2021-01-22 15:44:00 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieves the {@link Http.Session} object associated with the current user.
|
|
|
|
*/
|
|
|
|
public Http.Session getSession() {
|
2021-03-11 13:38:35 -08:00
|
|
|
return _context.session();
|
2021-01-22 15:44:00 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-03-11 13:38:35 -08:00
|
|
|
* Retrieves the {@link Http.Context} object associated with the current request.
|
2021-01-22 15:44:00 -08:00
|
|
|
*/
|
2021-03-11 13:38:35 -08:00
|
|
|
public Http.Context getPlayContext() {
|
|
|
|
return _context;
|
2021-01-22 15:44:00 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-03-11 13:38:35 -08:00
|
|
|
* Retrieves the {@link Config} object associated with the play application.
|
2021-01-22 15:44:00 -08:00
|
|
|
*/
|
2021-03-11 13:38:35 -08:00
|
|
|
public Config getAppConfig() {
|
|
|
|
return _appConfig;
|
2021-01-22 15:44:00 -08:00
|
|
|
}
|
|
|
|
}
|