/** * Construct a new LoginConfig with the specified properties. * * @param authMethod The authentication method * @param realmName The realm name * @param loginPage The login page URI * @param errorPage The error page URI */ public LoginConfig(String authMethod, String realmName, String loginPage, String errorPage) { super(); setAuthMethod(authMethod); setRealmName(realmName); setLoginPage(loginPage); setErrorPage(errorPage); }
LoginConfig loginConfig = new LoginConfig(); loginConfig.setAuthMethod("DIGEST"); loginConfig.setRealmName(InMemoryRealm.NAME); context.setLoginConfig(loginConfig);
public boolean contextHasFormBasedSecurityConstraint(){ if(_contextHasFormBasedSecurityConstraint != null) { return _contextHasFormBasedSecurityConstraint.booleanValue(); } final SecurityConstraint[] constraints = getContext().findConstraints(); final LoginConfig loginConfig = getContext().getLoginConfig(); _contextHasFormBasedSecurityConstraint = constraints != null && constraints.length > 0 && loginConfig != null && HttpServletRequest.FORM_AUTH.equals( loginConfig.getAuthMethod() ); return _contextHasFormBasedSecurityConstraint; }
throw new IllegalArgumentException (sm.getString("standardContext.loginConfig.required")); String loginPage = config.getLoginPage(); if ((loginPage != null) && !loginPage.startsWith("/")) { if (isServlet22()) { log.debug(sm.getString("standardContext.loginConfig.loginWarning", loginPage)); config.setLoginPage("/" + loginPage); } else { throw new IllegalArgumentException String errorPage = config.getErrorPage(); if ((errorPage != null) && !errorPage.startsWith("/")) { if (isServlet22()) { log.debug(sm.getString("standardContext.loginConfig.errorWarning", errorPage)); config.setErrorPage("/" + errorPage); } else { throw new IllegalArgumentException
sb.append(" <login-config>\n"); appendElement(sb, INDENT4, "auth-method", loginConfig.getAuthMethod()); appendElement(sb,INDENT4, "realm-name", loginConfig.getRealmName()); if (loginConfig.getErrorPage() != null || loginConfig.getLoginPage() != null) { sb.append(" <form-login-config>\n"); appendElement(sb, INDENT6, "form-login-page", loginConfig.getLoginPage()); appendElement(sb, INDENT6, "form-error-page", loginConfig.getErrorPage()); sb.append(" </form-login-config>\n");
this.redirectTo(request, response, request.getServletPath()); } else { this.redirectTo(request, response, loginConfig.getErrorPage()); this.redirectTo(request, response, loginConfig.getLoginPage()); return false;
static void enableBasicAuth(Context ctx, boolean enableSSL) { LoginConfig loginConfig = new LoginConfig(); loginConfig.setAuthMethod("BASIC"); ctx.setLoginConfig(loginConfig); ctx.addSecurityRole(AUTH_ROLE); SecurityConstraint securityConstraint = new SecurityConstraint(); securityConstraint.addAuthRole(AUTH_ROLE); if (enableSSL) { securityConstraint.setUserConstraint(TransportGuarantee.CONFIDENTIAL.toString()); } SecurityCollection securityCollection = new SecurityCollection(); securityCollection.addPattern("/*"); securityConstraint.addCollection(securityCollection); ctx.addConstraint(securityConstraint); }
@Override protected boolean forwardToErrorPageInternal(Request request, HttpServletResponse response, Object loginConfig) throws IOException { if (loginConfig == null) return false; LoginConfig config = (LoginConfig)loginConfig; if (config.getErrorPage() == null) return false; // had to do this to get around compiler/IDE issues :( try { Method method = null; /* for (Method m : getClass().getDeclaredMethods()) { if (m.getName().equals("forwardToErrorPage")) { method = m; break; } } */ method = FormAuthenticator.class.getDeclaredMethod("forwardToErrorPage", Request.class, HttpServletResponse.class, LoginConfig.class); method.setAccessible(true); method.invoke(this, request, response, config); } catch (Exception e) { throw new RuntimeException(e); } return true; }
public LoginConfigBuilder authMethod(final String authMethod) { loginConfig.setAuthMethod(authMethod); return this; }
log.debug(sm.getString("formAuthenticator.forwardLogin", request.getRequestURI(), request.getMethod(), config.getLoginPage(), context.getName())); String loginPage = config.getLoginPage(); if (loginPage == null || loginPage.length() == 0) { String msg = sm.getString("formAuthenticator.noLoginPage",
@Override public void lifecycleEvent(LifecycleEvent event) { try { Context context = (Context) event.getLifecycle(); if (event.getType().equals(Lifecycle.CONFIGURE_START_EVENT)) { context.setConfigured(true); } // LoginConfig is required to process @ServletSecurity // annotations if (context.getLoginConfig() == null) { context.setLoginConfig( new LoginConfig("NONE", null, null, null)); context.getPipeline().addValve(new NonLoginAuthenticator()); } } catch (ClassCastException e) { return; } }
public LoginConfigBuilder loginPage(final String loginPage) { loginConfig.setLoginPage(loginPage); return this; }
public LoginConfigBuilder realmName(final String realmName) { loginConfig.setRealmName(realmName); return this; }
public LoginConfigBuilder errorPage(final String errorPage) { loginConfig.setErrorPage(errorPage); return this; }
protected static String getRealmName(Context context) { if (context == null) { // Very unlikely return REALM_NAME; } LoginConfig config = context.getLoginConfig(); if (config == null) { return REALM_NAME; } String result = config.getRealmName(); if (result == null) { return REALM_NAME; } return result; }
throw new IllegalArgumentException (sm.getString("standardContext.loginConfig.required")); String loginPage = config.getLoginPage(); if ((loginPage != null) && !loginPage.startsWith("/")) { if (isServlet22()) { log.debug(sm.getString("standardContext.loginConfig.loginWarning", loginPage)); config.setLoginPage("/" + loginPage); } else { throw new IllegalArgumentException String errorPage = config.getErrorPage(); if ((errorPage != null) && !errorPage.startsWith("/")) { if (isServlet22()) { log.debug(sm.getString("standardContext.loginConfig.errorWarning", errorPage)); config.setErrorPage("/" + errorPage); } else { throw new IllegalArgumentException
sb.append(" <login-config>\n"); appendElement(sb, INDENT4, "auth-method", loginConfig.getAuthMethod()); appendElement(sb,INDENT4, "realm-name", loginConfig.getRealmName()); if (loginConfig.getErrorPage() != null || loginConfig.getLoginPage() != null) { sb.append(" <form-login-config>\n"); appendElement(sb, INDENT6, "form-login-page", loginConfig.getLoginPage()); appendElement(sb, INDENT6, "form-error-page", loginConfig.getErrorPage()); sb.append(" </form-login-config>\n");
this.redirectTo(request, response, request.getServletPath()); } else { this.redirectTo(request, response, loginConfig.getErrorPage()); this.redirectTo(request, response, loginConfig.getLoginPage()); return false;
static void enableBasicAuth(Context ctx, boolean enableSSL) { LoginConfig loginConfig = new LoginConfig(); loginConfig.setAuthMethod("BASIC"); ctx.setLoginConfig(loginConfig); ctx.addSecurityRole(AUTH_ROLE); SecurityConstraint securityConstraint = new SecurityConstraint(); securityConstraint.addAuthRole(AUTH_ROLE); if (enableSSL) { securityConstraint.setUserConstraint(TransportGuarantee.CONFIDENTIAL.toString()); } SecurityCollection securityCollection = new SecurityCollection(); securityCollection.addPattern("/*"); securityConstraint.addCollection(securityCollection); ctx.addConstraint(securityConstraint); }
@Override protected boolean forwardToErrorPageInternal(Request request, HttpServletResponse response, Object loginConfig) throws IOException { if (loginConfig == null) return false; LoginConfig config = (LoginConfig)loginConfig; if (config.getErrorPage() == null) return false; // had to do this to get around compiler/IDE issues :( try { Method method = null; /* for (Method m : getClass().getDeclaredMethods()) { if (m.getName().equals("forwardToErrorPage")) { method = m; break; } } */ method = FormAuthenticator.class.getDeclaredMethod("forwardToErrorPage", Request.class, HttpServletResponse.class, LoginConfig.class); method.setAccessible(true); method.invoke(this, request, response, config); } catch (Exception e) { throw new RuntimeException(e); } return true; }