Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions scouter.client/src/scouter/client/net/LoginMgr.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,21 @@ public static LoginResult login(int serverId, String user, String password){
return silentLogin(server, user, encrypted);
}

public static LoginResult silentLogin(Server server, String user, String encryptedPwd){
public static LoginResult login(int serverId, String user, String password, boolean ldapLogin){
Server server = ServerManager.getInstance().getServer(serverId);

if(!ldapLogin)
password = CipherUtil.sha256(password);

return silentLogin(server, user, password);
}

public static LoginResult silentLogin(Server server, String user, String password){
LoginResult result = new LoginResult();
try {
MapPack param = new MapPack();
param.put("id", user);
param.put("pass", encryptedPwd);
param.put("pass", password);
param.put("version", Version.getClientFullVersion());
param.put("hostname", SysJMX.getHostName());

Expand Down Expand Up @@ -71,7 +80,7 @@ public static LoginResult silentLogin(Server server, String user, String encrypt
server.setName(serverName);
server.setDelta(time);
server.setUserId(user);
server.setPassword(encryptedPwd);
server.setPassword(password);
server.setGroup(type);
server.setVersion(version);
server.setEmail(email);
Expand Down Expand Up @@ -121,4 +130,5 @@ public static MapPack getCounterXmlServer(int serverId) {
}
return (MapPack) p;
}

}
23 changes: 19 additions & 4 deletions scouter.client/src/scouter/client/popup/LoginDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ public class LoginDialog {

List list;

Button autoLoginCheck, showPass;
Button autoLoginCheck, showPass, ldapLoginCheck;
boolean autoLogin;
boolean ldapLogin;

String address = null;
boolean showPassword = false;
Expand Down Expand Up @@ -181,12 +182,26 @@ public void widgetSelected(SelectionEvent e) {
}
});
autoLoginCheck.setSelection(false);


ldapLoginCheck = new Button(parentGroup, SWT.CHECK);
ldapLoginCheck.setText("Ldap Login");
ldapLoginCheck.setLayoutData(UIUtil.formData(null, -1, autoLoginCheck, 10, 100, -5, null, -1));
ldapLoginCheck.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
if (ldapLoginCheck.getSelection()) {
ldapLogin = true;
} else {
ldapLogin = false;
}
}
});

list = new List(parentGroup, SWT.NONE);
list.setLayoutData(UIUtil.formData(0, 5, autoLoginCheck, 10, 100, -5, null, -1, -1, 60));
list.setLayoutData(UIUtil.formData(0, 5, ldapLoginCheck, 10, 100, -5, null, -1, -1, 60));
list.add("Type your authentication info...");
list.select(list.getItemCount() - 1);
list.showSelection();


Composite footer = new Composite(shell, SWT.NONE);
footer.setLayoutData(UIUtil.formData(0, 5, parentGroup, 10, 100, -5, null, -1));
Expand Down Expand Up @@ -336,7 +351,7 @@ public boolean loginInToServer(String address) {
existServer = true;
}

LoginResult result = LoginMgr.login(server.getId(), id.getText(), pass.getText());
LoginResult result = LoginMgr.login(server.getId(), id.getText(), pass.getText(), ldapLogin);
if (result.success) {
msg("Successfully log in to " + address);
ServerPrefUtil.addServerAddr(address);
Expand Down
78 changes: 71 additions & 7 deletions scouter.server/src/scouter/server/account/AccountManager.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,23 @@
*
*/
package scouter.server.account;

import java.io.File
import java.io.FileOutputStream
import java.io.InputStream
import java.util.ArrayList
import java.util.Enumeration
import java.util.List
import java.util.Properties;
import javax.naming.Context;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
import javax.naming.directory.DirContext;
import javax.naming.directory.InitialDirContext;
import javax.naming.directory.SearchControls;
import javax.naming.directory.SearchResult;
import scouter.server.Configure
import scouter.server.Logger
import scouter.lang.Account
Expand All @@ -34,12 +45,14 @@ import scouter.util.StringKeyLinkedMap
import scouter.util.ThreadUtil
import scouter.server.util.ThreadScala
import scouter.server.core.CoreRun

object AccountManager {
val ACCOUNT_FILENAME = "account.xml";
val GROUP_FILENAME = "account_group.xml";
var accountMap = new StringKeyLinkedMap[Account]();
var groupPolicyMap = new StringKeyLinkedMap[MapValue]();
val confPath = Configure.CONF_DIR;
val confPath = Configure.CONF_DIR;
var conf = Configure.getInstance();
FileUtil.mkdirs(confPath);
val groupFile = new File(confPath + GROUP_FILENAME);
val accountFile = new File(confPath + ACCOUNT_FILENAME);
Expand Down Expand Up @@ -88,6 +101,7 @@ object AccountManager {
lastModifiedGroupFile = groupFile.lastModified();
} catch {
case e: Exception => e.printStackTrace();

}
}
}
Expand Down Expand Up @@ -128,12 +142,62 @@ object AccountManager {
}
}
def authorizeAccount(id: String, pass: String): Account = {
val account = accountMap.get(id);
if (account == null) {
return null;
}
if (account.password.equals(pass)) {
return account;
if(conf.getBoolean("account_use_ldap",false)){
var ctx : DirContext = null;
var props : Properties = new Properties();

props.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
props.setProperty(Context.PROVIDER_URL, conf.getValue("account_ldap_provider_url"));
props.setProperty(Context.SECURITY_AUTHENTICATION, conf.getValue("account_ldap_auth=","simple"));
props.setProperty(Context.SECURITY_PRINCIPAL, id+conf.getValue("account_ldap_principal_domain"));
props.setProperty(Context.SECURITY_CREDENTIALS, pass);

try{
ctx = new InitialDirContext(props);
var cons : SearchControls = new SearchControls();
cons.setSearchScope(SearchControls.SUBTREE_SCOPE);
var searchFilter : String = "(cn="+id+")";

if(conf.getBoolean("account_ldap_debug", false)){
Logger.println("ldap id : "+id);
Logger.println("ldap pass : "+pass);
Logger.println("ldap properties : "+props.toString());
}

var result = ctx.search(conf.getValue("account_ldap_basedn"), searchFilter, cons);
var nextEntry : SearchResult = null;
if(result.hasMore()){
var attrs = result.next().getAttributes();
var nmEnum = attrs.getIDs();
while(nmEnum.hasMore()){
var _id = nmEnum.next();

if( id.equals( attrs.get(_id).get().toString()) ){
var account : Account = new Account();
account.id = id
try{
account.email = attrs.get(conf.getValue("account_ldap_email_id","")).get().toString();
account.group = attrs.get(conf.getValue("account_ldap_group_id","")).get().toString();
}catch{
case ne : NullPointerException => ne.printStackTrace()
}
return account;
}
}
}
}catch{
case e: Exception => Logger.println("Ldap Account Error : "+e.toString()); e.printStackTrace();
}finally{
if(null != ctx) ctx.close();
}
}else{
val account = accountMap.get(id);
if (account == null) {
return null;
}
if (account.password.equals(pass)) {
return account;
}
}
return null;
}
Expand Down