mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-09 06:55:47 +01:00
Cleanup
This commit is contained in:
@@ -35,11 +35,8 @@ package sonia.scm;
|
|||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
import com.github.sdorra.ssp.PermissionCheck;
|
|
||||||
|
|
||||||
import java.io.Closeable;
|
import java.io.Closeable;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.function.Function;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The base class of all handlers.
|
* The base class of all handlers.
|
||||||
@@ -78,15 +75,4 @@ public interface HandlerBase<T extends TypedObject>
|
|||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
void modify(T object) throws NotFoundException;
|
void modify(T object) throws NotFoundException;
|
||||||
|
|
||||||
/**
|
|
||||||
* Modifies a persistent object after checking with the given permission checker.
|
|
||||||
*
|
|
||||||
* @param object to modify
|
|
||||||
* @param permissionChecker check permission before to modify
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
|
||||||
default void modify(T object, Function<T, PermissionCheck> permissionChecker) throws NotFoundException{
|
|
||||||
modify(object);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
package sonia.scm.util;
|
|
||||||
|
|
||||||
import org.apache.shiro.SecurityUtils;
|
|
||||||
|
|
||||||
public class AuthenticationUtil {
|
|
||||||
|
|
||||||
public static String getAuthenticatedUsername() {
|
|
||||||
Object subject = SecurityUtils.getSubject().getPrincipal();
|
|
||||||
AssertUtil.assertIsNotNull(subject);
|
|
||||||
return subject.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -29,7 +29,7 @@ public class UserITCase {
|
|||||||
.assertStatusCode(200)
|
.assertStatusCode(200)
|
||||||
.assertAdmin(aBoolean -> assertThat(aBoolean).isEqualTo(Boolean.TRUE))
|
.assertAdmin(aBoolean -> assertThat(aBoolean).isEqualTo(Boolean.TRUE))
|
||||||
.assertPassword(Assert::assertNull)
|
.assertPassword(Assert::assertNull)
|
||||||
.requestChangePassword(password, newPassword) // the oldPassword is needed when the own password should be changed
|
.requestChangePassword(newPassword)
|
||||||
.assertStatusCode(204);
|
.assertStatusCode(204);
|
||||||
// assert password is changed -> login with the new Password
|
// assert password is changed -> login with the new Password
|
||||||
ScmRequests.start()
|
ScmRequests.start()
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import io.restassured.RestAssured;
|
|||||||
import io.restassured.response.Response;
|
import io.restassured.response.Response;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import sonia.scm.user.User;
|
||||||
import sonia.scm.web.VndMediaType;
|
import sonia.scm.web.VndMediaType;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -41,7 +42,7 @@ public class ScmRequests {
|
|||||||
return new IndexResponse(applyGETRequest(RestUtil.REST_BASE_URL.toString()));
|
return new IndexResponse(applyGETRequest(RestUtil.REST_BASE_URL.toString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserResponse<UserResponse> requestUser(String username, String password, String pathParam) {
|
public <SELF extends UserResponse<SELF, T>, T extends ModelResponse> UserResponse<SELF,T> requestUser(String username, String password, String pathParam) {
|
||||||
setUsername(username);
|
setUsername(username);
|
||||||
setPassword(password);
|
setPassword(password);
|
||||||
return new UserResponse<>(applyGETRequest(RestUtil.REST_BASE_URL.resolve("users/"+pathParam).toString()), null);
|
return new UserResponse<>(applyGETRequest(RestUtil.REST_BASE_URL.resolve("users/"+pathParam).toString()), null);
|
||||||
@@ -176,7 +177,7 @@ public class ScmRequests {
|
|||||||
return new MeResponse<>(applyGETRequestFromLink(response, LINK_ME), this);
|
return new MeResponse<>(applyGETRequestFromLink(response, LINK_ME), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserResponse<IndexResponse> requestUser(String username) {
|
public UserResponse<? extends UserResponse, IndexResponse> requestUser(String username) {
|
||||||
return new UserResponse<>(applyGETRequestFromLinkWithParams(response, LINK_USERS, username), this);
|
return new UserResponse<>(applyGETRequestFromLinkWithParams(response, LINK_USERS, username), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -288,7 +289,7 @@ public class ScmRequests {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class MeResponse<PREV extends ModelResponse> extends UserResponse<PREV> {
|
public class MeResponse<PREV extends ModelResponse> extends UserResponse<MeResponse<PREV>, PREV> {
|
||||||
|
|
||||||
|
|
||||||
public MeResponse(Response response, PREV previousResponse) {
|
public MeResponse(Response response, PREV previousResponse) {
|
||||||
@@ -300,7 +301,7 @@ public class ScmRequests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class UserResponse<PREV extends ModelResponse> extends ModelResponse<UserResponse<PREV>, PREV> {
|
public class UserResponse<SELF extends UserResponse<SELF, PREV>, PREV extends ModelResponse> extends ModelResponse<SELF, PREV> {
|
||||||
|
|
||||||
public static final String LINKS_PASSWORD_HREF = "_links.password.href";
|
public static final String LINKS_PASSWORD_HREF = "_links.password.href";
|
||||||
|
|
||||||
@@ -308,34 +309,29 @@ public class ScmRequests {
|
|||||||
super(response, previousResponse);
|
super(response, previousResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserResponse<PREV> assertPassword(Consumer<String> assertPassword) {
|
public SELF assertPassword(Consumer<String> assertPassword) {
|
||||||
return super.assertSingleProperty(assertPassword, "password");
|
return super.assertSingleProperty(assertPassword, "password");
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserResponse<PREV> assertType(Consumer<String> assertType) {
|
public SELF assertType(Consumer<String> assertType) {
|
||||||
return assertSingleProperty(assertType, "type");
|
return assertSingleProperty(assertType, "type");
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserResponse<PREV> assertAdmin(Consumer<Boolean> assertAdmin) {
|
public SELF assertAdmin(Consumer<Boolean> assertAdmin) {
|
||||||
return assertSingleProperty(assertAdmin, "admin");
|
return assertSingleProperty(assertAdmin, "admin");
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserResponse<PREV> assertPasswordLinkDoesNotExists() {
|
public SELF assertPasswordLinkDoesNotExists() {
|
||||||
return assertPropertyPathDoesNotExists(LINKS_PASSWORD_HREF);
|
return assertPropertyPathDoesNotExists(LINKS_PASSWORD_HREF);
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserResponse<PREV> assertPasswordLinkExists() {
|
public SELF assertPasswordLinkExists() {
|
||||||
return assertPropertyPathExists(LINKS_PASSWORD_HREF);
|
return assertPropertyPathExists(LINKS_PASSWORD_HREF);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ChangePasswordResponse<UserResponse> requestChangePassword(String newPassword) {
|
public ChangePasswordResponse<UserResponse> requestChangePassword(String newPassword) {
|
||||||
return requestChangePassword(null, newPassword);
|
return new ChangePasswordResponse<>(applyPUTRequestFromLink(super.response, LINKS_PASSWORD_HREF, VndMediaType.PASSWORD_OVERWRITE, createPasswordChangeJson(null, newPassword)), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ChangePasswordResponse<UserResponse> requestChangePassword(String oldPassword, String newPassword) {
|
|
||||||
return new ChangePasswordResponse<>(applyPUTRequestFromLink(super.response, LINKS_PASSWORD_HREF, VndMediaType.PASSWORD_OVERWRITE, createPasswordChangeJson(oldPassword, newPassword)), this);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,29 +1,18 @@
|
|||||||
package sonia.scm.api.v2.resources;
|
package sonia.scm.api.v2.resources;
|
||||||
|
|
||||||
import com.github.sdorra.ssp.PermissionCheck;
|
|
||||||
import de.otto.edison.hal.HalRepresentation;
|
import de.otto.edison.hal.HalRepresentation;
|
||||||
import sonia.scm.AlreadyExistsException;
|
import sonia.scm.AlreadyExistsException;
|
||||||
import sonia.scm.ConcurrentModificationException;
|
import sonia.scm.ConcurrentModificationException;
|
||||||
import sonia.scm.Manager;
|
import sonia.scm.Manager;
|
||||||
import sonia.scm.ModelObject;
|
import sonia.scm.ModelObject;
|
||||||
import sonia.scm.PageResult;
|
import sonia.scm.PageResult;
|
||||||
import sonia.scm.user.ChangePasswordNotAllowedException;
|
|
||||||
import sonia.scm.user.User;
|
|
||||||
import sonia.scm.user.UserManager;
|
|
||||||
import sonia.scm.user.UserPermissions;
|
|
||||||
import sonia.scm.util.AssertUtil;
|
|
||||||
import sonia.scm.util.AuthenticationUtil;
|
|
||||||
|
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
import java.text.MessageFormat;
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.function.Consumer;
|
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
import static sonia.scm.user.ChangePasswordNotAllowedException.WRONG_USER_TYPE;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Facade for {@link SingleResourceManagerAdapter} and {@link CollectionResourceManagerAdapter}
|
* Facade for {@link SingleResourceManagerAdapter} and {@link CollectionResourceManagerAdapter}
|
||||||
* for model objects handled by a single id.
|
* for model objects handled by a single id.
|
||||||
|
|||||||
Reference in New Issue
Block a user