Skip to content

Commit

Permalink
Rudimentary authentication for ng-control backdoor access
Browse files Browse the repository at this point in the history
  • Loading branch information
hugithordarson committed Oct 23, 2024
1 parent 5b79a35 commit efe2f45
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 1 deletion.
58 changes: 58 additions & 0 deletions ng-control/src/main/java/ng/control/NGControlLogin.java
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;
}
}
2 changes: 1 addition & 1 deletion ng-control/src/main/java/ng/control/NGControlPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ public class NGControlPlugin extends NGPlugin {

@Override
public void load( NGApplication application ) {
application.routeTable().mapComponent( "/control", NGControlOverview.class );
application.routeTable().mapComponent( "/control", NGControlLogin.class );
}
}
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.
13 changes: 13 additions & 0 deletions ng-control/src/main/resources/components/NGControlWrapper.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,19 @@
padding: 4px;
vertical-align: top;
}

.alert {
display: inline-block;
padding: 10px;
margin-bottom: 20px;
border-radius: 5px;
}

.alert-danger {
background-color: rgba(255,230,230,0.8);
border: 1px solid red;
box-shadow: 2px 2px 2px rgba(200,50,50,0.5);
}
</style>
</head>
<body>
Expand Down

0 comments on commit efe2f45

Please sign in to comment.