-
Notifications
You must be signed in to change notification settings - Fork 81
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 #40 from fcamblor/generators-update
$RestxSession special header, more samples in AppModule generated file (app.name, security) & test harness for restx-core-shell - $RestxSession special header in restx specs files, allowing to define a restx session content (with proper cookie name, given available RestxCookieDescriptor component) and sign it with current SignatureKey component - Improved HelloResource sample by providing a basic security implementation sample and using the @RolesAllowed annotation - Provides a test harness in restx-core-shell allowing to validate that app new shell command generates a new app and this app has green tests
- Loading branch information
Showing
47 changed files
with
794 additions
and
308 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
39 changes: 37 additions & 2 deletions
39
restx-core-shell/src/main/resources/restx/core/shell/AppModule.java.mustache
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,21 +1,56 @@ | ||
package {{mainPackage}}; | ||
|
||
import {{mainPackage}}.persistence.UserRepository; | ||
|
||
import com.google.common.base.Charsets; | ||
import com.google.common.base.Optional; | ||
import com.google.common.collect.ImmutableMap; | ||
import restx.SignatureKey; | ||
import restx.factory.Module; | ||
import restx.factory.Provides; | ||
import restx.security.BasicPrincipalAuthenticator; | ||
import restx.security.RestxPrincipal; | ||
import restx.security.RestxSession; | ||
import org.joda.time.Duration; | ||
import javax.inject.Named; | ||
|
||
@Module | ||
public class AppModule { | ||
@Provides | ||
public SignatureKey signatureKey() { | ||
return new SignatureKey("{{signatureKey}}".getBytes(Charsets.UTF_8)); | ||
} | ||
|
||
@Provides | ||
@Named("restx.admin.password") | ||
public String restxAdminPassword() { | ||
return "{{adminPassword}}"; | ||
} | ||
|
||
@Provides | ||
public SignatureKey signatureKey() { | ||
return new SignatureKey("{{signatureKey}}".getBytes(Charsets.UTF_8)); | ||
@Named("app.name") | ||
public String appName(){ | ||
return "{{appName}}"; | ||
} | ||
|
||
@Provides | ||
public BasicPrincipalAuthenticator basicPrincipalAuthenticator(final UserRepository userRepository) { | ||
return new BasicPrincipalAuthenticator() { | ||
@Override | ||
public Optional<? extends RestxPrincipal> findByName(String name) { | ||
return userRepository.findUserByName(name); | ||
} | ||
|
||
@Override | ||
public Optional<? extends RestxPrincipal> authenticate(String name, String passwordHash, ImmutableMap<String, ?> principalData) { | ||
boolean rememberMe = Boolean.valueOf((String) principalData.get("rememberMe")); | ||
Optional<? extends RestxPrincipal> user = userRepository.findUserByNameAndPasswordHash(name, passwordHash); | ||
if (user.isPresent()) { | ||
RestxSession.current().expires(rememberMe ? Duration.standardDays(30) : Duration.ZERO); | ||
} | ||
|
||
return user; | ||
} | ||
}; | ||
} | ||
} |
Oops, something went wrong.