本文整理汇总了Java中org.acegisecurity.AuthenticationException类的典型用法代码示例。如果您正苦于以下问题:Java AuthenticationException类的具体用法?Java AuthenticationException怎么用?Java AuthenticationException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AuthenticationException类属于org.acegisecurity包,在下文中一共展示了AuthenticationException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: authenticate
import org.acegisecurity.AuthenticationException; //导入依赖的package包/类
@Override
protected UserDetails authenticate(String username, String password) throws AuthenticationException {
try {
LOGGER.info("Trying to authenticate with username: " + username);
GitlabSession session = GitlabAPI.connect(this.gitLabUrl, username, password);
return this.userDetailsBuilder.buildUserDetails(this.gitLabUrl, session, session.getPrivateToken());
} catch(Exception e) {
this.LOGGER.log(Level.WARNING, "Authentication request failed for username: " + username, e);
throw new AuthenticationServiceException("Unable to process authentication for username: " + username, e);
}
}
示例2: createSecurityComponents
import org.acegisecurity.AuthenticationException; //导入依赖的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");
}
});
}
示例3: getToken
import org.acegisecurity.AuthenticationException; //导入依赖的package包/类
public String getToken() throws AuthenticationException, IllegalAccessException {
ISession session = this.context.createSession();
if (session == null) {
throw new IllegalAccessException("Can't allocate a new session!");
}
// Set credentials.
session.getAuthentication().setPassword(getPwd());
session.getAuthentication().setUsername(getUser());
// Login.
session.login();
// Might what something more clever here...
String token = Integer.toHexString(session.hashCode());
this.context.addSession(token, session);
return(token);
}
示例4: additionalAuthenticationChecks
import org.acegisecurity.AuthenticationException; //导入依赖的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);
}
}
示例5: authenticate
import org.acegisecurity.AuthenticationException; //导入依赖的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);
}
示例6: authenticate
import org.acegisecurity.AuthenticationException; //导入依赖的package包/类
private RESTController.ErrorCode authenticate(String username, String password, Authentication previousAuth) {
// Previously authenticated and username not overridden?
if (username == null && previousAuth != null) {
return null;
}
// Ensure password is given.
if (password == null) {
return RESTController.ErrorCode.MISSING_PARAMETER;
}
try {
UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken(username, password);
Authentication authResult = authenticationManager.authenticate(authRequest);
SecurityContextHolder.getContext().setAuthentication(authResult);
// LOG.info("Authentication succeeded for user " + username);
} catch (AuthenticationException x) {
LOG.info("Authentication failed for user " + username);
return RESTController.ErrorCode.NOT_AUTHENTICATED;
}
return null;
}
示例7: authenticateNow
import org.acegisecurity.AuthenticationException; //导入依赖的package包/类
/**
* This overridden method is differs from the super method by
* populating the user details by passing the full response
*
* @see org.acegisecurity.providers.cas.CasAuthenticationProvider#authenticateNow(Authentication authentication)
*/
private CasAuthenticationToken authenticateNow(Authentication authentication) throws AuthenticationException {
// Validate
KualiTicketResponse response = (KualiTicketResponse)this.getTicketValidator().confirmTicketValid(authentication.getCredentials().toString());
// Check proxy list is trusted
this.getCasProxyDecider().confirmProxyListTrusted(response.getProxyList());
if (logger.isDebugEnabled()) {
logger.debug("authenticationNOW:" + response);
}
// Lookup user details
logger.debug("\n\npopulating authorities\n\n");
UserDetails userDetails = ((KualiCasAuthoritiesPopulator)this.getCasAuthoritiesPopulator()).getUserDetails(response);
// Construct CasAuthenticationToken
return new CasAuthenticationToken(this.getKey(), userDetails, authentication.getCredentials(),
userDetails.getAuthorities(), userDetails, response.getProxyList(), response.getProxyGrantingTicketIou());
}
示例8: retrieveUser
import org.acegisecurity.AuthenticationException; //导入依赖的package包/类
protected final UserDetails retrieveUser(String username, UsernamePasswordAuthenticationToken authentication)
throws AuthenticationException {
UserDetails loadedUser;
try {
// Check if User is Authenticated. ?? TODO
loadedUser = this.getUserDetailsService().loadUserByUsername(username);
} catch (DataAccessException repositoryProblem) {
throw new AuthenticationServiceException(repositoryProblem.getMessage(), repositoryProblem);
}
if (loadedUser == null) {
throw new AuthenticationServiceException(
"UserDetailsService returned null, which is an interface contract violation");
}
return loadedUser;
}
示例9: triggerManual
import org.acegisecurity.AuthenticationException; //导入依赖的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;
}
}
示例10: doRebuildStep
import org.acegisecurity.AuthenticationException; //导入依赖的package包/类
@SuppressWarnings("UnusedDeclaration")
public void doRebuildStep(StaplerRequest request,
StaplerResponse response,
@QueryParameter String project,
@QueryParameter String buildId) throws IOException, ServletException {
if (project != null && buildId != null) {
try {
view.triggerRebuild(project, buildId);
response.setStatus(SC_OK);
} catch (AuthenticationException e) {
response.setStatus(SC_FORBIDDEN);
}
} else {
response.setStatus(SC_NOT_ACCEPTABLE);
}
}
示例11: triggerManual
import org.acegisecurity.AuthenticationException; //导入依赖的package包/类
@Override
public void triggerManual(String projectName, String upstreamName, String buildId)
throws TriggerException, AuthenticationException {
LOG.fine("Manual/Input step called for project: " + projectName + " and build id: " + buildId);
WorkflowJob workflowJob;
try {
workflowJob = ProjectUtil.getWorkflowJob(projectName, getOwnerItemGroup());
RunList<WorkflowRun> builds = workflowJob.getBuilds();
for (WorkflowRun run : builds) {
if (Integer.toString(run.getNumber()).equals(buildId)) {
InputAction inputAction = run.getAction(InputAction.class);
if (inputAction != null && !inputAction.getExecutions().isEmpty()) {
inputAction.getExecutions().get(0).doProceedEmpty();
}
}
}
throw new PipelineException("Failed to resolve manual/input step for build with id: "
+ buildId + " for project: " + projectName);
} catch (IOException | PipelineException e) {
LOG.warning("Failed to resolve project to trigger manual/input step for: " + e);
}
}
示例12: testRebuildNotAuthorized
import org.acegisecurity.AuthenticationException; //导入依赖的package包/类
@Test
public void testRebuildNotAuthorized() throws Exception {
FreeStyleProject projectA = jenkins.createFreeStyleProject("A");
jenkins.createFreeStyleProject("B");
projectA.getPublishersList().add(new BuildPipelineTrigger("B", null));
jenkins.getInstance().rebuildDependencyGraph();
DeliveryPipelineView view = new DeliveryPipelineView("View");
jenkins.getInstance().addView(view);
jenkins.getInstance().setSecurityRealm(jenkins.createDummySecurityRealm());
GlobalMatrixAuthorizationStrategy gmas = new GlobalMatrixAuthorizationStrategy();
gmas.add(Permission.READ, "devel");
jenkins.getInstance().setAuthorizationStrategy(gmas);
SecurityContext oldContext = ACL.impersonate(User.get("devel").impersonate());
try {
view.triggerRebuild("B", "1");
fail();
} catch (AuthenticationException e) {
//Should throw this
}
SecurityContextHolder.setContext(oldContext);
}
示例13: authenticate
import org.acegisecurity.AuthenticationException; //导入依赖的package包/类
/**
* Authenticate a login attempt.
* This method is the heart of a {@link AbstractPasswordBasedSecurityRealm}.
* <p>
* <p>
* If the user name and the password pair matches, retrieve the information about this user and
* return it as a {@link UserDetails} object. {@link User} is a convenient
* implementation to use, but if your backend offers additional data, you may want to use your own subtype
* so that the rest of Hudson can use those additional information (such as e-mail address --- see
* MailAddressResolver.)
* <p>
* <p>
* Properties like {@link UserDetails#getPassword()} make no sense, so just return an empty value from it.
* The only information that you need to pay real attention is {@link UserDetails#getAuthorities()}, which
* is a list of roles/groups that the user is in. At minimum, this must contain {@link #AUTHENTICATED_AUTHORITY}
* (which indicates that this user is authenticated and not anonymous), but if your backend supports a notion
* of groups, you should make sure that the authorities contain one entry per one group. This enables
* users to control authorization based on groups.
* <p>
* <p>
* If the user name and the password pair doesn't match, throw {@link AuthenticationException} to reject the login
* attempt.
*
* @param username userName
*/
@Override
protected UserDetails authenticate(String username, String password)
throws AuthenticationException {
String token;
try {
token = getLoadingCache().get(new UserAuth(currentAuth.getTeamId(), username, password));
if (token == null || token.isEmpty()) {
logger.info(
String.format("Login failed. namespace: %s, username: %s", currentAuth.getTeamId(),
username));
throw new UsernameNotFoundException("Invalid login");
}
AppsCodeUserDetails userDetails = getUserDetails(currentAuth.getTeamId(), username, token);
if (!username.equals(userDetails.getUsername())) {
logger.warning(String.format("Username doesn't match. given: %s, found: %s", username,
userDetails.getUsername()));
throw new UsernameNotFoundException("Username doesn't match");
}
return userDetails;
} catch (UsernameNotFoundException ue) {
throw ue;
} catch (Exception e) {
logger.log(Level.SEVERE, String.format("%s", e.getMessage()));
throw new UsernameNotFoundException(e.getMessage());
}
}
示例14: createSecurityComponents
import org.acegisecurity.AuthenticationException; //导入依赖的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);
}
});
}
示例15: authenticate
import org.acegisecurity.AuthenticationException; //导入依赖的package包/类
private RESTController.ErrorCode authenticate(String username, String password, String salt, String token, Authentication previousAuth) {
// Previously authenticated and username not overridden?
if (username == null && previousAuth != null) {
return null;
}
if (salt != null && token != null) {
User user = securityService.getUserByName(username);
if (user == null) {
return RESTController.ErrorCode.NOT_AUTHENTICATED;
}
String expectedToken = DigestUtils.md5Hex(user.getPassword() + salt);
if (!expectedToken.equals(token)) {
return RESTController.ErrorCode.NOT_AUTHENTICATED;
}
password = user.getPassword();
}
if (password != null) {
try {
UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken(username, password);
Authentication authResult = authenticationManager.authenticate(authRequest);
SecurityContextHolder.getContext().setAuthentication(authResult);
return null;
} catch (AuthenticationException x) {
return RESTController.ErrorCode.NOT_AUTHENTICATED;
}
}
return RESTController.ErrorCode.MISSING_PARAMETER;
}