List of usage examples for org.apache.wicket.authroles.authentication AuthenticatedWebSession get
public static AuthenticatedWebSession get()
From source file:com.apachecon.memories.ScrapbookPage.java
License:Apache License
@SuppressWarnings({ "rawtypes", "unchecked" }) public ScrapbookPage() { add(new ExternalLink("apacheCon", "http://na11.apachecon.com/")); add(new BookmarkablePageLink("logo", Index.class)); List<Class<? extends Page>> links = new ArrayList<Class<? extends Page>>(); links.add(Index.class); links.add(Upload.class); Roles roles = AuthenticatedWebSession.get().getRoles(); if (roles != null && roles.hasRole("admin")) { links.add(Browse.class); links.add(Approve.class); links.add(Logout.class); } else {// w ww .j av a 2s . c o m links.add(Browse.class); links.add(SignIn.class); } add(new ListView<Class>("menu", links) { private static final long serialVersionUID = 1L; @Override protected void populateItem(ListItem<Class> item) { BookmarkablePageLink link = new BookmarkablePageLink("link", item.getModelObject()); String simpleName = item.getModelObject().getSimpleName(); if (getPage().getClass().equals(item.getModelObject())) { item.add(AttributeModifier.append("class", "active")); } link.add(new Label("label", simpleName)); item.add(link); } }); }
From source file:com.apachecon.memories.session.Logout.java
License:Apache License
public Logout() { AuthenticatedWebSession.get().invalidateNow(); RequestCycle.get().setResponsePage(Index.class); }
From source file:com.barchart.kerberos.server.ui.panel.login.LoginPanel.java
License:Apache License
/** * Sign in user if possible./*from w ww .java 2 s . co m*/ * * @param username * The username * @param password * The password * @return True if signin was successful */ private boolean signIn(final String username, final String password) { return AuthenticatedWebSession.get().signIn(username, password); }
From source file:com.barchart.kerberos.server.ui.panel.login.LoginPanel.java
License:Apache License
/** * @return true, if signed in */ private boolean isSignedIn() { return AuthenticatedWebSession.get().isSignedIn(); }
From source file:com.github.ilmoeuro.hackmikkeli2016.ui.HmSession.java
License:Open Source License
@SuppressWarnings("unchecked") public static HmSession get() { try {/*from w w w . j ava 2s . c o m*/ return (HmSession) AuthenticatedWebSession.get(); } catch (ClassCastException ex) { String error = "Called get() from wrong app"; log.error(error, ex); throw new RuntimeException(error, ex); } }
From source file:com.romeikat.datamessie.core.base.ui.page.AbstractAuthenticatedPage.java
License:Open Source License
private boolean redirectToSignInPageIfNecessary() { if (!AuthenticatedWebSession.get().isSignedIn()) { final AuthenticatedWebApplication app = (AuthenticatedWebApplication) Application.get(); app.restartResponseAtSignInPage(); return true; }//from ww w . j a va 2s . c o m return false; }
From source file:com.romeikat.datamessie.core.base.ui.page.AbstractAuthenticatedPage.java
License:Open Source License
private void initialize() { // Active project final IModel<ProjectDto> activeProjectModel = new LoadableDetachableModel<ProjectDto>() { private static final long serialVersionUID = 1L; @Override/* w w w . j a v a 2 s .c o m*/ protected ProjectDto load() { // Determine requested project id final StringValue projectParameter = getRequest().getRequestParameters() .getParameterValue("project"); // Load respective project ProjectDto activeProject; if (projectParameter.isNull()) { activeProject = getDefaultProject(); } else { final Long userId = DataMessieSession.get().getUserId(); activeProject = projectDao.getAsDto(sessionFactory.getCurrentSession(), projectParameter.toLong(), userId); if (activeProject == null) { activeProject = getDefaultProject(); } } // Ensure project parameter if (activeProject != null) { getPageParameters().set("project", activeProject.getId()); DataMessieSession.get().getDocumentsFilterSettings().setProjectId(activeProject.getId()); } // Done return activeProject; } }; aciveProjectDropDownChoice = new ProjectSelector("activeProjectSelector", activeProjectModel) { private static final long serialVersionUID = 1L; @Override protected void onSelectionChanged(final ProjectDto newSelection) { if (newSelection == null) { return; } final PageParameters projectPageParameters = new PageParameters(); final Long selectedProjectId = newSelection.getId(); projectPageParameters.set("project", selectedProjectId); final Class<? extends Page> responsePage = AbstractAuthenticatedPage.this.getNavigationLinkClass(); final PageParameters pageParameters = getDefaultPageParameters(projectPageParameters); AbstractAuthenticatedPage.this.setResponsePage(responsePage, pageParameters); } @Override protected boolean wantOnSelectionChangedNotifications() { return true; } }; add(aciveProjectDropDownChoice); // Navigation links final List<NavigationLink<? extends Page>> navigationLinks = getDataMessieApplication() .getNavigationLinks(); final ListView<NavigationLink<? extends Page>> navigationLinksListView = new ListView<NavigationLink<? extends Page>>( "navigationLinks", navigationLinks) { private static final long serialVersionUID = 1L; @Override protected void populateItem(final ListItem<NavigationLink<? extends Page>> item) { // Link final NavigationLink<? extends Page> navigationLink = item.getModelObject(); final PageParameters projectPageParameters = createProjectPageParameters(); final BookmarkablePageLink<? extends Page> bookmarkablePageLink = createBookmarkablePageLink( "navigationLink", navigationLink, projectPageParameters); final Label bookmarkablePageLinkLabel = new Label("navigationLinkLabel", navigationLink.getLabel()); // Active link if (AbstractAuthenticatedPage.this.getNavigationLinkClass() == navigationLink.getPageClass()) { markLinkSelected(bookmarkablePageLink); } // Done bookmarkablePageLink.add(bookmarkablePageLinkLabel); item.add(bookmarkablePageLink); } }; add(navigationLinksListView); // Sign out link signOutLink = new Link<SignInPage>("signOutLink") { private static final long serialVersionUID = 1L; @Override public void onClick() { AuthenticatedWebSession.get().invalidate(); setResponsePage(getApplication().getHomePage()); } }; add(signOutLink); // Side panels final List<SidePanel> sidePanels = getDataMessieApplication().getSidePanels(); final ListView<SidePanel> sidePanelsListView = new ListView<SidePanel>("sidePanels", sidePanels) { private static final long serialVersionUID = 1L; @Override protected void populateItem(final ListItem<SidePanel> item) { // Link final SidePanel sidePanel = item.getModelObject(); final Panel panel = sidePanel.getPanel(); item.add(panel); } }; add(sidePanelsListView); // Task executions container final WebMarkupContainer taskExecutionsContainer = new WebMarkupContainer("taskExecutionsContainer"); taskExecutionsContainer.setOutputMarkupId(true); taskExecutionsContainer.add(new AjaxSelfUpdatingTimerBehavior(Duration.seconds(selfUpdatingInterval))); add(taskExecutionsContainer); // Task executions taskExecutionsPanel = new AjaxLazyLoadPanel("taskExecutionsPanel") { private static final long serialVersionUID = 1L; @Override public Component getLazyLoadComponent(final String id) { final TaskExecutionsPanel taskExecutionsPanel = new TaskExecutionsPanel(id); return taskExecutionsPanel; } }; taskExecutionsContainer.add(taskExecutionsPanel); }
From source file:com.romeikat.datamessie.core.base.ui.page.SignInPage.java
License:Open Source License
@Override protected void onInitialize() { super.onInitialize(); // Signin page sould be stateless setStatelessHint(true);//w w w. java2 s . c om // Form final StatelessForm<Void> form = new StatelessForm<Void>("signInForm") { private static final long serialVersionUID = 1L; @Override protected void onSubmit() { if (Strings.isEmpty(username)) { return; } // Authenticate final boolean authResult = AuthenticatedWebSession.get().signIn(username, password); // If authentication succeeds, redirect user to the requested page if (authResult) { continueToOriginalDestination(); // If we reach this line there was no intercept page, so go to home page setResponsePage(getApplication().getHomePage()); } } }; form.setDefaultModel(new CompoundPropertyModel<SignInPage>(this)); add(form); // Username final TextField<String> usernameTextField = new TextField<String>("username"); usernameTextField.add(new FocusBehavior()); form.add(usernameTextField); // Password final PasswordTextField passwordTextField = new PasswordTextField("password"); form.add(passwordTextField); }
From source file:cz.muni.fi.pa165.languageschoolweb.security.UserRolesAuthorizer.java
License:Apache License
/** * @see org.apache.wicket.authorization.strategies.role.IRoleCheckingStrategy#hasAnyRole(Roles) *///from w w w . ja v a 2 s .c o m @Override public boolean hasAnyRole(Roles roles) { SpringAuthenticatedWebSession session = (SpringAuthenticatedWebSession) AuthenticatedWebSession.get(); Roles loggedRoles = session.getLoggedRoles(); return loggedRoles.hasAnyRole(roles); }
From source file:de.inren.security.SignInPage.java
License:Apache License
@Override protected void onInitialize() { super.onInitialize(); StatelessForm form = new StatelessForm("form") { @Override/*from w ww . jav a 2 s. c om*/ protected void onSubmit() { if (Strings.isEmpty(username) || Strings.isEmpty(password)) return; boolean authResult = AuthenticatedWebSession.get().signIn(username, password); if (authResult) { continueToOriginalDestination(); setResponsePage(Application.get().getHomePage()); } else { error("Username and password are not equal!"); } } }; form.setDefaultModel(new CompoundPropertyModel(this)); form.add(new TextField("username")); form.add(new PasswordTextField("password")); form.add(new FeedbackPanel("feedbackPanel")); add(form); }