List of usage examples for org.apache.shiro.util StringUtils split
public static String[] split(String line)
From source file:com.aerospike.shiro.AerospikeSessionDAO.java
License:Apache License
@Override public void init() throws ShiroException { log.info("Initializing the Aerospike Client"); try {// w w w .j a v a 2 s . c om this.readEnvironmentVariables(); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { log.error(e.getMessage()); throw new ShiroException(e.getMessage()); } ClientPolicy policy = new ClientPolicy(); policy.failIfNotConnected = true; policy.user = this.user; policy.password = this.password; String[] hostnames = StringUtils.split(this.hostname); String[] ports = StringUtils.split(this.port); if (hostnames.length != ports.length) { throw new ShiroException("Number of hosts in configuration does not match number of ports"); } Host[] hosts = new Host[hostnames.length]; for (int i = 0; i < hostnames.length; i++) { hosts[i] = new Host(hostnames[i], Integer.valueOf(ports[i])); } this.client = new AerospikeClient(policy, hosts); this.writePolicy = new WritePolicy(); this.writePolicy.expiration = this.globalSessionTimeout; }
From source file:com.caricah.iotracah.bootstrap.security.realm.impl.IOTTextConfiguredRealm.java
License:Apache License
protected void processUserDefinitions(Map<String, String> userDefs) { if (userDefs == null || userDefs.isEmpty()) { return;//from w w w .j a va 2 s . co m } for (String username : userDefs.keySet()) { String value = userDefs.get(username); String[] passwordAndRolesArray = StringUtils.split(value); String password = passwordAndRolesArray[0]; String partition; Matcher matcher = usernamePartitionPattern.matcher(username); if (matcher.matches()) { partition = matcher.group("partition"); username = matcher.group("username"); } else { partition = getDefaultPartitionName(); } if (Objects.nonNull(username) && !username.isEmpty()) { IOTAccount account = getIOTAccount(partition, username); if (account == null) { account = addIOTAccount(partition, username, password); } account.setCredential(password); if (passwordAndRolesArray.length > 1) { for (int i = 1; i < passwordAndRolesArray.length; i++) { String rolename = passwordAndRolesArray[i]; account.addRole(rolename); } } saveIOTAccount(account); } } }
From source file:org.obiba.opal.core.upgrade.security.HashShiroIniPasswordUpgradeStepTest.java
License:Open Source License
@Test public void testExecute() throws Exception { String iniFileMd5 = new Md5Hash(iniFile).toHex(); upgradeStep.execute(null);// w w w .ja va 2 s. com assertThat(iniBackup.exists()).isTrue(); assertThat(new Md5Hash(iniBackup).toHex()).isEqualTo(iniFileMd5); assertThat(destIniFile.exists()).isTrue(); assertThat(new Md5Hash(destIniFile).toHex()).isNotEqualTo(iniFileMd5); Ini ini = new Ini(); ini.loadFromPath(destIniFile.getAbsolutePath()); Ini.Section section = ini.getSection(IniRealm.USERS_SECTION_NAME); assertThat(section).isNotNull(); assertThat(section).hasSize(3); for (String username : usernamePassword.keySet()) { assertThat(section.containsKey(username)).isTrue(); String[] passwordAndRolesArray = StringUtils.split(section.get(username)); String encrypted = passwordAndRolesArray[0]; assertThat(passwordService.passwordsMatch(usernamePassword.get(username), encrypted)).isTrue(); } }
From source file:org.obiba.opal.core.upgrade.v2_0_x.HashShiroIniPasswordUpgradeStep.java
License:Open Source License
private Map<String, String> getUsernamePasswords() { Ini ini = new Ini(); ini.loadFromPath(srcIniFile.getAbsolutePath()); Ini.Section section = ini.getSection(IniRealm.USERS_SECTION_NAME); if (section == null || section.isEmpty()) { return Collections.emptyMap(); }// ww w .j a va 2 s . co m Map<String, String> map = new LinkedHashMap<>(); for (Map.Entry<String, String> entry : section.entrySet()) { String username = entry.getKey(); String[] passwordAndRolesArray = StringUtils.split(entry.getValue()); String password = passwordAndRolesArray[0]; map.put(username, password); } return map; }