Skip to content

Commit 01083c0

Browse files
committed
UpdateService created
1 parent 332410c commit 01083c0

36 files changed

+1724
-65
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ src/main/webapp/style/css/
2121
env/data/settings/
2222
# vagrant
2323
.vagrant
24+
/.project

env/data/cas.xml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<cas>
33
<service>http://localhost:8084/universeadm/login/cas</service>
4-
<server-url>https://localhost:8443/cas</server-url>
4+
<server-url>https://192.168.115.52:8443/cas</server-url>
55
<failure-url>http://localhost:8084/universeadm/error/auth.html</failure-url>
6-
<login-url>https://localhost:8443/cas/login?service=http://localhost:8084/universeadm/login/cas</login-url>
7-
<logout-url>https://localhost:8443/cas/logout</logout-url>
6+
<login-url>https://192.168.115.52:8443/cas/login?service=http://localhost:8084/universeadm/login/cas</login-url>
7+
<logout-url>https://192.168.115.52:8443/cas/logout</logout-url>
88
<role-attribute-names>groups</role-attribute-names>
99
<administrator-role>admins</administrator-role>
1010
</cas>

nb-configuration.xml

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ Any value defined here will override the pom.xml file value but is only applicab
1515
-->
1616
<org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_j2eeVersion>1.6-web</org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_j2eeVersion>
1717
<org-netbeans-modules-maven-jaxws.rest_2e_config_2e_type>ide</org-netbeans-modules-maven-jaxws.rest_2e_config_2e_type>
18-
<org-netbeans-modules-maven-j2ee.netbeans_2e_deploy_2e_on_2e_save>false</org-netbeans-modules-maven-j2ee.netbeans_2e_deploy_2e_on_2e_save>
1918
<org-netbeans-modules-css-prep.less_2e_mappings>/style/less:/style/css</org-netbeans-modules-css-prep.less_2e_mappings>
2019
<org-netbeans-modules-css-prep.less_2e_enabled>true</org-netbeans-modules-css-prep.less_2e_enabled>
2120
<org-netbeans-modules-css-prep.less_2e_configured>true</org-netbeans-modules-css-prep.less_2e_configured>

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"dependencies": {},
44
"devDependencies": {
55
"bower": "^1.3.12",
6-
"gulp": "~3.8.10",
6+
"gulp": "^3.8.10",
77
"gulp-angular-templatecache": "^1.4.2",
88
"gulp-concat": "^2.4.2",
99
"gulp-filesize": "^0.0.6",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright (c) 2013 - 2014, TRIOLOGY GmbH
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions are met:
7+
*
8+
* 1. Redistributions of source code must retain the above copyright notice,
9+
* this list of conditions and the following disclaimer.
10+
* 2. Redistributions in binary form must reproduce the above copyright notice,
11+
* this list of conditions and the following disclaimer in the documentation
12+
* and/or other materials provided with the distribution.
13+
*
14+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17+
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
18+
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
21+
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24+
*
25+
* http://www.scm-manager.com
26+
*/
27+
28+
package de.triology.universeadm;
29+
30+
import javax.servlet.ServletContext;
31+
import org.apache.shiro.guice.web.ShiroWebModule;
32+
33+
/**
34+
*
35+
* @author Sebastian Sdorra <[email protected]>
36+
*/
37+
public abstract class BaseSecurityModule extends ShiroWebModule
38+
{
39+
40+
protected BaseSecurityModule(ServletContext context)
41+
{
42+
super(context);
43+
}
44+
45+
@Override
46+
@SuppressWarnings("unchecked")
47+
protected void configureShiroWeb()
48+
{
49+
addFilterChain("/error/*", ANON);
50+
addFilterChain("/style/**", ANON);
51+
addFilterChain("/components/**", ANON);
52+
addFilterChain("/api/logout", ANON);
53+
configureRealm();
54+
}
55+
56+
protected abstract void configureRealm();
57+
58+
}

src/main/java/de/triology/universeadm/BootstrapContextListener.java

+14-1
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,24 @@ protected List<? extends Module> getModules(ServletContext context)
8181
else
8282
{
8383
logger.info("load injection modules");
84+
85+
Module securityModule;
86+
if (Stage.get() == Stage.PRODUCTION)
87+
{
88+
logger.info("load cas security module for production stage");
89+
securityModule = new CasSecurityModule(context);
90+
}
91+
else
92+
{
93+
logger.info("load development security module for development stage");
94+
securityModule = new DevelopmentSecurityModule(context);
95+
}
96+
8497
//J-
8598
modules = ImmutableList.of(
8699
ShiroWebModule.guiceFilterModule(),
87100
new MainModule(ldapConfiguration),
88-
new SecurityModule(context)
101+
securityModule
89102
);
90103
//J+
91104
}

src/main/java/de/triology/universeadm/SecurityModule.java src/main/java/de/triology/universeadm/CasSecurityModule.java

+20-29
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
* Copyright (c) 2013 - 2014, TRIOLOGY GmbH
33
* All rights reserved.
44
*
@@ -24,7 +24,6 @@
2424
*
2525
* http://www.scm-manager.com
2626
*/
27-
2827
package de.triology.universeadm;
2928

3029
import com.google.inject.Inject;
@@ -42,7 +41,6 @@
4241
import org.apache.shiro.cas.CasFilter;
4342
import org.apache.shiro.cas.CasRealm;
4443
import org.apache.shiro.cas.CasSubjectFactory;
45-
import org.apache.shiro.guice.web.ShiroWebModule;
4644
import org.apache.shiro.mgt.SubjectFactory;
4745
import org.apache.shiro.realm.Realm;
4846
import org.apache.shiro.subject.PrincipalCollection;
@@ -53,11 +51,12 @@
5351

5452
/**
5553
*
56-
* @author Sebastian Sdorra <[email protected]>
54+
* @author mbehlendorf
5755
*/
58-
public class SecurityModule extends ShiroWebModule
59-
{
56+
public class CasSecurityModule extends BaseSecurityModule {
6057

58+
private static final Logger logger = LoggerFactory.getLogger(CasSecurityModule.class);
59+
6160
private static final Key<CasFilter> CAS = Key.get(CasFilter.class);
6261
private static final Key<ApiAuthenticationFilter> API = Key.get(ApiAuthenticationFilter.class);
6362

@@ -68,19 +67,10 @@ public class SecurityModule extends ShiroWebModule
6867
private static final String CAS_FAILURE_URL = "shiro.failureUrl";
6968
private static final String CAS_SERVICE = "shiro.casService";
7069

71-
private static final Logger logger = LoggerFactory.getLogger(SecurityModule.class);
72-
73-
public SecurityModule(ServletContext context)
74-
{
70+
public CasSecurityModule(ServletContext context) {
7571
super(context);
7672
}
77-
78-
private void config(String key, String value)
79-
{
80-
logger.debug("bind config {} to {}", key, value);
81-
bindConstant().annotatedWith(Names.named(key)).to(value);
82-
}
83-
73+
8474
private CasConfiguration getCasConfiguration()
8575
{
8676
CasConfiguration casConfiguration = BaseDirectory.getConfiguration(CasConfiguration.FILE, CasConfiguration.class);
@@ -91,10 +81,14 @@ private CasConfiguration getCasConfiguration()
9181
return casConfiguration;
9282
}
9383

94-
@Override
95-
@SuppressWarnings("unchecked")
96-
protected void configureShiroWeb()
84+
private void config(String key, String value)
9785
{
86+
logger.debug("bind config {} to {}", key, value);
87+
bindConstant().annotatedWith(Names.named(key)).to(value);
88+
}
89+
90+
@Override
91+
protected void configureRealm() {
9892
CasConfiguration cas = getCasConfiguration();
9993
bind(CasConfiguration.class).toInstance(cas);
10094
expose(CasConfiguration.class);
@@ -113,19 +107,16 @@ protected void configureShiroWeb()
113107
// beacuse it looks like guice does not set constants for multi binding
114108
bindRealm().toProvider(CasRealmProvider.class).in(Singleton.class);
115109
bind(SubjectFactory.class).to(CasSubjectFactory.class);
116-
117-
addFilterChain("/error/*", ANON);
118-
addFilterChain("/style/**", ANON);
119-
addFilterChain("/components/**", ANON);
110+
111+
// protect uris
120112
addFilterChain("/login/cas", ANON, CAS);
121-
addFilterChain("/api/logout", ANON);
122113
addFilterChain("/api/users", API, config(ROLES, Roles.ADMINISTRATOR));
123114
addFilterChain("/api/users/*", API, config(ROLES, Roles.ADMINISTRATOR));
124115
addFilterChain("/api/groups", API, config(ROLES, Roles.ADMINISTRATOR));
125116
addFilterChain("/api/groups/*", API, config(ROLES, Roles.ADMINISTRATOR));
126117
addFilterChain("/**", AUTHC);
127118
}
128-
119+
129120
private static class CasRealmProvider implements Provider<Realm>
130121
{
131122

@@ -144,8 +135,8 @@ public Realm get()
144135
}
145136

146137
}
147-
148-
/**
138+
139+
/**
149140
* CasRealm with fixed support for multi value attributes
150141
*
151142
* @see https://issues.apache.org/jira/browse/SHIRO-442
@@ -276,5 +267,5 @@ private List<String> split(String s)
276267
}
277268

278269
}
279-
270+
280271
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* Copyright (c) 2013 - 2014, TRIOLOGY GmbH
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions are met:
7+
*
8+
* 1. Redistributions of source code must retain the above copyright notice,
9+
* this list of conditions and the following disclaimer.
10+
* 2. Redistributions in binary form must reproduce the above copyright notice,
11+
* this list of conditions and the following disclaimer in the documentation
12+
* and/or other materials provided with the distribution.
13+
*
14+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17+
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
18+
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
21+
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24+
*
25+
* http://www.scm-manager.com
26+
*/
27+
package de.triology.universeadm;
28+
29+
import com.google.common.collect.Sets;
30+
import javax.servlet.ServletContext;
31+
import org.apache.shiro.authc.AuthenticationException;
32+
import org.apache.shiro.authc.AuthenticationInfo;
33+
import org.apache.shiro.authc.AuthenticationToken;
34+
import org.apache.shiro.authc.SimpleAuthenticationInfo;
35+
import org.apache.shiro.authc.UsernamePasswordToken;
36+
import org.apache.shiro.authz.AuthorizationInfo;
37+
import org.apache.shiro.authz.SimpleAuthorizationInfo;
38+
import org.apache.shiro.realm.AuthorizingRealm;
39+
import org.apache.shiro.subject.PrincipalCollection;
40+
41+
/**
42+
*
43+
* @author mbehlendorf
44+
*/
45+
public class DevelopmentSecurityModule extends BaseSecurityModule {
46+
47+
public DevelopmentSecurityModule(ServletContext servletContext) {
48+
super(servletContext);
49+
}
50+
51+
@Override
52+
protected void configureRealm() {
53+
bindRealm().to(DummyRealm.class);
54+
55+
// protect uris
56+
addFilterChain("/api/users**", AUTHC_BASIC, config(ROLES, Roles.ADMINISTRATOR));
57+
addFilterChain("/api/groups**", AUTHC_BASIC, config(ROLES, Roles.ADMINISTRATOR));
58+
addFilterChain("/**", AUTHC_BASIC);
59+
}
60+
61+
public static class DummyRealm extends AuthorizingRealm{
62+
63+
public DummyRealm() {
64+
setAuthenticationTokenClass(UsernamePasswordToken.class);
65+
}
66+
67+
@Override
68+
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
69+
return new SimpleAuthorizationInfo(Sets.newHashSet(Roles.ADMINISTRATOR));
70+
}
71+
72+
@Override
73+
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
74+
return new SimpleAuthenticationInfo("admin", "admin", "dummy");
75+
}
76+
77+
}
78+
79+
80+
81+
}

src/main/java/de/triology/universeadm/Stage.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,15 @@ public enum Stage
7373

7474
if (Strings.isNullOrEmpty(stage))
7575
{
76-
current = Stage.PRODUCTION;
76+
//WORKAROUND
77+
//current = Stage.PRODUCTION;
78+
current = Stage.DEVELOPMENT;
7779
}
7880
else
7981
{
8082
current = Stage.valueOf(stage.toUpperCase(Locale.ENGLISH));
8183
}
82-
84+
8385
logger.info("start with stage {}", stage);
8486
}
8587

src/main/java/de/triology/universeadm/account/AccountResource.java

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
package de.triology.universeadm.account;
2929

3030
import com.google.inject.Inject;
31+
import de.triology.universeadm.Manager;
3132
import de.triology.universeadm.user.User;
3233
import javax.ws.rs.Consumes;
3334
import javax.ws.rs.GET;

src/main/java/de/triology/universeadm/settings/SettingsResource.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,5 @@ public Settings getSettings()
6464
{
6565
return store.get();
6666
}
67-
67+
6868
}

0 commit comments

Comments
 (0)