mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-13 00:45:44 +01:00
move Anonymous Realm to webapp
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
package sonia.scm.security;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.inject.Inject;
|
||||
import org.apache.shiro.authc.AuthenticationException;
|
||||
import org.apache.shiro.authc.AuthenticationInfo;
|
||||
import org.apache.shiro.authc.AuthenticationToken;
|
||||
import org.apache.shiro.authc.credential.AllowAllCredentialsMatcher;
|
||||
import org.apache.shiro.realm.AuthenticatingRealm;
|
||||
import sonia.scm.SCMContext;
|
||||
import sonia.scm.plugin.Extension;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
@Singleton
|
||||
@Extension
|
||||
public class AnonymousRealm extends AuthenticatingRealm {
|
||||
|
||||
/**
|
||||
* realm name
|
||||
*/
|
||||
@VisibleForTesting
|
||||
static final String REALM = "AnonymousRealm";
|
||||
|
||||
/**
|
||||
* dao realm helper
|
||||
*/
|
||||
private final DAORealmHelper helper;
|
||||
|
||||
@Inject
|
||||
public AnonymousRealm(DAORealmHelperFactory helperFactory) {
|
||||
this.helper = helperFactory.create(REALM);
|
||||
|
||||
setAuthenticationTokenClass(AnonymousToken.class);
|
||||
setCredentialsMatcher(new AllowAllCredentialsMatcher());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
|
||||
return helper.authenticationInfoBuilder(SCMContext.USER_ANONYMOUS).build();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user