Skip to content

Commit b2e6adc

Browse files
author
Mark Kelly
committed
shiro context and base classes added
1 parent 207e6e3 commit b2e6adc

8 files changed

Lines changed: 119 additions & 11 deletions

File tree

common/src/main/resources/META-INF/email-context.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<beans xmlns="http://www.springframework.org/schema/beans"
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
4+
xsi:schemaLocation="http://www.springframework.org/schema/beans
5+
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
56

67
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
78
<property name="host" value="${mtt.mail.smtp.host:localhost}"/>

common/src/main/resources/META-INF/executer-context.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<beans xmlns="http://www.springframework.org/schema/beans"
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
4+
xsi:schemaLocation="http://www.springframework.org/schema/beans
5+
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
56

67
<bean id="emailDispatchExecutor" class="com.mtt.concurrent.ThreadPoolFactoryBean">
78
<constructor-arg name="threadCount" value="${mtt.email.dispatch.thread.count:5}"/>

pom.xml

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -323,27 +323,22 @@
323323
</dependency>
324324
<dependency>
325325
<groupId>org.apache.shiro</groupId>
326-
<artifactId>shiro-root</artifactId>
327-
<version>${shiro.version}</version>
328-
</dependency>
329-
<dependency>
330-
<groupId>org.apache.shiro</groupId>
331-
<artifactId>shiro-ehcache</artifactId>
326+
<artifactId>shiro-core</artifactId>
332327
<version>${shiro.version}</version>
333328
</dependency>
334329
<dependency>
335330
<groupId>org.apache.shiro</groupId>
336-
<artifactId>shiro-core</artifactId>
331+
<artifactId>shiro-web</artifactId>
337332
<version>${shiro.version}</version>
338333
</dependency>
339334
<dependency>
340335
<groupId>org.apache.shiro</groupId>
341-
<artifactId>shiro-web</artifactId>
336+
<artifactId>shiro-spring</artifactId>
342337
<version>${shiro.version}</version>
343338
</dependency>
344339
<dependency>
345340
<groupId>org.apache.shiro</groupId>
346-
<artifactId>shiro-spring</artifactId>
341+
<artifactId>shiro-ehcache</artifactId>
347342
<version>${shiro.version}</version>
348343
</dependency>
349344
<dependency>

server/pom.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,22 @@
9595
<groupId>${project.groupId}</groupId>
9696
<artifactId>model</artifactId>
9797
</dependency>
98+
<dependency>
99+
<groupId>org.apache.shiro</groupId>
100+
<artifactId>shiro-core</artifactId>
101+
</dependency>
102+
<dependency>
103+
<groupId>org.apache.shiro</groupId>
104+
<artifactId>shiro-web</artifactId>
105+
</dependency>
106+
<dependency>
107+
<groupId>org.apache.shiro</groupId>
108+
<artifactId>shiro-spring</artifactId>
109+
</dependency>
110+
<dependency>
111+
<groupId>org.apache.shiro</groupId>
112+
<artifactId>shiro-ehcache</artifactId>
113+
</dependency>
98114
<dependency>
99115
<groupId>${project.groupId}</groupId>
100116
<artifactId>client</artifactId>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.mtt.api.security;
2+
3+
import org.apache.shiro.authc.AuthenticationToken;
4+
import org.apache.shiro.web.filter.authc.AuthenticatingFilter;
5+
6+
import javax.servlet.ServletRequest;
7+
import javax.servlet.ServletResponse;
8+
9+
public class ApiKeyAuthenticationFilter extends AuthenticatingFilter {
10+
@Override
11+
protected AuthenticationToken createToken(ServletRequest servletRequest, ServletResponse servletResponse) throws Exception {
12+
return null; //To change body of implemented methods use File | Settings | File Templates.
13+
}
14+
15+
@Override
16+
protected boolean onAccessDenied(ServletRequest servletRequest, ServletResponse servletResponse) throws Exception {
17+
return false; //To change body of implemented methods use File | Settings | File Templates.
18+
}
19+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.mtt.api.security;
2+
3+
4+
import com.mtt.service.SecurityService;
5+
import org.apache.shiro.authc.AuthenticationException;
6+
import org.apache.shiro.authc.AuthenticationInfo;
7+
import org.apache.shiro.authc.AuthenticationToken;
8+
import org.apache.shiro.authz.AuthorizationInfo;
9+
import org.apache.shiro.realm.AuthorizingRealm;
10+
import org.apache.shiro.subject.PrincipalCollection;
11+
12+
public class PlatformRealm extends AuthorizingRealm {
13+
14+
private SecurityService securityService;
15+
16+
@Override
17+
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
18+
return null; //To change body of implemented methods use File | Settings | File Templates.
19+
}
20+
21+
@Override
22+
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
23+
return null; //To change body of implemented methods use File | Settings | File Templates.
24+
}
25+
26+
public final void setSecurityService(SecurityService securityService) {
27+
this.securityService = securityService;
28+
}
29+
}

server/src/main/resources/META-INF/application-context.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
<import resource="datasource-context.xml"/>
3636
<import resource="executer-context.xml" />
3737
<import resource="email-context.xml"/>
38+
<import resource="security-context.xml"/>
3839

3940
<bean id="mappingJacksonHttpMessageConverter"
4041
class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"/>
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<beans xmlns="http://www.springframework.org/schema/beans"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
5+
6+
<bean id="apiKeyFilter" class="com.mtt.api.security.ApiKeyAuthenticationFilter"/>
7+
8+
<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean" depends-on="apiKeyRepository">
9+
<property name="securityManager" ref="securityManager"/>
10+
<property name="filterChainDefinitions">
11+
<value>
12+
/api/tasks/** = noSessionCreation, apiKeyFilter
13+
</value>
14+
</property>
15+
</bean>
16+
17+
<bean id="shiroCacheManager" class="org.apache.shiro.cache.ehcache.EhCacheManager">
18+
<property name="cacheManager" ref="cacheManager"/>
19+
</bean>
20+
21+
<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
22+
<property name="configLocation" value="classpath:/META-INF/ehcache.xml"/>
23+
</bean>
24+
25+
<bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
26+
<property name="realm" ref="platformRealm"/>
27+
<property name="cacheManager" ref="shiroCacheManager"/>
28+
</bean>
29+
30+
<bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor"/>
31+
32+
<bean id="platformRealm" class="com.mtt.api.security.PlatformRealm" depends-on="userRepository">
33+
<property name="securityService" ref="securityServiceImpl"/>
34+
<property name="credentialsMatcher" ref="credentialsMatcher"/>
35+
<property name="authorizationCachingEnabled" value="${gumtree.api.security.cache.enabled:true}"/>
36+
</bean>
37+
38+
<bean id="credentialsMatcher" class="org.apache.shiro.authc.credential.AllowAllCredentialsMatcher"/>
39+
40+
<!-- <bean id="credentialsMatcher" class="org.apache.shiro.authc.credential.HashedCredentialsMatcher">
41+
<property name="hashAlgorithmName" value="SHA-256"/>
42+
<property name="storedCredentialsHexEncoded" value="false"/>
43+
<property name="hashIterations" value="1024"/>
44+
</bean>
45+
-->
46+
</beans>

0 commit comments

Comments
 (0)