mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 15:35:49 +01:00
removes admin flag from user object
This commit is contained in:
@@ -157,12 +157,6 @@ public class User extends BasicPropertiesAware implements Principal, ModelObject
|
|||||||
{
|
{
|
||||||
boolean result = false;
|
boolean result = false;
|
||||||
|
|
||||||
if (user.isAdmin() != admin)
|
|
||||||
{
|
|
||||||
result = true;
|
|
||||||
user.setAdmin(admin);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (user.isActive() != active)
|
if (user.isActive() != active)
|
||||||
{
|
{
|
||||||
result = true;
|
result = true;
|
||||||
@@ -229,7 +223,6 @@ public class User extends BasicPropertiesAware implements Principal, ModelObject
|
|||||||
&& Objects.equal(displayName, other.displayName)
|
&& Objects.equal(displayName, other.displayName)
|
||||||
&& Objects.equal(mail, other.mail)
|
&& Objects.equal(mail, other.mail)
|
||||||
&& Objects.equal(type, other.type)
|
&& Objects.equal(type, other.type)
|
||||||
&& Objects.equal(admin, other.admin)
|
|
||||||
&& Objects.equal(active, other.active)
|
&& Objects.equal(active, other.active)
|
||||||
&& Objects.equal(password, other.password)
|
&& Objects.equal(password, other.password)
|
||||||
&& Objects.equal(creationDate, other.creationDate)
|
&& Objects.equal(creationDate, other.creationDate)
|
||||||
@@ -246,7 +239,7 @@ public class User extends BasicPropertiesAware implements Principal, ModelObject
|
|||||||
@Override
|
@Override
|
||||||
public int hashCode()
|
public int hashCode()
|
||||||
{
|
{
|
||||||
return Objects.hashCode(name, displayName, mail, type, admin, password,
|
return Objects.hashCode(name, displayName, mail, type, password,
|
||||||
active, creationDate, lastModified, properties);
|
active, creationDate, lastModified, properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -269,7 +262,6 @@ public class User extends BasicPropertiesAware implements Principal, ModelObject
|
|||||||
.add("displayName",displayName)
|
.add("displayName",displayName)
|
||||||
.add("mail", mail)
|
.add("mail", mail)
|
||||||
.add("password", pwd)
|
.add("password", pwd)
|
||||||
.add("admin", admin)
|
|
||||||
.add("type", type)
|
.add("type", type)
|
||||||
.add("active", active)
|
.add("active", active)
|
||||||
.add("creationDate", creationDate)
|
.add("creationDate", creationDate)
|
||||||
@@ -385,17 +377,6 @@ public class User extends BasicPropertiesAware implements Principal, ModelObject
|
|||||||
return active;
|
return active;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public boolean isAdmin()
|
|
||||||
{
|
|
||||||
return admin;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
@@ -424,17 +405,6 @@ public class User extends BasicPropertiesAware implements Principal, ModelObject
|
|||||||
this.active = active;
|
this.active = active;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param admin
|
|
||||||
*/
|
|
||||||
public void setAdmin(boolean admin)
|
|
||||||
{
|
|
||||||
this.admin = admin;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
@@ -518,9 +488,6 @@ public class User extends BasicPropertiesAware implements Principal, ModelObject
|
|||||||
/** Field description */
|
/** Field description */
|
||||||
private boolean active = true;
|
private boolean active = true;
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private boolean admin = false;
|
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private Long creationDate;
|
private Long creationDate;
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ export type User = {
|
|||||||
name: string,
|
name: string,
|
||||||
mail: string,
|
mail: string,
|
||||||
password: string,
|
password: string,
|
||||||
admin: boolean,
|
|
||||||
active: boolean,
|
active: boolean,
|
||||||
type?: string,
|
type?: string,
|
||||||
creationDate?: string,
|
creationDate?: string,
|
||||||
|
|||||||
@@ -37,7 +37,6 @@ class UserForm extends React.Component<Props, State> {
|
|||||||
displayName: "",
|
displayName: "",
|
||||||
mail: "",
|
mail: "",
|
||||||
password: "",
|
password: "",
|
||||||
admin: false,
|
|
||||||
active: true,
|
active: true,
|
||||||
_links: {}
|
_links: {}
|
||||||
},
|
},
|
||||||
@@ -167,12 +166,6 @@ class UserForm extends React.Component<Props, State> {
|
|||||||
<div className="columns">
|
<div className="columns">
|
||||||
<div className="column">
|
<div className="column">
|
||||||
{passwordChangeField}
|
{passwordChangeField}
|
||||||
<Checkbox
|
|
||||||
label={t("user.admin")}
|
|
||||||
onChange={this.handleAdminChange}
|
|
||||||
checked={user ? user.admin : false}
|
|
||||||
helpText={t("help.adminHelpText")}
|
|
||||||
/>
|
|
||||||
<Checkbox
|
<Checkbox
|
||||||
label={t("user.active")}
|
label={t("user.active")}
|
||||||
onChange={this.handleActiveChange}
|
onChange={this.handleActiveChange}
|
||||||
@@ -225,10 +218,6 @@ class UserForm extends React.Component<Props, State> {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
handleAdminChange = (admin: boolean) => {
|
|
||||||
this.setState({ user: { ...this.state.user, admin } });
|
|
||||||
};
|
|
||||||
|
|
||||||
handleActiveChange = (active: boolean) => {
|
handleActiveChange = (active: boolean) => {
|
||||||
this.setState({ user: { ...this.state.user, active } });
|
this.setState({ user: { ...this.state.user, active } });
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,66 +1,60 @@
|
|||||||
//@flow
|
//@flow
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import type { User } from "@scm-manager/ui-types";
|
import type { User } from "@scm-manager/ui-types";
|
||||||
import { translate } from "react-i18next";
|
import { translate } from "react-i18next";
|
||||||
import { Checkbox, MailLink, DateFromNow } from "@scm-manager/ui-components";
|
import { Checkbox, MailLink, DateFromNow } from "@scm-manager/ui-components";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
user: User,
|
user: User,
|
||||||
t: string => string
|
t: string => string
|
||||||
};
|
};
|
||||||
|
|
||||||
class Details extends React.Component<Props> {
|
class Details extends React.Component<Props> {
|
||||||
render() {
|
render() {
|
||||||
const { user, t } = this.props;
|
const { user, t } = this.props;
|
||||||
return (
|
return (
|
||||||
<table className="table">
|
<table className="table">
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
<td className="has-text-weight-semibold">{t("user.name")}</td>
|
<td className="has-text-weight-semibold">{t("user.name")}</td>
|
||||||
<td>{user.name}</td>
|
<td>{user.name}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td className="has-text-weight-semibold">{t("user.displayName")}</td>
|
<td className="has-text-weight-semibold">{t("user.displayName")}</td>
|
||||||
<td>{user.displayName}</td>
|
<td>{user.displayName}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td className="has-text-weight-semibold">{t("user.mail")}</td>
|
<td className="has-text-weight-semibold">{t("user.mail")}</td>
|
||||||
<td>
|
<td>
|
||||||
<MailLink address={user.mail} />
|
<MailLink address={user.mail} />
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td className="has-text-weight-semibold">{t("user.admin")}</td>
|
<td className="has-text-weight-semibold">{t("user.active")}</td>
|
||||||
<td>
|
<td>
|
||||||
<Checkbox checked={user.admin} />
|
<Checkbox checked={user.active} />
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td className="has-text-weight-semibold">{t("user.active")}</td>
|
<td className="has-text-weight-semibold">{t("user.type")}</td>
|
||||||
<td>
|
<td>{user.type}</td>
|
||||||
<Checkbox checked={user.active} />
|
</tr>
|
||||||
</td>
|
<tr>
|
||||||
</tr>
|
<td className="has-text-weight-semibold">{t("user.creationDate")}</td>
|
||||||
<tr>
|
<td>
|
||||||
<td className="has-text-weight-semibold">{t("user.type")}</td>
|
<DateFromNow date={user.creationDate} />
|
||||||
<td>{user.type}</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td className="has-text-weight-semibold">{t("user.creationDate")}</td>
|
<td className="has-text-weight-semibold">{t("user.lastModified")}</td>
|
||||||
<td>
|
<td>
|
||||||
<DateFromNow date={user.creationDate} />
|
<DateFromNow date={user.lastModified} />
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
</tbody>
|
||||||
<td className="has-text-weight-semibold">{t("user.lastModified")}</td>
|
</table>
|
||||||
<td>
|
);
|
||||||
<DateFromNow date={user.lastModified} />
|
}
|
||||||
</td>
|
}
|
||||||
</tr>
|
|
||||||
</tbody>
|
export default translate("users")(Details);
|
||||||
</table>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default translate("users")(Details);
|
|
||||||
|
|||||||
@@ -1,31 +1,31 @@
|
|||||||
// @flow
|
// @flow
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { Link } from "react-router-dom";
|
import { Link } from "react-router-dom";
|
||||||
import type { User } from "@scm-manager/ui-types";
|
import type { User } from "@scm-manager/ui-types";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
user: User
|
user: User
|
||||||
};
|
};
|
||||||
|
|
||||||
export default class UserRow extends React.Component<Props> {
|
export default class UserRow extends React.Component<Props> {
|
||||||
renderLink(to: string, label: string) {
|
renderLink(to: string, label: string) {
|
||||||
return <Link to={to}>{label}</Link>;
|
return <Link to={to}>{label}</Link>;
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { user } = this.props;
|
const { user } = this.props;
|
||||||
const to = `/user/${user.name}`;
|
const to = `/user/${user.name}`;
|
||||||
return (
|
return (
|
||||||
<tr>
|
<tr>
|
||||||
<td className="is-hidden-mobile">{this.renderLink(to, user.name)}</td>
|
<td className="is-hidden-mobile">{this.renderLink(to, user.name)}</td>
|
||||||
<td>{this.renderLink(to, user.displayName)}</td>
|
<td>{this.renderLink(to, user.displayName)}</td>
|
||||||
<td>
|
<td>
|
||||||
<a href={`mailto: ${user.mail}`}>{user.mail}</a>
|
<a href={`mailto: ${user.mail}`}>{user.mail}</a>
|
||||||
</td>
|
</td>
|
||||||
<td className="is-hidden-mobile">
|
<td className="is-hidden-mobile">
|
||||||
<input type="checkbox" id="admin" checked={user.admin} readOnly />
|
<input type="checkbox" id="active" checked={user.active} readOnly />
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,37 +1,37 @@
|
|||||||
// @flow
|
// @flow
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { translate } from "react-i18next";
|
import { translate } from "react-i18next";
|
||||||
import UserRow from "./UserRow";
|
import UserRow from "./UserRow";
|
||||||
import type { User } from "@scm-manager/ui-types";
|
import type { User } from "@scm-manager/ui-types";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
t: string => string,
|
t: string => string,
|
||||||
users: User[]
|
users: User[]
|
||||||
};
|
};
|
||||||
|
|
||||||
;
|
;
|
||||||
|
|
||||||
class UserTable extends React.Component<Props> {
|
class UserTable extends React.Component<Props> {
|
||||||
render() {
|
render() {
|
||||||
const { users, t } = this.props;
|
const { users, t } = this.props;
|
||||||
return (
|
return (
|
||||||
<table className="card-table table is-hoverable is-fullwidth">
|
<table className="card-table table is-hoverable is-fullwidth">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th className="is-hidden-mobile">{t("user.name")}</th>
|
<th className="is-hidden-mobile">{t("user.name")}</th>
|
||||||
<th>{t("user.displayName")}</th>
|
<th>{t("user.displayName")}</th>
|
||||||
<th>{t("user.mail")}</th>
|
<th>{t("user.mail")}</th>
|
||||||
<th className="is-hidden-mobile">{t("user.admin")}</th>
|
<th className="is-hidden-mobile">{t("user.active")}</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{users.map((user, index) => {
|
{users.map((user, index) => {
|
||||||
return <UserRow key={index} user={user} />;
|
return <UserRow key={index} user={user} />;
|
||||||
})}
|
})}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default translate("users")(UserTable);
|
export default translate("users")(UserTable);
|
||||||
|
|||||||
@@ -49,15 +49,15 @@ import sonia.scm.user.UserEvent;
|
|||||||
import sonia.scm.user.UserModificationEvent;
|
import sonia.scm.user.UserModificationEvent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Receives all kinds of events, which affects authorization relevant data and fires an
|
* Receives all kinds of events, which affects authorization relevant data and fires an
|
||||||
* {@link AuthorizationChangedEvent} if authorization data has changed.
|
* {@link AuthorizationChangedEvent} if authorization data has changed.
|
||||||
*
|
*
|
||||||
* @author Sebastian Sdorra
|
* @author Sebastian Sdorra
|
||||||
* @since 1.52
|
* @since 1.52
|
||||||
*/
|
*/
|
||||||
@EagerSingleton
|
@EagerSingleton
|
||||||
public class AuthorizationChangedEventProducer {
|
public class AuthorizationChangedEventProducer {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the logger for AuthorizationChangedEventProducer
|
* the logger for AuthorizationChangedEventProducer
|
||||||
*/
|
*/
|
||||||
@@ -68,7 +68,7 @@ public class AuthorizationChangedEventProducer {
|
|||||||
*/
|
*/
|
||||||
public AuthorizationChangedEventProducer() {
|
public AuthorizationChangedEventProducer() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invalidates the cache of a user which was modified. The cache entries for the user will be invalidated for the
|
* Invalidates the cache of a user which was modified. The cache entries for the user will be invalidated for the
|
||||||
* following reasons:
|
* following reasons:
|
||||||
@@ -90,11 +90,11 @@ public class AuthorizationChangedEventProducer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isModificationEvent(HandlerEvent<?> event) {
|
private boolean isModificationEvent(HandlerEvent<?> event) {
|
||||||
return event instanceof ModificationHandlerEvent;
|
return event instanceof ModificationHandlerEvent;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleUserEvent(UserEvent event) {
|
private void handleUserEvent(UserEvent event) {
|
||||||
String username = event.getItem().getName();
|
String username = event.getItem().getName();
|
||||||
logger.debug(
|
logger.debug(
|
||||||
@@ -102,26 +102,26 @@ public class AuthorizationChangedEventProducer {
|
|||||||
);
|
);
|
||||||
fireEventForUser(username);
|
fireEventForUser(username);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleUserModificationEvent(UserModificationEvent event) {
|
private void handleUserModificationEvent(UserModificationEvent event) {
|
||||||
String username = event.getItem().getId();
|
String username = event.getItem().getId();
|
||||||
User beforeModification = event.getItemBeforeModification();
|
User beforeModification = event.getItemBeforeModification();
|
||||||
if (isAuthorizationDataModified(event.getItem(), beforeModification)) {
|
if (isAuthorizationDataModified(event.getItem(), beforeModification)) {
|
||||||
logger.debug(
|
logger.debug(
|
||||||
"fire authorization changed event for user {}, because of a authorization relevant field has changed",
|
"fire authorization changed event for user {}, because of a authorization relevant field has changed",
|
||||||
username
|
username
|
||||||
);
|
);
|
||||||
fireEventForUser(username);
|
fireEventForUser(username);
|
||||||
} else {
|
} else {
|
||||||
logger.debug(
|
logger.debug(
|
||||||
"authorization changed event for user {} is not fired, because no authorization relevant field has changed",
|
"authorization changed event for user {} is not fired, because no authorization relevant field has changed",
|
||||||
username
|
username
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isAuthorizationDataModified(User user, User beforeModification) {
|
private boolean isAuthorizationDataModified(User user, User beforeModification) {
|
||||||
return user.isAdmin() != beforeModification.isAdmin() || user.isActive() != beforeModification.isActive();
|
return user.isActive() != beforeModification.isActive();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fireEventForUser(String username) {
|
private void fireEventForUser(String username) {
|
||||||
@@ -148,7 +148,7 @@ public class AuthorizationChangedEventProducer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleRepositoryModificationEvent(RepositoryModificationEvent event) {
|
private void handleRepositoryModificationEvent(RepositoryModificationEvent event) {
|
||||||
Repository repository = event.getItem();
|
Repository repository = event.getItem();
|
||||||
if (isAuthorizationDataModified(repository, event.getItemBeforeModification())) {
|
if (isAuthorizationDataModified(repository, event.getItemBeforeModification())) {
|
||||||
@@ -169,14 +169,14 @@ public class AuthorizationChangedEventProducer {
|
|||||||
|| repository.isPublicReadable() != beforeModification.isPublicReadable()
|
|| repository.isPublicReadable() != beforeModification.isPublicReadable()
|
||||||
|| !(repository.getPermissions().containsAll(beforeModification.getPermissions()) && beforeModification.getPermissions().containsAll(repository.getPermissions()));
|
|| !(repository.getPermissions().containsAll(beforeModification.getPermissions()) && beforeModification.getPermissions().containsAll(repository.getPermissions()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fireEventForEveryUser() {
|
private void fireEventForEveryUser() {
|
||||||
sendEvent(AuthorizationChangedEvent.createForEveryUser());
|
sendEvent(AuthorizationChangedEvent.createForEveryUser());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleRepositoryEvent(RepositoryEvent event){
|
private void handleRepositoryEvent(RepositoryEvent event){
|
||||||
logger.debug(
|
logger.debug(
|
||||||
"fire authorization changed event, because of received {} event for repository {}",
|
"fire authorization changed event, because of received {} event for repository {}",
|
||||||
event.getEventType(), event.getItem().getName()
|
event.getEventType(), event.getItem().getName()
|
||||||
);
|
);
|
||||||
fireEventForEveryUser();
|
fireEventForEveryUser();
|
||||||
@@ -199,7 +199,7 @@ public class AuthorizationChangedEventProducer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleGroupPermissionChange(AssignedPermission permission) {
|
private void handleGroupPermissionChange(AssignedPermission permission) {
|
||||||
logger.debug(
|
logger.debug(
|
||||||
"fire authorization changed event for group {}, because permission {} has changed",
|
"fire authorization changed event for group {}, because permission {} has changed",
|
||||||
@@ -207,13 +207,13 @@ public class AuthorizationChangedEventProducer {
|
|||||||
);
|
);
|
||||||
fireEventForEveryUser();
|
fireEventForEveryUser();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleUserPermissionChange(AssignedPermission permission) {
|
private void handleUserPermissionChange(AssignedPermission permission) {
|
||||||
logger.debug(
|
logger.debug(
|
||||||
"fire authorization changed event for user {}, because permission {} has changed",
|
"fire authorization changed event for user {}, because permission {} has changed",
|
||||||
permission.getName(), permission.getPermission()
|
permission.getName(), permission.getPermission()
|
||||||
);
|
);
|
||||||
fireEventForUser(permission.getName());
|
fireEventForUser(permission.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -230,7 +230,7 @@ public class AuthorizationChangedEventProducer {
|
|||||||
public void onEvent(GroupEvent event) {
|
public void onEvent(GroupEvent event) {
|
||||||
if (event.getEventType().isPost()) {
|
if (event.getEventType().isPost()) {
|
||||||
if (isModificationEvent(event)) {
|
if (isModificationEvent(event)) {
|
||||||
handleGroupModificationEvent((GroupModificationEvent) event);
|
handleGroupModificationEvent((GroupModificationEvent) event);
|
||||||
} else {
|
} else {
|
||||||
handleGroupEvent(event);
|
handleGroupEvent(event);
|
||||||
}
|
}
|
||||||
@@ -244,28 +244,28 @@ public class AuthorizationChangedEventProducer {
|
|||||||
fireEventForEveryUser();
|
fireEventForEveryUser();
|
||||||
} else {
|
} else {
|
||||||
logger.debug(
|
logger.debug(
|
||||||
"authorization changed event is not fired, because non relevant field of group {} has changed",
|
"authorization changed event is not fired, because non relevant field of group {} has changed",
|
||||||
group.getId()
|
group.getId()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isAuthorizationDataModified(Group group, Group beforeModification) {
|
private boolean isAuthorizationDataModified(Group group, Group beforeModification) {
|
||||||
return !group.getMembers().equals(beforeModification.getMembers());
|
return !group.getMembers().equals(beforeModification.getMembers());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleGroupEvent(GroupEvent event){
|
private void handleGroupEvent(GroupEvent event){
|
||||||
logger.debug(
|
logger.debug(
|
||||||
"fire authorization changed event, because of received group event {} for group {}",
|
"fire authorization changed event, because of received group event {} for group {}",
|
||||||
event.getEventType(),
|
event.getEventType(),
|
||||||
event.getItem().getId()
|
event.getItem().getId()
|
||||||
);
|
);
|
||||||
fireEventForEveryUser();
|
fireEventForEveryUser();
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
protected void sendEvent(AuthorizationChangedEvent event) {
|
protected void sendEvent(AuthorizationChangedEvent event) {
|
||||||
ScmEventBus.getInstance().post(event);
|
ScmEventBus.getInstance().post(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -271,11 +271,6 @@ public class DefaultAuthorizationCollector implements AuthorizationCollector
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean isAdmin(User user, GroupNames groups) {
|
private boolean isAdmin(User user, GroupNames groups) {
|
||||||
boolean admin = user.isAdmin();
|
|
||||||
if (admin) {
|
|
||||||
logger.debug("user {} is marked as admin, because of the user flag", user.getName());
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (isUserAdminInConfiguration(user)) {
|
if (isUserAdminInConfiguration(user)) {
|
||||||
logger.debug("user {} is marked as admin, because of the admin user configuration", user.getName());
|
logger.debug("user {} is marked as admin, because of the admin user configuration", user.getName());
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -142,7 +142,6 @@ public class GitLfsITCase {
|
|||||||
dto.setDisplayName(user.getDisplayName());
|
dto.setDisplayName(user.getDisplayName());
|
||||||
dto.setType(user.getType());
|
dto.setType(user.getType());
|
||||||
dto.setActive(user.isActive());
|
dto.setActive(user.isActive());
|
||||||
dto.setAdmin(user.isAdmin());
|
|
||||||
dto.setPassword(user.getPassword());
|
dto.setPassword(user.getPassword());
|
||||||
createResource(adminClient, "users")
|
createResource(adminClient, "users")
|
||||||
.accept("*/*")
|
.accept("*/*")
|
||||||
|
|||||||
@@ -133,7 +133,6 @@ public class UserPermissionITCase extends AbstractPermissionITCaseBase<User>
|
|||||||
"scm-admin@scm-manager.org");
|
"scm-admin@scm-manager.org");
|
||||||
|
|
||||||
user.setPassword("hallo123");
|
user.setPassword("hallo123");
|
||||||
user.setAdmin(true);
|
|
||||||
user.setType("xml");
|
user.setType("xml");
|
||||||
|
|
||||||
return user;
|
return user;
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright (c) 2014, Sebastian Sdorra
|
* Copyright (c) 2014, Sebastian Sdorra
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are met:
|
* modification, are permitted provided that the following conditions are met:
|
||||||
*
|
*
|
||||||
* 1. Redistributions of source code must retain the above copyright notice,
|
* 1. Redistributions of source code must retain the above copyright notice,
|
||||||
* this list of conditions and the following disclaimer.
|
* this list of conditions and the following disclaimer.
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
@@ -13,7 +13,7 @@
|
|||||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
* 3. Neither the name of SCM-Manager; nor the names of its
|
||||||
* contributors may be used to endorse or promote products derived from this
|
* contributors may be used to endorse or promote products derived from this
|
||||||
* software without specific prior written permission.
|
* software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
@@ -24,9 +24,9 @@
|
|||||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* http://bitbucket.org/sdorra/scm-manager
|
* http://bitbucket.org/sdorra/scm-manager
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package sonia.scm.security;
|
package sonia.scm.security;
|
||||||
@@ -58,18 +58,18 @@ import static org.junit.Assert.assertTrue;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests for {@link AuthorizationChangedEventProducer}.
|
* Unit tests for {@link AuthorizationChangedEventProducer}.
|
||||||
*
|
*
|
||||||
* @author Sebastian Sdorra
|
* @author Sebastian Sdorra
|
||||||
*/
|
*/
|
||||||
public class AuthorizationChangedEventProducerTest {
|
public class AuthorizationChangedEventProducerTest {
|
||||||
|
|
||||||
private StoringAuthorizationChangedEventProducer producer;
|
private StoringAuthorizationChangedEventProducer producer;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUpProducer() {
|
public void setUpProducer() {
|
||||||
producer = new StoringAuthorizationChangedEventProducer();
|
producer = new StoringAuthorizationChangedEventProducer();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests {@link AuthorizationChangedEventProducer#onEvent(sonia.scm.user.UserEvent)}.
|
* Tests {@link AuthorizationChangedEventProducer#onEvent(sonia.scm.user.UserEvent)}.
|
||||||
*/
|
*/
|
||||||
@@ -79,15 +79,15 @@ public class AuthorizationChangedEventProducerTest {
|
|||||||
User user = UserTestData.createDent();
|
User user = UserTestData.createDent();
|
||||||
producer.onEvent(new UserEvent(HandlerEventType.BEFORE_CREATE, user));
|
producer.onEvent(new UserEvent(HandlerEventType.BEFORE_CREATE, user));
|
||||||
assertEventIsNotFired();
|
assertEventIsNotFired();
|
||||||
|
|
||||||
producer.onEvent(new UserEvent(HandlerEventType.CREATE, user));
|
producer.onEvent(new UserEvent(HandlerEventType.CREATE, user));
|
||||||
assertUserEventIsFired("dent");
|
assertUserEventIsFired("dent");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertEventIsNotFired(){
|
private void assertEventIsNotFired(){
|
||||||
assertNull(producer.event);
|
assertNull(producer.event);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertUserEventIsFired(String username){
|
private void assertUserEventIsFired(String username){
|
||||||
assertNotNull(producer.event);
|
assertNotNull(producer.event);
|
||||||
assertTrue(producer.event.isEveryUserAffected());
|
assertTrue(producer.event.isEveryUserAffected());
|
||||||
@@ -102,28 +102,28 @@ public class AuthorizationChangedEventProducerTest {
|
|||||||
/**
|
/**
|
||||||
* Tests {@link AuthorizationChangedEventProducer#onEvent(sonia.scm.user.UserEvent)} with modified user.
|
* Tests {@link AuthorizationChangedEventProducer#onEvent(sonia.scm.user.UserEvent)} with modified user.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testOnUserModificationEvent()
|
public void testOnUserModificationEvent()
|
||||||
{
|
{
|
||||||
User user = UserTestData.createDent();
|
User user = UserTestData.createDent();
|
||||||
User userModified = UserTestData.createDent();
|
User userModified = UserTestData.createDent();
|
||||||
userModified.setDisplayName("Super Dent");
|
userModified.setDisplayName("Super Dent");
|
||||||
|
|
||||||
producer.onEvent(new UserModificationEvent(HandlerEventType.BEFORE_CREATE, userModified, user));
|
producer.onEvent(new UserModificationEvent(HandlerEventType.BEFORE_CREATE, userModified, user));
|
||||||
assertEventIsNotFired();
|
assertEventIsNotFired();
|
||||||
|
|
||||||
producer.onEvent(new UserModificationEvent(HandlerEventType.CREATE, userModified, user));
|
producer.onEvent(new UserModificationEvent(HandlerEventType.CREATE, userModified, user));
|
||||||
assertEventIsNotFired();
|
assertEventIsNotFired();
|
||||||
|
|
||||||
userModified.setAdmin(true);
|
userModified.setActive(false);
|
||||||
|
|
||||||
producer.onEvent(new UserModificationEvent(HandlerEventType.BEFORE_CREATE, userModified, user));
|
producer.onEvent(new UserModificationEvent(HandlerEventType.BEFORE_CREATE, userModified, user));
|
||||||
assertEventIsNotFired();
|
assertEventIsNotFired();
|
||||||
|
|
||||||
producer.onEvent(new UserModificationEvent(HandlerEventType.CREATE, userModified, user));
|
producer.onEvent(new UserModificationEvent(HandlerEventType.CREATE, userModified, user));
|
||||||
assertUserEventIsFired("dent");
|
assertUserEventIsFired("dent");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests {@link AuthorizationChangedEventProducer#onEvent(sonia.scm.group.GroupEvent)}.
|
* Tests {@link AuthorizationChangedEventProducer#onEvent(sonia.scm.group.GroupEvent)}.
|
||||||
*/
|
*/
|
||||||
@@ -133,11 +133,11 @@ public class AuthorizationChangedEventProducerTest {
|
|||||||
Group group = new Group("xml", "base");
|
Group group = new Group("xml", "base");
|
||||||
producer.onEvent(new GroupEvent(HandlerEventType.BEFORE_CREATE, group));
|
producer.onEvent(new GroupEvent(HandlerEventType.BEFORE_CREATE, group));
|
||||||
assertEventIsNotFired();
|
assertEventIsNotFired();
|
||||||
|
|
||||||
producer.onEvent(new GroupEvent(HandlerEventType.CREATE, group));
|
producer.onEvent(new GroupEvent(HandlerEventType.CREATE, group));
|
||||||
assertGlobalEventIsFired();
|
assertGlobalEventIsFired();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests {@link AuthorizationChangedEventProducer#onEvent(sonia.scm.group.GroupEvent)} with modified groups.
|
* Tests {@link AuthorizationChangedEventProducer#onEvent(sonia.scm.group.GroupEvent)} with modified groups.
|
||||||
*/
|
*/
|
||||||
@@ -148,15 +148,15 @@ public class AuthorizationChangedEventProducerTest {
|
|||||||
Group modifiedGroup = new Group("xml", "base");
|
Group modifiedGroup = new Group("xml", "base");
|
||||||
producer.onEvent(new GroupModificationEvent(HandlerEventType.BEFORE_MODIFY, modifiedGroup, group));
|
producer.onEvent(new GroupModificationEvent(HandlerEventType.BEFORE_MODIFY, modifiedGroup, group));
|
||||||
assertEventIsNotFired();
|
assertEventIsNotFired();
|
||||||
|
|
||||||
producer.onEvent(new GroupModificationEvent(HandlerEventType.MODIFY, modifiedGroup, group));
|
producer.onEvent(new GroupModificationEvent(HandlerEventType.MODIFY, modifiedGroup, group));
|
||||||
assertEventIsNotFired();
|
assertEventIsNotFired();
|
||||||
|
|
||||||
modifiedGroup.add("test");
|
modifiedGroup.add("test");
|
||||||
producer.onEvent(new GroupModificationEvent(HandlerEventType.MODIFY, modifiedGroup, group));
|
producer.onEvent(new GroupModificationEvent(HandlerEventType.MODIFY, modifiedGroup, group));
|
||||||
assertGlobalEventIsFired();
|
assertGlobalEventIsFired();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests {@link AuthorizationChangedEventProducer#onEvent(sonia.scm.repository.RepositoryEvent)}.
|
* Tests {@link AuthorizationChangedEventProducer#onEvent(sonia.scm.repository.RepositoryEvent)}.
|
||||||
*/
|
*/
|
||||||
@@ -166,13 +166,13 @@ public class AuthorizationChangedEventProducerTest {
|
|||||||
Repository repository = RepositoryTestData.createHeartOfGold();
|
Repository repository = RepositoryTestData.createHeartOfGold();
|
||||||
producer.onEvent(new RepositoryEvent(HandlerEventType.BEFORE_CREATE, repository));
|
producer.onEvent(new RepositoryEvent(HandlerEventType.BEFORE_CREATE, repository));
|
||||||
assertEventIsNotFired();
|
assertEventIsNotFired();
|
||||||
|
|
||||||
producer.onEvent(new RepositoryEvent(HandlerEventType.CREATE, repository));
|
producer.onEvent(new RepositoryEvent(HandlerEventType.CREATE, repository));
|
||||||
assertGlobalEventIsFired();
|
assertGlobalEventIsFired();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests {@link AuthorizationChangedEventProducer#onEvent(sonia.scm.repository.RepositoryEvent)} with modified
|
* Tests {@link AuthorizationChangedEventProducer#onEvent(sonia.scm.repository.RepositoryEvent)} with modified
|
||||||
* repository.
|
* repository.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
@@ -224,11 +224,11 @@ public class AuthorizationChangedEventProducerTest {
|
|||||||
producer.onEvent(new RepositoryModificationEvent(HandlerEventType.CREATE, repositoryModified, repository));
|
producer.onEvent(new RepositoryModificationEvent(HandlerEventType.CREATE, repositoryModified, repository));
|
||||||
assertEventIsNotFired();
|
assertEventIsNotFired();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void resetStoredEvent(){
|
private void resetStoredEvent(){
|
||||||
producer.event = null;
|
producer.event = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests {@link AuthorizationChangedEventProducer#onEvent(AssignedPermissionEvent)}.
|
* Tests {@link AuthorizationChangedEventProducer#onEvent(AssignedPermissionEvent)}.
|
||||||
*/
|
*/
|
||||||
@@ -240,33 +240,33 @@ public class AuthorizationChangedEventProducerTest {
|
|||||||
);
|
);
|
||||||
producer.onEvent(new AssignedPermissionEvent(HandlerEventType.BEFORE_CREATE, groupPermission));
|
producer.onEvent(new AssignedPermissionEvent(HandlerEventType.BEFORE_CREATE, groupPermission));
|
||||||
assertEventIsNotFired();
|
assertEventIsNotFired();
|
||||||
|
|
||||||
producer.onEvent(new AssignedPermissionEvent(HandlerEventType.CREATE, groupPermission));
|
producer.onEvent(new AssignedPermissionEvent(HandlerEventType.CREATE, groupPermission));
|
||||||
assertGlobalEventIsFired();
|
assertGlobalEventIsFired();
|
||||||
|
|
||||||
resetStoredEvent();
|
resetStoredEvent();
|
||||||
|
|
||||||
StoredAssignedPermission userPermission = new StoredAssignedPermission(
|
StoredAssignedPermission userPermission = new StoredAssignedPermission(
|
||||||
"123", new AssignedPermission("trillian", false, "repository:read:*")
|
"123", new AssignedPermission("trillian", false, "repository:read:*")
|
||||||
);
|
);
|
||||||
producer.onEvent(new AssignedPermissionEvent(HandlerEventType.BEFORE_CREATE, userPermission));
|
producer.onEvent(new AssignedPermissionEvent(HandlerEventType.BEFORE_CREATE, userPermission));
|
||||||
assertEventIsNotFired();
|
assertEventIsNotFired();
|
||||||
|
|
||||||
resetStoredEvent();
|
resetStoredEvent();
|
||||||
|
|
||||||
producer.onEvent(new AssignedPermissionEvent(HandlerEventType.CREATE, userPermission));
|
producer.onEvent(new AssignedPermissionEvent(HandlerEventType.CREATE, userPermission));
|
||||||
assertUserEventIsFired("trillian");
|
assertUserEventIsFired("trillian");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class StoringAuthorizationChangedEventProducer extends AuthorizationChangedEventProducer {
|
private static class StoringAuthorizationChangedEventProducer extends AuthorizationChangedEventProducer {
|
||||||
|
|
||||||
private AuthorizationChangedEvent event;
|
private AuthorizationChangedEvent event;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void sendEvent(AuthorizationChangedEvent event) {
|
protected void sendEvent(AuthorizationChangedEvent event) {
|
||||||
this.event = event;
|
this.event = event;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -197,22 +197,6 @@ public class DefaultAuthorizationCollectorTest {
|
|||||||
assertThat(authInfo.getObjectPermissions(), nullValue());
|
assertThat(authInfo.getObjectPermissions(), nullValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests {@link AuthorizationCollector#collect()} as admin.
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
@SubjectAware(
|
|
||||||
configuration = "classpath:sonia/scm/shiro-001.ini"
|
|
||||||
)
|
|
||||||
public void testCollectAsAdmin() {
|
|
||||||
User trillian = UserTestData.createTrillian();
|
|
||||||
trillian.setAdmin(true);
|
|
||||||
authenticate(trillian, "main");
|
|
||||||
|
|
||||||
AuthorizationInfo authInfo = collector.collect();
|
|
||||||
assertIsAdmin(authInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests {@link AuthorizationCollector#collect()} with repository permissions.
|
* Tests {@link AuthorizationCollector#collect()} with repository permissions.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user