--- /dev/null
+Bundle-SymbolicName: org.argeo.server.demo.log4j
+Bundle-Version: 0.1.1.SNAPSHOT
+Fragment-Host: com.springsource.org.apache.log4j
--- /dev/null
+log4j.rootLogger=WARN, console
+
+## Levels
+log4j.logger.org.argeo=DEBUG
+
+log4j.logger.org.hibernate=WARN
+
+log4j.logger.org.springframework=WARN
+log4j.logger.org.springframework.web=DEBUG
+#log4j.logger.org.springframework.jms=WARN
+#log4j.logger.org.springframework.security=WARN
+
+log4j.logger.org.apache.activemq=WARN
+log4j.logger.org.apache.activemq.transport=WARN
+log4j.logger.org.apache.activemq.ActiveMQMessageConsumer=INFO
+log4j.logger.org.apache.activemq.ActiveMQMessageProducer=INFO
+
+log4j.logger.org.apache.catalina=INFO
+log4j.logger.org.apache.coyote=INFO
+log4j.logger.org.apache.tomcat=INFO
+
+## Appenders
+# console is set to be a ConsoleAppender.
+log4j.appender.console=org.apache.log4j.ConsoleAppender
+
+# console uses PatternLayout.
+log4j.appender.console.layout=org.apache.log4j.PatternLayout
+log4j.appender.console.layout.ConversionPattern= %-5p %d{ISO8601} %m - %c%n
<groupId>org.argeo.maven.plugins</groupId>
<artifactId>maven-argeo-osgi-plugin</artifactId>
<configuration>
- <execDir>target/exec/server</execDir>
+ <execDir>target/exec</execDir>
<osgiBootArtifactId>org.argeo.osgi.boot</osgiBootArtifactId>
+ <argsToAppend>
+ <arg>-clean</arg>
+ </argsToAppend>
+ <fork>false</fork>
<systemProperties>
<slc.osgi.start>
org.springframework.osgi.extender,
org.springframework.osgi.web.extender,
org.argeo.dep.osgi.catalina.start,
- org.argeo.server.security.webapp
+ org.argeo.security.webapp
</slc.osgi.start>
<slc.osgi.bundles>
${basedir};in=*;ex=pom.xml;ex=target;ex=.*,
${basedir}/../modules;in=*;ex=pom.xml;ex=target;ex=.*,
+ ${basedir}/../../server/modules;in=*;ex=pom.xml;ex=target;ex=.*,
</slc.osgi.bundles>
</systemProperties>
</configuration>
</plugins>
</build>
<dependencies>
+ <!-- Argeo -->
+ <dependency>
+ <groupId>org.argeo.commons.security</groupId>
+ <artifactId>org.argeo.security.mvc</artifactId>
+ <version>0.1.1-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.argeo.commons.server</groupId>
+ <artifactId>org.argeo.server.json</artifactId>
+ <version>0.1.1-SNAPSHOT</version>
+ </dependency>
+
<!-- Third Parties -->
<!-- OSGi -->
<artifactId>com.springsource.javax.xml.bind</artifactId>
</dependency>
- <!-- Taglibs
- <dependency>
- <groupId>org.apache.taglibs</groupId>
+ <!--
+ Taglibs <dependency> <groupId>org.apache.taglibs</groupId>
<artifactId>com.springsource.org.apache.taglibs.standard</artifactId>
- </dependency> -->
+ </dependency>
+ -->
<!-- Tomcat -->
Bundle-Version: 0.1.1.SNAPSHOT
Import-Package: javax.servlet,
javax.servlet.http,
- javax.servlet.resources
+ javax.servlet.resources,
+ org.argeo.security.mvc,
+ org.argeo.server.json.mvc,
+ org.springframework.osgi.web.context.support,
+ org.springframework.security.userdetails.memory,
+ org.springframework.web.context,
+ org.springframework.web.context.support,
+ org.springframework.web.filter,
+ org.springframework.web.servlet
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
+ xmlns:context="http://www.springframework.org/schema/context"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
+ http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
+ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
+
+ <context:component-scan base-package="org.argeo.security.mvc" />
+
+ <bean id="controller" class="org.argeo.security.mvc.UsersRolesController"></bean>
+
+ <bean id="viewResolver" class="org.argeo.server.json.mvc.JsonViewResolver">
+ </bean>
+
+</beans>
\ No newline at end of file
<groupId>org.argeo.security</groupId>
<artifactId>modules</artifactId>
<packaging>bundles</packaging>
- <name>Commons Server Modules</name>
+ <name>Commons Security Modules</name>
<build>
<plugins>
<plugin>
<dependencies>
<!-- Spring LDAP -->
<dependency>
- <groupId>org.springframework.ldap</groupId>
- <artifactId>org.springframework.ldap</artifactId>
- <version>1.3.0.RELEASE</version>
- </dependency>
- <dependency>
- <groupId>org.springframework.ldap</groupId>
- <artifactId>org.springframework.ldap.core.simple</artifactId>
- <version>1.3.0.RELEASE</version>
+ <groupId>org.argeo.dep.osgi</groupId>
+ <artifactId>org.argeo.dep.osgi.springframework.ldap</artifactId>
+ <version>1.3.0.0002</version>
</dependency>
<!-- Security -->
<artifactId>org.springframework.security</artifactId>
</dependency>
+ <!-- Logging -->
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>com.springsource.slf4j.org.apache.commons.logging</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.log4j</groupId>
+ <artifactId>com.springsource.org.apache.log4j</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>com.springsource.slf4j.log4j</artifactId>
+ </dependency>
+
<!-- JSON -->
<dependency>
<groupId>org.codehaus.jackson</groupId>
import java.util.List;
import org.argeo.security.ArgeoUser;
+import org.argeo.security.BasicArgeoUser;
import org.argeo.security.UserNature;
+import org.springframework.security.Authentication;
import org.springframework.security.GrantedAuthority;
import org.springframework.security.userdetails.User;
+import org.springframework.security.userdetails.UserDetails;
public class ArgeoUserDetails extends User implements ArgeoUser {
private static final long serialVersionUID = 1L;
throws IllegalArgumentException {
super(username, password, true, true, true, true, authorities);
this.userNatures = Collections.unmodifiableList(userNatures);
-
+
// Roles
- List<String> roles = new ArrayList<String>();
- for (GrantedAuthority authority : getAuthorities()) {
- roles.add(authority.getAuthority());
- }
- this.roles = Collections.unmodifiableList(roles);
+ this.roles = Collections.unmodifiableList(addAuthoritiesToRoles(
+ getAuthorities(), new ArrayList<String>()));
}
public List<UserNature> getUserNatures() {
public List<String> getRoles() {
return roles;
}
+
+ /** The provided list, for chaining using {@link Collections} */
+ protected static List<String> addAuthoritiesToRoles(
+ GrantedAuthority[] authorities, List<String> roles) {
+ for (GrantedAuthority authority : authorities) {
+ roles.add(authority.getAuthority());
+ }
+ return roles;
+ }
+
+ public static BasicArgeoUser createBasicArgeoUser(UserDetails userDetails) {
+ BasicArgeoUser argeoUser = new BasicArgeoUser();
+ argeoUser.setUsername(userDetails.getUsername());
+ addAuthoritiesToRoles(userDetails.getAuthorities(), argeoUser
+ .getRoles());
+ return argeoUser;
+ }
+
+ public static BasicArgeoUser createBasicArgeoUser(
+ Authentication authentication) {
+ BasicArgeoUser argeoUser = new BasicArgeoUser();
+ argeoUser.setUsername(authentication.getName());
+ addAuthoritiesToRoles(authentication.getAuthorities(), argeoUser
+ .getRoles());
+ return argeoUser;
+ }
}
<configuration>
<instructions>
<Export-Package>
- org.argeo.security.*
+ org.argeo.security.mvc.*
</Export-Package>
</instructions>
</configuration>
</plugins>
</build>
<dependencies>
+ <!-- Argeo Security -->
+ <dependency>
+ <groupId>org.argeo.commons.security</groupId>
+ <artifactId>org.argeo.security.core</artifactId>
+ <version>0.1.1-SNAPSHOT</version>
+ </dependency>
+
<!-- Spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>com.springsource.javax.servlet</artifactId>
</dependency>
- <!-- Security -->
- <dependency>
- <groupId>org.springframework.security</groupId>
- <artifactId>org.springframework.security</artifactId>
- </dependency>
-
- <dependency>
- <groupId>com.springsource.json</groupId>
- <artifactId>com.springsource.json</artifactId>
- <version>1.0.1.RELEASE</version>
- </dependency>
- <dependency>
- <groupId>org.antlr</groupId>
- <artifactId>com.springsource.org.antlr</artifactId>
- </dependency>
-
- <!-- LDAP -->
- <dependency>
- <groupId>org.springframework.ldap</groupId>
- <artifactId>org.springframework.ldap</artifactId>
- <version>1.3.0.RELEASE</version>
- </dependency>
- <dependency>
- <groupId>org.springframework.ldap</groupId>
- <artifactId>org.springframework.ldap.core.simple</artifactId>
- <version>1.3.0.RELEASE</version>
- </dependency>
</dependencies>
</project>
--- /dev/null
+package org.argeo.security.mvc;
+
+import org.argeo.security.ArgeoUser;
+import org.argeo.security.core.ArgeoUserDetails;
+import org.springframework.security.Authentication;
+import org.springframework.security.context.SecurityContextHolder;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.ModelAttribute;
+import org.springframework.web.bind.annotation.RequestMapping;
+
+@Controller
+public class UsersRolesController {
+
+ @RequestMapping("/getCredentials.security")
+ @ModelAttribute("getCredentials")
+ public ArgeoUser getCredentials() {
+ Authentication authentication = SecurityContextHolder.getContext()
+ .getAuthentication();
+
+ return ArgeoUserDetails.createBasicArgeoUser(authentication);
+ }
+}
<name>Commons Security Runtime</name>
<packaging>pom</packaging>
<modules>
- <module>org.argeo.security.ria</module>
+ <module>org.argeo.security.core</module>
+ <module>org.argeo.security.mvc</module>
</modules>
</project>
\ No newline at end of file
org.springframework.security.providers;resolution:=optional,
org.springframework.security.ui;resolution:=optional,
org.springframework.security.ui.savedrequest;resolution:=optional,
- org.springframework.security.userdetails;resolution:=optional
+ org.springframework.security.userdetails;resolution:=optional,
+ org.springframework.security.context;resolution:=optional
<name>Commons Server</name>
<packaging>pom</packaging>
<modules>
+ <module>runtime</module>
<module>modules</module>
</modules>
</project>
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" output="target/classes" path="src/main/java"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+ <classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
+ <classpathentry kind="output" path="target/classes"/>
+</classpath>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.argeo.server.core</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.maven.ide.eclipse.maven2Builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.maven.ide.eclipse.maven2Nature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
--- /dev/null
+#Wed Sep 16 10:02:19 CEST 2009
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.source=1.5
--- /dev/null
+#Wed Sep 16 10:02:18 CEST 2009
+activeProfiles=
+eclipse.preferences.version=1
+fullBuildGoals=process-test-resources
+includeModules=false
+resolveWorkspaceProjects=true
+resourceFilterGoals=process-resources resources\:testResources
+skipCompilerPlugin=true
+version=1
--- /dev/null
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.argeo.commons.server</groupId>
+ <artifactId>runtime</artifactId>
+ <version>0.1.1-SNAPSHOT</version>
+ <relativePath>..</relativePath>
+ </parent>
+ <artifactId>org.argeo.server.core</artifactId>
+ <name>Commons Server Core</name>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-source-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <version>${version.maven-bundle-plugin}</version>
+ <configuration>
+ <instructions>
+ <Export-Package>
+ org.argeo.server.*
+ </Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <!-- Apache Commons -->
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>com.springsource.org.apache.commons.io</artifactId>
+ </dependency>
+
+ <!-- Spring -->
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>org.springframework.web.servlet</artifactId>
+ </dependency>
+
+ <!-- J2EE -->
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>com.springsource.javax.servlet</artifactId>
+ </dependency>
+
+ </dependencies>
+</project>
--- /dev/null
+package org.argeo.server;
+
+public class ArgeoServerException extends RuntimeException {
+ private static final long serialVersionUID = 1L;
+
+ public ArgeoServerException() {
+ }
+
+ public ArgeoServerException(String message) {
+ super(message);
+ }
+
+ public ArgeoServerException(Throwable cause) {
+ super(cause);
+ }
+
+ public ArgeoServerException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+}
--- /dev/null
+package org.argeo.server;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+import org.apache.commons.io.IOUtils;
+
+/** Answer to an execution of a remote service which performed changes. */
+public class ServerAnswer {
+ public final static String OK = "OK";
+ public final static String ERROR = "ERROR";
+
+ private String status = OK;
+ private String message = "";
+
+ /** Canonical constructor */
+ public ServerAnswer(String status, String message) {
+ setStatus(status);
+ if (message == null)
+ throw new ArgeoServerException("Message cannot be null");
+ this.message = message;
+ }
+
+ /** Empty constructor */
+ public ServerAnswer() {
+ }
+
+ public String getStatus() {
+ return status;
+ }
+
+ public void setStatus(String status) {
+ if (status == null || (!status.equals(OK) && !status.equals(ERROR)))
+ throw new ArgeoServerException("Bad status format: " + status);
+ this.status = status;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public void setMessage(String message) {
+ this.message = message;
+ }
+
+ public Boolean isOk() {
+ return status.equals(OK);
+ }
+
+ public Boolean isError() {
+ return status.equals(ERROR);
+ }
+
+ public static ServerAnswer error(String message) {
+ return new ServerAnswer(ERROR, message);
+ }
+
+ public static ServerAnswer error(Throwable e) {
+ StringWriter writer = new StringWriter();
+ try {
+ e.printStackTrace(new PrintWriter(writer));
+ return new ServerAnswer(ERROR, writer.toString());
+ } finally {
+ IOUtils.closeQuietly(writer);
+ }
+ }
+
+ public static ServerAnswer ok(String message) {
+ return new ServerAnswer(OK, message);
+ }
+
+}
</plugins>
</build>
<dependencies>
+ <!-- Argeo Commons -->
+ <dependency>
+ <groupId>org.argeo.commons.server</groupId>
+ <artifactId>org.argeo.server.core</artifactId>
+ <version>0.1.1-SNAPSHOT</version>
+ </dependency>
+
<!-- JSON -->
<dependency>
<groupId>org.codehaus.jackson</groupId>
-package org.argeo.slc.web.mvc;
+package org.argeo.server.json.mvc;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import org.argeo.server.ArgeoServerException;
+import org.codehaus.jackson.JsonFactory;
+import org.codehaus.jackson.JsonGenerator;
+import org.codehaus.jackson.map.ObjectMapper;
import org.springframework.web.servlet.view.AbstractView;
/** Marshal one of the object of the map to the output. */
public class JsonView extends AbstractView {
+ private JsonFactory jsonFactory = new JsonFactory();
+ private ObjectMapper objectMapper = new ObjectMapper();
+
private String modelKey = null;
- public JsonView() {
+ public JsonView(String modelKey) {
+ this.modelKey = modelKey;
}
@Override
HttpServletRequest request, HttpServletResponse response)
throws Exception {
final Object answer;
- if (modelKey != null) {
+ if (model.size() == 1)
+ answer = model.values().iterator().next();
+ else if (modelKey != null) {
if (!model.containsKey(modelKey))
- throw new SlcException("Key " + modelKey
+ throw new ArgeoServerException("Key " + modelKey
+ " not found in model.");
answer = model.get(modelKey);
- } else {
- if (model.size() != 1)
- throw new SlcException(
- "Model has a size different from 1. Specify a modelKey.");
- answer = model.values().iterator().next();
+ } else {// models.size!=1 and no modelKey
+ throw new ArgeoServerException(
+ "Model has a size different from 1. Specify a modelKey.");
}
- if (answer instanceof JSONObject) {
- ((JSONObject) answer).write(response.getWriter());
- } else {
- JSONObject jsonObject = new JSONObject(answer);
- jsonObject.write(response.getWriter());
- }
+ response.setContentType("application/json");
+
+ JsonGenerator jsonGenerator = jsonFactory.createJsonGenerator(response
+ .getWriter());
+ jsonGenerator.useDefaultPrettyPrinter();
+
+ objectMapper.writeValue(jsonGenerator, answer);
+
}
public void setModelKey(String modelKey) {
--- /dev/null
+package org.argeo.server.json.mvc;
+
+import java.util.Locale;
+
+import org.springframework.web.servlet.View;
+import org.springframework.web.servlet.view.AbstractCachingViewResolver;
+
+/**
+ * Returns a {@link JsonView} based on the underlying. View name is the model
+ * key of the JSON view.
+ */
+public class JsonViewResolver extends AbstractCachingViewResolver {
+ @Override
+ protected View loadView(String viewName, Locale locale) throws Exception {
+ return new JsonView(viewName);
+ }
+
+}
<name>Commons Security Runtime</name>
<packaging>pom</packaging>
<modules>
+ <module>org.argeo.server.core</module>
<module>org.argeo.server.json</module>
</modules>
</project>
\ No newline at end of file