@Test public void beforeAttemptSupportingToken() { new SimpleAccountRealm(); }
public void addAccount(String username, String password) { addAccount(username, password, (String[]) null); }
protected void add(SimpleAccount account) { String username = getUsername(account); USERS_LOCK.writeLock().lock(); try { this.users.put(username, account); } finally { USERS_LOCK.writeLock().unlock(); } }
public boolean accountExists(String username) { return getUser(username) != null; }
public SimpleAccountRealm() { this.users = new LinkedHashMap<String, SimpleAccount>(); this.roles = new LinkedHashMap<String, SimpleRole>(); USERS_LOCK = new ReentrantReadWriteLock(); ROLES_LOCK = new ReentrantReadWriteLock(); //SimpleAccountRealms are memory-only realms - no need for an additional cache mechanism since we're //already as memory-efficient as we can be: setCachingEnabled(false); }
protected String getUsername(PrincipalCollection principals) { return getAvailablePrincipal(principals).toString(); }
public SimpleAccountRealm(String name) { this(); setName(name); }
public void addRole(String name) { add(new SimpleRole(name)); }
public boolean roleExists(String name) { return getRole(name) != null; }
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) { String username = getUsername(principals); USERS_LOCK.readLock().lock(); try { return this.users.get(username); } finally { USERS_LOCK.readLock().unlock(); } } }
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { UsernamePasswordToken upToken = (UsernamePasswordToken) token; SimpleAccount account = getUser(upToken.getUsername()); if (account != null) { if (account.isLocked()) { throw new LockedAccountException("Account [" + account + "] is locked."); } if (account.isCredentialsExpired()) { String msg = "The credentials for account [" + account + "] are expired"; throw new ExpiredCredentialsException(msg); } } return account; }
public SimpleAccountRealm() { this.users = new LinkedHashMap<String, SimpleAccount>(); this.roles = new LinkedHashMap<String, SimpleRole>(); USERS_LOCK = new ReentrantReadWriteLock(); ROLES_LOCK = new ReentrantReadWriteLock(); //SimpleAccountRealms are memory-only realms - no need for an additional cache mechanism since we're //already as memory-efficient as we can be: setCachingEnabled(false); }
protected String getUsername(PrincipalCollection principals) { return getAvailablePrincipal(principals).toString(); }
public SimpleAccountRealm(String name) { this(); setName(name); }
public void addRole(String name) { add(new SimpleRole(name)); }
public boolean roleExists(String name) { return getRole(name) != null; }
protected String getUsername(SimpleAccount account) { return getUsername(account.getPrincipals()); }
@Override public void start() { logger.info("Initializing Shiro environment"); WebEnvironment environment = environmentLoader.initEnvironment(servletContext); RealmSecurityManager rsm = (RealmSecurityManager) environment.getWebSecurityManager(); logger.debug("Creating SecurityGroovyRealm"); try { String securityGroovy = new File(groovyClasspath, "Security.groovy").toURI().toString(); logger.debug("Security.groovy URL: {}", securityGroovy); SecurityGroovyRealm realm = new SecurityGroovyRealm(groovyScriptEngine, securityGroovy, servletContext); LifecycleUtils.init(realm); rsm.setRealm(realm); status = ModuleStatus.STARTED; } catch (Exception e) { logger.error("Security.groovy not found or invalid; installing dummy realm", e); SimpleAccountRealm realm = new SimpleAccountRealm(); LifecycleUtils.init(realm); rsm.setRealm(realm); status = ModuleStatus.FAILED; } }