List of usage examples for org.apache.shiro.config ConfigurationException ConfigurationException
public ConfigurationException(Throwable cause)
From source file:aaa.realms.MySQLRealm.java
License:Apache License
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { VTNAuthNToken upToken = (VTNAuthNToken) token; String username = upToken.getUsername(); String domainID = Integer.toString(upToken.getDomainId()); // Null username is invalid if (username == null) { throw new AccountException("Null usernames are not allowed by this realm."); }/*w w w . j av a 2 s. c o m*/ Connection conn = null; SimpleAuthenticationInfo info = null; try { conn = dataSource.getConnection(); Set<String> domains = getUserDomain(conn, username); if (!(domains.contains(domainID))) { throw new AuthenticationException("Domain not found"); } String password = null; String salt = null; switch (saltStyle) { case NO_SALT: password = getPasswordForUser(conn, username)[0]; break; case CRYPT: // TODO: separate password and hash from getPasswordForUser[0] throw new ConfigurationException("Not implemented yet"); //break; case COLUMN: String[] queryResults = getPasswordForUser(conn, username); password = queryResults[0]; salt = queryResults[1]; break; case EXTERNAL: password = getPasswordForUser(conn, username)[0]; salt = getSaltForUser(username); } if (password == null) { throw new UnknownAccountException("No account found for user [" + username + "]"); } info = new SimpleAuthenticationInfo(username, password.toCharArray(), getName()); if (salt != null) { info.setCredentialsSalt(ByteSource.Util.bytes(salt)); } } catch (SQLException e) { final String message = "There was a SQL error while authenticating user [" + username + "]"; if (log.isErrorEnabled()) { log.error(message, e); } // Rethrow any SQL errors as an authentication exception throw new AuthenticationException(message, e); } finally { JdbcUtils.closeConnection(conn); } return info; }
From source file:br.com.betsportclub.controller.security.SecurityRealm.java
License:Apache License
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { UsernamePasswordToken upToken = (UsernamePasswordToken) token; String username = upToken.getUsername(); // Null username is invalid if (username == null) { throw new AccountException("Null usernames are not allowed by this realm."); }/* ww w.j a v a2 s .c o m*/ Connection conn = null; SimpleAuthenticationInfo info = null; try { conn = dataSource.getConnection(); String password = null; String salt = null; switch (saltStyle) { case NO_SALT: password = getPasswordForUser(conn, username)[0]; break; case CRYPT: // TODO: separate password and hash from getPasswordForUser[0] throw new ConfigurationException("Not implemented yet"); //break; case COLUMN: String[] queryResults = getPasswordForUser(conn, username); password = queryResults[0]; salt = queryResults[1]; break; case EXTERNAL: password = getPasswordForUser(conn, username)[0]; salt = getSaltForUser(username); } if (password == null) { throw new UnknownAccountException("No account found for user [" + username + "]"); } info = new SimpleAuthenticationInfo(username, password.toCharArray(), getName()); if (salt != null) { info.setCredentialsSalt(ByteSource.Util.bytes(salt)); } } catch (SQLException e) { final String message = "There was a SQL error while authenticating user [" + username + "]"; if (log.isErrorEnabled()) { log.error(message, e); } // Rethrow any SQL errors as an authentication exception throw new AuthenticationException(message, e); } finally { JdbcUtils.closeConnection(conn); } return info; }
From source file:co.cask.cdap.security.authorization.sentry.policy.PrivilegeValidator.java
License:Apache License
@Override public void validate(PrivilegeValidatorContext context) throws ConfigurationException { Deque<String> privileges = Lists .newLinkedList(PolicyConstants.AUTHORIZABLE_SPLITTER.split(context.getPrivilege())); // Check privilege splits length is at least 2 the smallest privilege possible with action. Example: // smallest privilege of size 2 : instance=instance1->action=read if (privileges.size() < 2) { throw new ConfigurationException("Invalid Privilege Exception: Privilege can be given to an " + "instance or " + "instance -> namespace or " + "instance -> namespace -> (artifact|applications|stream|dataset) or " + "instance -> namespace -> application -> program"); }/*from ww w . j a v a2s .co m*/ // Check the last part is a valid action if (!isAction(privileges.removeLast())) { throw new ConfigurationException("CDAP privilege must end with a valid action.\n"); } // the first valid authorizable type is instance since all privilege string should start with it Set<Authorizable.AuthorizableType> validTypes = EnumSet.of(Authorizable.AuthorizableType.INSTANCE); while (!privileges.isEmpty()) { Authorizable authorizable = ModelAuthorizables.from(privileges.removeFirst()); // if we were expecting no validTypes for this authorizable type that means the privilege string has more // authorizable when we were expecting it to end if (validTypes.isEmpty()) { throw new ConfigurationException(String.format( "Was expecting end of Authorizables. Found unexpected " + "authorizable %s of type %s", authorizable, authorizable.getAuthzType())); } validTypes = validatePrivilege(authorizable.getAuthzType(), validTypes); } }
From source file:co.cask.cdap.security.authorization.sentry.policy.PrivilegeValidator.java
License:Apache License
/** * Validates that the given authorizable type exists in the validTypes and updates the validTypes depending on the * current authorizable type./*from w w w. j ava 2s . co m*/ * * @param authzType the current authorizable type * @param validTypes expected authorizable types * @return updates {@link Set} of {@link Authorizable.AuthorizableType} which are expected for the given * authorizable type */ private Set<Authorizable.AuthorizableType> validatePrivilege(Authorizable.AuthorizableType authzType, Set<Authorizable.AuthorizableType> validTypes) { if (!validTypes.contains(authzType)) { throw new ConfigurationException(String.format("Expecting authorizable types %s but found %s", validTypes.toString(), authzType)); } switch (authzType) { case INSTANCE: validTypes = EnumSet.of(Authorizable.AuthorizableType.NAMESPACE); break; case NAMESPACE: validTypes = EnumSet.of(Authorizable.AuthorizableType.APPLICATION, Authorizable.AuthorizableType.ARTIFACT, Authorizable.AuthorizableType.STREAM, Authorizable.AuthorizableType.DATASET); break; case APPLICATION: validTypes = EnumSet.of(Authorizable.AuthorizableType.PROGRAM); break; case ARTIFACT: case STREAM: case DATASET: case PROGRAM: validTypes = new HashSet<>(); // we don't expect any other authorizable after this } return validTypes; }
From source file:com.charmyin.shiro.realm.jdbc.JMongodbRealm.java
License:Apache License
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { UsernamePasswordToken upToken = (UsernamePasswordToken) token; String username = upToken.getUsername(); // Null username is invalid if (username == null) { throw new AccountException("Null usernames are not allowed by this realm."); }//from w ww .j a va 2s.c o m SimpleAuthenticationInfo info = null; try { //conn = dataSource.getConnection(); String password = null; String salt = null; switch (saltStyle) { case NO_SALT: password = getPasswordForUser(username)[0]; break; case CRYPT: // TODO: separate password and hash from getPasswordForUser[0] throw new ConfigurationException("Not implemented yet"); //break; case COLUMN: String[] queryResults = getPasswordForUser(username); password = queryResults[0]; salt = queryResults[1]; break; case EXTERNAL: password = getPasswordForUser(username)[0]; salt = getSaltForUser(username); } if (password == null) { throw new UnknownAccountException("No account found for user [" + username + "]"); } info = new SimpleAuthenticationInfo(username, password.toCharArray(), getName()); if (salt != null) { info.setCredentialsSalt(ByteSource.Util.bytes(salt)); } } catch (MongoException e) { final String message = "There was a SQL error while authenticating user [" + username + "]"; if (log.isErrorEnabled()) { log.error(message, e); } // Rethrow any SQL errors as an authentication exception throw new AuthenticationException(message, e); } return info; }
From source file:com.cssnb.commons.shiro.MyJdbcRealm.java
License:Apache License
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { //UsernamePasswordToken upToken = (UsernamePasswordToken) token; CaptchaUsernamePasswordToken upToken = (CaptchaUsernamePasswordToken) token; //?? ?/*from w w w. j a v a 2s .co m*/ String captcha = null; Object obj_captcha = SecurityUtils.getSubject().getSession().getAttribute(Constants.CAPTCHA_KEY); //Object obj_count = SecurityUtils.getSubject().getSession().getAttribute( "login_fail_count" ); //int failed_count = (obj_count ==null || !(obj_count instanceof Integer))?0:(Integer)obj_count; if (obj_captcha instanceof String) captcha = (String) obj_captcha; log.debug("you input:{},img:{}", upToken.getCaptcha(), captcha); if (captcha != null //&& failed_count >0 && !captcha.equalsIgnoreCase(upToken.getCaptcha())) { throw new IncorrectCaptchaException("???"); } String username = upToken.getUsername(); // Null username is invalid if (username == null) { throw new AccountException("Null usernames are not allowed by this realm."); } Connection conn = null; SimpleAuthenticationInfo info = null; try { conn = dataSource.getConnection(); String password = null; String salt = null; switch (saltStyle) { case NO_SALT: password = getPasswordForUser(conn, username)[0]; break; case CRYPT: // TODO: separate password and hash from getPasswordForUser[0] throw new ConfigurationException("Not implemented yet"); //break; case COLUMN: String[] queryResults = getPasswordForUser(conn, username); password = queryResults[0]; salt = queryResults[1]; break; case EXTERNAL: password = getPasswordForUser(conn, username)[0]; salt = getSaltForUser(username); } if (password == null) { throw new UnknownAccountException("No account found for user [" + username + "]"); } info = new SimpleAuthenticationInfo(new ShiroUser(username, username), password.toCharArray(), getName()); if (salt != null) { info.setCredentialsSalt(ByteSource.Util.bytes(salt)); } } catch (SQLException e) { final String message = "There was a SQL error while authenticating user [" + username + "]"; if (log.isErrorEnabled()) { log.error(message, e); } // Rethrow any SQL errors as an authentication exception throw new AuthenticationException(message, e); } finally { JdbcUtils.closeConnection(conn); } return info; }
From source file:com.github.pires.example.shiro.SMRealm.java
License:Apache License
@Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { UsernamePasswordToken upToken = (UsernamePasswordToken) token; final String email = upToken.getUsername(); // null email is invalid if (email == null) { throw new AccountException("Null email is not allowed by this realm."); }/*from w w w .ja v a2s. com*/ Connection conn = null; SimpleAuthenticationInfo info = null; try { conn = dataSource.getConnection(); String password = null; String salt = null; switch (saltStyle) { case NO_SALT: password = getPasswordForUser(conn, email)[0]; break; case CRYPT: // TODO: separate password and hash from getPasswordForUser[0] throw new ConfigurationException("Not implemented yet"); // break; case COLUMN: String[] queryResults = getPasswordForUser(conn, email); password = queryResults[0]; salt = queryResults[1]; break; case EXTERNAL: password = getPasswordForUser(conn, email)[0]; salt = getSaltForUser(email); } if (password == null) { throw new UnknownAccountException("No account found for user identified by [" + email + "]"); } info = new SimpleAuthenticationInfo(email, password.toCharArray(), getName()); if (salt != null) { info.setCredentialsSalt(ByteSource.Util.bytes(salt)); } } catch (SQLException e) { final String message = "There was a SQL error while authenticating user identified by [" + email + "]"; logger.error(message, e); // rethrow any SQL errors as an authentication exception throw new AuthenticationException(message, e); } finally { JdbcUtils.closeConnection(conn); } return info; }
From source file:com.stormpath.shiro.servlet.config.AppendingConfigFactory.java
License:Apache License
private Collection<PropertiesSource> getPropertiesSources(ServletContext servletContext) { Object attribute = servletContext.getAttribute(SHIRO_STORMPATH_ADDITIONAL_PROPERTIES_ATTRIBUTE); if (attribute != null && !(attribute instanceof Collection)) { throw new ConfigurationException( "Servlet Context attribute: '" + SHIRO_STORMPATH_ADDITIONAL_PROPERTIES_ATTRIBUTE + "' should have been a collection, but was: '" + attribute.getClass() + "'"); }/*from w ww .java2 s.c o m*/ return (Collection<PropertiesSource>) attribute; }
From source file:com.stormpath.shiro.spring.boot.autoconfigure.StormpathShiroWebAutoConfiguration.java
License:Apache License
@Bean public ShiroPrioritizedFilterChainResolver shiroPrioritizedFilterChainResolver( @Qualifier("filterShiroFilterRegistrationBean") FilterRegistrationBean filterShiroFilterRegistrationBean, @Qualifier("stormpathFilter") FilterRegistrationBean stormpathFilter) { if (!(filterShiroFilterRegistrationBean.getFilter() instanceof AbstractShiroFilter)) { throw new ConfigurationException( "Shiro filter registration bean did not contain a AbstractShiroFitler"); }// w w w . ja va 2 s . c o m AbstractShiroFilter filter = (AbstractShiroFilter) filterShiroFilterRegistrationBean.getFilter(); FilterChainResolver originalFilterChainResolver = filter.getFilterChainResolver(); List<Filter> prioritizedFilters = new ArrayList<>(); prioritizedFilters.add(stormpathFilter.getFilter()); stormpathFilter.setEnabled(false); prioritizedFilters.add(new StormpathShiroPassiveLoginFilter()); ShiroPrioritizedFilterChainResolver prioritizedFilterChainResolver = new ShiroPrioritizedFilterChainResolver( originalFilterChainResolver, prioritizedFilters); filter.setFilterChainResolver(prioritizedFilterChainResolver); return prioritizedFilterChainResolver; }
From source file:com.wms.studio.filter.HttpFilter.java
License:Apache License
protected int toPort(Object mappedValue) { String[] ports = (String[]) mappedValue; if (ports == null || ports.length == 0) { return getPort(); }//from ww w . ja v a 2 s . c o m if (ports.length > 1) { throw new ConfigurationException("PortFilter can only be configured with a single port. You have " + "configured " + ports.length + ": " + StringUtils.toString(ports)); } return Integer.parseInt(ports[0]); }