org.actioncontrollerdemo.UserController Maven / Gradle / Ivy
package org.actioncontrollerdemo;
import org.actioncontroller.ContentBody;
import org.actioncontroller.GET;
import org.actioncontroller.POST;
import org.actioncontroller.RequestParam;
import org.actioncontroller.SendRedirect;
import org.actioncontroller.UnencryptedCookie;
import java.security.Principal;
import java.util.Optional;
import java.util.function.Consumer;
public class UserController {
@GET("/user/optional")
@ContentBody
public String getUsername(
@RequestParam.Principal Optional principal
) {
return "Hello, " + principal.map(Principal::getName).orElse("stranger");
}
@GET("/user/required")
@ContentBody
public String getRealUsername(
@RequestParam.Principal Principal principal
) {
return "Hello - required, " + principal.getName();
}
@GET("/user/admin")
@ContentBody
public String getAdminPage(
@RequestParam.Principal AdminPrincipal principal
) {
return "Hello - boss, " + principal.getName();
}
@GET("/login")
@ContentBody(contentType = "text/html")
public String getLogin(@RequestParam("redirectAfterLogin") Optional redirectAfterLogin) {
return "";
}
@POST("/login")
@SendRedirect
public String postLogin(
@RequestParam("username") String username,
@RequestParam("redirectAfterLogin") Optional redirectAfterLogin,
@UnencryptedCookie(value = "username", secure = false) Consumer setUsername
) {
setUsername.accept(username);
return redirectAfterLogin.orElse("user/required");
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy