-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rudimentary authentication for ng-control backdoor access
- Loading branch information
1 parent
5b79a35
commit efe2f45
Showing
5 changed files
with
85 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package ng.control; | ||
|
||
import java.util.Objects; | ||
|
||
import ng.appserver.NGActionResults; | ||
import ng.appserver.NGComponent; | ||
import ng.appserver.NGContext; | ||
|
||
public class NGControlLogin extends NGComponent { | ||
|
||
public String password; | ||
private String _errorMessage; | ||
|
||
public NGControlLogin( NGContext context ) { | ||
super( context ); | ||
} | ||
|
||
/** | ||
* @return Perform a "login" (in a very wide sense of that word) | ||
* | ||
* CHECKME: We should really involve some authentication here... // Hugi 2024-10-23 | ||
*/ | ||
public NGActionResults login() { | ||
|
||
if( !Objects.equals( environmentPassword(), password ) ) { | ||
_errorMessage = "Wrong password"; | ||
return null; | ||
} | ||
|
||
return pageWithName( NGControlOverview.class ); | ||
} | ||
|
||
/** | ||
* @return Error message shown to the user | ||
*/ | ||
public String errorMessage() { | ||
|
||
if( !environmentPasswordIsSet() ) { | ||
return "To access this page, you must set the property 'ng.control.password'"; | ||
} | ||
|
||
return _errorMessage; | ||
} | ||
|
||
/** | ||
* @return The password required for access to the environment | ||
*/ | ||
public String environmentPassword() { | ||
return application().properties().get( "ng.control.password" ); | ||
} | ||
|
||
/** | ||
* @return true if the environment password is set | ||
*/ | ||
public boolean environmentPasswordIsSet() { | ||
return environmentPassword() != null; | ||
} | ||
} |
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
13 changes: 13 additions & 0 deletions
13
ng-control/src/main/resources/components/NGControlLogin.wo/NGControlLogin.html
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,13 @@ | ||
<wo:NGControlWrapper> | ||
<wo:if condition="$errorMessage.length"> | ||
<div class="alert alert-danger"> | ||
<wo:str value="$errorMessage" /> | ||
</div> | ||
</wo:if> | ||
<wo:if condition="$environmentPasswordIsSet"> | ||
<wo:form> | ||
<label>Enter password</label><br> | ||
<wo:textfield value="$password" /> <wo:submit action="$login" value="Login" /> | ||
</wo:form> | ||
</wo:if> | ||
</wo:NGControlWrapper> |
Empty file.
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