mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-09 15:05:44 +01:00
small fixes and cleanup after review
This commit is contained in:
@@ -20,6 +20,10 @@ public class ScmConfigurationChangedListener {
|
||||
|
||||
@Subscribe
|
||||
public void handleEvent(ScmConfigurationChangedEvent event) {
|
||||
createAnonymousUserIfRequired(event);
|
||||
}
|
||||
|
||||
private void createAnonymousUserIfRequired(ScmConfigurationChangedEvent event) {
|
||||
if (event.getConfiguration().isAnonymousAccessEnabled() && !userManager.contains(SCMContext.USER_ANONYMOUS)) {
|
||||
userManager.create(SCMContext.ANONYMOUS);
|
||||
}
|
||||
|
||||
@@ -6,10 +6,10 @@ import sonia.scm.SCMContext;
|
||||
public class Authentications {
|
||||
|
||||
public static boolean isAuthenticatedSubjectAnonymous() {
|
||||
return SecurityUtils.getSubject().getPrincipal().equals(SCMContext.USER_ANONYMOUS);
|
||||
return isSubjectAnonymous((String) SecurityUtils.getSubject().getPrincipal());
|
||||
}
|
||||
|
||||
public static boolean isSubjectAnonymous(String principal) {
|
||||
return principal.equals(SCMContext.USER_ANONYMOUS);
|
||||
return SCMContext.USER_ANONYMOUS.equals(principal);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,10 +38,10 @@ class App extends Component<Props> {
|
||||
}
|
||||
|
||||
render() {
|
||||
const {me, loading, error, authenticated, links, t} = this.props;
|
||||
const { me, loading, error, authenticated, links, t } = this.props;
|
||||
|
||||
let content;
|
||||
const navigation = authenticated ? <PrimaryNavigation links={links}/> : "";
|
||||
const navigation = authenticated ? <PrimaryNavigation links={links} /> : "";
|
||||
|
||||
if (loading) {
|
||||
content = <Loading />;
|
||||
@@ -60,7 +60,7 @@ class App extends Component<Props> {
|
||||
<div className="App">
|
||||
<Header>{navigation}</Header>
|
||||
{content}
|
||||
{authenticated && <Footer me={me}/>}
|
||||
{authenticated && <Footer me={me} />}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -49,14 +49,9 @@ import sonia.scm.TransformFilter;
|
||||
import sonia.scm.search.SearchRequest;
|
||||
import sonia.scm.search.SearchUtil;
|
||||
import sonia.scm.util.CollectionAppender;
|
||||
import sonia.scm.util.IOUtil;
|
||||
import sonia.scm.util.Util;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
@@ -114,42 +114,6 @@ public class ConfigResourceTest {
|
||||
assertTrue("link not found", response.getContentAsString().contains("\"update\":{\"href\":\"/v2/config"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@SubjectAware(username = "readWrite")
|
||||
public void shouldUpdateConfigAndCreateAnonymousUser() throws URISyntaxException, IOException {
|
||||
MockHttpRequest request = post("sonia/scm/api/v2/config-test-update-with-anonymous-access.json");
|
||||
|
||||
MockHttpResponse response = new MockHttpResponse();
|
||||
dispatcher.invoke(request, response);
|
||||
assertEquals(HttpServletResponse.SC_NO_CONTENT, response.getStatus());
|
||||
|
||||
request = MockHttpRequest.get("/" + ConfigResource.CONFIG_PATH_V2);
|
||||
response = new MockHttpResponse();
|
||||
dispatcher.invoke(request, response);
|
||||
assertEquals(HttpServletResponse.SC_OK, response.getStatus());
|
||||
assertTrue(response.getContentAsString().contains("\"proxyPassword\":\"newPassword\""));
|
||||
assertTrue(response.getContentAsString().contains("\"self\":{\"href\":\"/v2/config"));
|
||||
assertTrue("link not found", response.getContentAsString().contains("\"update\":{\"href\":\"/v2/config"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@SubjectAware(username = "readWrite")
|
||||
public void shouldUpdateConfigAndNotCreateAnonymousUserIfAlreadyExists() throws URISyntaxException, IOException {
|
||||
MockHttpRequest request = post("sonia/scm/api/v2/config-test-update-with-anonymous-access.json");
|
||||
|
||||
MockHttpResponse response = new MockHttpResponse();
|
||||
dispatcher.invoke(request, response);
|
||||
assertEquals(HttpServletResponse.SC_NO_CONTENT, response.getStatus());
|
||||
|
||||
request = MockHttpRequest.get("/" + ConfigResource.CONFIG_PATH_V2);
|
||||
response = new MockHttpResponse();
|
||||
dispatcher.invoke(request, response);
|
||||
assertEquals(HttpServletResponse.SC_OK, response.getStatus());
|
||||
assertTrue(response.getContentAsString().contains("\"proxyPassword\":\"newPassword\""));
|
||||
assertTrue(response.getContentAsString().contains("\"self\":{\"href\":\"/v2/config"));
|
||||
assertTrue("link not found", response.getContentAsString().contains("\"update\":{\"href\":\"/v2/config"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@SubjectAware(username = "readOnly")
|
||||
public void shouldNotUpdateConfigWhenNotAuthorized() throws URISyntaxException, IOException {
|
||||
@@ -188,7 +152,6 @@ public class ConfigResourceTest {
|
||||
private static ScmConfiguration createConfiguration() {
|
||||
ScmConfiguration scmConfiguration = new ScmConfiguration();
|
||||
scmConfiguration.setProxyPassword("heartOfGold");
|
||||
scmConfiguration.setAnonymousAccessEnabled(true);
|
||||
|
||||
return scmConfiguration;
|
||||
}
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"proxyPassword": "newPassword",
|
||||
"anonymousAccessEnabled": "true"
|
||||
}
|
||||
Reference in New Issue
Block a user