-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from ClaudioWaldvogel/feat/authentication
Closes #18: feature: Add WebSecurity to EUM Server
- Loading branch information
Showing
20 changed files
with
1,143 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<code_scheme name="Ocelot" version="173"> | ||
<option name="LINE_SEPARATOR" value="
" /> | ||
<option name="FORMATTER_TAGS_ENABLED" value="true" /> | ||
<JavaCodeStyleSettings> | ||
<option name="JD_ADD_BLANK_AFTER_PARM_COMMENTS" value="true" /> | ||
<option name="JD_ADD_BLANK_AFTER_RETURN" value="true" /> | ||
<option name="JD_KEEP_INVALID_TAGS" value="false" /> | ||
<option name="JD_DO_NOT_WRAP_ONE_LINE_COMMENTS" value="true" /> | ||
</JavaCodeStyleSettings> | ||
<codeStyleSettings language="JAVA"> | ||
<option name="RIGHT_MARGIN" value="120" /> | ||
<option name="KEEP_LINE_BREAKS" value="false" /> | ||
<option name="KEEP_FIRST_COLUMN_COMMENT" value="false" /> | ||
<option name="KEEP_CONTROL_STATEMENT_IN_ONE_LINE" value="false" /> | ||
<option name="KEEP_BLANK_LINES_IN_DECLARATIONS" value="1" /> | ||
<option name="KEEP_BLANK_LINES_IN_CODE" value="1" /> | ||
<option name="KEEP_BLANK_LINES_BETWEEN_PACKAGE_DECLARATION_AND_HEADER" value="1" /> | ||
<option name="KEEP_BLANK_LINES_BEFORE_RBRACE" value="1" /> | ||
<option name="BLANK_LINES_AROUND_FIELD" value="1" /> | ||
<option name="BLANK_LINES_AROUND_FIELD_IN_INTERFACE" value="1" /> | ||
<option name="BLANK_LINES_AFTER_CLASS_HEADER" value="1" /> | ||
<option name="METHOD_CALL_CHAIN_WRAP" value="5" /> | ||
<option name="IF_BRACE_FORCE" value="3" /> | ||
<option name="DOWHILE_BRACE_FORCE" value="3" />, | ||
<option name="WHILE_BRACE_FORCE" value="3" /> | ||
<option name="FOR_BRACE_FORCE" value="3" /> | ||
<option name="WRAP_ON_TYPING" value="0" /> | ||
</codeStyleSettings> | ||
<codeStyleSettings language="JavaScript"> | ||
<indentOptions> | ||
<option name="INDENT_SIZE" value="2" /> | ||
<option name="CONTINUATION_INDENT_SIZE" value="2" /> | ||
<option name="TAB_SIZE" value="2" /> | ||
</indentOptions> | ||
</codeStyleSettings> | ||
</code_scheme> |
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,26 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project version="4"> | ||
<component name="SaveActionSettings"> | ||
<option name="actions"> | ||
<set> | ||
<option value="activate"/> | ||
<option value="organizeImports"/> | ||
<option value="reformat"/> | ||
<option value="missingOverrideAnnotation"/> | ||
<option value="useBlocks"/> | ||
<option value="unnecessaryThis"/> | ||
<option value="finalPrivateMethod"/> | ||
<option value="unnecessaryFinalOnLocalVariableOrParameter"/> | ||
<option value="explicitTypeCanBeDiamond"/> | ||
<option value="suppressAnnotation"/> | ||
<option value="unnecessarySemicolon"/> | ||
</set> | ||
</option> | ||
<option name="configurationPath" value=""/> | ||
<option name="inclusions"> | ||
<set> | ||
<option value=".*\.java"/> | ||
</set> | ||
</option> | ||
</component> | ||
</project> |
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,4 +1,4 @@ | ||
FROM openjdk:11-jre-slim | ||
FROM openjdk:19-slim-buster | ||
COPY inspectit-ocelot-eum-server.jar / | ||
COPY entrypoint.sh / | ||
ENTRYPOINT ["sh", "/entrypoint.sh"] | ||
ENTRYPOINT ["sh", "/entrypoint.sh"] |
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
34 changes: 34 additions & 0 deletions
34
...in/java/rocks/inspectit/oce/eum/server/configuration/model/security/SecuritySettings.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,34 @@ | ||
package rocks.inspectit.oce.eum.server.configuration.model.security; | ||
|
||
import lombok.Data; | ||
import org.springframework.validation.annotation.Validated; | ||
import rocks.inspectit.oce.eum.server.configuration.model.security.authProvider.AuthenticationProviderSettings; | ||
|
||
import javax.validation.Valid; | ||
import javax.validation.constraints.NotEmpty; | ||
import java.util.List; | ||
|
||
@Data | ||
@Validated | ||
public class SecuritySettings { | ||
|
||
/** | ||
* Enable/Disable Security | ||
*/ | ||
private boolean enabled; | ||
|
||
/** | ||
* Name of authorization header | ||
*/ | ||
@NotEmpty | ||
private String authorizationHeader; | ||
|
||
/** | ||
* List of white listed urls which must not be secured | ||
*/ | ||
private List<String> permittedUrls; | ||
|
||
@Valid | ||
private AuthenticationProviderSettings authProvider; | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
.../eum/server/configuration/model/security/authProvider/AuthenticationProviderSettings.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,14 @@ | ||
package rocks.inspectit.oce.eum.server.configuration.model.security.authProvider; | ||
|
||
import lombok.Data; | ||
import org.springframework.validation.annotation.Validated; | ||
|
||
import javax.validation.Valid; | ||
|
||
@Data | ||
@Validated | ||
public class AuthenticationProviderSettings { | ||
|
||
@Valid | ||
private SimpleApiTokenAuthenticationProviderSettings simple; | ||
} |
45 changes: 45 additions & 0 deletions
45
...nfiguration/model/security/authProvider/SimpleApiTokenAuthenticationProviderSettings.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,45 @@ | ||
package rocks.inspectit.oce.eum.server.configuration.model.security.authProvider; | ||
|
||
import lombok.Data; | ||
import org.hibernate.validator.constraints.time.DurationMin; | ||
import org.springframework.util.StringUtils; | ||
import org.springframework.validation.annotation.Validated; | ||
|
||
import javax.validation.constraints.AssertTrue; | ||
import java.time.Duration; | ||
|
||
@Data | ||
@Validated | ||
public class SimpleApiTokenAuthenticationProviderSettings { | ||
|
||
/** | ||
* Flag indicates if the {@link rocks.inspectit.oce.eum.server.security.authprovider.SimpleApiTokenAuthenticationProvider} should be enabled. | ||
*/ | ||
private boolean enabled; | ||
|
||
/** | ||
* Path to directory where token provider files can be loaded from. | ||
*/ | ||
private String tokenDirectory; | ||
|
||
/** | ||
* Duration how often {@link #tokenDirectory} should be checked for changes. | ||
*/ | ||
@DurationMin(millis = 1000) | ||
private Duration frequency; | ||
|
||
/** | ||
* Flag indicates if {@link #tokenDirectory} should be watched for changes. | ||
*/ | ||
private boolean watch; | ||
|
||
/** | ||
* Name of the default token provider file. If the file does not already exists in the tokenDirectory, it will be created. | ||
*/ | ||
private String defaultFileName; | ||
|
||
@AssertTrue(message = "tokenDirectory can not be null or empty if SimpleApiTokenAuthentication is enabled") | ||
public boolean isTokenDirectoryNotNullIfEnabled() { | ||
return !isEnabled() || (isEnabled() && StringUtils.hasText(tokenDirectory)); | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
src/main/java/rocks/inspectit/oce/eum/server/security/ApiTokenAuthentication.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,61 @@ | ||
package rocks.inspectit.oce.eum.server.security; | ||
|
||
import org.springframework.security.authentication.AbstractAuthenticationToken; | ||
import org.springframework.security.core.Authentication; | ||
import org.springframework.security.core.GrantedAuthority; | ||
|
||
import java.util.Collection; | ||
import java.util.Collections; | ||
|
||
/** | ||
* {@link Authentication} implementation for ApiToken Authentications | ||
*/ | ||
public class ApiTokenAuthentication extends AbstractAuthenticationToken { | ||
|
||
/** | ||
* Default principal name for unauthorized users | ||
*/ | ||
private static final String UNAUTHORIZED_TOKEN_USER = "unauthorized_token_user"; | ||
|
||
/** | ||
* The current authenticated principal. {@link ApiTokenAuthentication#UNAUTHORIZED_TOKEN_USER} if not yet authorized | ||
*/ | ||
private String principal = UNAUTHORIZED_TOKEN_USER; | ||
|
||
/** | ||
* The token used for authentication | ||
*/ | ||
private String token; | ||
|
||
/** | ||
* Creates an unauthenticated ApiTokenAuthentication instance | ||
* | ||
* @param token The token used for later authentication | ||
*/ | ||
public ApiTokenAuthentication(String token) { | ||
super(Collections.emptyList()); | ||
this.token = token; | ||
} | ||
|
||
/** | ||
* Creates an authenticated ApiTokenAuthentication instance | ||
* | ||
* @param principal The name of the authenticated principal | ||
* @param authorities List of {@link GrantedAuthority}s (TODO Currently not in use) | ||
*/ | ||
public ApiTokenAuthentication(String principal, Collection<? extends GrantedAuthority> authorities) { | ||
super(authorities); | ||
this.principal = principal; | ||
setAuthenticated(true); | ||
} | ||
|
||
@Override | ||
public Object getCredentials() { | ||
return token; | ||
} | ||
|
||
@Override | ||
public Object getPrincipal() { | ||
return principal; | ||
} | ||
} |
Oops, something went wrong.