move Anonymous Realm to webapp

This commit is contained in:
Eduard Heimbuch
2019-10-14 16:18:14 +02:00
parent 09409bae33
commit b26f9068f4

View File

@@ -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();
}
}