List of usage examples for org.apache.shiro.authc SimpleAccount SimpleAccount
public SimpleAccount(Collection principals, Object credentials, String realmName, Set<String> roleNames,
Set<Permission> permissions)
From source file:graphene.security.tomcat.preaa.PreAASecurityRealm.java
License:Apache License
@Override protected AuthenticationInfo doGetAuthenticationInfo(final AuthenticationToken authToken) throws AuthenticationException { logger.debug("doGetAuthenticationInfo " + authToken.getPrincipal()); // return null; final UsernamePasswordToken upToken = (UsernamePasswordToken) authToken; G_User g_User = null;/*from w w w . j av a2 s. com*/ SimpleAccount account = null; try { g_User = userDataAccess.getByUsername(upToken.getUsername()); final Set<String> roleNames = CollectionUtils.asSet((String[]) null); account = new SimpleAccount(g_User.getUsername(), "password", getName(), roleNames, null); } catch (final AvroRemoteException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (account != null) { if (account.isLocked()) { throw new LockedAccountException("Account [" + account + "] is locked."); } if (account.isCredentialsExpired()) { final String msg = "The credentials for account [" + account + "] are expired"; throw new ExpiredCredentialsException(msg); } } else { logger.error("user was null"); } return account; }
From source file:graphene.security.tomcat.preaa.PreAASecurityRealm.java
License:Apache License
@Override protected AuthorizationInfo doGetAuthorizationInfo(final PrincipalCollection principals) { logger.debug("doGetAuthorizationInfo " + principals.asList()); // return null; final Set<String> roleNames = CollectionUtils.asSet((String[]) null); final SimpleAccount simpleAccount = new SimpleAccount(getUsername(principals), "password", getName(), roleNames, null);/*from w ww. j av a 2 s . co m*/ return simpleAccount; }
From source file:org.atteo.moonshine.shiro.simple.AdminSimpleAccountRealm.java
License:Apache License
public void addAccount(String username, String password, boolean isAdmin, String... roles) { Set<String> roleNames = CollectionUtils.asSet(roles); Set<Permission> permissions = null; if (isAdmin) { permissions = Sets.<Permission>newHashSet(new AllPermission()); }//from w w w . j a va 2 s .c o m SimpleAccount account = new SimpleAccount(username, password, getName(), roleNames, permissions); add(account); }
From source file:org.graylog2.security.realm.GraylogSimpleAccountRealm.java
License:Open Source License
public void addRootAccount(String username, String password) { LOG.debug("Adding root account named {}, having all permissions", username); add(new SimpleAccount(username, password, getName(), CollectionUtils.asSet("root"), CollectionUtils.<Permission>asSet(new AllPermission()))); }
From source file:org.graylog2.security.realm.RootAccountRealm.java
License:Open Source License
private void addRootAccount(String username, String password) { LOG.debug("Adding root account named {}, having all permissions", username); add(new SimpleAccount(username, password, getName(), CollectionUtils.asSet("root"), CollectionUtils.<Permission>asSet(new AllPermission()))); }
From source file:org.ms123.common.permission.MyRealm.java
License:Open Source License
public void addAccount(String username, String password, String... roles) { Set<String> roleNames = CollectionUtils.asSet(roles); SimpleAccount account = new SimpleAccount(username, password, getName(), roleNames, null); add(account);//from w w w .ja v a 2 s . co m }
From source file:org.ow2.proactive.workflowcatalog.security.RestSchedulerRealm.java
License:Open Source License
@Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException { UsernamePasswordToken usernamePasswordToken = (UsernamePasswordToken) authenticationToken; String user = authenticationToken.getPrincipal().toString(); String pass = getPass(usernamePasswordToken.getPassword()); String cred = getCred(usernamePasswordToken.getCredentials()); if (user == null || user.isEmpty()) throw new AuthenticationException("No user provided"); MyPrincipal principal = null;/*w ww . j ava 2 s.c o m*/ try { if (pass != null) { principal = mySecurityManagerService.findMyPrincipalByUsernamePassword(user, pass); } else if (cred != null) { principal = mySecurityManagerService.findMyPrincipalByUsernameCredentials(user, cred); } else { throw new LoginException("Neither pass nor credentials were provided for: " + user); } } catch (LoginException e) { throw new AuthenticationException("Login failed for user: " + user, e); } catch (SchedulerRestException e) { throw new AuthenticationException("REST error during login of user: " + user, e); } return new SimpleAccount(principal.getUsername(), principal.getCredentials(), getName(), principal.getRoles(), new HashSet()); }
From source file:org.sonatype.activemq.security.shiro.ShiroAuthenticationBrokerFilterTest.java
License:Open Source License
public void setUp() throws Exception { super.setUp(); PojoSimpleAccountRealm simpleAccountRealm = new PojoSimpleAccountRealm(); // jcoder has access to ALL queues and topics Set<Permission> jcoderPermissions = new HashSet<Permission>(); jcoderPermissions.add(new WildcardPermission("jms:queue:*")); jcoderPermissions.add(new WildcardPermission("jms:topic:*")); SimpleAccount jcoder = new SimpleAccount("jcoder", "jcoder123", simpleAccountRealm.getName(), Collections.<String>emptySet(), jcoderPermissions); simpleAccountRealm.add(jcoder);/*from w w w. jav a 2 s . c o m*/ // jcoder has access to all queues but NO topics Set<Permission> jbeanPermissions = new HashSet<Permission>(); jbeanPermissions.add(new WildcardPermission("jms:queue:*")); SimpleAccount jbean = new SimpleAccount("jbean", "jbean123", simpleAccountRealm.getName(), Collections.<String>emptySet(), jbeanPermissions); simpleAccountRealm.add(jbean); // onlyTestQueue has access to All topics and only the TEST queue Set<Permission> onlyTestQueuePermissions = new HashSet<Permission>(); onlyTestQueuePermissions.add(new WildcardPermission("jms:queue:TEST:read")); onlyTestQueuePermissions.add(new WildcardPermission("jms:topic:*")); SimpleAccount onlyTestQueue = new SimpleAccount("onlyTestQueue", "onlyTestQueue123", simpleAccountRealm.getName(), Collections.<String>emptySet(), onlyTestQueuePermissions); simpleAccountRealm.add(onlyTestQueue); // Set up the security manager DefaultSecurityManager securityManager = new DefaultSecurityManager(simpleAccountRealm); SecurityUtils.setSecurityManager(securityManager); // TODO maybe this should be configured as part of the Plugin and NOT using a ThreadLocal }