当前位置: 首页>>代码示例>>Java>>正文


Java BadCredentialsException类代码示例

本文整理汇总了Java中org.acegisecurity.BadCredentialsException的典型用法代码示例。如果您正苦于以下问题:Java BadCredentialsException类的具体用法?Java BadCredentialsException怎么用?Java BadCredentialsException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


BadCredentialsException类属于org.acegisecurity包,在下文中一共展示了BadCredentialsException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createSecurityComponents

import org.acegisecurity.BadCredentialsException; //导入依赖的package包/类
@Override
public SecurityComponents createSecurityComponents() {
    return new SecurityRealm.SecurityComponents(new AuthenticationManager() {
        public Authentication authenticate(Authentication authentication) throws AuthenticationException {
            if (authentication instanceof DeepinAuthenticationToken) {
                return authentication;
            }

            throw new BadCredentialsException("Unexpected authentication type: " + authentication);
        }
    }, new UserDetailsService() {
        public UserDetails loadUserByUsername(String username)  throws UserMayOrMayNotExistException, DataAccessException {
            throw new UserMayOrMayNotExistException("Cannot verify users in this context");
        }
    });
}
 
开发者ID:Iceyer,项目名称:deepin-oauth-plugin,代码行数:17,代码来源:DeepinSecurityRealm.java

示例2: additionalAuthenticationChecks

import org.acegisecurity.BadCredentialsException; //导入依赖的package包/类
@Override
protected void additionalAuthenticationChecks(UserDetails userDetails,
        UsernamePasswordAuthenticationToken authentication) throws AuthenticationException {
    Object salt = null;

    System.out.println("User pwd: "+userDetails.getPassword());
    System.out.println("Auth pwd raw: "+authentication.getCredentials().toString());
    
    if (getSaltSource() != null) {
        salt = getSaltSource().getSalt(userDetails);
    }
    
    System.out.println("Auth pwd: "+getPasswordEncoder().encodePassword(authentication.getCredentials().toString().trim(), salt));
    
    System.out.println("Salt: "+salt);
    System.out.println("Encoder: "+getPasswordEncoder());

    if (!getPasswordEncoder().isPasswordValid(userDetails.getPassword(),
            authentication.getCredentials().toString(), salt)) {
        throw new BadCredentialsException(messages.getMessage(
                "AbstractUserDetailsAuthenticationProvider.badCredentials",
                "Bad credentials"), userDetails);
    }
}
 
开发者ID:DIA-NZ,项目名称:webcurator,代码行数:25,代码来源:DebugDaoAuthenticationProvider.java

示例3: authenticate

import org.acegisecurity.BadCredentialsException; //导入依赖的package包/类
@Override
protected UserDetails authenticate(final String username, final String password)
        throws AuthenticationException {

    try {
        HtPasswdFile htpasswd = getHtPasswdFile();
        if (htpasswd.isPasswordValid(username, password)) {
            return new User(username, password,
                    true, true, true, true,
                    getAuthenticatedUserGroups(username));
        }
    } catch (Exception ex) {
        throw new BadCredentialsException(ex.getMessage());
    }
    String msg = String.format("Invalid user '%s' credentials", username);
    throw new BadCredentialsException(msg);
}
 
开发者ID:kkesha,项目名称:jenkins-htpasswd-auth,代码行数:18,代码来源:HtPasswdSecurityRealm.java

示例4: triggerManual

import org.acegisecurity.BadCredentialsException; //导入依赖的package包/类
@JavaScriptMethod
@Override
public void triggerManual(String projectName, String upstreamName, String buildId)
        throws TriggerException, AuthenticationException {
    try {
        LOG.fine("Trigger manual build " + projectName + " " + upstreamName + " " + buildId);
        AbstractProject project = ProjectUtil.getProject(projectName, Jenkins.getInstance());
        if (!project.hasPermission(Item.BUILD)) {
            throw new BadCredentialsException("Not authorized to trigger build");
        }
        AbstractProject upstream = ProjectUtil.getProject(upstreamName, Jenkins.getInstance());
        ManualTrigger trigger = ManualTriggerFactory.getManualTrigger(project, upstream);
        if (trigger != null) {
            trigger.triggerManual(project, upstream, buildId, getOwner().getItemGroup());
        } else {
            String message = "Trigger not found for manual build " + projectName + " for upstream "
                    + upstreamName + " id: " + buildId;
            LOG.log(Level.WARNING, message);
            throw new TriggerException(message);
        }
    } catch (TriggerException e) {
        LOG.log(Level.WARNING, triggerExceptionMessage(projectName, upstreamName, buildId), e);
        throw e;
    }
}
 
开发者ID:Diabol,项目名称:delivery-pipeline-plugin,代码行数:26,代码来源:DeliveryPipelineView.java

示例5: triggerRebuild

import org.acegisecurity.BadCredentialsException; //导入依赖的package包/类
@Override
public void triggerRebuild(String projectName, String buildId) {
    AbstractProject project = ProjectUtil.getProject(projectName, Jenkins.getInstance());
    if (!project.hasPermission(Item.BUILD)) {
        throw new BadCredentialsException("Not authorized to trigger build");
    }
    AbstractBuild build = project.getBuildByNumber(Integer.parseInt(buildId));

    @SuppressWarnings("unchecked")
    List<Cause> prevCauses = build.getCauses();
    List<Cause> newCauses = new ArrayList<>();
    for (Cause cause : prevCauses) {
        if (!(cause instanceof Cause.UserIdCause)) {
            newCauses.add(cause);
        }
    }
    newCauses.add(new Cause.UserIdCause());
    CauseAction causeAction = new CauseAction(newCauses);
    project.scheduleBuild2(project.getQuietPeriod(),null, causeAction, build.getAction(ParametersAction.class));
}
 
开发者ID:Diabol,项目名称:delivery-pipeline-plugin,代码行数:21,代码来源:DeliveryPipelineView.java

示例6: testDoRebuild

import org.acegisecurity.BadCredentialsException; //导入依赖的package包/类
@Test
public void testDoRebuild() throws Exception {
    StaplerRequest request = Mockito.mock(StaplerRequest.class);
    StaplerResponse response = Mockito.mock(StaplerResponse.class);
    DeliveryPipelineView view = Mockito.mock(DeliveryPipelineView.class);
    doThrow(new BadCredentialsException("Ops")).when(view).triggerRebuild("secretproject", "1");
    PipelineApi api = new PipelineApi(view);

    api.doRebuildStep(request, response, null, null);
    verify(response, times(1)).setStatus(HttpServletResponse.SC_NOT_ACCEPTABLE);

    api.doRebuildStep(request, response, "project", "1");
    verify(response, times(1)).setStatus(HttpServletResponse.SC_OK);

    api.doRebuildStep(request, response, "secretproject", "1");
    verify(response, times(1)).setStatus(HttpServletResponse.SC_FORBIDDEN);
}
 
开发者ID:Diabol,项目名称:delivery-pipeline-plugin,代码行数:18,代码来源:PipelineApiTest.java

示例7: createSecurityComponents

import org.acegisecurity.BadCredentialsException; //导入依赖的package包/类
@Override
public SecurityComponents createSecurityComponents() {
	return new SecurityComponents(new AuthenticationManager() {
		public Authentication authenticate(Authentication authentication) throws AuthenticationException {
			if (authentication instanceof KeycloakAuthentication)
				return authentication;
			throw new BadCredentialsException("Unexpected authentication type: " + authentication);
		}
	});
}
 
开发者ID:devlauer,项目名称:jenkins-keycloak-plugin,代码行数:11,代码来源:KeycloakSecurityRealm.java

示例8: authenticate

import org.acegisecurity.BadCredentialsException; //导入依赖的package包/类
public LdapUserDetails authenticate(String username, String password) {

        // LDAP authentication must be enabled on the system.
        if (!settingsService.isLdapEnabled()) {
            throw new BadCredentialsException("LDAP authentication disabled.");
        }

        // User must be defined in Subsonic, unless auto-shadowing is enabled.
        User user = securityService.getUserByName(username);
        if (user == null && !settingsService.isLdapAutoShadowing()) {
            throw new BadCredentialsException("User does not exist.");
        }

        // LDAP authentication must be enabled for the given user.
        if (user != null && !user.isLdapAuthenticated()) {
            throw new BadCredentialsException("LDAP authentication disabled for user.");
        }

        try {
            createDelegate();
            LdapUserDetails details = delegateAuthenticator.authenticate(username, password);
            if (details != null) {
                LOG.info("User '" + username + "' successfully authenticated in LDAP. DN: " + details.getDn());

                if (user == null) {
                    User newUser = new User(username, "", null, true, 0L, 0L, 0L);
                    newUser.setStreamRole(true);
                    newUser.setSettingsRole(true);
                    securityService.createUser(newUser);
                    LOG.info("Created local user '" + username + "' for DN " + details.getDn());
                }
            }

            return details;
        } catch (RuntimeException x) {
            LOG.info("Failed to authenticate user '" + username + "' in LDAP.", x);
            throw x;
        }
    }
 
开发者ID:sindremehus,项目名称:subsonic,代码行数:40,代码来源:SubsonicLdapBindAuthenticator.java

示例9: authenticate

import org.acegisecurity.BadCredentialsException; //导入依赖的package包/类
/**
 * Tries to authenticate a user with the given username and password.
 *
 * @param username the username of the user
 * @param password the password of the user
 * @return a UserDetails object with user information
 * @throws AuthenticationException if the authentication failed
 */
@Override
protected UserDetails authenticate(String username, String password) throws AuthenticationException {
    try {
        // authenticate credentials and create user details
        return loadUserWithCredentials(username, password);
    } catch (GitLabApiException e) {
        // authentication or connection to the API failed
        throw new BadCredentialsException("Authentication against GitLab failed", e);
    }
}
 
开发者ID:enil,项目名称:gitlab-auth-plugin,代码行数:19,代码来源:GitLabSecurityRealm.java

示例10: authenticate

import org.acegisecurity.BadCredentialsException; //导入依赖的package包/类
public LdapUserDetails authenticate(String username, String password) {

        // LDAP authentication must be enabled on the system.
        if (!settingsService.isLdapEnabled()) {
            throw new BadCredentialsException("LDAP authentication disabled.");
        }

        // User must be defined in Subsonic, unless auto-shadowing is enabled.
        User user = securityService.getUserByName(username);
        if (user == null && !settingsService.isLdapAutoShadowing()) {
            throw new BadCredentialsException("User does not exist.");
        }

        // LDAP authentication must be enabled for the given user.
        if (user != null && !user.isLdapAuthenticated()) {
            throw new BadCredentialsException("LDAP authentication disabled for user.");
        }

        try {
            createDelegate();
            LdapUserDetails details = delegateAuthenticator.authenticate(username, password);
            if (details != null) {
                LOG.info("User '" + username + "' successfully authenticated in LDAP. DN: " + details.getDn());

                if (user == null) {
                    User newUser = new User(username, "", null, true, 0L, 0L, 0L, 0, false);
                    newUser.setStreamRole(true);
                    newUser.setSettingsRole(true);
                    securityService.createUser(newUser);
                    LOG.info("Created local user '" + username + "' for DN " + details.getDn());
                }
            }

            return details;
        } catch (RuntimeException x) {
            LOG.info("Failed to authenticate user '" + username + "' in LDAP.", x);
            throw x;
        }
    }
 
开发者ID:FutureSonic,项目名称:FutureSonic-Server,代码行数:40,代码来源:SubsonicLdapBindAuthenticator.java

示例11: getUserDetails

import org.acegisecurity.BadCredentialsException; //导入依赖的package包/类
/**
   * Obtains the granted authorities for the specified user.
   * <P>
   * May throw any <code>AuthenticationException</code> or return <code>null</code> if the
   * authorities are unavailable.
   * </p>
   */
  public UserDetails getUserDetails(String casUserId) throws AuthenticationException {
  	WebSSOUser user = (WebSSOUser) userDetailsService.loadUserByUsername(casUserId);
String delegationEPR =user.getDelegatedEPR(); 
log.debug("User Info "+user);
try {
	GlobusCredential userCredential = WebSSOClientHelper.getUserCredential(delegationEPR,hostCertificate,hostKey);
	user.setGridCredential(userCredential);
} catch (WebSSOClientException e) {
	log.info(FaultUtil.printFaultToString(e));
	throw new BadCredentialsException("Error occured while validating user credentials ",e);
}
return user;
  }
 
开发者ID:NCIP,项目名称:cagrid-core,代码行数:21,代码来源:WebSSOAuthoritiesPopulator.java

示例12: authenticated

import org.acegisecurity.BadCredentialsException; //导入依赖的package包/类
@Override
protected void authenticated(UserDetails userDetails) {
    if (!checkLatch(userDetails)) {
        throw new BadCredentialsException("Invalid credentials");
    }
}
 
开发者ID:ElevenPaths,项目名称:latch-plugin-jenkins,代码行数:7,代码来源:LatchSecurityListener.java

示例13: authenticate

import org.acegisecurity.BadCredentialsException; //导入依赖的package包/类
/**
 * This overridden method is copied from CAS verbatim.  For some reason 
 * {@link authenticateNow} would not override and the super method 
 * would get called until did this method was also overridden.
 * 
 * @see org.acegisecurity.providers.cas.CasAuthenticationProvider#authenticate(org.acegisecurity.Authentication)
 */
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
    StatelessTicketCache statelessTicketCache = this.getStatelessTicketCache();
    String key = this.getKey();
    if (!supports(authentication.getClass())) {
        return null;
    }

    if (authentication instanceof UsernamePasswordAuthenticationToken
        && (!CasProcessingFilter.CAS_STATEFUL_IDENTIFIER.equals(authentication.getPrincipal().toString())
        && !CasProcessingFilter.CAS_STATELESS_IDENTIFIER.equals(authentication.getPrincipal().toString()))) {
        // UsernamePasswordAuthenticationToken not CAS related
        return null;
    }

    // If an existing CasAuthenticationToken, just check we created it
    if (authentication instanceof CasAuthenticationToken) {
        if (key.hashCode() == ((CasAuthenticationToken) authentication).getKeyHash()) {
            return authentication;
        } else {
            throw new BadCredentialsException(messages.getMessage("CasAuthenticationProvider.incorrectKey",
                    "The presented CasAuthenticationToken does not contain the expected key"));
        }
    }

    // Ensure credentials are presented
    if ((authentication.getCredentials() == null) || "".equals(authentication.getCredentials())) {
        throw new BadCredentialsException(messages.getMessage("CasAuthenticationProvider.noServiceTicket",
                "Failed to provide a CAS service ticket to validate"));
    }

    boolean stateless = false;

    if (authentication instanceof UsernamePasswordAuthenticationToken
        && CasProcessingFilter.CAS_STATELESS_IDENTIFIER.equals(authentication.getPrincipal())) {
        stateless = true;
    }

    CasAuthenticationToken result = null;

    if (stateless) {
        // Try to obtain from cache
        result = statelessTicketCache.getByTicketId(authentication.getCredentials().toString());
    }

    if (result == null) {
        result = this.authenticateNow(authentication);
        result.setDetails(authentication.getDetails());
    }

    if (stateless) {
        // Add to cache
        statelessTicketCache.putTicketInCache(result);
    }

    return result;
}
 
开发者ID:kuali,项目名称:rice,代码行数:64,代码来源:KualiCasAuthenticationProvider.java

示例14: validateNow

import org.acegisecurity.BadCredentialsException; //导入依赖的package包/类
/**
     * This overridden method gets the authentication source and 
     * Distributed Session Ticket from the response
     * 
     * @see org.acegisecurity.providers.cas.ticketvalidator.CasProxyTicketValidator#validateNow(edu.yale.its.tp.cas.client.ProxyTicketValidator)
     */
    protected TicketResponse validateNow(ProxyTicketValidator pv)
        throws AuthenticationServiceException, BadCredentialsException {
		String					sAuthenticationSource = null;
		String                  sDST = null;

        try {
            pv.validate();
        } catch (Exception internalProxyTicketValidatorProblem) {
            throw new AuthenticationServiceException(internalProxyTicketValidatorProblem.getMessage());
        }

        if (!pv.isAuthenticationSuccesful()) {
            throw new BadCredentialsException(pv.getErrorCode() + ": " + pv.getErrorMessage());
        }
        
        logger.debug("PROXY RESPONSE: " + pv.getResponse());
        
        if (logger.isDebugEnabled()) {
            logger.debug("DEBUG");
        }
                
        try {
			DocumentBuilderFactory	factory = DocumentBuilderFactory.newInstance();
			DocumentBuilder			builder = factory.newDocumentBuilder();
			InputSource inStream = new InputSource();
			inStream.setCharacterStream(new StringReader(pv.getResponse()));
			Document				doc     = builder.parse(inStream);
			Element 				head = doc.getDocumentElement();
			NodeList 				attrs = head.getElementsByTagName("cas:attribute");
			for (int i=0; i<attrs.getLength(); i++) {
				logger.debug(("Field name:" + ((Element)attrs.item(i)).getAttribute("name")) + "=" + ((Element)attrs.item(i)).getAttribute("value"));
				if ( ((Element)attrs.item(i)).getAttribute("name").equals("authenticationMethod") ) {
					sAuthenticationSource = ((Element)attrs.item(i)).getAttribute("value");
				} else if ( ((Element)attrs.item(i)).getAttribute("name").equals("DST") ) {
				    sDST = ((Element)attrs.item(i)).getAttribute("value");
				}
			}
			if (sAuthenticationSource != null && sDST != null) {
                String sPrincipal = pv.getUser() + "@" + sAuthenticationSource;

                if (logger.isDebugEnabled()) {
			        logger.debug("Updating session: " + sDST + " " + sPrincipal);
			    }
// Touching here may be overkill since it should happen in the filter
                distributedSession.touchSesn(sDST);
              //  distributedSession.addPrincipalToSesn(sDST, sPrincipal);
			} else {
			    if (logger.isDebugEnabled()) {
                    logger.debug("Incomplete data from CAS:" + sAuthenticationSource + ":" + sDST);
                }
			}
        } catch (Exception e) {
        	logger.error("Error parsing CAS Result", e);
        }
        
        logger.debug("Authentication Method:" + sAuthenticationSource);
        return new KualiTicketResponse(pv.getUser(), pv.getProxyList(), pv.getPgtIou(), sDST);
    }
 
开发者ID:kuali,项目名称:rice,代码行数:65,代码来源:KualiCasProxyTicketValidator.java

示例15: testDoManualStep

import org.acegisecurity.BadCredentialsException; //导入依赖的package包/类
@Test
public void testDoManualStep() throws Exception {
    StaplerRequest request = Mockito.mock(StaplerRequest.class);
    StaplerResponse response = Mockito.mock(StaplerResponse.class);

    DeliveryPipelineView view = Mockito.mock(DeliveryPipelineView.class);
    doThrow(new TriggerException("Ops")).when(view).triggerManual("upstream", "downstream", "12");
    doThrow(new BadCredentialsException("Ops")).when(view).triggerManual("upstream", "downstream", "13");

    PipelineApi api = new PipelineApi(view);

    api.doManualStep(request, response, null, null, null);
    verify(response, times(1)).setStatus(HttpServletResponse.SC_NOT_ACCEPTABLE);

    response = Mockito.mock(StaplerResponse.class);
    api.doManualStep(request, response, null, "hej", null);
    verify(response, times(1)).setStatus(HttpServletResponse.SC_NOT_ACCEPTABLE);

    response = Mockito.mock(StaplerResponse.class);
    api.doManualStep(request, response, "hej", "hej", null);
    verify(response, times(1)).setStatus(HttpServletResponse.SC_NOT_ACCEPTABLE);

    response = Mockito.mock(StaplerResponse.class);
    api.doManualStep(request, response, null, "hej", "hej");
    verify(response, times(1)).setStatus(HttpServletResponse.SC_NOT_ACCEPTABLE);

    response = Mockito.mock(StaplerResponse.class);
    api.doManualStep(request, response, null, null, "hej");
    verify(response, times(1)).setStatus(HttpServletResponse.SC_NOT_ACCEPTABLE);

    response = Mockito.mock(StaplerResponse.class);
    api.doManualStep(request, response,"upstream", "downstream", "12");
    verify(response, times(1)).setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);

    response = Mockito.mock(StaplerResponse.class);
    api.doManualStep(request, response,"upstream", "downstream", "13");
    verify(response, times(1)).setStatus(HttpServletResponse.SC_FORBIDDEN);

    view = Mockito.mock(DeliveryPipelineView.class);
    api = new PipelineApi(view);
    response = Mockito.mock(StaplerResponse.class);
    api.doManualStep(request, response,"upstream", "downstream", "14");
    verify(response, times(1)).setStatus(HttpServletResponse.SC_OK);
    verify(view).triggerManual("upstream", "downstream", "14");
}
 
开发者ID:Diabol,项目名称:delivery-pipeline-plugin,代码行数:46,代码来源:PipelineApiTest.java


注:本文中的org.acegisecurity.BadCredentialsException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。