當前位置: 首頁>>代碼示例>>Java>>正文


Java AuthenticationFailureException類代碼示例

本文整理匯總了Java中org.biokoframework.system.services.authentication.AuthenticationFailureException的典型用法代碼示例。如果您正苦於以下問題:Java AuthenticationFailureException類的具體用法?Java AuthenticationFailureException怎麽用?Java AuthenticationFailureException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


AuthenticationFailureException類屬於org.biokoframework.system.services.authentication包,在下文中一共展示了AuthenticationFailureException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: executeCommand

import org.biokoframework.system.services.authentication.AuthenticationFailureException; //導入依賴的package包/類
@Override
public Fields executeCommand(Fields input) throws SystemException, ValidationException {
       AuthResponse authResponse = null;
	try {
		authResponse = fAuthService.authenticate(input, fRequiredRoles);
		input.putAll(authResponse.getMergeFields());
	} catch (AuthenticationFailureException exception) {
		if (fRequireValidAuthentication) {
			throw exception;
		}
	}
       Fields output = fWrappedHandler.executeCommand(input);
       if (authResponse != null && authResponse.getOverrideFields() != null) {
           output.putAll(authResponse.getOverrideFields());
       }
	return output;
}
 
開發者ID:bioko,項目名稱:http-exposer,代碼行數:18,代碼來源:SecurityHandler.java

示例2: httpAuthenticate

import org.biokoframework.system.services.authentication.AuthenticationFailureException; //導入依賴的package包/類
@Override
public Fields httpAuthenticate(Fields input) throws AuthenticationFailureException {
	String encodedAuth = getHeader(AUTHORIZATION);
	String decodedAuth = new String(Base64.decodeBase64(encodedAuth.substring(BASIC_AUTH_START.length())));
	
	String userName = decodedAuth.replaceFirst(":.*", "");
	String password = decodedAuth.replaceFirst(".*:", "");
	
	Login login = fLoginRepository.retrieveByForeignKey(GenericFieldNames.USER_EMAIL, userName);
	if (login == null) {
		throw CommandExceptionsFactory.createInvalidLoginException();
	} else if (!login.get(GenericFieldNames.PASSWORD).equals(password)) {
		throw CommandExceptionsFactory.createInvalidLoginException();
	}
	
	return new Fields(Login.class.getSimpleName(), login);
}
 
開發者ID:bioko,項目名稱:http-exposer,代碼行數:18,代碼來源:BasicAccessAuthenticationStrategy.java

示例3: authenticate

import org.biokoframework.system.services.authentication.AuthenticationFailureException; //導入依賴的package包/類
@Override
public AuthResponse authenticate(Fields fields, List<String> requiredRoles) throws AuthenticationFailureException {
	for (IAuthenticationService anAuthService : fAuthServices) {
		if (!(anAuthService instanceof AllAuthenticationService)) {
               try {
                   AuthResponse authResponse = anAuthService.authenticate(fields, requiredRoles);
                   if (authResponse != null) {
                       return authResponse;
                   }
               } catch (AuthenticationFailureException exception) {
                   Long errorCode = exception.getErrors().get(0).get(ErrorEntity.ERROR_CODE);
                   if (FieldNames.AUTHENTICATION_REQUIRED_CODE != errorCode) {
                       throw exception;
                   }
               }
		}
	}
	
	throw CommandExceptionsFactory.createUnauthorisedAccessException();
}
 
開發者ID:bioko,項目名稱:system,代碼行數:21,代碼來源:AllAuthenticationService.java

示例4: testSuccessfulAuthenticationUsingToken

import org.biokoframework.system.services.authentication.AuthenticationFailureException; //導入依賴的package包/類
@Test
public void testSuccessfulAuthenticationUsingToken() throws ValidationException, RepositoryException, AuthenticationFailureException {
    TestCurrentTimeService.setCalendar("2014-01-22T18:00:05Z");

    Login login = fLoginBuilder.loadDefaultExample().build(false);
    login = fLoginRepo.save(login);

    fAuthService = fInjector.getInstance(TokenAuthenticationServiceImpl.class);

    Authentication auth = fAuthBuilder.loadDefaultExample()
            .set(Authentication.LOGIN_ID, login.getId()).build(false);
    fAuthRepo.save(auth);

    Fields fields = new Fields("authToken", auth.get(Authentication.TOKEN));
    AuthResponse authResponse = fAuthService.authenticate(fields, Collections.<String>emptyList());

    assertThat(authResponse.getMergeFields(), contains(GenericFieldNames.AUTH_LOGIN_ID, login.getId()));

    DateTime authTokenExpire = ISODateTimeFormat.dateTimeNoMillis().parseDateTime((String) authResponse.getOverrideFields().get(Authentication.TOKEN_EXPIRE));
    assertThat(authTokenExpire, is(equalTo(fTimeService.getCurrentTimeAsDateTime().plus(fTokenValiditySecs * 1000))));
}
 
開發者ID:bioko,項目名稱:system,代碼行數:22,代碼來源:TokenAuthenticationServiceImplTest.java

示例5: testFailedAuthenticationBecauseTokenExpired

import org.biokoframework.system.services.authentication.AuthenticationFailureException; //導入依賴的package包/類
@Test
public void testFailedAuthenticationBecauseTokenExpired() throws ValidationException, RepositoryException, AuthenticationFailureException {
       TestCurrentTimeService.setCalendar("2014-01-24T18:00:05Z");

       Login login = fLoginBuilder.loadDefaultExample().build(false);
       login = fLoginRepo.save(login);

       fAuthService = fInjector.getInstance(TokenAuthenticationServiceImpl.class);

       Authentication auth = fAuthBuilder.loadDefaultExample()
               .set(Authentication.LOGIN_ID, login.getId())
               .build(false);
       auth = fAuthRepo.save(auth);

       Fields fields = new Fields("authToken", auth.get(Authentication.TOKEN));

       try {
           fAuthService.authenticate(fields, Collections.<String>emptyList());
           fail(AuthenticationFailureException.class + " not thrown");
       } catch (AuthenticationFailureException exception) {
           assertThat(exception.getErrors(), is(equalTo(CommandExceptionsFactory.createTokenExpiredException().getErrors())));
       }

       assertThat(fAuthRepo.retrieve(auth.getId()), is(nullValue()));
   }
 
開發者ID:bioko,項目名稱:system,代碼行數:26,代碼來源:TokenAuthenticationServiceImplTest.java

示例6: testFailedBecauseRoleExpected

import org.biokoframework.system.services.authentication.AuthenticationFailureException; //導入依賴的package包/類
@Test
public void testFailedBecauseRoleExpected() throws ValidationException, RepositoryException, AuthenticationFailureException {
    TestCurrentTimeService.setCalendar("2014-01-22T18:00:05Z");

    Login login = fLoginBuilder.loadDefaultExample().build(false);
    login = fLoginRepo.save(login);

    fAuthService = fInjector.getInstance(TokenAuthenticationServiceImpl.class);

    Authentication auth = fAuthBuilder.loadDefaultExample()
            .set(Authentication.LOGIN_ID, login.getId())
            .build(false);
    auth = fAuthRepo.save(auth);

    Fields fields = new Fields("authToken", auth.get(Authentication.TOKEN));

    expected.expect(AuthenticationFailureException.class);
    expected.expectMessage(containsString("\"errorCode\":113"));
    fAuthService.authenticate(fields, Collections.singletonList("aRole"));
}
 
開發者ID:bioko,項目名稱:system,代碼行數:21,代碼來源:TokenAuthenticationServiceImplTest.java

示例7: simpleAuthenticationTest

import org.biokoframework.system.services.authentication.AuthenticationFailureException; //導入依賴的package包/類
@Test
public void simpleAuthenticationTest() throws AuthenticationFailureException, ValidationException, RepositoryException {
    Login login = fLoginBuilder.loadDefaultExample().build(false);
    login = fLoginRepo.save(login);

    SimpleAuthenticationService authenticationService = fInjector.getInstance(SimpleAuthenticationService.class);

    Fields fields = new Fields(
            Login.USER_EMAIL, login.get(Login.USER_EMAIL),
            Login.PASSWORD, login.get(Login.PASSWORD));

    AuthResponse response = authenticationService.authenticate(fields, Collections.<String>emptyList());

    assertThat(response, is(notNullValue()));
    assertThat((String) response.getMergeFields().get("authLoginId"), is(equalTo(login.getId())));
}
 
開發者ID:bioko,項目名稱:system,代碼行數:17,代碼來源:SimpleAuthenticationServiceTest.java

示例8: create

import org.biokoframework.system.services.authentication.AuthenticationFailureException; //導入依賴的package包/類
public static HashMap<Class<? extends BiokoException>, HttpError> create() {
	HashMap<Class<? extends BiokoException>, HttpError> exceptionMap = new HashMap<Class<? extends BiokoException>, HttpError>();
	exceptionMap.put(BadCommandInvocationException.class, new HttpError(400));
	exceptionMap.put(AuthenticationFailureException.class, new HttpError(401));
	exceptionMap.put(EntityNotFoundException.class, new HttpError(404));
	exceptionMap.put(CommandNotFoundException.class, new HttpError(404));
	
	exceptionMap.put(ValidationException.class, new HttpError(400));
	exceptionMap.put(CommandException.class, new HttpError(500));
	
	exceptionMap.put(EasterEggException.class, new HttpError(418));
	return exceptionMap;
}
 
開發者ID:bioko,項目名稱:http-test,代碼行數:14,代碼來源:HttpResponseExceptionFactory.java

示例9: createInvalidLoginException

import org.biokoframework.system.services.authentication.AuthenticationFailureException; //導入依賴的package包/類
public static AuthenticationFailureException createInvalidLoginException() {
	String[] message = sErrorMap.get(FieldNames.INVALID_LOGIN_CODE);
	Fields fields = new Fields(
			ErrorEntity.ERROR_CODE, FieldNames.INVALID_LOGIN_CODE,
			ErrorEntity.ERROR_MESSAGE, new StringBuilder()
				.append(message[0])
				.toString());
	
	ErrorEntity entity = new ErrorEntity();
	entity.setAll(fields);
	return new AuthenticationFailureException(entity);
}
 
開發者ID:bioko,項目名稱:system,代碼行數:13,代碼來源:CommandExceptionsFactory.java

示例10: createTokenNotFoundException

import org.biokoframework.system.services.authentication.AuthenticationFailureException; //導入依賴的package包/類
public static AuthenticationFailureException createTokenNotFoundException() {
	String[] message = sErrorMap.get(FieldNames.AUTHENTICATION_REQUIRED_CODE);
	Fields fields = new Fields(
			ErrorEntity.ERROR_CODE, FieldNames.AUTHENTICATION_REQUIRED_CODE,
			ErrorEntity.ERROR_MESSAGE, new StringBuilder()
				.append(message[0])
				.toString());

	ErrorEntity entity = new ErrorEntity();
	entity.setAll(fields);
	return new AuthenticationFailureException(entity);
}
 
開發者ID:bioko,項目名稱:system,代碼行數:13,代碼來源:CommandExceptionsFactory.java

示例11: createUnauthorisedAccessException

import org.biokoframework.system.services.authentication.AuthenticationFailureException; //導入依賴的package包/類
public static AuthenticationFailureException createUnauthorisedAccessException() {
	String[] message = sErrorMap.get(FieldNames.AUTHENTICATION_REQUIRED_CODE);
	Fields fields = new Fields(
			ErrorEntity.ERROR_CODE, FieldNames.AUTHENTICATION_REQUIRED_CODE,
			ErrorEntity.ERROR_MESSAGE, new StringBuilder()
				.append(message[0])
				.toString());
	
	ErrorEntity entity = new ErrorEntity();
	entity.setAll(fields);
	return new AuthenticationFailureException(entity);
}
 
開發者ID:bioko,項目名稱:system,代碼行數:13,代碼來源:CommandExceptionsFactory.java

示例12: createInsufficientPrivilegesException

import org.biokoframework.system.services.authentication.AuthenticationFailureException; //導入依賴的package包/類
public static AuthenticationFailureException createInsufficientPrivilegesException() {
	String[] message = sErrorMap.get(FieldNames.INSUFFICIENT_PRIVILEGES_CODE);
	Fields fields = new Fields(
			ErrorEntity.ERROR_CODE, FieldNames.INSUFFICIENT_PRIVILEGES_CODE,
			ErrorEntity.ERROR_MESSAGE, new StringBuilder()
				.append(message[0])
				.toString());
	
	ErrorEntity entity = new ErrorEntity();
	entity.setAll(fields);
	return new AuthenticationFailureException(entity);
}
 
開發者ID:bioko,項目名稱:system,代碼行數:13,代碼來源:CommandExceptionsFactory.java

示例13: createTokenExpiredException

import org.biokoframework.system.services.authentication.AuthenticationFailureException; //導入依賴的package包/類
public static AuthenticationFailureException createTokenExpiredException() {
	String[] message = sErrorMap.get(FieldNames.TOKEN_EXPIRED_CODE);
	Fields fields = new Fields(
			ErrorEntity.ERROR_CODE, FieldNames.TOKEN_EXPIRED_CODE,
			ErrorEntity.ERROR_MESSAGE, new StringBuilder()
				.append(message[0])
				.toString());
	
	ErrorEntity entity = new ErrorEntity();
	entity.setAll(fields);
	return new AuthenticationFailureException(entity);
}
 
開發者ID:bioko,項目名稱:system,代碼行數:13,代碼來源:CommandExceptionsFactory.java

示例14: createFacebookAuthenticationFailure

import org.biokoframework.system.services.authentication.AuthenticationFailureException; //導入依賴的package包/類
public static AuthenticationFailureException createFacebookAuthenticationFailure(String facebookErrorType) {
	String[] message = sErrorMap.get(FieldNames.FACEBOOK_AUTH_FAILURE_CODE);
	Fields fields = new Fields(
			ErrorEntity.ERROR_CODE, FieldNames.FACEBOOK_AUTH_FAILURE_CODE,
			ErrorEntity.ERROR_MESSAGE, new StringBuilder()
				.append(message[0])
				.append(facebookErrorType).toString());
	
	ErrorEntity entity = new ErrorEntity();
	entity.setAll(fields);
	return new AuthenticationFailureException(entity);
}
 
開發者ID:bioko,項目名稱:system,代碼行數:13,代碼來源:CommandExceptionsFactory.java

示例15: authenticate

import org.biokoframework.system.services.authentication.AuthenticationFailureException; //導入依賴的package包/類
@Override
public AuthResponse authenticate(Fields fields, List<String> requiredRoles) throws AuthenticationFailureException {
       String token = (String) fields.get(AUTH_TOKEN);
       if (token == null) {
           throw CommandExceptionsFactory.createUnauthorisedAccessException();
       }
       Authentication auth = fAuthRepo.retrieveByForeignKey(Authentication.TOKEN, token);
       if (auth == null) {
		throw CommandExceptionsFactory.createUnauthorisedAccessException();
       } else if (isExpired(auth)) {
           fAuthRepo.delete(auth.getId());
           throw CommandExceptionsFactory.createTokenExpiredException();
	} else if (!requiredRoles.isEmpty()) {
		String userRoles = auth.get(Authentication.ROLES);
		ensureRoles(requiredRoles, userRoles);
	}

       auth.set(Authentication.TOKEN_EXPIRE, renewAuthentication());
       try {
           fAuthRepo.save(auth);
       } catch (ValidationException|RepositoryException exception) {
           LOGGER.error("Unexpected error while updating authentication", exception);
           throw new AuthenticationFailureException(exception);
       }
	
	return new AuthResponse(
               new Fields(GenericFieldNames.AUTH_LOGIN_ID, auth.get(Authentication.LOGIN_ID)),
               new Fields(AUTH_TOKEN, token,
                       AUTH_TOKEN_EXPIRE, auth.get(Authentication.TOKEN_EXPIRE)));
}
 
開發者ID:bioko,項目名稱:system,代碼行數:31,代碼來源:TokenAuthenticationServiceImpl.java


注:本文中的org.biokoframework.system.services.authentication.AuthenticationFailureException類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。