Files
pi_mcps/java/mss-failsafe/mss/src/main/java/httpauthenticationmechanism/ApplicationConfig.java
T
Patrick Plate 155d56e8e8 chore: reorganize into polyglot monorepo (workshop)
- Move bigmind/ -> mcp/bigmind/
- Move webscraper/ -> mcp/webscraper/
- Move mss-failsafe/ -> java/mss-failsafe/
- Move Wellmann-Shop/ -> java/wellmann-shop/ (normalize to kebab-case)
- Add .roo/ IDE config files to tracking
- Add plans/REPO_STRATEGY.md (monorepo strategy document)
- Expand .gitignore: Java/Maven, Node/TS, coverage, uv.lock
- Rewrite README.md as navigation index
- Update .roo/mcp.json webscraper path to mcp/webscraper/
2026-04-04 08:51:15 +02:00

86 lines
3.0 KiB
Java

package httpauthenticationmechanism;
import business.user.PersonManager;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.inject.Named;
import javax.security.enterprise.AuthenticationStatus;
import javax.security.enterprise.authentication.mechanism.http.AutoApplySession;
import javax.security.enterprise.authentication.mechanism.http.CustomFormAuthenticationMechanismDefinition;
import javax.security.enterprise.authentication.mechanism.http.HttpAuthenticationMechanism;
import javax.security.enterprise.authentication.mechanism.http.HttpMessageContext;
import javax.security.enterprise.authentication.mechanism.http.LoginToContinue;
import javax.security.enterprise.authentication.mechanism.http.RememberMe;
import javax.security.enterprise.credential.Credential;
import javax.security.enterprise.identitystore.IdentityStore;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
/**
*
* @author Patrick
*/
@AutoApplySession // For "Is user already logged-in?"
@RememberMe(
cookieMaxAgeSeconds = 60 * 60 * 24 * 14, // 14 days
cookieSecureOnly = false, // Remove this when login is served over HTTPS.
isRememberMeExpression = "#{self.isRememberMe(httpMessageContext)}"
)
@LoginToContinue(
loginPage = "/index.xhtml",
errorPage = "/error.xhtml",
useForwardToLogin = true
)
@ApplicationScoped
public class ApplicationConfig implements HttpAuthenticationMechanism{
final static Logger LOGGER = LogManager.getLogger(ApplicationConfig.class);
public ApplicationConfig() {
}
@Inject
private IdentityStore identityStore;
@Inject
private ManagedPerson managedPerson;
@EJB
private PersonManager personManager;
@PostConstruct
private void init(){
managedPerson.getLogins();
personManager.demo();
System.out.println("PostConstruct DEMO");
}
@Override
public AuthenticationStatus validateRequest(HttpServletRequest req, HttpServletResponse res, HttpMessageContext context) {
Credential credential = context.getAuthParameters().getCredential();
if (credential != null) {
return context.notifyContainerAboutLogin(this.identityStore.validate(credential));
} else {
return context.doNothing();
}
}
// this was called on @RememberMe annotations
public Boolean isRememberMe(HttpMessageContext httpMessageContext) {
return httpMessageContext.getAuthParameters().isRememberMe();
}
@Override
public void cleanSubject(HttpServletRequest request, HttpServletResponse response, HttpMessageContext httpMessageContext) {
HttpAuthenticationMechanism.super.cleanSubject(request, response, httpMessageContext);
}
}