mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 07:25:44 +01:00
allow anonymous access
This commit is contained in:
@@ -94,7 +94,19 @@ public class AuthenticationResource
|
||||
{
|
||||
securityContext.logout(request, response);
|
||||
|
||||
return Response.ok().build();
|
||||
Response resp = null;
|
||||
User user = securityContext.getUser();
|
||||
|
||||
if (user != null)
|
||||
{
|
||||
resp = Response.ok(getState(user)).build();
|
||||
}
|
||||
else
|
||||
{
|
||||
resp = Response.ok().build();
|
||||
}
|
||||
|
||||
return resp;
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
@@ -78,6 +78,7 @@ public class ScmConfiguration
|
||||
this.pluginUrl = other.pluginUrl;
|
||||
this.sslPort = other.sslPort;
|
||||
this.enableSSL = other.enableSSL;
|
||||
this.anonymousAccessEnabled = other.anonymousAccessEnabled;
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
@@ -115,6 +116,17 @@ public class ScmConfiguration
|
||||
return sslPort;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean isAnonymousAccessEnabled()
|
||||
{
|
||||
return anonymousAccessEnabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
@@ -128,6 +140,17 @@ public class ScmConfiguration
|
||||
|
||||
//~--- set methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param anonymousAccessEnabled
|
||||
*/
|
||||
public void setAnonymousAccessEnabled(boolean anonymousAccessEnabled)
|
||||
{
|
||||
this.anonymousAccessEnabled = anonymousAccessEnabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
@@ -186,4 +209,7 @@ public class ScmConfiguration
|
||||
|
||||
/** Field description */
|
||||
private int sslPort = 8181;
|
||||
|
||||
/** Field description */
|
||||
private boolean anonymousAccessEnabled = false;
|
||||
}
|
||||
|
||||
@@ -41,6 +41,7 @@ import com.google.inject.servlet.SessionScoped;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.config.ScmConfiguration;
|
||||
import sonia.scm.user.User;
|
||||
import sonia.scm.user.UserManager;
|
||||
|
||||
@@ -57,6 +58,9 @@ import javax.servlet.http.HttpServletResponse;
|
||||
public class BasicSecurityContext implements WebSecurityContext
|
||||
{
|
||||
|
||||
/** Field description */
|
||||
public static final String USER_ANONYMOUS = "anonymous";
|
||||
|
||||
/** the logger for BasicSecurityContext */
|
||||
private static final Logger logger =
|
||||
LoggerFactory.getLogger(BasicSecurityContext.class);
|
||||
@@ -67,13 +71,17 @@ public class BasicSecurityContext implements WebSecurityContext
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param configuration
|
||||
* @param authenticator
|
||||
* @param userManager
|
||||
*/
|
||||
@Inject
|
||||
public BasicSecurityContext(AuthenticationManager authenticator,
|
||||
public BasicSecurityContext(ScmConfiguration configuration,
|
||||
AuthenticationManager authenticator,
|
||||
UserManager userManager)
|
||||
{
|
||||
this.configuration = configuration;
|
||||
this.authenticator = authenticator;
|
||||
this.userManager = userManager;
|
||||
}
|
||||
@@ -155,6 +163,11 @@ public class BasicSecurityContext implements WebSecurityContext
|
||||
@Override
|
||||
public User getUser()
|
||||
{
|
||||
if ((user == null) && configuration.isAnonymousAccessEnabled())
|
||||
{
|
||||
user = userManager.get(USER_ANONYMOUS);
|
||||
}
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
@@ -167,7 +180,7 @@ public class BasicSecurityContext implements WebSecurityContext
|
||||
@Override
|
||||
public boolean isAuthenticated()
|
||||
{
|
||||
return user != null;
|
||||
return getUser() != null;
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
@@ -175,6 +188,9 @@ public class BasicSecurityContext implements WebSecurityContext
|
||||
/** Field description */
|
||||
private AuthenticationManager authenticator;
|
||||
|
||||
/** Field description */
|
||||
private ScmConfiguration configuration;
|
||||
|
||||
/** Field description */
|
||||
private User user;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user