Search in sources :

Example 1 with AuthorizationType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.AuthorizationType in project midpoint by Evolveum.

the class InitialDataImport method init.

public void init() throws SchemaException {
    LOGGER.info("Starting initial object import (if necessary).");
    OperationResult mainResult = new OperationResult(OPERATION_INITIAL_OBJECTS_IMPORT);
    Task task = taskManager.createTaskInstance(OPERATION_INITIAL_OBJECTS_IMPORT);
    task.setChannel(SchemaConstants.CHANNEL_GUI_INIT_URI);
    int count = 0;
    int errors = 0;
    File[] files = getInitialImportObjects();
    LOGGER.debug("Files to be imported: {}.", Arrays.toString(files));
    // We need to provide a fake Spring security context here.
    // We have to fake it because we do not have anything in the repository yet. And to get
    // something to the repository we need a context. Chicken and egg. So we fake the egg.
    SecurityContext securityContext = SecurityContextHolder.getContext();
    UserType userAdministrator = new UserType();
    prismContext.adopt(userAdministrator);
    userAdministrator.setName(new PolyStringType(new PolyString("initAdmin", "initAdmin")));
    MidPointPrincipal principal = new MidPointPrincipal(userAdministrator);
    AuthorizationType superAutzType = new AuthorizationType();
    prismContext.adopt(superAutzType, RoleType.class, new ItemPath(RoleType.F_AUTHORIZATION));
    superAutzType.getAction().add(AuthorizationConstants.AUTZ_ALL_URL);
    Authorization superAutz = new Authorization(superAutzType);
    Collection<Authorization> authorities = principal.getAuthorities();
    authorities.add(superAutz);
    Authentication authentication = new PreAuthenticatedAuthenticationToken(principal, null);
    securityContext.setAuthentication(authentication);
    for (File file : files) {
        try {
            LOGGER.debug("Considering initial import of file {}.", file.getName());
            PrismObject object = prismContext.parseObject(file);
            if (ReportType.class.equals(object.getCompileTimeClass())) {
                ReportTypeUtil.applyDefinition(object, prismContext);
            }
            Boolean importObject = importObject(object, file, task, mainResult);
            if (importObject == null) {
                continue;
            }
            if (importObject) {
                count++;
            } else {
                errors++;
            }
        } catch (Exception ex) {
            LoggingUtils.logUnexpectedException(LOGGER, "Couldn't import file {}", ex, file.getName());
            mainResult.recordFatalError("Couldn't import file '" + file.getName() + "'", ex);
        }
    }
    securityContext.setAuthentication(null);
    mainResult.recomputeStatus("Couldn't import objects.");
    LOGGER.info("Initial object import finished ({} objects imported, {} errors)", count, errors);
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("Initialization status:\n" + mainResult.debugDump());
    }
}
Also used : PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) Task(com.evolveum.midpoint.task.api.Task) PreAuthenticatedAuthenticationToken(org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) URISyntaxException(java.net.URISyntaxException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) IOException(java.io.IOException) Authorization(com.evolveum.midpoint.security.api.Authorization) PrismObject(com.evolveum.midpoint.prism.PrismObject) Authentication(org.springframework.security.core.Authentication) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) SecurityContext(org.springframework.security.core.context.SecurityContext) AuthorizationType(com.evolveum.midpoint.xml.ns._public.common.common_3.AuthorizationType) File(java.io.File) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) MidPointPrincipal(com.evolveum.midpoint.security.api.MidPointPrincipal) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 2 with AuthorizationType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.AuthorizationType in project midpoint by Evolveum.

the class TestAbstractAuthenticationEvaluator method addFakeAuthorization.

private void addFakeAuthorization(MidPointPrincipal principal) {
    if (principal == null) {
        return;
    }
    if (principal.getAuthorities().isEmpty()) {
        AuthorizationType authorizationType = new AuthorizationType();
        authorizationType.getAction().add("FAKE");
        principal.getAuthorities().add(new Authorization(authorizationType));
    }
}
Also used : AuthorizationType(com.evolveum.midpoint.xml.ns._public.common.common_3.AuthorizationType)

Example 3 with AuthorizationType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.AuthorizationType in project midpoint by Evolveum.

the class GuiAuthenticationChannel method resolveAuthorities.

@Override
public Collection<Authorization> resolveAuthorities(Collection<Authorization> authorities) {
    if (isPostAuthenticationEnabled()) {
        AuthorizationType authorizationType = new AuthorizationType();
        authorizationType.getAction().add(AuthorizationConstants.AUTZ_UI_SELF_POST_AUTHENTICATION_URL);
        Authorization postAuthenticationAuthz = new Authorization(authorizationType);
        return Collections.singletonList(postAuthenticationAuthz);
    }
    return super.resolveAuthorities(authorities);
}
Also used : Authorization(com.evolveum.midpoint.security.api.Authorization) AuthorizationType(com.evolveum.midpoint.xml.ns._public.common.common_3.AuthorizationType)

Example 4 with AuthorizationType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.AuthorizationType in project midpoint by Evolveum.

the class ResetPasswordAuthenticationChannel method resolveAuthorities.

public Collection<Authorization> resolveAuthorities(@NotNull Collection<Authorization> authorities) {
    ArrayList<Authorization> newAuthorities = new ArrayList<>();
    for (Authorization authzI : authorities) {
        authzI.getAction().removeIf(action -> action.contains(AuthorizationConstants.NS_AUTHORIZATION_UI));
    }
    AuthorizationType authorizationType = new AuthorizationType();
    authorizationType.getAction().add(AuthorizationConstants.AUTZ_UI_SELF_CREDENTIALS_URL);
    Authorization selfServiceCredentialsAuthz = new Authorization(authorizationType);
    newAuthorities.add(selfServiceCredentialsAuthz);
    authorities.addAll(newAuthorities);
    return authorities;
}
Also used : Authorization(com.evolveum.midpoint.security.api.Authorization) ArrayList(java.util.ArrayList) AuthorizationType(com.evolveum.midpoint.xml.ns._public.common.common_3.AuthorizationType)

Example 5 with AuthorizationType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.AuthorizationType in project midpoint by Evolveum.

the class SecurityContextManagerImpl method createPrivilegedAuthorization.

private Authorization createPrivilegedAuthorization() {
    AuthorizationType authorizationType = new AuthorizationType();
    authorizationType.getAction().add(AuthorizationConstants.AUTZ_ALL_URL);
    return new Authorization(authorizationType);
}
Also used : AuthorizationType(com.evolveum.midpoint.xml.ns._public.common.common_3.AuthorizationType)

Aggregations

AuthorizationType (com.evolveum.midpoint.xml.ns._public.common.common_3.AuthorizationType)9 Authorization (com.evolveum.midpoint.security.api.Authorization)5 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)2 RoleType (com.evolveum.midpoint.xml.ns._public.common.common_3.RoleType)2 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)2 ArrayList (java.util.ArrayList)2 Test (org.testng.annotations.Test)2 AbstractInitializedModelIntegrationTest (com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)1 PrismObject (com.evolveum.midpoint.prism.PrismObject)1 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)1 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)1 MidPointPrincipal (com.evolveum.midpoint.security.api.MidPointPrincipal)1 Task (com.evolveum.midpoint.task.api.Task)1 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)1 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1 ActivationType (com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationType)1 AssignmentType (com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType)1 OwnedObjectSelectorType (com.evolveum.midpoint.xml.ns._public.common.common_3.OwnedObjectSelectorType)1 PolicyExceptionType (com.evolveum.midpoint.xml.ns._public.common.common_3.PolicyExceptionType)1 PolicyRuleType (com.evolveum.midpoint.xml.ns._public.common.common_3.PolicyRuleType)1