本文整理汇总了Java中org.apache.shiro.realm.text.IniRealm类的典型用法代码示例。如果您正苦于以下问题:Java IniRealm类的具体用法?Java IniRealm怎么用?Java IniRealm使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IniRealm类属于org.apache.shiro.realm.text包,在下文中一共展示了IniRealm类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createRealm
import org.apache.shiro.realm.text.IniRealm; //导入依赖的package包/类
@Override
public Realm createRealm(Injector injector) {
Ini ini = new Ini();
if (users != null && !users.isEmpty()) {
ini.addSection("users").putAll(users);
}
if (roles != null && !roles.isEmpty()) {
ini.addSection("roles").putAll(roles);
}
IniRealm realm = new IniRealm(ini);
realm.setIni(ini);
if (name != null) {
realm.setName(name);
}
return realm;
}
示例2: testCreateRealm
import org.apache.shiro.realm.text.IniRealm; //导入依赖的package包/类
@Test
public void testCreateRealm() {
IniRealmFactory factory = new IniRealmFactory();
factory.setName("xyz");
factory.setRoles(Collections.singletonMap("r1", "p1, p2"));
factory.setUsers(Collections.singletonMap("u1", "up, r1"));
IniRealm realm = (IniRealm) factory.createRealm(mock(Injector.class));
assertEquals("xyz", realm.getName());
assertNull(realm.getResourcePath());
Ini ini = realm.getIni();
assertNotNull(realm.getIni());
assertNotNull(ini.getSection("users"));
assertNotNull(ini.getSection("roles"));
}
示例3: readRealms
import org.apache.shiro.realm.text.IniRealm; //导入依赖的package包/类
private Collection<Realm> readRealms() {
// create Realms
Collection<Realm> realms = new ArrayList<>();
//if (dataSource == null) {
try {
// try to read user specified security.ini
realms.add(new IniRealm("classpath:security.ini"));
} catch (IllegalArgumentException | ConfigurationException e){
// one failed - use default instead
realms.add(new IniRealm("classpath:jawn_default_security.ini"));
}
//} else {
//realms.add(createJdbcRealm());
//}
//realms.add(createSimpleRealm());
return realms;
}
示例4: createRealm
import org.apache.shiro.realm.text.IniRealm; //导入依赖的package包/类
@Override
protected Realm createRealm(Ini ini) {
// Set the resolvers first, because IniRealm is initialized before the resolvers
// are applied by the ModularRealmAuthorizer
IniRealm realm = new IniRealm() {
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
SimpleAccount account = (SimpleAccount) super.doGetAuthorizationInfo(principals);
// implicitly, give the role agate-user to all users from ini
if(account != null) account.addRole(Roles.AGATE_USER.toString());
return account;
}
};
realm.setName(INI_REALM);
// realm.setRolePermissionResolver(rolePermissionResolver);
realm.setPermissionResolver(permissionResolver);
realm.setResourcePath(getShiroIniPath());
realm.setCredentialsMatcher(new PasswordMatcher());
realm.setIni(ini);
return realm;
}
示例5: configureShiroWeb
import org.apache.shiro.realm.text.IniRealm; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
protected void configureShiroWeb() {
//if you would like to expose the CredentialsMatcher listed here, uncomment the following line.
//expose(CredentialsMatcher.class);
try {
bindRealm().toConstructor(IniRealm.class.getConstructor(Ini.class));
} catch (NoSuchMethodException e) {
addError(e);
}
addFilterChain("/logout", LOGOUT);
addFilterChain("/rest/public/**",ANON);
addFilterChain("/rest/**",NO_SESSION_CREATION, AUTHC_BASIC);
addFilterChain("/**", AUTHC_BASIC);
}
示例6: configureShiroWeb
import org.apache.shiro.realm.text.IniRealm; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
protected void configureShiroWeb() {
logger.entry();
//if you would like to expose the CredentialsMatcher listed here, uncomment the following line.
//expose(CredentialsMatcher.class);
expose(WebSecurityManager.class);
expose(FilterChainResolver.class);
//avoid 4 times instantiation
bindRealm().to(IniRealm.class);
addFilterChain("/logout", LOGOUT);
//addFilterChain("/rest/public/**",ANON);
addFilterChain("/rest/**",NO_SESSION_CREATION, AUTHC_BASIC);
addFilterChain("/**", AUTHC_BASIC);
logger.exit();
}
示例7: getCdiBeanFromIni
import org.apache.shiro.realm.text.IniRealm; //导入依赖的package包/类
@Test
public void getCdiBeanFromIni() {
CdiIniSecurityManagerFactory securityManagerFactory = new CdiIniSecurityManagerFactory("classpath:test-shiro-cdi.ini", beanManager);
DefaultSecurityManager securityManager = (DefaultSecurityManager) securityManagerFactory.createInstance();
assertThat(securityManager, is(notNullValue()));
SecurityUtils.setSecurityManager(securityManager);
Object passwordMatcher = securityManagerFactory.getBeans().get("myPasswordMatcher");
assertThat(passwordMatcher, is(instanceOf(MyPasswordMatcher.class)));
IniRealm realm = (IniRealm) securityManager.getRealms().iterator().next();
assertThat(realm.getCredentialsMatcher(), is(instanceOf(MyPasswordMatcher.class)));
Subject subject = SecurityUtils.getSubject();
assertThat(subject, is(notNullValue()));
assertThat(subject.getPrincipal(), is(nullValue()));
assertThat(subject.isAuthenticated(), is(false));
UsernamePasswordToken token = new UsernamePasswordToken("admin", "secret");
subject.login(token);
assertThat(subject.isAuthenticated(), is(true));
subject.logout();
assertThat(subject.isAuthenticated(), is(false));
}
示例8: configure
import org.apache.shiro.realm.text.IniRealm; //导入依赖的package包/类
@Override
protected void configure() {
if (ini.isPresent()) {
bind(Ini.class).toInstance(ini.get());
} else {
addError("shiro.ini is required.");
}
try {
ShiroUtils.addRealmBinding(binder()).toConstructor(IniRealm.class.getConstructor(Ini.class));
} catch (NoSuchMethodException e) {
addError(e);
}
bind(IniRealm.class).in(Singleton.class);
}
示例9: setUp
import org.apache.shiro.realm.text.IniRealm; //导入依赖的package包/类
@Before
public void setUp() {
ini = new Ini();
Ini.Section users = ini.addSection(IniRealm.USERS_SECTION_NAME);
users.put(ROOT.getUserName(), COMMA_JOINER.join(ROOT.getPassword(), ADMIN_ROLE));
users.put(WFARNER.getUserName(), COMMA_JOINER.join(WFARNER.getPassword(), ENG_ROLE));
users.put(UNPRIVILEGED.getUserName(), UNPRIVILEGED.getPassword());
users.put(
BACKUP_SERVICE.getUserName(),
COMMA_JOINER.join(BACKUP_SERVICE.getPassword(), BACKUP_ROLE));
users.put(
DEPLOY_SERVICE.getUserName(),
COMMA_JOINER.join(DEPLOY_SERVICE.getPassword(), DEPLOY_ROLE));
users.put(H2_USER.getUserName(), COMMA_JOINER.join(H2_USER.getPassword(), H2_ROLE));
Ini.Section roles = ini.addSection(IniRealm.ROLES_SECTION_NAME);
roles.put(ADMIN_ROLE, "*");
roles.put(ENG_ROLE, "thrift.AuroraSchedulerManager:*");
roles.put(BACKUP_ROLE, "thrift.AuroraAdmin:listBackups");
roles.put(
DEPLOY_ROLE,
"thrift.AuroraSchedulerManager:killTasks:"
+ ADS_STAGING_JOB.getRole()
+ ":"
+ ADS_STAGING_JOB.getEnvironment()
+ ":"
+ ADS_STAGING_JOB.getName());
roles.put(H2_ROLE, H2_PERM);
auroraAdmin = createMock(AnnotatedAuroraAdmin.class);
shiroAfterAuthFilter = createMock(Filter.class);
}
示例10: testDoParseOptionalSections
import org.apache.shiro.realm.text.IniRealm; //导入依赖的package包/类
@Test
public void testDoParseOptionalSections() {
assertEquals(
ImmutableSet.of(IniRealm.ROLES_SECTION_NAME),
parser
.doParse(ShiroIniParserTest.class.getResource(MISSING_SECTIONS_SHIRO_INI).toString())
.getSectionNames());
}
示例11: createRealm
import org.apache.shiro.realm.text.IniRealm; //导入依赖的package包/类
@Override
protected Realm createRealm(Ini ini) {
//IniRealm realm = new IniRealm(ini); changed to support SHIRO-322
IniRealm realm = new TestIniRealm();
realm.setName(INI_REALM_NAME);
realm.setIni(ini); //added for SHIRO-322
return realm;
}
示例12: beforeClassHttpLittleProxyShiroIT
import org.apache.shiro.realm.text.IniRealm; //导入依赖的package包/类
@BeforeClass
public static void beforeClassHttpLittleProxyShiroIT() throws Exception {
DBHelper.beforeClass();
Realm realm = new IniRealm("classpath:shiro.ini");
SecurityManager securityManager = new DefaultSecurityManager(realm);
// Make the SecurityManager instance available to the entire application via static memory:
SecurityUtils.setSecurityManager(securityManager);
}
示例13: createRealm
import org.apache.shiro.realm.text.IniRealm; //导入依赖的package包/类
/**
* 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;
}
示例14: configureShiroWeb
import org.apache.shiro.realm.text.IniRealm; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
protected void configureShiroWeb() {
super.configureShiroWeb();
bindRealm().to(IniRealm.class);
addFilterChain("/logout", LOGOUT);
addFilterChain("/rest/**", NO_SESSION_CREATION, AUTHC_BASIC);
addFilterChain("/**", AUTHC_BASIC);
}
示例15: getUserList
import org.apache.shiro.realm.text.IniRealm; //导入依赖的package包/类
/**
* function to extract users from shiro.ini
*/
public List<String> getUserList(IniRealm r) {
List<String> userList = new ArrayList<>();
Map getIniUser = r.getIni().get("users");
if (getIniUser != null) {
Iterator it = getIniUser.entrySet().iterator();
while (it.hasNext()) {
Map.Entry pair = (Map.Entry) it.next();
userList.add(pair.getKey().toString().trim());
}
}
return userList;
}