package io.core9.module.auth.standard;

import io.core9.module.auth.AuthenticationConnector;
import io.core9.plugin.database.repository.NoCollectionNamePresentException;
import io.core9.plugin.database.repository.RepositoryFactory;
import net.xeoh.plugins.base.annotations.PluginImplementation;
import net.xeoh.plugins.base.annotations.injections.InjectPlugin;

import org.apache.shiro.authc.credential.HashedCredentialsMatcher;
import org.apache.shiro.mgt.DefaultSecurityManager;
import org.apache.shiro.mgt.SecurityManager;

@PluginImplementation
public class StandardAuthenticationImpl extends DefaultSecurityManager implements AuthenticationConnector {
	
	@InjectPlugin
	private RepositoryFactory factory;
	
	@Override
	public SecurityManager getSecurityManager() {
		try {
			HashedCredentialsMatcher matcher = new HashedCredentialsMatcher("SHA-256");
			StandardRealm realm = new StandardRealm(factory.getRepository(UserEntity.class), factory.getRepository(RoleEntity.class));
			realm.setCredentialsMatcher(matcher);
			return new DefaultSecurityManager(realm);
		} catch (NoCollectionNamePresentException e) {
			e.printStackTrace();
			return new DefaultSecurityManager();
		}
	}

}

@@ -477,53 +477,8 @@
 ger;
-%0Aimport org.apache.shiro.mgt.SecurityManager;
 %0A%0A@P
@@ -541,39 +541,8 @@
 mpl 
-extends DefaultSecurityManager 
 impl
@@ -648,16 +648,23 @@
 %09public 
+Default
 Security

Use default security manager