001/* 002 * Copyright (c) 2017 The Regents of the University of California. 003 * All rights reserved. 004 * 005 * '$Author: crawl $' 006 * '$Date: 2017-05-10 16:55:24 -0700 (Wed, 10 May 2017) $' 007 * '$Revision: 1181 $' 008 * 009 * Permission is hereby granted, without written agreement and without 010 * license or royalty fees, to use, copy, modify, and distribute this 011 * software and its documentation for any purpose, provided that the above 012 * copyright notice and the following two paragraphs appear in all copies 013 * of this software. 014 * 015 * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY 016 * FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 017 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF 018 * THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF 019 * SUCH DAMAGE. 020 * 021 * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, 022 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 023 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE 024 * PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF 025 * CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, 026 * ENHANCEMENTS, OR MODIFICATIONS. 027 * 028 */ 029package org.kepler.webview.server.auth; 030 031import org.kepler.webview.server.WebViewConfiguration; 032 033import io.vertx.core.AsyncResult; 034import io.vertx.core.Future; 035import io.vertx.core.Handler; 036import io.vertx.core.json.JsonObject; 037import io.vertx.ext.auth.AuthProvider; 038import io.vertx.ext.auth.User; 039 040/** Simple AuthProvider implementation that reads passwords from configuration.xml. 041 * 042 * @author Daniel Crawl 043 * @version $Id: SimpleAuth.java 1181 2017-05-10 23:55:24Z crawl $ 044 * 045 */ 046public class SimpleAuth implements AuthProvider { 047 048 @Override 049 public void authenticate(JsonObject authInfo, Handler<AsyncResult<User>> handler) { 050 051 String username = authInfo.getString("username"); 052 if (username == null) { 053 handler.handle(Future.failedFuture("authInfo must contain username in 'username' field")); 054 return; 055 } 056 057 String password = authInfo.getString("password"); 058 if (password == null) { 059 handler.handle(Future.failedFuture("authInfo must contain password in 'password' field")); 060 return; 061 } 062 063 String group = WebViewConfiguration.getSimpleAuthGroup(username, password); 064 if(group == null) { 065 handler.handle(Future.failedFuture("Incorrect password.")); 066 } else { 067 handler.handle(Future.succeededFuture(new NoneUser(username, group))); 068 } 069 } 070}