作者:手机用户2702936363 | 来源:互联网 | 2023-10-09 20:55
本文整理了Java中org.apache.shiro.web.env.WebEnvironment.getSecurityManager()方法的一些代码示例,展示了
本文整理了Java中org.apache.shiro.web.env.WebEnvironment.getSecurityManager()
方法的一些代码示例,展示了WebEnvironment.getSecurityManager()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WebEnvironment.getSecurityManager()
方法的具体详情如下:
包路径:org.apache.shiro.web.env.WebEnvironment
类名称:WebEnvironment
方法名:getSecurityManager
WebEnvironment.getSecurityManager介绍
暂无
代码示例
代码示例来源:origin: Atmosphere/atmosphere
@Override
public Action inspect(AtmosphereResource r) {
if (Utils.webSocketMessage(r)) return Action.CONTINUE;
if (r.getRequest().localAttributes().containsKey(FrameworkConfig.SECURITY_SUBJECT) == false) {
try {
Subject currentUser = null;
if (r.transport().equals(TRANSPORT.WEBSOCKET)) {
WebEnvironment env = WebUtils.getRequiredWebEnvironment(r.getAtmosphereConfig().getServletContext());
currentUser = new WebSubject.Builder(env.getSecurityManager(), r.getRequest(), r.getResponse()).buildWebSubject();
} else {
currentUser = SecurityUtils.getSubject();
}
if (currentUser != null) {
r.getRequest().setAttribute(FrameworkConfig.SECURITY_SUBJECT, currentUser);
}
} catch (UnavailableSecurityManagerException ex) {
logger.info("Shiro Web Security : {}", ex.getMessage());
} catch (java.lang.IllegalStateException ex) {
logger.info("Shiro Web Environment : {}", ex.getMessage());
}
}
return Action.CONTINUE;
}
}
代码示例来源:origin: stackoverflow.com
public class CustomEnvironmentLoaderListener extends EnvironmentLoaderListener {
@Inject
private JpaRealm jpaRealm;
@Override
protected WebEnvironment createEnvironment(ServletContext pServletContext) {
WebEnvironment envirOnment= super.createEnvironment(pServletContext);
RealmSecurityManager rsm = (RealmSecurityManager) environment.getSecurityManager();
PasswordService passwordService = new DefaultPasswordService();
PasswordMatcher passwordMatcher = new PasswordMatcher();
passwordMatcher.setPasswordService(passwordService);
jpaRealm.setCredentialsMatcher(passwordMatcher);
rsm.setRealm(jpaRealm);
((DefaultWebEnvironment) environment).setSecurityManager(rsm);
return environment;
}
}
代码示例来源:origin: stackoverflow.com
public class CdiEnvironmentLoaderListener extends EnvironmentLoaderListener {
//this is your implementation that extends Authorizing Realm
ShiroRealm shiroRealm = null;
@Override
protected WebEnvironment createEnvironment(ServletContext sc) {
WebEnvironment envirOnment= super.createEnvironment(sc);
shiroRealm = new ShiroRealm();
RealmSecurityManager rsm = (RealmSecurityManager) environment
.getSecurityManager();
HashedCredentialsMatcher matcher = new HashedCredentialsMatcher();
matcher.setHashAlgorithmName(Sha512Hash.ALGORITHM_NAME);
shiroRealm.setCredentialsMatcher(matcher);
rsm.setRealm(shiroRealm);
((DefaultWebEnvironment) environment).setSecurityManager(rsm);
return environment;
}
}
代码示例来源:origin: org.apache.polygene.libraries/org.apache.polygene.library.shiro-web
@Override
public void contextInitialized( ServletContextEvent sce )
{
configuration.refresh();
ShiroIniConfiguration cOnfig= configuration.get();
String iniResourcePath = config.iniResourcePath().get() == null ? "classpath:shiro.ini" : config.iniResourcePath().get();
sce.getServletContext().setInitParameter( "shiroConfigLocations", iniResourcePath );
WebEnvironment env = initEnvironment( sce.getServletContext() );
if ( realmsRefs != null && realmsRefs.iterator().hasNext() ) {
// Register Realms Services
RealmSecurityManager realmSecurityManager = ( RealmSecurityManager ) env.getSecurityManager();
Collection iniRealms = new ArrayList( realmSecurityManager.getRealms() );
for ( ServiceReference realmRef : realmsRefs ) {
iniRealms.add( realmRef.get() );
LOG.debug( "Realm Service '{}' registered!", realmRef.identity() );
}
realmSecurityManager.setRealms( iniRealms );
}
}
代码示例来源:origin: apache/attic-polygene-java
@Override
public void contextInitialized( ServletContextEvent sce )
{
configuration.refresh();
ShiroIniConfiguration cOnfig= configuration.get();
String iniResourcePath = config.iniResourcePath().get() == null ? "classpath:shiro.ini" : config.iniResourcePath().get();
sce.getServletContext().setInitParameter( "shiroConfigLocations", iniResourcePath );
WebEnvironment env = initEnvironment( sce.getServletContext() );
if ( realmsRefs != null && realmsRefs.iterator().hasNext() ) {
// Register Realms Services
RealmSecurityManager realmSecurityManager = ( RealmSecurityManager ) env.getSecurityManager();
Collection iniRealms = new ArrayList( realmSecurityManager.getRealms() );
for ( ServiceReference realmRef : realmsRefs ) {
iniRealms.add( realmRef.get() );
LOG.debug( "Realm Service '{}' registered!", realmRef.identity() );
}
realmSecurityManager.setRealms( iniRealms );
}
}
代码示例来源:origin: org.qi4j.library/org.qi4j.library.shiro-web
@Override
public void contextInitialized( ServletContextEvent sce )
{
configuration.refresh();
ShiroIniConfiguration cOnfig= configuration.get();
String iniResourcePath = config.iniResourcePath().get() == null ? "classpath:shiro.ini" : config.iniResourcePath().get();
sce.getServletContext().setInitParameter( "shiroConfigLocations", iniResourcePath );
WebEnvironment env = initEnvironment( sce.getServletContext() );
if ( realmsRefs != null && Iterables.count( realmsRefs ) > 0 ) {
// Register Realms Services
RealmSecurityManager realmSecurityManager = ( RealmSecurityManager ) env.getSecurityManager();
Collection iniRealms = new ArrayList( realmSecurityManager.getRealms() );
for ( ServiceReference realmRef : realmsRefs ) {
iniRealms.add( realmRef.get() );
LOG.debug( "Realm Service '{}' registered!", realmRef.identity() );
}
realmSecurityManager.setRealms( iniRealms );
}
}
代码示例来源:origin: peterl1084/cdiexample
@Override
protected WebEnvironment createEnvironment(ServletContext sc) {
WebEnvironment webEnvirOnment= super.createEnvironment(sc);
RealmSecurityManager rsm = (RealmSecurityManager) webEnvironment
.getSecurityManager();
HashedCredentialsMatcher hashedCredentialsMatcher = new HashedCredentialsMatcher(
HASHING_ALGORITHM);
hashedCredentialsMatcher.setStoredCredentialsHexEncoded(true);
jpaRealm.setCredentialsMatcher(hashedCredentialsMatcher);
Collection realms = rsm.getRealms();
realms.add(jpaRealm);
rsm.setRealms(realms);
((DefaultWebEnvironment) webEnvironment).setSecurityManager(rsm);
return webEnvironment;
}
}