From 6142e86c1aea434fdb1ad0d32eadc2de6b293880 Mon Sep 17 00:00:00 2001 From: mck Date: Mon, 21 Jan 2019 06:44:19 +1100 Subject: [PATCH] Full Shiro protection. - Authentication is now enabled by default. Default is the dummy admin/admin credentials, see shiro.ini - shiro.ini now embedded in app. can still be configured/overridden - REST endpoints are protected, requiring JWT specified in a request header ('Authorization: Bearer ') - The JWT for a user can be gained at the /jwt URL - add 'remember me' to login page ref: https://github.com/thelastpickle/cassandra-reaper/pull/604 --- .../cassandra-reaper-cassandra-ssl.yaml | 13 ++-- .../resource/cassandra-reaper-cassandra.yaml | 13 ++-- .../resource/cassandra-reaper-h2.yaml | 13 ++-- .../resource/cassandra-reaper-memory.yaml | 13 ++-- .../resource/cassandra-reaper-postgres.yaml | 13 ++-- src/packaging/resource/cassandra-reaper.yaml | 13 ++-- src/server/pom.xml | 7 +- .../io/cassandrareaper/ReaperApplication.java | 6 +- .../resources/auth/LoginResource.java | 32 ++------- .../resources/auth/ShiroJwtProvider.java | 65 +++++++++++++++++++ .../auth/ShiroJwtVerifyingFilter.java | 52 +++++++++++++++ .../storage/CassandraStorage.java | 4 ++ .../src/main/resources}/shiro.ini | 21 ++++-- .../acceptance/BasicSteps.java | 3 +- .../resources/auth/LoginResourceTest.java | 50 ++++++++++++++ src/server/src/test/resources/shiro.ini | 31 --------- src/ui/app/jsx/login-form.jsx | 14 +++- 17 files changed, 250 insertions(+), 113 deletions(-) create mode 100644 src/server/src/main/java/io/cassandrareaper/resources/auth/ShiroJwtProvider.java create mode 100644 src/server/src/main/java/io/cassandrareaper/resources/auth/ShiroJwtVerifyingFilter.java rename src/{packaging/resource => server/src/main/resources}/shiro.ini (62%) create mode 100644 src/server/src/test/java/io/cassandrareaper/resources/auth/LoginResourceTest.java delete mode 100644 src/server/src/test/resources/shiro.ini diff --git a/src/packaging/resource/cassandra-reaper-cassandra-ssl.yaml b/src/packaging/resource/cassandra-reaper-cassandra-ssl.yaml index 09896d422..71c04a6fb 100644 --- a/src/packaging/resource/cassandra-reaper-cassandra-ssl.yaml +++ b/src/packaging/resource/cassandra-reaper-cassandra-ssl.yaml @@ -1,5 +1,5 @@ # Copyright 2015-2017 Spotify AB -# Copyright 2016-2018 The Last Pickle Ltd +# Copyright 2016-2019 The Last Pickle Ltd # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -134,9 +134,8 @@ autoScheduling: # - type: log # logger: metrics -# Uncomment the following block to enable authentication - -#accessControl: -# sessionTimeout: PT10M -# shiro: -# iniConfigs: ["file:/path/to/shiro.ini"] +# Authentication is enabled by default +accessControl: + sessionTimeout: PT10M + shiro: + iniConfigs: ["classpath:shiro.ini"] diff --git a/src/packaging/resource/cassandra-reaper-cassandra.yaml b/src/packaging/resource/cassandra-reaper-cassandra.yaml index f39b76307..365d83082 100644 --- a/src/packaging/resource/cassandra-reaper-cassandra.yaml +++ b/src/packaging/resource/cassandra-reaper-cassandra.yaml @@ -1,5 +1,5 @@ # Copyright 2015-2017 Spotify AB -# Copyright 2016-2018 The Last Pickle Ltd +# Copyright 2016-2019 The Last Pickle Ltd # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -128,9 +128,8 @@ autoScheduling: # - type: log # logger: metrics -# Uncomment the following block to enable authentication - -#accessControl: -# sessionTimeout: PT10M -# shiro: -# iniConfigs: ["file:/path/to/shiro.ini"] +# Authentication is enabled by default +accessControl: + sessionTimeout: PT10M + shiro: + iniConfigs: ["classpath:shiro.ini"] diff --git a/src/packaging/resource/cassandra-reaper-h2.yaml b/src/packaging/resource/cassandra-reaper-h2.yaml index aea1c8ce4..bc0dfd514 100644 --- a/src/packaging/resource/cassandra-reaper-h2.yaml +++ b/src/packaging/resource/cassandra-reaper-h2.yaml @@ -1,5 +1,5 @@ # Copyright 2015-2017 Spotify AB -# Copyright 2016-2018 The Last Pickle Ltd +# Copyright 2016-2019 The Last Pickle Ltd # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -112,9 +112,8 @@ autoScheduling: # - type: log # logger: metrics -# Uncomment the following block to enable authentication - -#accessControl: -# sessionTimeout: PT10M -# shiro: -# iniConfigs: ["file:/path/to/shiro.ini"] +# Authentication is enabled by default +accessControl: + sessionTimeout: PT10M + shiro: + iniConfigs: ["classpath:shiro.ini"] diff --git a/src/packaging/resource/cassandra-reaper-memory.yaml b/src/packaging/resource/cassandra-reaper-memory.yaml index b2f0d8497..addc78633 100644 --- a/src/packaging/resource/cassandra-reaper-memory.yaml +++ b/src/packaging/resource/cassandra-reaper-memory.yaml @@ -1,5 +1,5 @@ # Copyright 2015-2017 Spotify AB -# Copyright 2016-2018 The Last Pickle Ltd +# Copyright 2016-2019 The Last Pickle Ltd # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -107,9 +107,8 @@ autoScheduling: # - type: log # logger: metrics -# Uncomment the following block to enable authentication - -#accessControl: -# sessionTimeout: PT10M -# shiro: -# iniConfigs: ["file:/path/to/shiro.ini"] +# Authentication is enabled by default +accessControl: + sessionTimeout: PT10M + shiro: + iniConfigs: ["classpath:shiro.ini"] diff --git a/src/packaging/resource/cassandra-reaper-postgres.yaml b/src/packaging/resource/cassandra-reaper-postgres.yaml index 907210e95..5638f29fa 100644 --- a/src/packaging/resource/cassandra-reaper-postgres.yaml +++ b/src/packaging/resource/cassandra-reaper-postgres.yaml @@ -1,5 +1,5 @@ # Copyright 2015-2017 Spotify AB -# Copyright 2016-2018 The Last Pickle Ltd +# Copyright 2016-2019 The Last Pickle Ltd # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -112,9 +112,8 @@ autoScheduling: # - type: log # logger: metrics -# Uncomment the following block to enable authentication - -#accessControl: -# sessionTimeout: PT10M -# shiro: -# iniConfigs: ["file:/path/to/shiro.ini"] +# Authentication is enabled by default +accessControl: + sessionTimeout: PT10M + shiro: + iniConfigs: ["classpath:shiro.ini"] diff --git a/src/packaging/resource/cassandra-reaper.yaml b/src/packaging/resource/cassandra-reaper.yaml index afaf35efd..c8d715f92 100644 --- a/src/packaging/resource/cassandra-reaper.yaml +++ b/src/packaging/resource/cassandra-reaper.yaml @@ -1,5 +1,5 @@ # Copyright 2015-2017 Spotify AB -# Copyright 2016-2018 The Last Pickle Ltd +# Copyright 2016-2019 The Last Pickle Ltd # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -107,9 +107,8 @@ autoScheduling: # - type: log # logger: metrics -# Uncomment the following block to enable authentication - -#accessControl: -# sessionTimeout: PT10M -# shiro: -# iniConfigs: ["file:/path/to/shiro.ini"] +# Authentication is enabled by default +accessControl: + sessionTimeout: PT10M + shiro: + iniConfigs: ["classpath:shiro.ini"] diff --git a/src/server/pom.xml b/src/server/pom.xml index 4bd902472..6efb5c72e 100755 --- a/src/server/pom.xml +++ b/src/server/pom.xml @@ -29,7 +29,7 @@ jar - 1.1.8 + 1.3.8 src/main/docker ${maven.build.timestamp} yyyy-MM-dd HH:mm:ss @@ -181,6 +181,11 @@ dropwizard-shiro 0.2.0 + + io.jsonwebtoken + jjwt + 0.9.1 +