@Override public void onInit() { super.onInit(); //TODO - cleanup - this method shouldn't be necessary afterRoleCacheSet(); }
protected void processRoleDefinitions() throws ParseException { String roleDefinitions = getRoleDefinitions(); if (roleDefinitions == null) { return; } Map<String, String> roleDefs = toMap(toLines(roleDefinitions)); processRoleDefinitions(roleDefs); }
protected void processUserDefinitions() throws ParseException { String userDefinitions = getUserDefinitions(); if (userDefinitions == null) { return; } Map<String, String> userDefs = toMap(toLines(userDefinitions)); processUserDefinitions(userDefs); }
/** * Creates a {@code Realm} from the Ini instance containing account data. * * @param ini the Ini instance from which to acquire the account data. * @return a new Realm instance reflecting the account data discovered in the {@code Ini}. */ protected Realm createRealm(Ini ini) { //IniRealm realm = new IniRealm(ini); changed to support SHIRO-322 IniRealm realm = new IniRealm(); realm.setName(INI_REALM_NAME); realm.setIni(ini); //added for SHIRO-322 return realm; }
@Bean public Realm realm() { TextConfigurationRealm realm = new TextConfigurationRealm(); realm.setUserDefinitions("joe.coder=password,user\n" + "jill.coder=password,admin"); realm.setRoleDefinitions("admin=read,write\n" + "user=read"); realm.setCachingEnabled(true); return realm; }
protected Realm iniRealmFromLocation(String iniLocation) { Ini ini = Ini.fromResourcePath(iniLocation); return new IniRealm( ini ); } }
private void reloadPropertiesIfNecessary() { if (isSourceModified()) { restart(); } }
protected void afterRoleCacheSet() { loadProperties(); //we can only determine if files have been modified at runtime (not classpath entries or urls), so only //start the thread in this case: if (this.resourcePath.startsWith(ResourceUtils.FILE_PREFIX) && scheduler == null) { startReloadThread(); } }
protected void processDefinitions() { try { processRoleDefinitions(); processUserDefinitions(); } catch (ParseException e) { String msg = "Unable to parse user and/or role definitions."; throw new ConfigurationException(msg, e); } }
private void executeTest(Runnable runnable) throws InterruptedException { TestThread testThread = new TestThread(runnable); Thread testTask = new Thread(testThread); realm.test(testTask); testTask.join(500); // Check whether any assertion error was thrown by the read thread testThread.test(); }
protected String getRolename(String key) { return getName(key, ROLENAME_PREFIX); } }
/** * This constructor will immediately process the definitions in the {@code Ini} argument. If you need to perform * additional configuration before processing (e.g. setting a permissionResolver, etc), do not call this * constructor. Instead, do the following: * <ol> * <li>Call the default no-arg constructor</li> * <li>Set the Ini instance you wish to use via {@code #setIni}</li> * <li>Set any other configuration properties</li> * <li>Call {@link #init()}</li> * </ol> * * @param ini the Ini instance which will be inspected to create accounts, groups and permissions for this realm. */ public IniRealm(Ini ini) { this(); processDefinitions(ini); }
public void run() { try { reloadPropertiesIfNecessary(); } catch (Exception e) { if (log.isErrorEnabled()) { log.error("Error while reloading property files for realm.", e); } } }
@Test public void testRoleAndUserAccount() throws InterruptedException { setUpForReadConfigurationTest(); executeTest(new Runnable() { public void run() { assertTrue("role not found when it was expected", realm.roleExists("role1")); assertTrue("user not found when it was expected", realm.accountExists("user1")); } }); }
public void run() { assertTrue("role not found when it was expected", realm.roleExists("role1")); assertTrue("user not found when it was expected", realm.accountExists("user1")); } });
/** * Will call 'processDefinitions' on startup. * * @since 1.2 * @see <a href="https://issues.apache.org/jira/browse/SHIRO-223">SHIRO-223</a> */ @Override protected void onInit() { super.onInit(); processDefinitions(); }
private void setRoles() { StringBuilder roleDefinitions = new StringBuilder() .append("role1 = role1_permission1\n") .append("role2 = role2_persission1, role2_permission2\n"); realm.setRoleDefinitions(roleDefinitions.toString()); }
public void run() { try { realm.processRoleDefinitions(); } catch (ParseException e) { fail("Unable to parse role definitions"); } } });
public void run() { try { realm.processUserDefinitions(); } catch (ParseException e) { fail("Unable to parse user definitions"); } } });
protected String getUsername(String key) { return getName(key, USERNAME_PREFIX); }