67,513
社区成员
发帖
与我相关
我的任务
分享
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext_*.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<filter>
<filter-name>shiroFilter</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
<init-param>
<param-name>targetFilterLifecycle</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>shiroFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>cloudServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:config/dispatcher-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>cloudServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
<property name="cacheManager" ref="cacheManager"/>
<property name="sessionMode" value="native"/>
<property name="realm" ref="hfrealm"/>
<property name="sessionManager" ref="hfsessionManager"/>
</bean>
<bean id="hf_session_listener" class="com.hf.hfmo.shiro.hf_session_listener"></bean>
<bean id="hfsessionManager" class="com.hf.hfmo.shiro.SessionManager">
<property name="globalSessionTimeout" value="86400000" />
<property name="sessionListeners" ref="hf_session_listener">
</property>
<property name="sessionValidationInterval" value="3600000"></property>
</bean>
<bean id="cacheManager" class="org.apache.shiro.cache.ehcache.EhCacheManager"> </bean>
<bean id="hfrealm" class="com.hf.hfmo.shiro.OrientDbRealm">
<property name="name" value="OrientDbRealm"/>
<property name="credentialsMatcher">
<bean class="org.apache.shiro.authc.credential.AllowAllCredentialsMatcher">
</bean>
</property>
</bean>
<bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor"/>
<bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"
depends-on="lifecycleBeanPostProcessor"/>
<bean class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor">
<property name="securityManager" ref="securityManager"/>
</bean>
<bean id="secureRemoteInvocationExecutor" class="org.apache.shiro.spring.remoting.SecureRemoteInvocationExecutor">
<property name="securityManager" ref="securityManager"/>
</bean>
<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
<property name="securityManager" ref="securityManager"/>
<property name="loginUrl" value="/consumer/login"/>
<property name="successUrl" value="/s/index"/>
<property name="unauthorizedUrl" value="/s/unauthorized"/>
<property name="filterChainDefinitions">
<value>
/favicon.ico = anon
/logo.png = anon
/index.html = anon
/shiro.css = anon
/consumer/login = anon
/consumer/regist = anon
/messages/** = authc
/information/** = anon
# allow WebStart to pull the jars for the swing app:
/*.jar = anon
# everything else requires authentication:
/** = authc
</value>
</property>
</bean>
</beans>
@Component
public class OrientDbRealm extends AuthorizingRealm {
private Logger logger = Logger.getLogger(OrientDbRealm.class);
@Autowired
private LoginService loginService;
@Override
protected AuthenticationInfo doGetAuthenticationInfo(
final AuthenticationToken token)
throws AuthenticationException {
final HFUsernamePasswordToken credentials = (HFUsernamePasswordToken) token;
final String username = credentials.getUsername();
if (username == null) {
logger.warn("Userame is null");
return null;
}
HashMap<String,Object> map = new HashMap<String,Object>();
map.put("telephone", username);
map.put("pwd", new String(credentials.getPassword()));
//final User user = userRepository.findByEmailAndActive(email, true);
User user = loginService.findUser(map);
if (user == null) {
//throw new UnknownAccountException("Account does not exist");
logger.warn("Account does not exist");
return null;
}
return new SimpleAuthenticationInfo(username, credentials.getPassword(),
ByteSource.Util.bytes(username), getName());
}
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
// TODO Auto-generated method stub
return null;
}
}