upd to Jetty 9.4.6.v20170531

Modify loginservice to the changes in Jetty, partially based on pull 
request #101 https://github.com/yacy/yacy_search_server/pull/101 bu @automenta
This commit is contained in:
reger committed 2017-07-01 23:58:28 +02:00
1 parent e4c730b99f
commit e6e20dab52
37 files changed
+135 -79

No files matched your search

+14 -14
View File
@@ -45,20 +45,20 @@
<classpathentry kind="lib" path="lib/commons-io-2.5.jar"/>
<classpathentry kind="lib" path="lib/slf4j-api-1.7.24.jar"/>
<classpathentry kind="lib" path="lib/chardet.jar"/>
<classpathentry kind="lib" path="lib/jetty-client-9.2.21.v20170120.jar"/>
<classpathentry kind="lib" path="lib/jetty-continuation-9.2.21.v20170120.jar"/>
<classpathentry kind="lib" path="lib/jetty-deploy-9.2.21.v20170120.jar"/>
<classpathentry kind="lib" path="lib/jetty-http-9.2.21.v20170120.jar"/>
<classpathentry kind="lib" path="lib/jetty-io-9.2.21.v20170120.jar"/>
<classpathentry kind="lib" path="lib/jetty-jmx-9.2.21.v20170120.jar"/>
<classpathentry kind="lib" path="lib/jetty-proxy-9.2.21.v20170120.jar"/>
<classpathentry kind="lib" path="lib/jetty-security-9.2.21.v20170120.jar"/>
<classpathentry kind="lib" path="lib/jetty-server-9.2.21.v20170120.jar"/>
<classpathentry kind="lib" path="lib/jetty-servlet-9.2.21.v20170120.jar"/>
<classpathentry kind="lib" path="lib/jetty-servlets-9.2.21.v20170120.jar"/>
<classpathentry kind="lib" path="lib/jetty-util-9.2.21.v20170120.jar"/>
<classpathentry kind="lib" path="lib/jetty-webapp-9.2.21.v20170120.jar"/>
<classpathentry kind="lib" path="lib/jetty-xml-9.2.21.v20170120.jar"/>
<classpathentry kind="lib" path="lib/jetty-client-9.4.6.v20170531.jar"/>
<classpathentry kind="lib" path="lib/jetty-continuation-9.4.6.v20170531.jar"/>
<classpathentry kind="lib" path="lib/jetty-deploy-9.4.6.v20170531.jar"/>
<classpathentry kind="lib" path="lib/jetty-http-9.4.6.v20170531.jar"/>
<classpathentry kind="lib" path="lib/jetty-io-9.4.6.v20170531.jar"/>
<classpathentry kind="lib" path="lib/jetty-jmx-9.4.6.v20170531.jar"/>
<classpathentry kind="lib" path="lib/jetty-proxy-9.4.6.v20170531.jar"/>
<classpathentry kind="lib" path="lib/jetty-security-9.4.6.v20170531.jar"/>
<classpathentry kind="lib" path="lib/jetty-server-9.4.6.v20170531.jar"/>
<classpathentry kind="lib" path="lib/jetty-servlet-9.4.6.v20170531.jar"/>
<classpathentry kind="lib" path="lib/jetty-servlets-9.4.6.v20170531.jar"/>
<classpathentry kind="lib" path="lib/jetty-util-9.4.6.v20170531.jar"/>
<classpathentry kind="lib" path="lib/jetty-webapp-9.4.6.v20170531.jar"/>
<classpathentry kind="lib" path="lib/jetty-xml-9.4.6.v20170531.jar"/>
<classpathentry kind="lib" path="lib/httpclient-4.5.3.jar"/>
<classpathentry kind="lib" path="lib/httpmime-4.5.3.jar"/>
<classpathentry kind="lib" path="lib/noggit-0.6.jar"/>
+14 -14
View File
@@ -202,20 +202,20 @@
<pathelement location="${lib}/javax.servlet-api-3.1.0.jar" />
<pathelement location="${lib}/jcifs-1.3.17.jar" />
<pathelement location="${lib}/jcl-over-slf4j-1.7.24.jar" />
<pathelement location="${lib}/jetty-client-9.2.21.v20170120.jar" />
<pathelement location="${lib}/jetty-continuation-9.2.21.v20170120.jar" />
<pathelement location="${lib}/jetty-deploy-9.2.21.v20170120.jar" />
<pathelement location="${lib}/jetty-http-9.2.21.v20170120.jar" />
<pathelement location="${lib}/jetty-io-9.2.21.v20170120.jar" />
<pathelement location="${lib}/jetty-jmx-9.2.21.v20170120.jar" />
<pathelement location="${lib}/jetty-proxy-9.2.21.v20170120.jar" />
<pathelement location="${lib}/jetty-security-9.2.21.v20170120.jar" />
<pathelement location="${lib}/jetty-server-9.2.21.v20170120.jar" />
<pathelement location="${lib}/jetty-servlet-9.2.21.v20170120.jar" />
<pathelement location="${lib}/jetty-servlets-9.2.21.v20170120.jar" />
<pathelement location="${lib}/jetty-util-9.2.21.v20170120.jar" />
<pathelement location="${lib}/jetty-webapp-9.2.21.v20170120.jar" />
<pathelement location="${lib}/jetty-xml-9.2.21.v20170120.jar" />
<pathelement location="${lib}/jetty-client-9.4.6.v20170531.jar" />
<pathelement location="${lib}/jetty-continuation-9.4.6.v20170531.jar" />
<pathelement location="${lib}/jetty-deploy-9.4.6.v20170531.jar" />
<pathelement location="${lib}/jetty-http-9.4.6.v20170531.jar" />
<pathelement location="${lib}/jetty-io-9.4.6.v20170531.jar" />
<pathelement location="${lib}/jetty-jmx-9.4.6.v20170531.jar" />
<pathelement location="${lib}/jetty-proxy-9.4.6.v20170531.jar" />
<pathelement location="${lib}/jetty-security-9.4.6.v20170531.jar" />
<pathelement location="${lib}/jetty-server-9.4.6.v20170531.jar" />
<pathelement location="${lib}/jetty-servlet-9.4.6.v20170531.jar" />
<pathelement location="${lib}/jetty-servlets-9.4.6.v20170531.jar" />
<pathelement location="${lib}/jetty-util-9.4.6.v20170531.jar" />
<pathelement location="${lib}/jetty-webapp-9.4.6.v20170531.jar" />
<pathelement location="${lib}/jetty-xml-9.4.6.v20170531.jar" />
<pathelement location="${lib}/jsch-0.1.54.jar" />
<pathelement location="${lib}/json-simple-1.1.1.jar" />
<pathelement location="${lib}/jsonic-1.2.0.jar" />
+5 -1
View File
@@ -25,6 +25,7 @@ import net.yacy.cora.protocol.RequestHeader;
import net.yacy.cora.util.ConcurrentLog;
import net.yacy.data.UserDB;
import net.yacy.data.UserDB.AccessRight;
import net.yacy.http.Jetty9HttpServerImpl;
import net.yacy.search.Switchboard;
import net.yacy.search.SwitchboardConstants;
import net.yacy.server.serverObjects;
@@ -153,7 +154,8 @@ public class ConfigUser_p {
} catch (final Exception e) {
ConcurrentLog.logException(e);
}
Jetty9HttpServerImpl jhttpserver = (Jetty9HttpServerImpl) sb.getHttpServer();
jhttpserver.resetUser(entry.getUserName());
} else {
prop.put("error", "1");
}
@@ -163,6 +165,8 @@ public class ConfigUser_p {
prop.putHTML("username", username);
} else if (post.containsKey("delete")) {
sb.userDB.removeEntry(post.get("username"));
Jetty9HttpServerImpl jhttpserver = (Jetty9HttpServerImpl) sb.getHttpServer();
jhttpserver.removeUser(post.get("username"));
prop.put(serverObjects.ACTION_LOCATION, "ConfigAccountList_p.html"); // jump back to user list
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File renamed without changes.
+1 -1
View File
@@ -36,7 +36,7 @@
<!-- the Solr version used in dependency section for all related dependencies -->
<solr.version>6.6.0</solr.version>
<!-- the Jetty version used in dependency section for all related dependencies -->
<jetty.version>9.2.21.v20170120</jetty.version>
<jetty.version>9.4.6.v20170531</jetty.version>
<!-- properties used for filtering yacyBuildProperties.java -->
<REPL_DATE>${DSTAMP}</REPL_DATE>
@@ -340,7 +340,9 @@ public class Jetty9HttpServerImpl implements YaCyHttpServer {
Jetty9YaCySecurityHandler hx = this.server.getChildHandlerByClass(Jetty9YaCySecurityHandler.class);
if (hx != null) {
YaCyLoginService loginservice = (YaCyLoginService) hx.getLoginService();
loginservice.loadUser(username);
if (loginservice.removeUser(username)) { // remove old credential from cache
loginservice.loadUserInfo(username);
}
}
}
+1 -1
View File
@@ -59,7 +59,7 @@ public class MonitorHandler extends AbstractHandler {
final ConnectionInfo info = new ConnectionInfo(
baseRequest.getScheme(),
baseRequest.getRemoteAddr() + ":" + baseRequest.getRemotePort(),
baseRequest.getMethod() + " " + baseRequest.getUri().getPathAndParam(),
baseRequest.getMethod() + " " + baseRequest.getHttpURI().getPathQuery(),
connection.hashCode(),
baseRequest.getTimeStamp(),
-1);
@@ -87,7 +87,7 @@ public class YaCyLegacyCredential extends Credential {
}
// normal users (and new admin pwd) for BASIC auth
if (hash.startsWith(MD5.__TYPE) && hash != null) {
if (hash.startsWith("MD5:") && hash != null) {
boolean success = (Digest.encodeMD5Hex(foruser + ":" + Switchboard.getSwitchboard().getConfig(SwitchboardConstants.ADMIN_REALM,"YaCy")+":" + pw).equals(hash.substring(4)));
// exception: allow the hash as pwd (used in bin/apicall.sh)
if (!success && foruser.equals(Switchboard.getSwitchboard().getConfig(SwitchboardConstants.ADMIN_ACCOUNT_USER_NAME, "admin"))) {
+96 -46
View File
@@ -2,7 +2,7 @@
// YaCyLoginService
// Copyright 2011 by Florian Richter
// First released 16.04.2011 at http://yacy.net
//
//
// $LastChangedDate$
// $LastChangedRevision$
// $LastChangedBy$
@@ -11,12 +11,12 @@
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program in the file lgpl21.txt
// If not, see <http://www.gnu.org/licenses/>.
@@ -24,68 +24,118 @@
package net.yacy.http;
import java.io.IOException;
import java.util.ArrayList;
import net.yacy.data.UserDB.AccessRight;
import net.yacy.data.UserDB.Entry;
import net.yacy.search.Switchboard;
import net.yacy.search.SwitchboardConstants;
import org.eclipse.jetty.security.AbstractLoginService;
import org.eclipse.jetty.security.HashLoginService;
import org.eclipse.jetty.security.LoginService;
import org.eclipse.jetty.security.MappedLoginService;
import org.eclipse.jetty.security.UserStore;
import org.eclipse.jetty.server.UserIdentity;
import org.eclipse.jetty.util.security.Credential;
/**
* jetty login service, provides admin and YaCy.UserDB users with role assignment
* with DIGEST auth by default Jetty uses the name of the loginSevice as realmname (which is part of all password hashes)
* jetty login service, provides admin and YaCy.UserDB users with role
* assignment with DIGEST auth by default Jetty uses the name of the loginSevice
* as realmname (which is part of all password hashes)
*/
public class YaCyLoginService extends MappedLoginService implements LoginService {
public class YaCyLoginService extends HashLoginService implements LoginService {
private UserStore _userStore; // user cache for known/authenticated users
/**
* Initialize a user cache
* @throws Exception
*/
@Override
protected UserIdentity loadUser(String username) {
if (username == null || username.isEmpty()) return null; // quick exit
protected void doStart() throws Exception {
_userStore = new UserStore();
this.setUserStore(_userStore);
super.doStart();
}
final Switchboard sb = Switchboard.getSwitchboard();
String adminuser = sb.getConfig(SwitchboardConstants.ADMIN_ACCOUNT_USER_NAME, "admin");
Credential credential = null;
String[] roles = null;
if (username.equals(adminuser)) {
final String adminAccountBase64MD5 = sb.getConfig(SwitchboardConstants.ADMIN_ACCOUNT_B64MD5, "");
// in YaCy the credential hash is composed of username:pwd so the username is needed to create valid credential
// not just the password (as usually in Jetty). As the accountname for the std. adminuser is not stored a useridentity
// is created for current user (and the pwd checked against the stored username:pwd setting)
credential = YaCyLegacyCredential.getCredentialForAdmin(username, adminAccountBase64MD5);
// TODO: YaCy user:pwd hashes should longterm likely be switched to separable username + pwd-hash entries
// and/or the standard admin account username should be fix = "admin"
roles = new String[]{AccessRight.ADMIN_RIGHT.toString()};
} else {
Entry user = sb.userDB.getEntry(username);
if (user != null && user.getMD5EncodedUserPwd() != null) {
// assigning roles from userDB
ArrayList<String> roletmp = new ArrayList<String>();
for (final AccessRight right : AccessRight.values()) {
if (user.hasRight(right)) {
roletmp.add(right.toString());
/**
* Free space used by user cache
* @throws Exception
*/
@Override
protected void doStop() throws Exception {
super.doStop();
if (_userStore != null) {
_userStore.stop();
_userStore = null;
}
}
/**
* Load the user from cache (of authenticated users) or from the YaCy user db
* @param username
* @return known user or null
*/
@Override
protected AbstractLoginService.UserPrincipal loadUserInfo(String username) {
if (username == null || username.isEmpty()) {
return null; // quick exit
}
AbstractLoginService.UserPrincipal theUser = super.loadUserInfo(username); // load from cache (the internal _userStore)
if (theUser == null) {
final Switchboard sb = Switchboard.getSwitchboard();
String adminuser = sb.getConfig(SwitchboardConstants.ADMIN_ACCOUNT_USER_NAME, "admin");
Credential credential = null;
String[] roles = null;
if (username.equals(adminuser)) {
final String adminAccountBase64MD5 = sb.getConfig(SwitchboardConstants.ADMIN_ACCOUNT_B64MD5, "");
// in YaCy the credential hash is composed of username:pwd so the username is needed to create valid credential
// not just the password (as usually in Jetty). As the accountname for the std. adminuser is not stored a useridentity
// is created for current user (and the pwd checked against the stored username:pwd setting)
credential = YaCyLegacyCredential.getCredentialForAdmin(username, adminAccountBase64MD5);
// TODO: YaCy user:pwd hashes should longterm likely be switched to separable username + pwd-hash entries
// and/or the standard admin account username should be fix = "admin"
roles = new String[]{AccessRight.ADMIN_RIGHT.toString()};
} else {
Entry user = sb.userDB.getEntry(username);
if (user != null && user.getMD5EncodedUserPwd() != null) {
// assigning roles from userDB
ArrayList<String> roletmp = new ArrayList<String>();
for (final AccessRight right : AccessRight.values()) {
if (user.hasRight(right)) {
roletmp.add(right.toString());
}
}
if (roletmp.size() > 0) {
roles = roletmp.toArray(new String[roletmp.size()]);
}
credential = YaCyLegacyCredential.getCredentialForUserDB(username, user.getMD5EncodedUserPwd());
}
if (roletmp.size() > 0) roles = roletmp.toArray(new String[roletmp.size()]);
credential = YaCyLegacyCredential.getCredentialForUserDB(username, user.getMD5EncodedUserPwd());
}
if (credential != null) { // if credential exist, user is known, create or get info
theUser = new AbstractLoginService.UserPrincipal(username, credential);
_userStore.addUser(username, credential, roles); // add to jetty user cache
_userStore.getUserIdentity(username).getUserPrincipal();
theUser.authenticate(credential);
}
}
return theUser;
}
if (credential != null) {
if (roles != null) {
return putUser(username, credential, roles);
}
return putUser(username, credential); // w/o role makes not much sense, but succeeds login....
/**
* Delete a user from the internal cache. If user found in cache user is
* loged out before delete.
* @param username
* @return true if user deleted, if not found in user cache false
*/
public boolean removeUser(String username) {
UserIdentity uid = _userStore.getUserIdentity(username);
if (uid != null) {
logout(uid);
_userStore.removeUser(username);
return true;
}
return null;
return false;
}
@Override
protected void loadUsers() throws IOException {
// don't load any users into MappedLoginService on startup
// we use loadUser for dynamic checking
}
}
}