List of usage examples for org.apache.wicket.authroles.authorization.strategies.role Roles hasRole
public boolean hasRole(final String role)
From source file:ca.travelagency.authentication.AuthenticatedSessionTest.java
License:Apache License
@Test public void testGetRoles() throws Exception { // setup//from ww w . jav a2 s. c om fixture.signIn(systemUser.getName(), PASSWORD); // execute Roles roles = fixture.getRoles(); // validate for (SystemUserRole systemUserRole : systemUser.getSystemUserRoles()) { Assert.assertTrue(systemUserRole.getRole().name(), roles.hasRole(systemUserRole.getRole().name())); } Mockito.verify(systemUserService).authorize(systemUser.getName(), PASSWORD); Mockito.verify(daoSupport).find(SystemUser.class, systemUser.getId()); }
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 {/*from w w w . j a v 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.userweave.application.UserWeaveApplication.java
License:Open Source License
private void setupAuthorization() { UserWeaveAuthorizationStrategy authStrat = new UserWeaveAuthorizationStrategy(); RoleAuthorizationStrategy roleStrat = new RoleAuthorizationStrategy(new IRoleCheckingStrategy() { @Override//from ww w . j a v a 2 s.c om public boolean hasAnyRole(Roles roles) { /* * Only deny roles contain the empty role. If this fact changes, * go to hell. */ if (roles.hasRole("")) { return false; } else { User user = UserWeaveSession.get().getUser(); return user.isAdmin() || user.hasAnyRole(roles); } } }); roleStrat.add(authStrat); ISecuritySettings securitySettings = getSecuritySettings(); //securitySettings.setAuthorizationStrategy(authStrat); securitySettings.setAuthorizationStrategy(roleStrat); securitySettings.setUnauthorizedComponentInstantiationListener(authStrat); if (!ENCRYPTION) { securitySettings.setCryptFactory(new CachingSunJceCryptFactory( HashProvider.md5("do what you desire", System.currentTimeMillis()))); } }
From source file:sf.wicklet.gwt.site.server.MyAuthenticatedWebSession.java
License:Apache License
public boolean hasRole(final Role role) { final Roles roles = getRoles(); return roles != null && roles.hasRole(role.name()); }
From source file:sf.wicklet.gwt.site.server.MyAuthenticatedWebSession.java
License:Apache License
public boolean hasAllRole(final Role... roles) { final Roles a = getRoles(); if (a == null) { return false; }// ww w .jav a 2 s . co m for (final Role role : roles) { if (!a.hasRole(role.name())) { return false; } } return true; }
From source file:sf.wicklet.gwt.site.server.MyAuthenticatedWebSession.java
License:Apache License
public boolean hasAnyRole(final Role... roles) { final Roles a = getRoles(); if (a == null) { return false; }//from www. j a va 2s.c om for (final Role role : roles) { if (a.hasRole(role.name())) { return true; } } return false; }