[Minor] code cleanup
This commit is contained in:
parent
8b780368d7
commit
59e25a8e75
332
pom.xml
332
pom.xml
|
@ -1,201 +1,163 @@
|
|||
<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>
|
||||
<groupId>ch.eitchnet</groupId>
|
||||
<artifactId>ch.eitchnet.privilege</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
<name>ch.eitchnet.privilege</name>
|
||||
<url>https://github.com/eitch/ch.eitchnet.privilege</url>
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<groupId>ch.eitchnet</groupId>
|
||||
<artifactId>ch.eitchnet.privilege</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
<name>ch.eitchnet.privilege</name>
|
||||
<url>https://github.com/eitch/ch.eitchnet.privilege</url>
|
||||
|
||||
<!-- POM Reference: http://maven.apache.org/pom.html#Licenses -->
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<inceptionYear>2011</inceptionYear>
|
||||
<licenses>
|
||||
<license>
|
||||
<name>GNU Lesser General Public License</name>
|
||||
<url>http://www.gnu.org/licenses/lgpl.html</url>
|
||||
<distribution>repo</distribution>
|
||||
</license>
|
||||
</licenses>
|
||||
<organization>
|
||||
<name>eitchnet.ch</name>
|
||||
<url>http://blog.eitchnet.ch</url>
|
||||
</organization>
|
||||
<developers>
|
||||
<developer>
|
||||
<id>eitch</id>
|
||||
<name>Robert von Vurg</name>
|
||||
<email>eitch@eitchnet.ch</email>
|
||||
<url>http://blog.eitchnet.ch</url>
|
||||
<organization>eitchnet.ch</organization>
|
||||
<organizationUrl>http://blog.eitchnet.ch</organizationUrl>
|
||||
<roles>
|
||||
<role>architect</role>
|
||||
<role>developer</role>
|
||||
</roles>
|
||||
<timezone>+1</timezone>
|
||||
<properties>
|
||||
<picUrl>http://localhost</picUrl>
|
||||
</properties>
|
||||
</developer>
|
||||
</developers>
|
||||
<!-- POM Reference: http://maven.apache.org/pom.html#Licenses -->
|
||||
|
||||
<issueManagement>
|
||||
<system>Github Issues</system>
|
||||
<url>https://github.com/eitch/ch.eitchnet.privilege/issues</url>
|
||||
</issueManagement>
|
||||
<inceptionYear>2011</inceptionYear>
|
||||
<licenses>
|
||||
<license>
|
||||
<name>GNU Lesser General Public License</name>
|
||||
<url>http://www.gnu.org/licenses/lgpl.html</url>
|
||||
<distribution>repo</distribution>
|
||||
</license>
|
||||
</licenses>
|
||||
<organization>
|
||||
<name>eitchnet.ch</name>
|
||||
<url>http://blog.eitchnet.ch</url>
|
||||
</organization>
|
||||
<developers>
|
||||
<developer>
|
||||
<id>eitch</id>
|
||||
<name>Robert von Vurg</name>
|
||||
<email>eitch@eitchnet.ch</email>
|
||||
<url>http://blog.eitchnet.ch</url>
|
||||
<organization>eitchnet.ch</organization>
|
||||
<organizationUrl>http://blog.eitchnet.ch</organizationUrl>
|
||||
<roles>
|
||||
<role>architect</role>
|
||||
<role>developer</role>
|
||||
</roles>
|
||||
<timezone>+1</timezone>
|
||||
<properties>
|
||||
<picUrl>http://localhost</picUrl>
|
||||
</properties>
|
||||
</developer>
|
||||
</developers>
|
||||
|
||||
<!--
|
||||
<ciManagement>
|
||||
<system>continuum</system>
|
||||
<url>http://127.0.0.1:8080/continuum</url>
|
||||
<notifiers>
|
||||
<notifier>
|
||||
<type>mail</type>
|
||||
<sendOnError>true</sendOnError>
|
||||
<sendOnFailure>true</sendOnFailure>
|
||||
<sendOnSuccess>false</sendOnSuccess>
|
||||
<sendOnWarning>false</sendOnWarning>
|
||||
<configuration><address>continuum@127.0.0.1</address></configuration>
|
||||
</notifier>
|
||||
</notifiers>
|
||||
</ciManagement>
|
||||
<issueManagement>
|
||||
<system>Github Issues</system>
|
||||
<url>https://github.com/eitch/ch.eitchnet.privilege/issues</url>
|
||||
</issueManagement>
|
||||
|
||||
<mailingLists>
|
||||
<mailingList>
|
||||
<name>User List</name>
|
||||
<subscribe>user-subscribe@127.0.0.1</subscribe>
|
||||
<unsubscribe>user-unsubscribe@127.0.0.1</unsubscribe>
|
||||
<post>user@127.0.0.1</post>
|
||||
<archive>http://127.0.0.1/user/</archive>
|
||||
<otherArchives>
|
||||
<otherArchive>http://base.google.com/base/1/127.0.0.1</otherArchive>
|
||||
</otherArchives>
|
||||
</mailingList>
|
||||
</mailingLists>
|
||||
-->
|
||||
<!-- <ciManagement> <system>continuum</system> <url>http://127.0.0.1:8080/continuum</url>
|
||||
<notifiers> <notifier> <type>mail</type> <sendOnError>true</sendOnError>
|
||||
<sendOnFailure>true</sendOnFailure> <sendOnSuccess>false</sendOnSuccess>
|
||||
<sendOnWarning>false</sendOnWarning> <configuration><address>continuum@127.0.0.1</address></configuration>
|
||||
</notifier> </notifiers> </ciManagement> <mailingLists> <mailingList> <name>User
|
||||
List</name> <subscribe>user-subscribe@127.0.0.1</subscribe> <unsubscribe>user-unsubscribe@127.0.0.1</unsubscribe>
|
||||
<post>user@127.0.0.1</post> <archive>http://127.0.0.1/user/</archive> <otherArchives>
|
||||
<otherArchive>http://base.google.com/base/1/127.0.0.1</otherArchive> </otherArchives>
|
||||
</mailingList> </mailingLists> -->
|
||||
|
||||
<scm>
|
||||
<connection>scm:git:https://github.com/eitch/ch.eitchnet.privilege.git</connection>
|
||||
<developerConnection>scm:git:git@github.com:eitch/ch.eitchnet.privilege.git</developerConnection>
|
||||
<url>https://github.com/eitch/ch.eitchnet.privilege</url>
|
||||
</scm>
|
||||
<scm>
|
||||
<connection>scm:git:https://github.com/eitch/ch.eitchnet.privilege.git</connection>
|
||||
<developerConnection>scm:git:git@github.com:eitch/ch.eitchnet.privilege.git</developerConnection>
|
||||
<url>https://github.com/eitch/ch.eitchnet.privilege</url>
|
||||
</scm>
|
||||
|
||||
<!--
|
||||
<repositories>
|
||||
<repository>
|
||||
<releases>
|
||||
<enabled>false</enabled>
|
||||
<updatePolicy>always</updatePolicy>
|
||||
<checksumPolicy>warn</checksumPolicy>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
<updatePolicy>never</updatePolicy>
|
||||
<checksumPolicy>fail</checksumPolicy>
|
||||
</snapshots>
|
||||
<id>codehausSnapshots</id>
|
||||
<name>Codehaus Snapshots</name>
|
||||
<url>http://snapshots.maven.codehaus.org/maven2</url>
|
||||
<layout>default</layout>
|
||||
</repository>
|
||||
</repositories>
|
||||
<pluginRepositories>
|
||||
...
|
||||
</pluginRepositories>
|
||||
-->
|
||||
<!-- <repositories> <repository> <releases> <enabled>false</enabled> <updatePolicy>always</updatePolicy>
|
||||
<checksumPolicy>warn</checksumPolicy> </releases> <snapshots> <enabled>true</enabled>
|
||||
<updatePolicy>never</updatePolicy> <checksumPolicy>fail</checksumPolicy>
|
||||
</snapshots> <id>codehausSnapshots</id> <name>Codehaus Snapshots</name> <url>http://snapshots.maven.codehaus.org/maven2</url>
|
||||
<layout>default</layout> </repository> </repositories> <pluginRepositories>
|
||||
... </pluginRepositories> -->
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.10</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
<version>1.2.17</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>maven</groupId>
|
||||
<artifactId>dom4j</artifactId>
|
||||
<version>1.7-20060614</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ch.eitchnet</groupId>
|
||||
<artifactId>ch.eitchnet.utils</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.10</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
<version>1.2.17</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>maven</groupId>
|
||||
<artifactId>dom4j</artifactId>
|
||||
<version>1.7-20060614</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ch.eitchnet</groupId>
|
||||
<artifactId>ch.eitchnet.utils</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-eclipse-plugin</artifactId>
|
||||
<version>2.9</version>
|
||||
<configuration>
|
||||
<downloadJavadocs>true</downloadJavadocs>
|
||||
<downloadSources>true</downloadSources>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-eclipse-plugin</artifactId>
|
||||
<version>2.9</version>
|
||||
<configuration>
|
||||
<downloadJavadocs>true</downloadJavadocs>
|
||||
<downloadSources>true</downloadSources>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>2.3.2</version>
|
||||
<configuration>
|
||||
<source>1.6</source>
|
||||
<target>1.6</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<version>2.1.2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-sources</id>
|
||||
<phase>verify</phase>
|
||||
<goals>
|
||||
<goal>jar-no-fork</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.0</version>
|
||||
<configuration>
|
||||
<source>1.6</source>
|
||||
<target>1.6</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>2.4</version>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifest>
|
||||
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
|
||||
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
|
||||
<!--mainClass>ch.eitchnet.App</mainClass-->
|
||||
</manifest>
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<version>2.1.2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-sources</id>
|
||||
<phase>verify</phase>
|
||||
<goals>
|
||||
<goal>jar-no-fork</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-site-plugin</artifactId>
|
||||
<version>2.3</version>
|
||||
<configuration>
|
||||
<outputEncoding>UTF-8</outputEncoding>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>2.4</version>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifest>
|
||||
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
|
||||
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
|
||||
<!--mainClass>ch.eitchnet.App</mainClass -->
|
||||
</manifest>
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
</plugins>
|
||||
</build>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-site-plugin</artifactId>
|
||||
<version>2.3</version>
|
||||
<configuration>
|
||||
<outputEncoding>UTF-8</outputEncoding>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
|
|
@ -124,7 +124,7 @@ public class DefaultEncryptionHandler implements EncryptionHandler {
|
|||
// test hash algorithm
|
||||
try {
|
||||
convertToHash("test");
|
||||
logger.info("Using hashing algorithm " + this.hashAlgorithm);
|
||||
DefaultEncryptionHandler.logger.info("Using hashing algorithm " + this.hashAlgorithm);
|
||||
} catch (Exception e) {
|
||||
throw new PrivilegeException("[" + EncryptionHandler.class.getName() + "] Defined parameter "
|
||||
+ XmlConstants.XML_PARAM_HASH_ALGORITHM + " is invalid because of underlying exception: "
|
||||
|
|
|
@ -403,7 +403,7 @@ public class DefaultPrivilegeHandler implements PrivilegeHandler {
|
|||
// ignore if user already has role
|
||||
Set<String> currentRoles = user.getRoles();
|
||||
if (currentRoles.contains(roleName)) {
|
||||
logger.error("User " + username + " already has role " + roleName);
|
||||
DefaultPrivilegeHandler.logger.error("User " + username + " already has role " + roleName);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -496,7 +496,7 @@ public class DefaultPrivilegeHandler implements PrivilegeHandler {
|
|||
// ignore if user does not have role
|
||||
Set<String> currentRoles = user.getRoles();
|
||||
if (!currentRoles.contains(roleName)) {
|
||||
logger.error("User " + user + " does not have role " + roleName);
|
||||
DefaultPrivilegeHandler.logger.error("User " + user + " does not have role " + roleName);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -714,10 +714,10 @@ public class DefaultPrivilegeHandler implements PrivilegeHandler {
|
|||
this.sessionMap.put(sessionId, new CertificateSessionPair(session, certificate));
|
||||
|
||||
// log
|
||||
logger.info("User " + username + " authenticated: " + session);
|
||||
DefaultPrivilegeHandler.logger.info("User " + username + " authenticated: " + session);
|
||||
|
||||
} catch (RuntimeException e) {
|
||||
logger.error("User " + username + " Failed to authenticate: " + e.getLocalizedMessage());
|
||||
DefaultPrivilegeHandler.logger.error("User " + username + " Failed to authenticate: " + e.getLocalizedMessage());
|
||||
throw e;
|
||||
} finally {
|
||||
clearPassword(password);
|
||||
|
@ -742,9 +742,9 @@ public class DefaultPrivilegeHandler implements PrivilegeHandler {
|
|||
// return true if object was really removed
|
||||
boolean loggedOut = certificateSessionPair != null;
|
||||
if (loggedOut)
|
||||
logger.info("User " + certificate.getUsername() + " logged out.");
|
||||
DefaultPrivilegeHandler.logger.info("User " + certificate.getUsername() + " logged out.");
|
||||
else
|
||||
logger.warn("User already logged out!");
|
||||
DefaultPrivilegeHandler.logger.warn("User already logged out!");
|
||||
return loggedOut;
|
||||
}
|
||||
|
||||
|
@ -785,7 +785,7 @@ public class DefaultPrivilegeHandler implements PrivilegeHandler {
|
|||
|
||||
Role role = this.persistenceHandler.getRole(roleName);
|
||||
if (role == null) {
|
||||
logger.error("No role is defined with name " + roleName + " which is configured for user " + user);
|
||||
DefaultPrivilegeHandler.logger.error("No role is defined with name " + roleName + " which is configured for user " + user);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -861,7 +861,7 @@ public class DefaultPrivilegeHandler implements PrivilegeHandler {
|
|||
}
|
||||
|
||||
// otherwise delegate checking to the policy configured for this privilege
|
||||
PrivilegePolicy policy = this.getPolicy(privilege.getPolicy());
|
||||
PrivilegePolicy policy = getPolicy(privilege.getPolicy());
|
||||
if (policy == null) {
|
||||
throw new PrivilegeException("PrivilegePolicy " + privilege.getPolicy() + " does not exist for Privilege "
|
||||
+ privilegeName);
|
||||
|
@ -921,7 +921,7 @@ public class DefaultPrivilegeHandler implements PrivilegeHandler {
|
|||
public void validateIsPrivilegeAdmin(Certificate certificate) throws PrivilegeException {
|
||||
|
||||
// validate certificate
|
||||
this.isCertificateValid(certificate);
|
||||
isCertificateValid(certificate);
|
||||
|
||||
// get user object
|
||||
User user = this.persistenceHandler.getUser(certificate.getUsername());
|
||||
|
@ -1139,7 +1139,7 @@ public class DefaultPrivilegeHandler implements PrivilegeHandler {
|
|||
private Certificate getSystemUserCertificate(String systemUsername) {
|
||||
|
||||
// see if a certificate has already been created for this system user
|
||||
Certificate systemUserCertificate = systemUserCertificateMap.get(systemUsername);
|
||||
Certificate systemUserCertificate = this.systemUserCertificateMap.get(systemUsername);
|
||||
if (systemUserCertificate != null)
|
||||
return systemUserCertificate;
|
||||
|
||||
|
@ -1187,7 +1187,7 @@ public class DefaultPrivilegeHandler implements PrivilegeHandler {
|
|||
this.sessionMap.put(sessionId, new CertificateSessionPair(session, systemUserCertificate));
|
||||
|
||||
// log
|
||||
logger.info("The system user " + systemUsername + " is logged in with session " + session);
|
||||
DefaultPrivilegeHandler.logger.info("The system user " + systemUsername + " is logged in with session " + session);
|
||||
|
||||
return systemUserCertificate;
|
||||
}
|
||||
|
|
|
@ -153,7 +153,7 @@ public class XmlPersistenceHandler implements PersistenceHandler {
|
|||
File modelFile = new File(this.modelPath);
|
||||
boolean modelFileUnchanged = modelFile.exists() && modelFile.lastModified() == this.modelsFileDate;
|
||||
if (!(modelFileUnchanged && this.roleMapDirty && this.userMapDirty)) {
|
||||
logger.warn("Not persisting as current file is unchanged and model data is not dirty");
|
||||
XmlPersistenceHandler.logger.warn("Not persisting as current file is unchanged and model data is not dirty");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -164,7 +164,7 @@ public class XmlPersistenceHandler implements PersistenceHandler {
|
|||
|
||||
// USERS
|
||||
// build XML DOM of users
|
||||
List<Element> users = toDomUsers(this.userMap);
|
||||
List<Element> users = XmlPersistenceHandler.toDomUsers(this.userMap);
|
||||
Element usersElement = docFactory.createElement(XmlConstants.XML_USERS);
|
||||
for (Element userElement : users) {
|
||||
usersElement.add(userElement);
|
||||
|
@ -173,7 +173,7 @@ public class XmlPersistenceHandler implements PersistenceHandler {
|
|||
|
||||
// ROLES
|
||||
// build XML DOM of roles
|
||||
List<Element> roles = toDomRoles(this.roleMap);
|
||||
List<Element> roles = XmlPersistenceHandler.toDomRoles(this.roleMap);
|
||||
Element rolesElement = docFactory.createElement(XmlConstants.XML_ROLES);
|
||||
for (Element roleElement : roles) {
|
||||
rolesElement.add(roleElement);
|
||||
|
@ -233,8 +233,8 @@ public class XmlPersistenceHandler implements PersistenceHandler {
|
|||
this.userMapDirty = false;
|
||||
this.roleMapDirty = false;
|
||||
|
||||
logger.info("Read " + this.userMap.size() + " Users");
|
||||
logger.info("Read " + this.roleMap.size() + " Roles");
|
||||
XmlPersistenceHandler.logger.info("Read " + this.userMap.size() + " Users");
|
||||
XmlPersistenceHandler.logger.info("Read " + this.roleMap.size() + " Roles");
|
||||
|
||||
// validate we have a user with PrivilegeAdmin access
|
||||
boolean privilegeAdminExists = false;
|
||||
|
@ -247,7 +247,7 @@ public class XmlPersistenceHandler implements PersistenceHandler {
|
|||
}
|
||||
|
||||
if (!privilegeAdminExists) {
|
||||
logger.warn("No User with role '" + PrivilegeHandler.PRIVILEGE_ADMIN_ROLE
|
||||
XmlPersistenceHandler.logger.warn("No User with role '" + PrivilegeHandler.PRIVILEGE_ADMIN_ROLE
|
||||
+ "' exists. Privilege modifications will not be possible!");
|
||||
}
|
||||
|
||||
|
@ -279,7 +279,7 @@ public class XmlPersistenceHandler implements PersistenceHandler {
|
|||
this.modelPath = basePath + "/" + modelFileName;
|
||||
|
||||
if (reload())
|
||||
logger.info("Privilege Data loaded.");
|
||||
XmlPersistenceHandler.logger.info("Privilege Data loaded.");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -320,9 +320,9 @@ public class XmlPersistenceHandler implements PersistenceHandler {
|
|||
for (Element roleElement : rolesElementList) {
|
||||
String roleName = roleElement.getTextTrim();
|
||||
if (roleName.isEmpty()) {
|
||||
logger.error("User " + username + " has a role defined with no name, Skipped.");
|
||||
XmlPersistenceHandler.logger.error("User " + username + " has a role defined with no name, Skipped.");
|
||||
} else if (!this.roleMap.containsKey(roleName)) {
|
||||
logger.error("User " + username + " has a inexistant role " + roleName + ", Skipped.");
|
||||
XmlPersistenceHandler.logger.error("User " + username + " has a inexistant role " + roleName + ", Skipped.");
|
||||
} else {
|
||||
roles.add(roleName);
|
||||
}
|
||||
|
@ -330,14 +330,14 @@ public class XmlPersistenceHandler implements PersistenceHandler {
|
|||
|
||||
// read properties
|
||||
Element propertiesElement = userElement.element(XmlConstants.XML_PROPERTIES);
|
||||
Map<String, String> propertyMap = convertToPropertyMap(propertiesElement);
|
||||
Map<String, String> propertyMap = XmlPersistenceHandler.convertToPropertyMap(propertiesElement);
|
||||
|
||||
// create user
|
||||
User user = new User(userId, username, password, firstname, surname, userState, roles, locale, propertyMap);
|
||||
|
||||
// put user in map
|
||||
userMap.put(username, user);
|
||||
logger.info("Loaded user " + user);
|
||||
XmlPersistenceHandler.logger.info("Loaded user " + user);
|
||||
}
|
||||
|
||||
return userMap;
|
||||
|
@ -508,7 +508,7 @@ public class XmlPersistenceHandler implements PersistenceHandler {
|
|||
roleElement.addAttribute(XmlConstants.XML_ATTR_NAME, role.getName());
|
||||
|
||||
// add all the privileges
|
||||
toDomPrivileges(roleElement, role.getPrivilegeMap());
|
||||
XmlPersistenceHandler.toDomPrivileges(roleElement, role.getPrivilegeMap());
|
||||
|
||||
// add element to return list
|
||||
rolesAsElements.add(roleElement);
|
||||
|
|
|
@ -75,12 +75,12 @@ public class BootstrapConfigurationHelper {
|
|||
Logger.getRootLogger().setLevel(Level.INFO);
|
||||
|
||||
// get current directory
|
||||
path = System.getProperty("user.dir") + "/newConfig";
|
||||
BootstrapConfigurationHelper.path = System.getProperty("user.dir") + "/newConfig";
|
||||
|
||||
// TODO ask user where to save configuration, default is pwd/newConfig/....
|
||||
|
||||
// see if path already exists
|
||||
File pathF = new File(path);
|
||||
File pathF = new File(BootstrapConfigurationHelper.path);
|
||||
if (pathF.exists()) {
|
||||
throw new RuntimeException("Path already exists: " + pathF.getAbsolutePath());
|
||||
}
|
||||
|
@ -92,9 +92,9 @@ public class BootstrapConfigurationHelper {
|
|||
// TODO ask other questions...
|
||||
|
||||
// now perform work:
|
||||
createXmlPrivilegeContainer();
|
||||
createPolicyConfiguration();
|
||||
createModel();
|
||||
BootstrapConfigurationHelper.createXmlPrivilegeContainer();
|
||||
BootstrapConfigurationHelper.createPolicyConfiguration();
|
||||
BootstrapConfigurationHelper.createModel();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -133,34 +133,34 @@ public class BootstrapConfigurationHelper {
|
|||
// create PersistenceHandler
|
||||
Element persistenceHandlerElem = factory.createElement(XmlConstants.XML_HANDLER_PERSISTENCE);
|
||||
containerElement.add(persistenceHandlerElem);
|
||||
persistenceHandlerElem.addAttribute(XmlConstants.XML_ATTR_CLASS, defaultPersistenceHandler);
|
||||
persistenceHandlerElem.addAttribute(XmlConstants.XML_ATTR_CLASS, BootstrapConfigurationHelper.defaultPersistenceHandler);
|
||||
parametersElement = factory.createElement(XmlConstants.XML_PARAMETERS);
|
||||
persistenceHandlerElem.add(parametersElement);
|
||||
// Parameter basePath
|
||||
parameterElement = factory.createElement(XmlConstants.XML_PARAMETER);
|
||||
parameterElement.addAttribute(XmlConstants.XML_ATTR_NAME, XmlConstants.XML_PARAM_BASE_PATH);
|
||||
parameterElement.addAttribute(XmlConstants.XML_ATTR_VALUE, basePath);
|
||||
parameterElement.addAttribute(XmlConstants.XML_ATTR_VALUE, BootstrapConfigurationHelper.basePath);
|
||||
parametersElement.add(parameterElement);
|
||||
// Parameter modelXmlFile
|
||||
parameterElement = factory.createElement(XmlConstants.XML_PARAMETER);
|
||||
parameterElement.addAttribute(XmlConstants.XML_ATTR_NAME, XmlConstants.XML_PARAM_MODEL_FILE);
|
||||
parameterElement.addAttribute(XmlConstants.XML_ATTR_VALUE, modelFileName);
|
||||
parameterElement.addAttribute(XmlConstants.XML_ATTR_VALUE, BootstrapConfigurationHelper.modelFileName);
|
||||
parametersElement.add(parameterElement);
|
||||
|
||||
// create EncryptionHandler
|
||||
Element encryptionHandlerElem = factory.createElement(XmlConstants.XML_HANDLER_ENCRYPTION);
|
||||
containerElement.add(encryptionHandlerElem);
|
||||
encryptionHandlerElem.addAttribute(XmlConstants.XML_ATTR_CLASS, defaultEncryptionHandler);
|
||||
encryptionHandlerElem.addAttribute(XmlConstants.XML_ATTR_CLASS, BootstrapConfigurationHelper.defaultEncryptionHandler);
|
||||
parametersElement = factory.createElement(XmlConstants.XML_PARAMETERS);
|
||||
encryptionHandlerElem.add(parametersElement);
|
||||
// Parameter hashAlgorithm
|
||||
parameterElement = factory.createElement(XmlConstants.XML_PARAMETER);
|
||||
parameterElement.addAttribute(XmlConstants.XML_ATTR_NAME, XmlConstants.XML_PARAM_HASH_ALGORITHM);
|
||||
parameterElement.addAttribute(XmlConstants.XML_ATTR_VALUE, hashAlgorithm);
|
||||
parameterElement.addAttribute(XmlConstants.XML_ATTR_VALUE, BootstrapConfigurationHelper.hashAlgorithm);
|
||||
parametersElement.add(parameterElement);
|
||||
|
||||
// write the container file to disk
|
||||
File privilegeContainerFile = new File(path + "/" + defaultPrivilegeContainerXmlFile);
|
||||
File privilegeContainerFile = new File(BootstrapConfigurationHelper.path + "/" + BootstrapConfigurationHelper.defaultPrivilegeContainerXmlFile);
|
||||
XmlHelper.writeDocument(doc, privilegeContainerFile);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,14 +33,14 @@ public class CertificateThreadLocal extends ThreadLocal<Certificate> {
|
|||
}
|
||||
|
||||
public static CertificateThreadLocal getInstance() {
|
||||
return instance;
|
||||
return CertificateThreadLocal.instance;
|
||||
}
|
||||
|
||||
public static Certificate getCert() {
|
||||
return instance.get();
|
||||
return CertificateThreadLocal.instance.get();
|
||||
}
|
||||
|
||||
public static void setCert(Certificate certificate) {
|
||||
instance.set(certificate);
|
||||
CertificateThreadLocal.instance.set(certificate);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ public class HashHelper {
|
|||
*/
|
||||
public static String stringToHash(String hashAlgorithm, String string) throws NoSuchAlgorithmException,
|
||||
UnsupportedEncodingException {
|
||||
return stringToHash(hashAlgorithm, string.getBytes());
|
||||
return HashHelper.stringToHash(hashAlgorithm, string.getBytes());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -83,8 +83,8 @@ public class HashHelper {
|
|||
|
||||
for (byte b : hashArray) {
|
||||
int v = b & 0xFF;
|
||||
hex[index++] = HEX_CHAR_TABLE[v >>> 4];
|
||||
hex[index++] = HEX_CHAR_TABLE[v & 0xF];
|
||||
hex[index++] = HashHelper.HEX_CHAR_TABLE[v >>> 4];
|
||||
hex[index++] = HashHelper.HEX_CHAR_TABLE[v & 0xF];
|
||||
}
|
||||
|
||||
return new String(hex, "ASCII");
|
||||
|
|
|
@ -35,7 +35,6 @@ import ch.eitchnet.privilege.handler.PrivilegeHandler;
|
|||
import ch.eitchnet.privilege.i18n.PrivilegeException;
|
||||
import ch.eitchnet.privilege.policy.PrivilegePolicy;
|
||||
import ch.eitchnet.utils.helper.StringHelper;
|
||||
import ch.eitchnet.utils.helper.SystemHelper;
|
||||
|
||||
/**
|
||||
* This class implements the initializing of the {@link PrivilegeHandler} by loading an XML file containing the
|
||||
|
@ -81,19 +80,19 @@ public class InitializationHelper {
|
|||
|
||||
// get policies
|
||||
Element policiesElement = rootElement.element(XmlConstants.XML_POLICIES);
|
||||
Map<String, Class<PrivilegePolicy>> policyMap = convertToPolicyMap(policiesElement);
|
||||
Map<String, Class<PrivilegePolicy>> policyMap = InitializationHelper.convertToPolicyMap(policiesElement);
|
||||
|
||||
try {
|
||||
|
||||
// get parameters
|
||||
Element parameterElement = encryptionHandlerElement.element(XmlConstants.XML_PARAMETERS);
|
||||
Map<String, String> parameterMap = convertToParameterMap(parameterElement);
|
||||
Map<String, String> parameterMap = InitializationHelper.convertToParameterMap(parameterElement);
|
||||
|
||||
// initialize encryption handler
|
||||
encryptionHandler.initialize(parameterMap);
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error(e, e);
|
||||
InitializationHelper.logger.error(e, e);
|
||||
throw new PrivilegeException("EncryptionHandler " + encryptionHandlerClassName
|
||||
+ " could not be initialized");
|
||||
}
|
||||
|
@ -102,13 +101,13 @@ public class InitializationHelper {
|
|||
|
||||
// get parameters
|
||||
Element parameterElement = persistenceHandlerElement.element(XmlConstants.XML_PARAMETERS);
|
||||
Map<String, String> parameterMap = convertToParameterMap(parameterElement);
|
||||
Map<String, String> parameterMap = InitializationHelper.convertToParameterMap(parameterElement);
|
||||
|
||||
// initialize persistence handler
|
||||
persistenceHandler.initialize(parameterMap);
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error(e, e);
|
||||
InitializationHelper.logger.error(e, e);
|
||||
throw new PrivilegeException("PersistenceHandler " + persistenceHandlerElement
|
||||
+ " could not be initialized");
|
||||
}
|
||||
|
@ -117,13 +116,13 @@ public class InitializationHelper {
|
|||
|
||||
// get parameters
|
||||
Element parameterElement = containerElement.element(XmlConstants.XML_PARAMETERS);
|
||||
Map<String, String> parameterMap = convertToParameterMap(parameterElement);
|
||||
Map<String, String> parameterMap = InitializationHelper.convertToParameterMap(parameterElement);
|
||||
|
||||
// initialize privilege handler
|
||||
privilegeHandler.initialize(parameterMap, encryptionHandler, persistenceHandler, policyMap);
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error(e, e);
|
||||
InitializationHelper.logger.error(e, e);
|
||||
throw new PrivilegeException("PrivilegeHandler " + privilegeHandler.getClass().getName()
|
||||
+ " could not be initialized");
|
||||
}
|
||||
|
|
|
@ -69,7 +69,7 @@ public class XmlHelper {
|
|||
SAXReader reader = new SAXReader();
|
||||
Document document = reader.read(inStream);
|
||||
|
||||
logger.info("Read XML document " + document.getRootElement().getName());
|
||||
XmlHelper.logger.info("Read XML document " + document.getRootElement().getName());
|
||||
return document;
|
||||
|
||||
} catch (FileNotFoundException e) {
|
||||
|
@ -89,7 +89,7 @@ public class XmlHelper {
|
|||
*/
|
||||
public static void writeDocument(Document document, File file) {
|
||||
|
||||
logger.info("Exporting document element " + document.getName() + " to " + file.getAbsolutePath());
|
||||
XmlHelper.logger.info("Exporting document element " + document.getName() + " to " + file.getAbsolutePath());
|
||||
|
||||
OutputStream fileOutputStream = null;
|
||||
|
||||
|
@ -99,7 +99,7 @@ public class XmlHelper {
|
|||
|
||||
String aEncodingScheme = document.getXMLEncoding();
|
||||
if (aEncodingScheme == null || aEncodingScheme.isEmpty()) {
|
||||
aEncodingScheme = DEFAULT_ENCODING;
|
||||
aEncodingScheme = XmlHelper.DEFAULT_ENCODING;
|
||||
}
|
||||
OutputFormat outformat = OutputFormat.createPrettyPrint();
|
||||
outformat.setEncoding(aEncodingScheme);
|
||||
|
@ -117,7 +117,7 @@ public class XmlHelper {
|
|||
try {
|
||||
fileOutputStream.close();
|
||||
} catch (IOException e) {
|
||||
logger.error("Could not close file output stream: " + e, e);
|
||||
XmlHelper.logger.error("Could not close file output stream: " + e, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -133,10 +133,10 @@ public class XmlHelper {
|
|||
*/
|
||||
public static void writeElement(Element rootElement, File file) {
|
||||
|
||||
Document document = DocumentFactory.getInstance().createDocument(DEFAULT_ENCODING);
|
||||
Document document = DocumentFactory.getInstance().createDocument(XmlHelper.DEFAULT_ENCODING);
|
||||
document.setRootElement(rootElement);
|
||||
document.setName(rootElement.getName());
|
||||
|
||||
writeDocument(document, file);
|
||||
XmlHelper.writeDocument(document, file);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -87,9 +87,9 @@ public class PrivilegeTest {
|
|||
// initialize container
|
||||
String pwd = System.getProperty("user.dir");
|
||||
File privilegeContainerXmlFile = new File(pwd + "/config/Privilege.xml");
|
||||
privilegeHandler = InitializationHelper.initializeFromXml(privilegeContainerXmlFile);
|
||||
PrivilegeTest.privilegeHandler = InitializationHelper.initializeFromXml(privilegeContainerXmlFile);
|
||||
} catch (Exception e) {
|
||||
logger.error(e, e);
|
||||
PrivilegeTest.logger.error(e, e);
|
||||
|
||||
throw new RuntimeException("Initialization failed: " + e.getLocalizedMessage(), e);
|
||||
}
|
||||
|
@ -102,9 +102,9 @@ public class PrivilegeTest {
|
|||
@Test
|
||||
public void testAuthenticationOk() throws Exception {
|
||||
|
||||
Certificate certificate = privilegeHandler.authenticate(ADMIN, copyBytes(PASS_ADMIN));
|
||||
Certificate certificate = PrivilegeTest.privilegeHandler.authenticate(PrivilegeTest.ADMIN, copyBytes(PrivilegeTest.PASS_ADMIN));
|
||||
org.junit.Assert.assertTrue("Certificate is null!", certificate != null);
|
||||
privilegeHandler.invalidateSession(certificate);
|
||||
PrivilegeTest.privilegeHandler.invalidateSession(certificate);
|
||||
}
|
||||
|
||||
private byte[] copyBytes(byte[] bytes) {
|
||||
|
@ -120,9 +120,9 @@ public class PrivilegeTest {
|
|||
@Test(expected = AccessDeniedException.class)
|
||||
public void testFailAuthenticationNOk() throws Exception {
|
||||
|
||||
Certificate certificate = privilegeHandler.authenticate(ADMIN, copyBytes(PASS_BAD));
|
||||
Certificate certificate = PrivilegeTest.privilegeHandler.authenticate(PrivilegeTest.ADMIN, copyBytes(PrivilegeTest.PASS_BAD));
|
||||
org.junit.Assert.assertTrue("Certificate is null!", certificate != null);
|
||||
privilegeHandler.invalidateSession(certificate);
|
||||
PrivilegeTest.privilegeHandler.invalidateSession(certificate);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -132,9 +132,9 @@ public class PrivilegeTest {
|
|||
@Test(expected = PrivilegeException.class)
|
||||
public void testFailAuthenticationPWNull() throws Exception {
|
||||
|
||||
Certificate certificate = privilegeHandler.authenticate(ADMIN, null);
|
||||
Certificate certificate = PrivilegeTest.privilegeHandler.authenticate(PrivilegeTest.ADMIN, null);
|
||||
org.junit.Assert.assertTrue("Certificate is null!", certificate != null);
|
||||
privilegeHandler.invalidateSession(certificate);
|
||||
PrivilegeTest.privilegeHandler.invalidateSession(certificate);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -144,18 +144,18 @@ public class PrivilegeTest {
|
|||
@Test
|
||||
public void testAddUserBobAsAdmin() throws Exception {
|
||||
|
||||
Certificate certificate = privilegeHandler.authenticate(ADMIN, copyBytes(PASS_ADMIN));
|
||||
Certificate certificate = PrivilegeTest.privilegeHandler.authenticate(PrivilegeTest.ADMIN, copyBytes(PrivilegeTest.PASS_ADMIN));
|
||||
|
||||
// let's add a new user bob
|
||||
UserRep userRep = new UserRep("1", BOB, "Bob", "Newman", UserState.NEW, new HashSet<String>(), null,
|
||||
UserRep userRep = new UserRep("1", PrivilegeTest.BOB, "Bob", "Newman", UserState.NEW, new HashSet<String>(), null,
|
||||
new HashMap<String, String>());
|
||||
privilegeHandler.addOrReplaceUser(certificate, userRep, null);
|
||||
logger.info("Added user " + BOB);
|
||||
PrivilegeTest.privilegeHandler.addOrReplaceUser(certificate, userRep, null);
|
||||
PrivilegeTest.logger.info("Added user " + PrivilegeTest.BOB);
|
||||
|
||||
// set bob's password
|
||||
privilegeHandler.setUserPassword(certificate, BOB, copyBytes(PASS_BOB));
|
||||
logger.info("Set Bob's password");
|
||||
privilegeHandler.invalidateSession(certificate);
|
||||
PrivilegeTest.privilegeHandler.setUserPassword(certificate, PrivilegeTest.BOB, copyBytes(PrivilegeTest.PASS_BOB));
|
||||
PrivilegeTest.logger.info("Set Bob's password");
|
||||
PrivilegeTest.privilegeHandler.invalidateSession(certificate);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -166,8 +166,8 @@ public class PrivilegeTest {
|
|||
*/
|
||||
@Test(expected = AccessDeniedException.class)
|
||||
public void testFailAuthAsBob() throws Exception {
|
||||
Certificate certificate = privilegeHandler.authenticate(BOB, copyBytes(PASS_BOB));
|
||||
privilegeHandler.invalidateSession(certificate);
|
||||
Certificate certificate = PrivilegeTest.privilegeHandler.authenticate(PrivilegeTest.BOB, copyBytes(PrivilegeTest.PASS_BOB));
|
||||
PrivilegeTest.privilegeHandler.invalidateSession(certificate);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -176,9 +176,9 @@ public class PrivilegeTest {
|
|||
*/
|
||||
@Test
|
||||
public void testEnableUserBob() throws Exception {
|
||||
Certificate certificate = privilegeHandler.authenticate(ADMIN, copyBytes(PASS_ADMIN));
|
||||
privilegeHandler.setUserState(certificate, BOB, UserState.ENABLED);
|
||||
privilegeHandler.invalidateSession(certificate);
|
||||
Certificate certificate = PrivilegeTest.privilegeHandler.authenticate(PrivilegeTest.ADMIN, copyBytes(PrivilegeTest.PASS_ADMIN));
|
||||
PrivilegeTest.privilegeHandler.setUserState(certificate, PrivilegeTest.BOB, UserState.ENABLED);
|
||||
PrivilegeTest.privilegeHandler.invalidateSession(certificate);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -190,9 +190,9 @@ public class PrivilegeTest {
|
|||
@Test(expected = PrivilegeException.class)
|
||||
public void testFailAuthUserBob() throws Exception {
|
||||
|
||||
Certificate certificate = privilegeHandler.authenticate(BOB, copyBytes(PASS_BOB));
|
||||
Certificate certificate = PrivilegeTest.privilegeHandler.authenticate(PrivilegeTest.BOB, copyBytes(PrivilegeTest.PASS_BOB));
|
||||
org.junit.Assert.assertTrue("Certificate is null!", certificate != null);
|
||||
privilegeHandler.invalidateSession(certificate);
|
||||
PrivilegeTest.privilegeHandler.invalidateSession(certificate);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -201,13 +201,13 @@ public class PrivilegeTest {
|
|||
*/
|
||||
@Test
|
||||
public void testAddRole() throws Exception {
|
||||
Certificate certificate = privilegeHandler.authenticate(ADMIN, copyBytes(PASS_ADMIN));
|
||||
Certificate certificate = PrivilegeTest.privilegeHandler.authenticate(PrivilegeTest.ADMIN, copyBytes(PrivilegeTest.PASS_ADMIN));
|
||||
|
||||
Map<String, PrivilegeRep> privilegeMap = new HashMap<String, PrivilegeRep>();
|
||||
RoleRep roleRep = new RoleRep(ROLE_USER, privilegeMap);
|
||||
RoleRep roleRep = new RoleRep(PrivilegeTest.ROLE_USER, privilegeMap);
|
||||
|
||||
privilegeHandler.addOrReplaceRole(certificate, roleRep);
|
||||
privilegeHandler.invalidateSession(certificate);
|
||||
PrivilegeTest.privilegeHandler.addOrReplaceRole(certificate, roleRep);
|
||||
PrivilegeTest.privilegeHandler.invalidateSession(certificate);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -216,9 +216,9 @@ public class PrivilegeTest {
|
|||
*/
|
||||
@Test
|
||||
public void testAddRoleToBob() throws Exception {
|
||||
Certificate certificate = privilegeHandler.authenticate(ADMIN, copyBytes(PASS_ADMIN));
|
||||
privilegeHandler.addRoleToUser(certificate, BOB, ROLE_USER);
|
||||
privilegeHandler.invalidateSession(certificate);
|
||||
Certificate certificate = PrivilegeTest.privilegeHandler.authenticate(PrivilegeTest.ADMIN, copyBytes(PrivilegeTest.PASS_ADMIN));
|
||||
PrivilegeTest.privilegeHandler.addRoleToUser(certificate, PrivilegeTest.BOB, PrivilegeTest.ROLE_USER);
|
||||
PrivilegeTest.privilegeHandler.invalidateSession(certificate);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -227,8 +227,8 @@ public class PrivilegeTest {
|
|||
*/
|
||||
@Test
|
||||
public void testAuthAsBob() throws Exception {
|
||||
Certificate certificate = privilegeHandler.authenticate(BOB, copyBytes(PASS_BOB));
|
||||
privilegeHandler.invalidateSession(certificate);
|
||||
Certificate certificate = PrivilegeTest.privilegeHandler.authenticate(PrivilegeTest.BOB, copyBytes(PrivilegeTest.PASS_BOB));
|
||||
PrivilegeTest.privilegeHandler.invalidateSession(certificate);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -241,15 +241,15 @@ public class PrivilegeTest {
|
|||
public void testFailAddUserTedAsBob() throws Exception {
|
||||
|
||||
// auth as Bog
|
||||
Certificate certificate = privilegeHandler.authenticate(BOB, copyBytes(PASS_BOB));
|
||||
Certificate certificate = PrivilegeTest.privilegeHandler.authenticate(PrivilegeTest.BOB, copyBytes(PrivilegeTest.PASS_BOB));
|
||||
org.junit.Assert.assertTrue("Certificate is null!", certificate != null);
|
||||
|
||||
// let's add a new user Ted
|
||||
UserRep userRep = new UserRep("1", TED, "Ted", "And then Some", UserState.NEW, new HashSet<String>(), null,
|
||||
UserRep userRep = new UserRep("1", PrivilegeTest.TED, "Ted", "And then Some", UserState.NEW, new HashSet<String>(), null,
|
||||
new HashMap<String, String>());
|
||||
privilegeHandler.addOrReplaceUser(certificate, userRep, null);
|
||||
logger.info("Added user " + TED);
|
||||
privilegeHandler.invalidateSession(certificate);
|
||||
PrivilegeTest.privilegeHandler.addOrReplaceUser(certificate, userRep, null);
|
||||
PrivilegeTest.logger.info("Added user " + PrivilegeTest.TED);
|
||||
PrivilegeTest.privilegeHandler.invalidateSession(certificate);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -259,10 +259,10 @@ public class PrivilegeTest {
|
|||
@Test
|
||||
public void testAddAdminRoleToBob() throws Exception {
|
||||
|
||||
Certificate certificate = privilegeHandler.authenticate(ADMIN, copyBytes(PASS_ADMIN));
|
||||
privilegeHandler.addRoleToUser(certificate, BOB, PrivilegeHandler.PRIVILEGE_ADMIN_ROLE);
|
||||
logger.info("Added " + PrivilegeHandler.PRIVILEGE_ADMIN_ROLE + " to " + ADMIN);
|
||||
privilegeHandler.invalidateSession(certificate);
|
||||
Certificate certificate = PrivilegeTest.privilegeHandler.authenticate(PrivilegeTest.ADMIN, copyBytes(PrivilegeTest.PASS_ADMIN));
|
||||
PrivilegeTest.privilegeHandler.addRoleToUser(certificate, PrivilegeTest.BOB, PrivilegeHandler.PRIVILEGE_ADMIN_ROLE);
|
||||
PrivilegeTest.logger.info("Added " + PrivilegeHandler.PRIVILEGE_ADMIN_ROLE + " to " + PrivilegeTest.ADMIN);
|
||||
PrivilegeTest.privilegeHandler.invalidateSession(certificate);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -272,18 +272,18 @@ public class PrivilegeTest {
|
|||
@Test
|
||||
public void testAddUserTedAsBob() throws Exception {
|
||||
|
||||
Certificate certificate = privilegeHandler.authenticate(BOB, copyBytes(PASS_BOB));
|
||||
Certificate certificate = PrivilegeTest.privilegeHandler.authenticate(PrivilegeTest.BOB, copyBytes(PrivilegeTest.PASS_BOB));
|
||||
org.junit.Assert.assertTrue("Certificate is null!", certificate != null);
|
||||
|
||||
// let's add a new user ted
|
||||
HashSet<String> roles = new HashSet<String>();
|
||||
roles.add(ROLE_USER);
|
||||
UserRep userRep = new UserRep("2", TED, "Ted", "Newman", UserState.ENABLED, roles, null,
|
||||
roles.add(PrivilegeTest.ROLE_USER);
|
||||
UserRep userRep = new UserRep("2", PrivilegeTest.TED, "Ted", "Newman", UserState.ENABLED, roles, null,
|
||||
new HashMap<String, String>());
|
||||
privilegeHandler.addOrReplaceUser(certificate, userRep, null);
|
||||
logger.info("Added user " + TED);
|
||||
PrivilegeTest.privilegeHandler.addOrReplaceUser(certificate, userRep, null);
|
||||
PrivilegeTest.logger.info("Added user " + PrivilegeTest.TED);
|
||||
|
||||
privilegeHandler.invalidateSession(certificate);
|
||||
PrivilegeTest.privilegeHandler.invalidateSession(certificate);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -293,13 +293,13 @@ public class PrivilegeTest {
|
|||
@Test
|
||||
public void testSetTedPwdAsBob() throws Exception {
|
||||
|
||||
Certificate certificate = privilegeHandler.authenticate(BOB, copyBytes(PASS_BOB));
|
||||
Certificate certificate = PrivilegeTest.privilegeHandler.authenticate(PrivilegeTest.BOB, copyBytes(PrivilegeTest.PASS_BOB));
|
||||
org.junit.Assert.assertTrue("Certificate is null!", certificate != null);
|
||||
|
||||
// set ted's password to default
|
||||
privilegeHandler.setUserPassword(certificate, TED, copyBytes(PASS_DEF));
|
||||
PrivilegeTest.privilegeHandler.setUserPassword(certificate, PrivilegeTest.TED, copyBytes(PrivilegeTest.PASS_DEF));
|
||||
|
||||
privilegeHandler.invalidateSession(certificate);
|
||||
PrivilegeTest.privilegeHandler.invalidateSession(certificate);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -308,9 +308,9 @@ public class PrivilegeTest {
|
|||
*/
|
||||
@Test
|
||||
public void testTedChangesOwnPwd() throws Exception {
|
||||
Certificate certificate = privilegeHandler.authenticate(TED, copyBytes(PASS_DEF));
|
||||
privilegeHandler.setUserPassword(certificate, TED, copyBytes(PASS_TED));
|
||||
privilegeHandler.invalidateSession(certificate);
|
||||
Certificate certificate = PrivilegeTest.privilegeHandler.authenticate(PrivilegeTest.TED, copyBytes(PrivilegeTest.PASS_DEF));
|
||||
PrivilegeTest.privilegeHandler.setUserPassword(certificate, PrivilegeTest.TED, copyBytes(PrivilegeTest.PASS_TED));
|
||||
PrivilegeTest.privilegeHandler.invalidateSession(certificate);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -319,8 +319,8 @@ public class PrivilegeTest {
|
|||
*/
|
||||
@Test
|
||||
public void testAuthAsTed() throws Exception {
|
||||
Certificate certificate = privilegeHandler.authenticate(TED, copyBytes(PASS_TED));
|
||||
privilegeHandler.invalidateSession(certificate);
|
||||
Certificate certificate = PrivilegeTest.privilegeHandler.authenticate(PrivilegeTest.TED, copyBytes(PrivilegeTest.PASS_TED));
|
||||
PrivilegeTest.privilegeHandler.invalidateSession(certificate);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -330,13 +330,13 @@ public class PrivilegeTest {
|
|||
@Test
|
||||
public void testPerformRestrictableAsAdmin() throws Exception {
|
||||
|
||||
Certificate certificate = privilegeHandler.authenticate(ADMIN, copyBytes(PASS_ADMIN));
|
||||
Certificate certificate = PrivilegeTest.privilegeHandler.authenticate(PrivilegeTest.ADMIN, copyBytes(PrivilegeTest.PASS_ADMIN));
|
||||
org.junit.Assert.assertTrue("Certificate is null!", certificate != null);
|
||||
|
||||
// see if eitch can perform restrictable
|
||||
Restrictable restrictable = new TestRestrictable();
|
||||
privilegeHandler.actionAllowed(certificate, restrictable);
|
||||
privilegeHandler.invalidateSession(certificate);
|
||||
PrivilegeTest.privilegeHandler.actionAllowed(certificate, restrictable);
|
||||
PrivilegeTest.privilegeHandler.invalidateSession(certificate);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -347,15 +347,15 @@ public class PrivilegeTest {
|
|||
*/
|
||||
@Test(expected = AccessDeniedException.class)
|
||||
public void testFailPerformRestrictableAsBob() throws Exception {
|
||||
Certificate certificate = privilegeHandler.authenticate(BOB, copyBytes(PASS_BOB));
|
||||
Certificate certificate = PrivilegeTest.privilegeHandler.authenticate(PrivilegeTest.BOB, copyBytes(PrivilegeTest.PASS_BOB));
|
||||
org.junit.Assert.assertTrue("Certificate is null!", certificate != null);
|
||||
|
||||
// see if bob can perform restrictable
|
||||
Restrictable restrictable = new TestRestrictable();
|
||||
try {
|
||||
privilegeHandler.actionAllowed(certificate, restrictable);
|
||||
PrivilegeTest.privilegeHandler.actionAllowed(certificate, restrictable);
|
||||
} finally {
|
||||
privilegeHandler.invalidateSession(certificate);
|
||||
PrivilegeTest.privilegeHandler.invalidateSession(certificate);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -366,10 +366,10 @@ public class PrivilegeTest {
|
|||
@Test
|
||||
public void testAddAppRoleToBob() throws Exception {
|
||||
|
||||
Certificate certificate = privilegeHandler.authenticate(ADMIN, copyBytes(PASS_ADMIN));
|
||||
privilegeHandler.addRoleToUser(certificate, BOB, ROLE_APP_USER);
|
||||
logger.info("Added " + ROLE_APP_USER + " to " + BOB);
|
||||
privilegeHandler.invalidateSession(certificate);
|
||||
Certificate certificate = PrivilegeTest.privilegeHandler.authenticate(PrivilegeTest.ADMIN, copyBytes(PrivilegeTest.PASS_ADMIN));
|
||||
PrivilegeTest.privilegeHandler.addRoleToUser(certificate, PrivilegeTest.BOB, PrivilegeTest.ROLE_APP_USER);
|
||||
PrivilegeTest.logger.info("Added " + PrivilegeTest.ROLE_APP_USER + " to " + PrivilegeTest.BOB);
|
||||
PrivilegeTest.privilegeHandler.invalidateSession(certificate);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -380,15 +380,15 @@ public class PrivilegeTest {
|
|||
*/
|
||||
@Test
|
||||
public void testPerformRestrictableAsBob() throws Exception {
|
||||
Certificate certificate = privilegeHandler.authenticate(BOB, copyBytes(PASS_BOB));
|
||||
Certificate certificate = PrivilegeTest.privilegeHandler.authenticate(PrivilegeTest.BOB, copyBytes(PrivilegeTest.PASS_BOB));
|
||||
org.junit.Assert.assertTrue("Certificate is null!", certificate != null);
|
||||
|
||||
// see if bob can perform restrictable
|
||||
Restrictable restrictable = new TestRestrictable();
|
||||
try {
|
||||
privilegeHandler.actionAllowed(certificate, restrictable);
|
||||
PrivilegeTest.privilegeHandler.actionAllowed(certificate, restrictable);
|
||||
} finally {
|
||||
privilegeHandler.invalidateSession(certificate);
|
||||
PrivilegeTest.privilegeHandler.invalidateSession(certificate);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -402,10 +402,10 @@ public class PrivilegeTest {
|
|||
public void testPerformSystemRestrictable() throws Exception {
|
||||
|
||||
// create the action to be performed as a system user
|
||||
TestSystemUserAction action = new TestSystemUserAction(privilegeHandler);
|
||||
TestSystemUserAction action = new TestSystemUserAction(PrivilegeTest.privilegeHandler);
|
||||
|
||||
// and then perform the action
|
||||
privilegeHandler.runAsSystem(SYSTEM_USER_ADMIN, action);
|
||||
PrivilegeTest.privilegeHandler.runAsSystem(PrivilegeTest.SYSTEM_USER_ADMIN, action);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -418,10 +418,10 @@ public class PrivilegeTest {
|
|||
public void testPerformSystemRestrictableFailPrivilege() throws Exception {
|
||||
|
||||
// create the action to be performed as a system user
|
||||
TestSystemUserActionDeny action = new TestSystemUserActionDeny(privilegeHandler);
|
||||
TestSystemUserActionDeny action = new TestSystemUserActionDeny(PrivilegeTest.privilegeHandler);
|
||||
|
||||
// and then perform the action
|
||||
privilegeHandler.runAsSystem(SYSTEM_USER_ADMIN, action);
|
||||
PrivilegeTest.privilegeHandler.runAsSystem(PrivilegeTest.SYSTEM_USER_ADMIN, action);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -433,13 +433,13 @@ public class PrivilegeTest {
|
|||
@Test(expected = AccessDeniedException.class)
|
||||
public void testLoginSystemUser() throws Exception {
|
||||
|
||||
privilegeHandler.authenticate(SYSTEM_USER_ADMIN, SYSTEM_USER_ADMIN.getBytes());
|
||||
PrivilegeTest.privilegeHandler.authenticate(PrivilegeTest.SYSTEM_USER_ADMIN, PrivilegeTest.SYSTEM_USER_ADMIN.getBytes());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCertificateThreadLocal() {
|
||||
|
||||
Certificate certificate = privilegeHandler.authenticate(ADMIN, copyBytes(PASS_ADMIN));
|
||||
Certificate certificate = PrivilegeTest.privilegeHandler.authenticate(PrivilegeTest.ADMIN, copyBytes(PrivilegeTest.PASS_ADMIN));
|
||||
org.junit.Assert.assertTrue("Certificate is null!", certificate != null);
|
||||
|
||||
// set certificate into thread local
|
||||
|
@ -448,9 +448,9 @@ public class PrivilegeTest {
|
|||
// see if bob can perform restrictable by returning certificate from CertificateThreadLocal
|
||||
Restrictable restrictable = new TestRestrictable();
|
||||
try {
|
||||
privilegeHandler.actionAllowed(CertificateThreadLocal.getInstance().get(), restrictable);
|
||||
PrivilegeTest.privilegeHandler.actionAllowed(CertificateThreadLocal.getInstance().get(), restrictable);
|
||||
} finally {
|
||||
privilegeHandler.invalidateSession(certificate);
|
||||
PrivilegeTest.privilegeHandler.invalidateSession(certificate);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ public class TestSystemUserAction implements SystemUserAction {
|
|||
|
||||
TestSystemRestrictable restrictable = new TestSystemRestrictable();
|
||||
|
||||
handler.actionAllowed(certificate, restrictable);
|
||||
this.handler.actionAllowed(certificate, restrictable);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -45,6 +45,6 @@ public class TestSystemUserActionDeny implements SystemUserAction {
|
|||
public void execute(Certificate certificate) {
|
||||
|
||||
TestRestrictable restrictable = new TestRestrictable();
|
||||
handler.actionAllowed(certificate, restrictable);
|
||||
this.handler.actionAllowed(certificate, restrictable);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue