本文整理汇总了Java中org.wildfly.security.auth.server.RealmUnavailableException类的典型用法代码示例。如果您正苦于以下问题:Java RealmUnavailableException类的具体用法?Java RealmUnavailableException怎么用?Java RealmUnavailableException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RealmUnavailableException类属于org.wildfly.security.auth.server包,在下文中一共展示了RealmUnavailableException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: executeRuntimeStep
import org.wildfly.security.auth.server.RealmUnavailableException; //导入依赖的package包/类
@Override
protected void executeRuntimeStep(final OperationContext context, final ModelNode operation) throws OperationFailedException {
String principalName = IDENTITY.resolveModelAttribute(context, operation).asString();
ModifiableSecurityRealm modifiableRealm = getModifiableSecurityRealm(context);
ModifiableRealmIdentity identity = null;
try {
identity = modifiableRealm.getRealmIdentityForUpdate(new NamePrincipal(principalName));
if (!identity.exists()) {
throw new OperationFailedException(ROOT_LOGGER.identityNotFound(principalName));
}
identity.delete();
identity.dispose();
} catch (RealmUnavailableException e) {
throw ROOT_LOGGER.couldNotDeleteIdentity(principalName, e);
} finally {
if (identity != null) {
identity.dispose();
}
}
}
示例2: getRealmIdentity
import org.wildfly.security.auth.server.RealmUnavailableException; //导入依赖的package包/类
/**
* Try to obtain a {@link ModifiableRealmIdentity} based on the identity and {@link ModifiableSecurityRealm} associated with given {@link OperationContext}.
*
* @param context the current context
* @return the current identity
* @throws OperationFailedException if the identity does not exists or if any error occurs while obtaining it.
*/
static ModifiableRealmIdentity getRealmIdentity(OperationContext context, String principalName) throws OperationFailedException {
ModifiableSecurityRealm modifiableRealm = getModifiableSecurityRealm(context);
ModifiableRealmIdentity realmIdentity = null;
try {
realmIdentity = modifiableRealm.getRealmIdentityForUpdate(new NamePrincipal(principalName));
if (!realmIdentity.exists()) {
throw new OperationFailedException(ROOT_LOGGER.identityNotFound(principalName));
}
return realmIdentity;
} catch (RealmUnavailableException e) {
throw ROOT_LOGGER.couldNotReadIdentity(principalName, e);
} finally {
if (realmIdentity != null) {
realmIdentity.dispose();
}
}
}
示例3: performOutflow
import org.wildfly.security.auth.server.RealmUnavailableException; //导入依赖的package包/类
private static SecurityIdentity[] performOutflow(SecurityIdentity identity, boolean outflowAnonymous, Set<SecurityDomain> outflowDomains) {
List<SecurityIdentity> outflowIdentities = new ArrayList<>(outflowDomains.size());
for (SecurityDomain d : outflowDomains) {
ServerAuthenticationContext sac = d.createNewAuthenticationContext();
try {
if (sac.importIdentity(identity)) {
outflowIdentities.add(sac.getAuthorizedIdentity());
} else if (outflowAnonymous) {
outflowIdentities.add(d.getAnonymousSecurityIdentity());
}
} catch (RealmUnavailableException e) {
throw ROOT_LOGGER.unableToPerformOutflow(identity.getPrincipal().getName(), e);
}
}
return outflowIdentities.toArray(new SecurityIdentity[outflowIdentities.size()]);
}
示例4: verifyEvidence
import org.wildfly.security.auth.server.RealmUnavailableException; //导入依赖的package包/类
@Override
public boolean verifyEvidence(Evidence evidence) throws RealmUnavailableException {
if (user == null || evidence instanceof PasswordGuessEvidence == false) {
return false;
}
final char[] guess = ((PasswordGuessEvidence) evidence).getGuess();
String password = user.require(PASSWORD).asString();
final PasswordFactory passwordFactory = getPasswordFactory(ALGORITHM_CLEAR);
final PasswordSpec passwordSpec = new ClearPasswordSpec(password.toCharArray());
final Password actualPassword;
try {
actualPassword = passwordFactory.generatePassword(passwordSpec);
return passwordFactory.verify(actualPassword, guess);
} catch (InvalidKeySpecException | InvalidKeyException | IllegalStateException e) {
throw new IllegalStateException(e);
}
}
示例5: restoreIdentity
import org.wildfly.security.auth.server.RealmUnavailableException; //导入依赖的package包/类
private boolean restoreIdentity() {
if (securityDomain == null) {
return false;
}
HttpScope sessionScope = httpExchange.getScope(Scope.SESSION);
if (sessionScope != null && sessionScope.supportsAttachments()) {
String principalName = sessionScope.getAttachment(AUTHENTICATED_PRINCIPAL_KEY, String.class);
if (principalName != null) {
ServerAuthenticationContext authenticationContext = securityDomain.createNewAuthenticationContext();
try {
authenticationContext.setAuthenticationName(principalName);
if (authenticationContext.authorize()) {
SecurityIdentity authorizedIdentity = authenticationContext.getAuthorizedIdentity();
authenticationComplete(new ElytronAccount(authorizedIdentity), programaticMechanismName, false);
setupProgramaticLogout(sessionScope);
return true;
} else {
sessionScope.setAttachment(AUTHENTICATED_PRINCIPAL_KEY, null); // Whatever was in there no longer works so just drop it.
}
} catch (IllegalArgumentException | RealmUnavailableException | IllegalStateException e) {
authenticationFailed(e.getMessage(), programaticMechanismName);
}
}
}
return false;
}
示例6: roleToSecurityIdentity
import org.wildfly.security.auth.server.RealmUnavailableException; //导入依赖的package包/类
private static SecurityIdentity roleToSecurityIdentity(StandardRole role) throws RealmUnavailableException {
if (role == null) {
return testDomain.getAnonymousSecurityIdentity();
}
ServerAuthenticationContext authenticationContext = testDomain.createNewAuthenticationContext();
authenticationContext.setAuthenticationName(roleToUserName(role));
assertTrue("Authorized", authenticationContext.authorize());
return authenticationContext.getAuthorizedIdentity();
}
示例7: getRealmIdentity
import org.wildfly.security.auth.server.RealmUnavailableException; //导入依赖的package包/类
@Override
public RealmIdentity getRealmIdentity(Principal principal) throws RealmUnavailableException {
String name = principal.getName();
if (allowAll || allowedUsersSet.contains(name)) {
return new LocalRealmIdentity(principal);
}
return RealmIdentity.NON_EXISTENT;
}
示例8: getAuthorizationIdentity
import org.wildfly.security.auth.server.RealmUnavailableException; //导入依赖的package包/类
@Override
public AuthorizationIdentity getAuthorizationIdentity() throws RealmUnavailableException {
List<String> list = new ArrayList<>();
for (RealmGroup realmGroup : subject.getPrincipals(RealmGroup.class)) {
String realmGroupName = realmGroup.getName();
list.add(realmGroupName);
}
Attributes attributes = new MapAttributes(Collections.singletonMap("GROUPS",
list));
return AuthorizationIdentity.basicIdentity(attributes);
}
示例9: createSecurityIdentity
import org.wildfly.security.auth.server.RealmUnavailableException; //导入依赖的package包/类
private static SecurityIdentity createSecurityIdentity(Principal principal, Set<String> roles) {
ServerAuthenticationContext serverAuthenticationContext = INFLOW_SECURITY_DOMAIN.createNewAuthenticationContext();
try {
serverAuthenticationContext.verifyEvidence(new EvidenceWithRoles(principal, roles));
serverAuthenticationContext.authorize();
} catch (RealmUnavailableException e) {
// As the domain is backed by a dummy realm that never throws this Exception it is impossible for it to be thrown.
throw new IllegalStateException(e);
}
return serverAuthenticationContext.getAuthorizedIdentity();
}
示例10: getRealmIdentity
import org.wildfly.security.auth.server.RealmUnavailableException; //导入依赖的package包/类
@Override
public RealmIdentity getRealmIdentity(Principal principal) throws RealmUnavailableException {
try {
Properties users = getProperties();
String name = principal.getName();
return new RealmIdentityImpl(principal, users.getProperty(name));
} catch (IOException e) {
throw new RealmUnavailableException(e);
}
}
示例11: getAuthorizationIdentity
import org.wildfly.security.auth.server.RealmUnavailableException; //导入依赖的package包/类
@Override
public AuthorizationIdentity getAuthorizationIdentity() throws RealmUnavailableException {
Map<String, List<String>> groupsAttributeMap = new HashMap<String, List<String>>();
groupsAttributeMap.put("GROUPS", Arrays.asList(groups));
return AuthorizationIdentity.basicIdentity(new MapAttributes(Collections.unmodifiableMap(groupsAttributeMap)));
}
示例12: getAuthorizationIdentity
import org.wildfly.security.auth.server.RealmUnavailableException; //导入依赖的package包/类
@Override
public AuthorizationIdentity getAuthorizationIdentity() throws RealmUnavailableException {
Set<String> groups = getGroups();
if (groups != null && groups.size() > 0) {
Map<String, Set<String>> groupsAttributeMap = new HashMap<String, Set<String>>();
groupsAttributeMap.put("GROUPS",Collections.unmodifiableSet(groups));
return AuthorizationIdentity.basicIdentity(new MapAttributes(Collections.unmodifiableMap(groupsAttributeMap)));
} else {
SECURITY_LOGGER.tracef("No groups found for identity '%s' in LDAP file.", principal.getName());
return AuthorizationIdentity.EMPTY;
}
}
示例13: getGroups
import org.wildfly.security.auth.server.RealmUnavailableException; //导入依赖的package包/类
private synchronized Set<String> getGroups() throws RealmUnavailableException {
if (groups == null) {
try {
groups = ldapGroupSearcher.loadGroups(Collections.singleton(principal.getName()));
} catch (IOException e) {
throw new RealmUnavailableException(e);
}
}
return groups;
}
示例14: getRealmIdentity
import org.wildfly.security.auth.server.RealmUnavailableException; //导入依赖的package包/类
@Override
public RealmIdentity getRealmIdentity(Evidence evidence) throws RealmUnavailableException {
try {
sharedStateLocal.set(new HashMap<>());
return wrapped.getRealmIdentity(evidence);
} finally {
sharedStateLocal.remove();
}
}
示例15: getRealmIdentity
import org.wildfly.security.auth.server.RealmUnavailableException; //导入依赖的package包/类
@Override
public RealmIdentity getRealmIdentity(Principal principal) throws RealmUnavailableException {
try {
Properties groups = getProperties();
String name = principal.getName();
return new RealmIdentityImpl(principal, groups.getProperty(name, "").trim());
} catch (IOException e) {
throw new RealmUnavailableException(e);
}
}