-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
eaf36b3
commit 1e62341
Showing
37 changed files
with
2,253 additions
and
57 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<!-- | ||
Copyright © 2023 JAdaptive Limited (support@jadaptive.com) | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>com.sshtools</groupId> | ||
<artifactId>jenny-auth</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<relativePath>../</relativePath> | ||
</parent> | ||
<properties> | ||
<!-- Linid needs Java 22 for the official FFM API --> | ||
<maven.compiler.target>22</maven.compiler.target> | ||
<maven.compiler.source>22</maven.compiler.source> | ||
</properties> | ||
<name>Jenny - Alternative (Java 22) Linux Authentication</name> | ||
<artifactId>jenny-auth-linid</artifactId> | ||
<dependencies> | ||
|
||
<!-- Framework Supplied --> | ||
<dependency> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>jenny-auth-api</artifactId> | ||
<version>${project.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<!-- Framework Provided --> | ||
<dependency> | ||
<groupId>com.sshtools</groupId> | ||
<artifactId>bootlace-api</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>jenny-api</artifactId> | ||
<version>${project.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<!-- Required --> | ||
<dependency> | ||
<groupId>uk.co.bithatch</groupId> | ||
<artifactId>linid</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
</dependency> | ||
|
||
|
||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<release>22</release> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
100 changes: 100 additions & 0 deletions
100
auth/linid/src/main/java/com/sshtools/jenny/auth/linux/LinidAuth.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,100 @@ | ||
/** | ||
* Copyright © 2023 JAdaptive Limited (support@jadaptive.com) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.sshtools.jenny.auth.linux; | ||
|
||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
|
||
import com.sshtools.bootlace.api.Plugin; | ||
import com.sshtools.bootlace.api.PluginContext; | ||
import com.sshtools.jenny.api.Api; | ||
import com.sshtools.jenny.auth.api.Auth.AuthResult; | ||
import com.sshtools.jenny.auth.api.Auth.AuthState; | ||
import com.sshtools.jenny.auth.api.Auth.PasswordAuthProvider; | ||
import com.sshtools.jenny.auth.api.ExtendedUserPrincipal; | ||
|
||
import uk.co.bitatch.linid.Linid; | ||
import uk.co.bitatch.linid.LinuxUserId; | ||
|
||
public class LinidAuth implements Plugin { | ||
|
||
public final static class Provider implements PasswordAuthProvider { | ||
@Override | ||
public AuthResult logon(String username, char[] password) { | ||
return Linid.get().authenticate(username, password).map(id -> { | ||
var linId = (LinuxUserId)id; | ||
return new AuthResult(AuthState.COMPLETE, new ExtendedUserPrincipal.LinuxUser() { | ||
|
||
@Override | ||
public String getName() { | ||
return id.getName(); | ||
} | ||
|
||
@Override | ||
public int uid() { | ||
return linId.uid(); | ||
} | ||
|
||
@Override | ||
public Optional<String> shell() { | ||
return Optional.of(linId.shell()); | ||
} | ||
|
||
@Override | ||
public Set<String> groups() { | ||
return Set.of(linId.collectionNames()); | ||
} | ||
|
||
@Override | ||
public int gid() { | ||
return linId.gid(); | ||
} | ||
|
||
@Override | ||
public Optional<String> gecos() { | ||
return Optional.of(String.join(",", linId.gecos())); | ||
} | ||
|
||
@Override | ||
public Optional<Path> dir() { | ||
return Optional.of(linId.home()).map(Paths::get); | ||
} | ||
}); | ||
}).orElseGet(() -> new AuthResult(AuthState.DENY)); | ||
} | ||
|
||
@Override | ||
public int weight() { | ||
return 0; | ||
} | ||
} | ||
|
||
private Api api; | ||
|
||
@Override | ||
public void afterOpen(PluginContext context) { | ||
api = context.plugin(Api.class); | ||
|
||
var provider = new Provider(); | ||
|
||
context.autoClose(api.extensions(). | ||
group(). | ||
point(PasswordAuthProvider.class, (a) -> provider)); | ||
} | ||
|
||
} |
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,27 @@ | ||
/** | ||
* Copyright © 2023 JAdaptive Limited (support@jadaptive.com) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
import com.sshtools.bootlace.api.Plugin; | ||
import com.sshtools.jenny.auth.linux.LinidAuth; | ||
|
||
module com.sshtools.jenny.auth.linid { | ||
exports com.sshtools.jenny.auth.linux; | ||
requires transitive com.sshtools.jenny.auth.api; | ||
requires com.sshtools.bootlace.api; | ||
requires com.sshtools.jenny.api; | ||
requires uk.co.bithatch.linid; | ||
|
||
provides Plugin with LinidAuth; | ||
} |
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,7 @@ | ||
[component] | ||
id = com.sshtools.jenny.auth.api.linid | ||
name = Linux Authentication (Alternative version) | ||
|
||
[artifacts] | ||
uk.co.bithatch:linid:0.0.1-SNAPSHOT | ||
|
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
Oops, something went wrong.