aerogear demo update

This commit is contained in:
Bill Burke 2014-05-12 15:35:54 -04:00
parent 06b98589eb
commit 3e32bd116b
6 changed files with 86 additions and 1 deletions

View file

@ -21,6 +21,16 @@
</auth-constraint> </auth-constraint>
</security-constraint> </security-constraint>
<security-constraint>
<web-resource-collection>
<web-resource-name>AdminConsole</web-resource-name>
<url-pattern>/admin/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>admin</role-name>
</auth-constraint>
</security-constraint>
<security-constraint> <security-constraint>
<web-resource-collection> <web-resource-collection>
<web-resource-name>Database</web-resource-name> <web-resource-name>Database</web-resource-name>

View file

@ -0,0 +1 @@
<h1>This would be the admin page for the UPS admin console.</h1>

View file

@ -135,6 +135,17 @@
<artifactId>keycloak-timer-basic</artifactId> <artifactId>keycloak-timer-basic</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-export-import-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-export-import-impl</artifactId>
<version>${project.version}</version>
</dependency>
<dependency> <dependency>
<groupId>org.jboss.spec.javax.servlet</groupId> <groupId>org.jboss.spec.javax.servlet</groupId>

View file

@ -0,0 +1,40 @@
package org.aerogear.ups.security;
import org.jboss.resteasy.core.Dispatcher;
import org.keycloak.models.KeycloakSession;
import org.keycloak.models.RealmModel;
import org.keycloak.models.UserModel;
import org.keycloak.services.managers.RealmManager;
import org.keycloak.services.resources.KeycloakApplication;
import javax.servlet.ServletContext;
import javax.ws.rs.core.Context;
/**
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
* @version $Revision: 1 $
*/
public class UpsSecurityApplication extends KeycloakApplication {
public UpsSecurityApplication(@Context ServletContext context, @Context Dispatcher dispatcher) {
super(context, dispatcher);
}
@Override
protected void setupDefaultRealm(String contextPath) {
super.setupDefaultRealm(contextPath);
KeycloakSession session = factory.createSession();
session.getTransaction().begin();
// disable master realm by deleting the admin user.
try {
RealmManager manager = new RealmManager(session);
RealmModel master = manager.getKeycloakAdminstrationRealm();
UserModel admin = master.getUser("admin");
if (admin != null) master.removeUser(admin.getLoginName());
session.getTransaction().commit();
} finally {
session.close();
}
}
}

View file

@ -20,6 +20,19 @@
{ "type" : "password", { "type" : "password",
"value" : "password" } "value" : "password" }
] ]
},
{
"username" : "admin",
"enabled": true,
"firstName": "Bill",
"lastName": "Burke",
"credentials" : [
{ "type" : "password",
"value" : "admin" }
],
"requiredActions": [
"UPDATE_PASSWORD"
]
} }
], ],
"roles" : { "roles" : {
@ -38,6 +51,10 @@
{ {
"username": "bburke@redhat.com", "username": "bburke@redhat.com",
"roles": ["user"] "roles": ["user"]
},
{
"username": "admin",
"roles": ["user", "admin"]
} }
], ],
"scopeMappings": [ "scopeMappings": [
@ -64,6 +81,12 @@
"username": "bburke@redhat.com", "username": "bburke@redhat.com",
"roles": ["manage-account"] "roles": ["manage-account"]
} }
],
"demo-realm": [
{
"username": "admin",
"roles": ["realm-admin"]
}
] ]
} }

View file

@ -16,7 +16,7 @@
<servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServlet30Dispatcher</servlet-class> <servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServlet30Dispatcher</servlet-class>
<init-param> <init-param>
<param-name>javax.ws.rs.Application</param-name> <param-name>javax.ws.rs.Application</param-name>
<param-value>org.keycloak.services.resources.KeycloakApplication</param-value> <param-value>org.aerogear.ups.security.UpsSecurityApplication</param-value>
</init-param> </init-param>
<init-param> <init-param>
<param-name>resteasy.servlet.mapping.prefix</param-name> <param-name>resteasy.servlet.mapping.prefix</param-name>