mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 23:45:44 +01:00
merge with branch issue-73
This commit is contained in:
@@ -362,7 +362,7 @@
|
|||||||
<aether.version>1.13</aether.version>
|
<aether.version>1.13</aether.version>
|
||||||
<wagon.version>1.0</wagon.version>
|
<wagon.version>1.0</wagon.version>
|
||||||
<maven.version>3.0.3</maven.version>
|
<maven.version>3.0.3</maven.version>
|
||||||
<netbeans.hint.deploy.server>gfv3ee6</netbeans.hint.deploy.server>
|
<netbeans.hint.deploy.server>Tomcat</netbeans.hint.deploy.server>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<profiles>
|
<profiles>
|
||||||
|
|||||||
@@ -123,43 +123,82 @@ public class BasicSecurityContext implements WebSecurityContext
|
|||||||
AuthenticationResult ar = authenticator.authenticate(request, response,
|
AuthenticationResult ar = authenticator.authenticate(request, response,
|
||||||
username, password);
|
username, password);
|
||||||
|
|
||||||
if (ar != null)
|
if ((ar != null) && (ar.getState() == AuthenticationState.SUCCESS))
|
||||||
{
|
{
|
||||||
user = ar.getUser();
|
user = ar.getUser();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
Set<String> groupSet = new HashSet<String>();
|
||||||
|
|
||||||
|
// load external groups
|
||||||
|
Collection<String> extGroups = ar.getGroups();
|
||||||
|
|
||||||
|
if (extGroups != null)
|
||||||
|
{
|
||||||
|
groupSet.addAll(extGroups);
|
||||||
|
}
|
||||||
|
|
||||||
|
// load internal groups
|
||||||
|
loadGroups(groupSet);
|
||||||
|
|
||||||
|
// check for admin user
|
||||||
|
if (!user.isAdmin())
|
||||||
|
{
|
||||||
|
user.setAdmin(isAdmin(groupSet));
|
||||||
|
|
||||||
|
if (logger.isDebugEnabled() && user.isAdmin())
|
||||||
|
{
|
||||||
|
logger.debug("user '{}' is marked as admin by configuration",
|
||||||
|
user.getType(), user.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (logger.isDebugEnabled())
|
||||||
|
{
|
||||||
|
logger.debug("authenticator {} marked user '{}' as admin",
|
||||||
|
user.getType(), user.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
// store user
|
||||||
User dbUser = userManager.get(user.getName());
|
User dbUser = userManager.get(user.getName());
|
||||||
|
|
||||||
if ((dbUser != null) && user.copyProperties(dbUser, false))
|
if (dbUser != null)
|
||||||
{
|
{
|
||||||
userManager.modify(dbUser);
|
|
||||||
|
// if database user is an admin, set admin for the current user
|
||||||
|
if (dbUser.isAdmin())
|
||||||
|
{
|
||||||
|
if (logger.isDebugEnabled())
|
||||||
|
{
|
||||||
|
logger.debug("user '{}' is marked as admin by local database",
|
||||||
|
user.getType(), user.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
user.setAdmin(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// modify existing user, copy properties except password and admin
|
||||||
|
if (user.copyProperties(dbUser, false))
|
||||||
|
{
|
||||||
|
userManager.modify(dbUser);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// create new user
|
||||||
else if (dbUser == null)
|
else if (dbUser == null)
|
||||||
{
|
{
|
||||||
userManager.create(user);
|
userManager.create(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
Collection<String> groupCollection = ar.getGroups();
|
groups = groupSet;
|
||||||
|
|
||||||
if (groupCollection != null)
|
|
||||||
{
|
|
||||||
groups.addAll(groupCollection);
|
|
||||||
}
|
|
||||||
|
|
||||||
loadGroups();
|
|
||||||
|
|
||||||
if (!user.isAdmin())
|
|
||||||
{
|
|
||||||
user.setAdmin(isAdmin());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (logger.isDebugEnabled())
|
if (logger.isDebugEnabled())
|
||||||
{
|
{
|
||||||
logGroups();
|
logGroups();
|
||||||
}
|
}
|
||||||
|
|
||||||
String credentials = dbUser.getName();
|
// store encrypted credentials in session
|
||||||
|
String credentials = user.getName();
|
||||||
|
|
||||||
if (Util.isNotEmpty(password))
|
if (Util.isNotEmpty(password))
|
||||||
{
|
{
|
||||||
@@ -172,6 +211,12 @@ public class BasicSecurityContext implements WebSecurityContext
|
|||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
user = null;
|
user = null;
|
||||||
|
|
||||||
|
if (groups != null)
|
||||||
|
{
|
||||||
|
groups.clear();
|
||||||
|
}
|
||||||
|
|
||||||
logger.error("authentication failed", ex);
|
logger.error("authentication failed", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -253,8 +298,10 @@ public class BasicSecurityContext implements WebSecurityContext
|
|||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
|
*
|
||||||
|
* @param groupSet
|
||||||
*/
|
*/
|
||||||
private void loadGroups()
|
private void loadGroups(Set<String> groupSet)
|
||||||
{
|
{
|
||||||
Collection<Group> groupCollection =
|
Collection<Group> groupCollection =
|
||||||
groupManager.getGroupsForMember(user.getName());
|
groupManager.getGroupsForMember(user.getName());
|
||||||
@@ -263,7 +310,7 @@ public class BasicSecurityContext implements WebSecurityContext
|
|||||||
{
|
{
|
||||||
for (Group group : groupCollection)
|
for (Group group : groupCollection)
|
||||||
{
|
{
|
||||||
groups.add(group.getName());
|
groupSet.add(group.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -308,9 +355,11 @@ public class BasicSecurityContext implements WebSecurityContext
|
|||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
|
*
|
||||||
|
* @param groups
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private boolean isAdmin()
|
private boolean isAdmin(Collection<String> groups)
|
||||||
{
|
{
|
||||||
boolean result = false;
|
boolean result = false;
|
||||||
Set<String> adminUsers = configuration.getAdminUsers();
|
Set<String> adminUsers = configuration.getAdminUsers();
|
||||||
|
|||||||
@@ -62,12 +62,14 @@ Sonia.user.FormPanel = Ext.extend(Sonia.rest.FormPanel,{
|
|||||||
fieldLabel: this.displayNameText,
|
fieldLabel: this.displayNameText,
|
||||||
name: 'displayName',
|
name: 'displayName',
|
||||||
allowBlank: false,
|
allowBlank: false,
|
||||||
|
readOnly: this.item != null && this.item != 'xml',
|
||||||
helpText: this.displayNameHelpText
|
helpText: this.displayNameHelpText
|
||||||
},{
|
},{
|
||||||
fieldLabel: this.mailText,
|
fieldLabel: this.mailText,
|
||||||
name: 'mail',
|
name: 'mail',
|
||||||
allowBlank: true,
|
allowBlank: true,
|
||||||
vtype: 'email',
|
vtype: 'email',
|
||||||
|
readOnly: this.item != null && this.item != 'xml',
|
||||||
helpText: this.mailHelpText
|
helpText: this.mailHelpText
|
||||||
}];
|
}];
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user