-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
vzakharchenko
committed
Jan 10, 2020
1 parent
4ad41fd
commit 9194322
Showing
40 changed files
with
1,132 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
#Generated by Git-Commit-Id-Plugin | ||
#Fri Jan 10 10:11:57 EET 2020 | ||
#Fri Jan 10 20:08:19 EET 2020 | ||
git.build.version=1.0-SNAPSHOT | ||
git.commit.id.abbrev=583a377 | ||
git.commit.id.abbrev=4ad41fd | ||
git.branch=master | ||
git.build.host=Vasyls-MacBook-Pro-8066.local | ||
git.commit.id.describe-short=583a377-dirty | ||
git.commit.id.describe=583a377-dirty | ||
git.commit.id=583a37772b1ddd2640a94adfc6bb1b0ec1ba5d53 | ||
git.commit.time=10.01.2020 @ 07\:43\:16 UTC | ||
git.build.time=10.01.2020 @ 08\:11\:57 UTC | ||
git.commit.id.describe-short=4ad41fd-dirty | ||
git.commit.id.describe=4ad41fd-dirty | ||
git.commit.id=4ad41fdf6f0f0b29d2ef900555605543625ee68f | ||
git.commit.time=10.01.2020 @ 09\:47\:27 UTC | ||
git.build.time=10.01.2020 @ 18\:08\:19 UTC | ||
git.build.user.name=vzakharchenko | ||
git.commit.message.full=Initial commit | ||
git.commit.message.full=include coveralls report |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...java/ua/zaskarius/keycloak/plugins/radius/configuration/ConfigurationEndpointFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package ua.zaskarius.keycloak.plugins.radius.configuration; | ||
|
||
import org.keycloak.Config; | ||
import org.keycloak.models.KeycloakSession; | ||
import org.keycloak.models.KeycloakSessionFactory; | ||
import org.keycloak.services.resource.RealmResourceProvider; | ||
import org.keycloak.services.resource.RealmResourceProviderFactory; | ||
|
||
public class ConfigurationEndpointFactory implements RealmResourceProviderFactory { | ||
|
||
public static final String RADIUS_CONFIGURATION_ENDPOINT = "Radius-configuration-endpoint"; | ||
|
||
@Override | ||
public RealmResourceProvider create(KeycloakSession session) { | ||
return new ConfigurationProvider(session); | ||
} | ||
|
||
@Override | ||
public void init(Config.Scope config) { | ||
|
||
} | ||
|
||
@Override | ||
public void postInit(KeycloakSessionFactory factory) { | ||
|
||
} | ||
|
||
@Override | ||
public void close() { | ||
|
||
} | ||
|
||
@Override | ||
public String getId() { | ||
return RADIUS_CONFIGURATION_ENDPOINT; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...c/main/java/ua/zaskarius/keycloak/plugins/radius/configuration/ConfigurationProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package ua.zaskarius.keycloak.plugins.radius.configuration; | ||
|
||
import org.keycloak.models.KeycloakSession; | ||
import org.keycloak.services.resource.RealmResourceProvider; | ||
|
||
public class ConfigurationProvider implements RealmResourceProvider { | ||
|
||
private final KeycloakSession session; | ||
|
||
public ConfigurationProvider(KeycloakSession session) { | ||
this.session = session; | ||
} | ||
|
||
@Override | ||
public Object getResource() { | ||
return new ConfigurationResourceImpl(session); | ||
} | ||
|
||
@Override | ||
public void close() { | ||
|
||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...c/main/java/ua/zaskarius/keycloak/plugins/radius/configuration/ConfigurationResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package ua.zaskarius.keycloak.plugins.radius.configuration; | ||
|
||
import org.jboss.resteasy.annotations.cache.NoCache; | ||
import ua.zaskarius.keycloak.plugins.radius.models.ConfigurationRepresentation; | ||
|
||
import javax.ws.rs.*; | ||
import javax.ws.rs.core.MediaType; | ||
|
||
public interface ConfigurationResource { | ||
|
||
@POST | ||
@Path("admin/config/save") | ||
@NoCache | ||
@Produces(MediaType.APPLICATION_JSON) | ||
@Consumes(MediaType.APPLICATION_JSON) | ||
ConfigurationRepresentation saveConfig(ConfigurationRepresentation configuration); | ||
|
||
@GET | ||
@Path("admin/config/get") | ||
@NoCache | ||
@Produces(MediaType.APPLICATION_JSON) | ||
ConfigurationRepresentation getConfig(); | ||
} |
76 changes: 76 additions & 0 deletions
76
...in/java/ua/zaskarius/keycloak/plugins/radius/configuration/ConfigurationResourceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package ua.zaskarius.keycloak.plugins.radius.configuration; | ||
|
||
import com.google.common.annotations.VisibleForTesting; | ||
import org.keycloak.models.KeycloakSession; | ||
import org.keycloak.services.ForbiddenException; | ||
import org.keycloak.services.managers.AuthenticationManager; | ||
import ua.zaskarius.keycloak.plugins.radius.models.ConfigurationRepresentation; | ||
import ua.zaskarius.keycloak.plugins.radius.models.RadiusConfigModel; | ||
import ua.zaskarius.keycloak.plugins.radius.transaction.KeycloakRadiusUtils; | ||
|
||
public class ConfigurationResourceImpl implements ConfigurationResource { | ||
|
||
private IRadiusConfigJPA radiusConfigJPA; | ||
|
||
private AuthenticationManager.AuthResult auth; | ||
|
||
|
||
public ConfigurationResourceImpl(KeycloakSession session) { | ||
this.radiusConfigJPA = new RadiusConfigJPA(session); | ||
this.auth = KeycloakRadiusUtils | ||
.getKeycloakHelper() | ||
.getAuthResult(session); | ||
if (auth == null || auth.getUser() == null) { | ||
throw new ForbiddenException(); | ||
} | ||
} | ||
|
||
@Override | ||
public ConfigurationRepresentation saveConfig(ConfigurationRepresentation configuration) { | ||
return transform(radiusConfigJPA | ||
.saveConfig(transform(configuration), auth.getUser())); | ||
} | ||
|
||
@Override | ||
public ConfigurationRepresentation getConfig() { | ||
RadiusConfigModel config = radiusConfigJPA.getConfig(); | ||
|
||
if (config == null) { | ||
ConfigurationRepresentation configurationRepresentation = | ||
new ConfigurationRepresentation(); | ||
configurationRepresentation.setAccountPort(1813); | ||
configurationRepresentation.setAuthPort(1812); | ||
configurationRepresentation.setRadiusShared(null); | ||
configurationRepresentation.setStart(true); | ||
return saveConfig(configurationRepresentation); | ||
} | ||
return transform(config); | ||
} | ||
|
||
public ConfigurationRepresentation transform(RadiusConfigModel configModel) { | ||
ConfigurationRepresentation configurationRepresentation = | ||
new ConfigurationRepresentation(); | ||
configurationRepresentation.setId(configModel.getId()); | ||
configurationRepresentation.setAccountPort(configModel.getAccountPort()); | ||
configurationRepresentation.setAuthPort(configModel.getAuthPort()); | ||
configurationRepresentation.setRadiusShared(configModel.getRadiusShared()); | ||
configurationRepresentation.setStart(configModel.isStart()); | ||
return configurationRepresentation; | ||
} | ||
|
||
public RadiusConfigModel transform(ConfigurationRepresentation configurationRepresentation) { | ||
RadiusConfigModel configModel = | ||
new RadiusConfigModel(); | ||
configModel.setId(configurationRepresentation.getId()); | ||
configModel.setAccountPort(configurationRepresentation.getAccountPort()); | ||
configModel.setAuthPort(configurationRepresentation.getAuthPort()); | ||
configModel.setRadiusShared(configurationRepresentation.getRadiusShared()); | ||
configModel.setStart(configurationRepresentation.isStart()); | ||
return configModel; | ||
} | ||
|
||
@VisibleForTesting | ||
void setRadiusConfigJPA(IRadiusConfigJPA radiusConfigJPA) { | ||
this.radiusConfigJPA = radiusConfigJPA; | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
...c/main/java/ua/zaskarius/keycloak/plugins/radius/configuration/DBRadiusConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package ua.zaskarius.keycloak.plugins.radius.configuration; | ||
|
||
import org.keycloak.models.KeycloakSession; | ||
import org.keycloak.models.RealmModel; | ||
import ua.zaskarius.keycloak.plugins.radius.models.RadiusCommonSettings; | ||
import ua.zaskarius.keycloak.plugins.radius.models.RadiusConfigModel; | ||
import ua.zaskarius.keycloak.plugins.radius.models.RadiusServerSettings; | ||
|
||
public class DBRadiusConfiguration implements IRadiusConfiguration { | ||
|
||
protected DBRadiusConfiguration() { | ||
} | ||
|
||
@Override | ||
public RadiusServerSettings getRadiusSettings(KeycloakSession session) { | ||
RadiusConfigJPA radiusConfigJPA = new RadiusConfigJPA(session); | ||
RadiusConfigModel config = radiusConfigJPA.getConfig(); | ||
RadiusServerSettings radiusServerSettings = new RadiusServerSettings(); | ||
radiusServerSettings.setSecret(config.getRadiusShared()); | ||
radiusServerSettings.setAccountPort(config.getAccountPort()); | ||
radiusServerSettings.setAccountPort(config.getAccountPort()); | ||
radiusServerSettings.setUseRadius(config.isStart()); | ||
return radiusServerSettings; | ||
} | ||
|
||
@Override | ||
public RadiusCommonSettings getCommonSettings(RealmModel realmModel) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public RadiusServerSettings getRadiusSettings(RealmModel realmModel) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public boolean isUsedRadius(RealmModel realmModel) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean isUsedRadius(KeycloakSession session) { | ||
return getRadiusSettings(session).isUseRadius(); | ||
} | ||
|
||
@Override | ||
public boolean init(RealmModel realmModel) { | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
...in/src/main/java/ua/zaskarius/keycloak/plugins/radius/configuration/IRadiusConfigJPA.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package ua.zaskarius.keycloak.plugins.radius.configuration; | ||
|
||
import org.keycloak.models.UserModel; | ||
import ua.zaskarius.keycloak.plugins.radius.models.RadiusConfigModel; | ||
|
||
public interface IRadiusConfigJPA { | ||
RadiusConfigModel getConfig(); | ||
|
||
RadiusConfigModel saveConfig(RadiusConfigModel configModel, UserModel userModel); | ||
} |
Oops, something went wrong.