Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<shiro.version>1.13.0</shiro.version>
<shiro.version>2.0.5</shiro.version>
</properties>

<repositories>
Expand Down Expand Up @@ -88,11 +88,13 @@
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-core</artifactId>
<version>${shiro.version}</version>
<classifier>jakarta</classifier>
</dependency>
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-web</artifactId>
<version>${shiro.version}</version>
<classifier>jakarta</classifier>
</dependency>

<dependency>
Expand Down
21 changes: 17 additions & 4 deletions src/main/java/com/epimorphics/appbase/security/AppRealm.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authc.SaltedAuthenticationInfo;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.authc.credential.CredentialsMatcher;
import org.apache.shiro.authc.credential.HashedCredentialsMatcher;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.authz.SimpleAuthorizationInfo;
import org.apache.shiro.cache.Cache;
Expand Down Expand Up @@ -52,8 +54,8 @@ public static AppRealm getRealm() {
public AppRealm() {
setCredentialsMatcher( new AppRealmCredentialsMatcher() );
DefaultHashService hashing = new DefaultHashService();
hashing.setHashAlgorithmName( DEFAULT_ALGORITHM );
hashing.setHashIterations( DEFAULT_ITERATIONS );
hashing.setDefaultAlgorithmName( DEFAULT_ALGORITHM );
// hashing.setHashIterations( DEFAULT_ITERATIONS );
hashService = hashing;
}

Expand All @@ -62,8 +64,19 @@ public AppRealm() {
* Must be set before any new credentials (including bootstrap ones) are hashed.
*/
public void setHashIterations(int iterations) {
((DefaultHashService) hashService).setHashIterations(iterations);
((AppRealmCredentialsMatcher)getCredentialsMatcher()).setHashIterations(iterations);
CredentialsMatcher cm = getCredentialsMatcher();
if (cm instanceof HashedCredentialsMatcher hcm) {
hcm.setHashIterations(iterations);
}
}

public int getHashIterations() {
CredentialsMatcher cm = getCredentialsMatcher();
if (cm instanceof HashedCredentialsMatcher hcm) {
return hcm.getHashIterations();
} else {
return 0;
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.SaltedAuthenticationInfo;
import org.apache.shiro.authc.SimpleAuthenticationInfo;
import org.apache.shiro.codec.Hex;
import org.apache.shiro.lang.codec.Hex;
import org.apache.shiro.crypto.SecureRandomNumberGenerator;
import org.apache.shiro.crypto.hash.Hash;
import org.apache.shiro.crypto.hash.HashRequest;
import org.apache.shiro.util.ByteSource;
import org.apache.shiro.lang.util.ByteSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -305,6 +305,7 @@ public void setPassword(ByteSource password, long minstolive) {
HashRequest request = new HashRequest.Builder()
.setSource(password)
.setSalt( getSalt() )
.addParameter("SimpleHash.iterations", realm.getHashIterations())
.build();
Hash hash = realm.getHashService().computeHash(request);
this.password = hash.toHex();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@
import java.util.List;
import java.util.Set;

import org.apache.jena.atlas.web.TypedInputStream;
import org.apache.jena.riot.system.stream.StreamManager;
import org.apache.shiro.util.ByteSource;
import org.apache.shiro.lang.util.ByteSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -81,8 +82,10 @@ protected boolean initstore() {

if (!exists) {
startTransaction();
String schema = FileManager.get().readWholeFileAsUTF8(DATABASE_SCHEMA);
Statement s = conn.createStatement();
String schema;
try (TypedInputStream input = StreamManager.get().open(DATABASE_SCHEMA)) {
schema = new String(input.readAllBytes());
} Statement s = conn.createStatement();
for (String statement : schema.split(";")) {
String sql = statement.trim();
if (!sql.isEmpty() && ! sql.startsWith("--")) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/epimorphics/appbase/security/Login.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.apache.shiro.util.ByteSource;
import org.apache.shiro.lang.util.ByteSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import java.util.Map;
import java.util.Set;

import org.apache.shiro.util.ByteSource;
import org.apache.shiro.lang.util.ByteSource;


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import java.util.Set;

import org.apache.shiro.authc.SaltedAuthenticationInfo;
import org.apache.shiro.util.ByteSource;
import org.apache.shiro.lang.util.ByteSource;

/**
* Interface abstraction for the store of registered users. The actual
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import java.util.Set;

import org.apache.shiro.authc.SaltedAuthenticationInfo;
import org.apache.shiro.util.ByteSource;
import org.apache.shiro.lang.util.ByteSource;
import org.junit.jupiter.api.Test;

import com.epimorphics.appbase.security.BaseUserStore.UserRecord;
Expand Down
Loading