You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by il...@apache.org on 2016/03/09 12:52:51 UTC
[15/17] syncope git commit: Further refactoring as per SYNCOPE-620
http://git-wip-us.apache.org/repos/asf/syncope/blob/28569df5/core/misc/src/main/java/org/apache/syncope/core/misc/security/SyncopeAccessDeniedHandler.java
----------------------------------------------------------------------
diff --git a/core/misc/src/main/java/org/apache/syncope/core/misc/security/SyncopeAccessDeniedHandler.java b/core/misc/src/main/java/org/apache/syncope/core/misc/security/SyncopeAccessDeniedHandler.java
deleted file mode 100644
index 8ab1d31..0000000
--- a/core/misc/src/main/java/org/apache/syncope/core/misc/security/SyncopeAccessDeniedHandler.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.syncope.core.misc.security;
-
-import java.io.IOException;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import org.apache.syncope.common.rest.api.RESTHeaders;
-import org.springframework.security.access.AccessDeniedException;
-import org.springframework.security.web.access.AccessDeniedHandlerImpl;
-
-/**
- * Render Spring's {@link AccessDeniedException} as other Syncope errors.
- */
-public class SyncopeAccessDeniedHandler extends AccessDeniedHandlerImpl {
-
- @Override
- public void handle(final HttpServletRequest request, final HttpServletResponse response,
- final AccessDeniedException accessDeniedException) throws IOException, ServletException {
-
- response.addHeader(RESTHeaders.ERROR_INFO, accessDeniedException.getMessage());
-
- super.handle(request, response, accessDeniedException);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/syncope/blob/28569df5/core/misc/src/main/java/org/apache/syncope/core/misc/security/SyncopeAuthenticationDetails.java
----------------------------------------------------------------------
diff --git a/core/misc/src/main/java/org/apache/syncope/core/misc/security/SyncopeAuthenticationDetails.java b/core/misc/src/main/java/org/apache/syncope/core/misc/security/SyncopeAuthenticationDetails.java
deleted file mode 100644
index 68b27f4..0000000
--- a/core/misc/src/main/java/org/apache/syncope/core/misc/security/SyncopeAuthenticationDetails.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.syncope.core.misc.security;
-
-import java.io.Serializable;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpSession;
-import org.apache.commons.lang3.builder.EqualsBuilder;
-import org.apache.commons.lang3.builder.HashCodeBuilder;
-import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
-import org.apache.commons.lang3.builder.ToStringStyle;
-import org.apache.syncope.common.rest.api.RESTHeaders;
-
-public class SyncopeAuthenticationDetails implements Serializable {
-
- private static final long serialVersionUID = -5899959397393502897L;
-
- private final String remoteAddress;
-
- private final String sessionId;
-
- private String domain;
-
- public SyncopeAuthenticationDetails(final HttpServletRequest request) {
- this.remoteAddress = request.getRemoteAddr();
-
- HttpSession session = request.getSession(false);
- this.sessionId = session == null ? null : session.getId();
-
- this.domain = request.getHeader(RESTHeaders.DOMAIN);
- }
-
- public SyncopeAuthenticationDetails(final String domain) {
- this.remoteAddress = null;
- this.sessionId = null;
- this.domain = domain;
- }
-
- public String getRemoteAddress() {
- return remoteAddress;
- }
-
- public String getSessionId() {
- return sessionId;
- }
-
- public String getDomain() {
- return domain;
- }
-
- public void setDomain(final String domain) {
- this.domain = domain;
- }
-
- @Override
- public boolean equals(final Object obj) {
- return EqualsBuilder.reflectionEquals(this, obj);
- }
-
- @Override
- public int hashCode() {
- return HashCodeBuilder.reflectionHashCode(this);
- }
-
- @Override
- public String toString() {
- return ReflectionToStringBuilder.toString(this, ToStringStyle.MULTI_LINE_STYLE);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/syncope/blob/28569df5/core/misc/src/main/java/org/apache/syncope/core/misc/security/SyncopeAuthenticationDetailsSource.java
----------------------------------------------------------------------
diff --git a/core/misc/src/main/java/org/apache/syncope/core/misc/security/SyncopeAuthenticationDetailsSource.java b/core/misc/src/main/java/org/apache/syncope/core/misc/security/SyncopeAuthenticationDetailsSource.java
deleted file mode 100644
index b943edf..0000000
--- a/core/misc/src/main/java/org/apache/syncope/core/misc/security/SyncopeAuthenticationDetailsSource.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.syncope.core.misc.security;
-
-import javax.servlet.http.HttpServletRequest;
-import org.springframework.security.authentication.AuthenticationDetailsSource;
-
-public class SyncopeAuthenticationDetailsSource
- implements AuthenticationDetailsSource<HttpServletRequest, SyncopeAuthenticationDetails> {
-
- @Override
- public SyncopeAuthenticationDetails buildDetails(final HttpServletRequest context) {
- return new SyncopeAuthenticationDetails(context);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/syncope/blob/28569df5/core/misc/src/main/java/org/apache/syncope/core/misc/security/SyncopeAuthenticationEntryPoint.java
----------------------------------------------------------------------
diff --git a/core/misc/src/main/java/org/apache/syncope/core/misc/security/SyncopeAuthenticationEntryPoint.java b/core/misc/src/main/java/org/apache/syncope/core/misc/security/SyncopeAuthenticationEntryPoint.java
deleted file mode 100644
index 6213264..0000000
--- a/core/misc/src/main/java/org/apache/syncope/core/misc/security/SyncopeAuthenticationEntryPoint.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.syncope.core.misc.security;
-
-import java.io.IOException;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import org.apache.syncope.common.rest.api.RESTHeaders;
-import org.springframework.security.core.AuthenticationException;
-import org.springframework.security.web.authentication.www.BasicAuthenticationEntryPoint;
-
-/**
- * Render Spring's {@link AuthenticationException} as other Syncope errors.
- */
-public class SyncopeAuthenticationEntryPoint extends BasicAuthenticationEntryPoint {
-
- @Override
- public void commence(final HttpServletRequest request, final HttpServletResponse response,
- final AuthenticationException authException) throws IOException, ServletException {
-
- response.addHeader(RESTHeaders.ERROR_INFO, authException.getMessage());
-
- super.commence(request, response, authException);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/syncope/blob/28569df5/core/misc/src/main/java/org/apache/syncope/core/misc/security/SyncopeAuthenticationProvider.java
----------------------------------------------------------------------
diff --git a/core/misc/src/main/java/org/apache/syncope/core/misc/security/SyncopeAuthenticationProvider.java b/core/misc/src/main/java/org/apache/syncope/core/misc/security/SyncopeAuthenticationProvider.java
deleted file mode 100644
index 313b0f1..0000000
--- a/core/misc/src/main/java/org/apache/syncope/core/misc/security/SyncopeAuthenticationProvider.java
+++ /dev/null
@@ -1,210 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.syncope.core.misc.security;
-
-import javax.annotation.Resource;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.commons.lang3.tuple.Pair;
-import org.apache.syncope.common.lib.SyncopeConstants;
-import org.apache.syncope.common.lib.types.AuditElements;
-import org.apache.syncope.common.lib.types.AuditElements.Result;
-import org.apache.syncope.common.lib.types.CipherAlgorithm;
-import org.apache.syncope.core.misc.security.AuthContextUtils.Executable;
-import org.apache.syncope.core.persistence.api.entity.Domain;
-import org.apache.syncope.core.provisioning.api.UserProvisioningManager;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Configurable;
-import org.springframework.security.authentication.AuthenticationProvider;
-import org.springframework.security.authentication.BadCredentialsException;
-import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
-import org.springframework.security.core.Authentication;
-import org.springframework.security.core.userdetails.UserDetailsService;
-
-@Configurable
-public class SyncopeAuthenticationProvider implements AuthenticationProvider {
-
- protected static final Logger LOG = LoggerFactory.getLogger(SyncopeAuthenticationProvider.class);
-
- @Autowired
- protected AuthDataAccessor dataAccessor;
-
- @Autowired
- protected UserProvisioningManager provisioningManager;
-
- @Resource(name = "adminUser")
- protected String adminUser;
-
- @Resource(name = "anonymousUser")
- protected String anonymousUser;
-
- protected String adminPassword;
-
- protected String adminPasswordAlgorithm;
-
- protected String anonymousKey;
-
- protected UserDetailsService userDetailsService;
-
- protected final Encryptor encryptor = Encryptor.getInstance();
-
- /**
- * @param adminPassword the adminPassword to set
- */
- public void setAdminPassword(final String adminPassword) {
- this.adminPassword = adminPassword;
- }
-
- /**
- * @param adminPasswordAlgorithm the adminPasswordAlgorithm to set
- */
- public void setAdminPasswordAlgorithm(final String adminPasswordAlgorithm) {
- this.adminPasswordAlgorithm = adminPasswordAlgorithm;
- }
-
- /**
- * @param anonymousKey the anonymousKey to set
- */
- public void setAnonymousKey(final String anonymousKey) {
- this.anonymousKey = anonymousKey;
- }
-
- public void setUserDetailsService(final UserDetailsService syncopeUserDetailsService) {
- this.userDetailsService = syncopeUserDetailsService;
- }
-
- @Override
- public Authentication authenticate(final Authentication authentication) {
- String domainKey = SyncopeAuthenticationDetails.class.cast(authentication.getDetails()).getDomain();
- if (StringUtils.isBlank(domainKey)) {
- domainKey = SyncopeConstants.MASTER_DOMAIN;
- }
- SyncopeAuthenticationDetails.class.cast(authentication.getDetails()).setDomain(domainKey);
-
- Boolean authenticated;
- if (anonymousUser.equals(authentication.getName())) {
- authenticated = authentication.getCredentials().toString().equals(anonymousKey);
- } else if (adminUser.equals(authentication.getName())) {
- if (SyncopeConstants.MASTER_DOMAIN.equals(domainKey)) {
- authenticated = encryptor.verify(
- authentication.getCredentials().toString(),
- CipherAlgorithm.valueOf(adminPasswordAlgorithm),
- adminPassword);
- } else {
- final String domainToFind = domainKey;
- authenticated = AuthContextUtils.execWithAuthContext(
- SyncopeConstants.MASTER_DOMAIN, new Executable<Boolean>() {
-
- @Override
- public Boolean exec() {
- Domain domain = dataAccessor.findDomain(domainToFind);
-
- return encryptor.verify(
- authentication.getCredentials().toString(),
- domain.getAdminCipherAlgorithm(),
- domain.getAdminPwd());
- }
- });
- }
- } else {
- final Pair<Long, Boolean> authResult =
- AuthContextUtils.execWithAuthContext(domainKey, new Executable<Pair<Long, Boolean>>() {
-
- @Override
- public Pair<Long, Boolean> exec() {
- return dataAccessor.authenticate(authentication);
- }
- });
- authenticated = authResult.getValue();
- if (authenticated != null && !authenticated) {
- AuthContextUtils.execWithAuthContext(domainKey, new Executable<Void>() {
-
- @Override
- public Void exec() {
- provisioningManager.internalSuspend(authResult.getKey());
- return null;
- }
- });
- }
- }
-
- final boolean isAuthenticated = authenticated != null && authenticated;
- UsernamePasswordAuthenticationToken token;
- if (isAuthenticated) {
- token = AuthContextUtils.execWithAuthContext(
- domainKey, new Executable<UsernamePasswordAuthenticationToken>() {
-
- @Override
- public UsernamePasswordAuthenticationToken exec() {
- UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(
- authentication.getPrincipal(),
- null,
- userDetailsService.loadUserByUsername(authentication.getPrincipal().toString()).
- getAuthorities());
- token.setDetails(authentication.getDetails());
-
- dataAccessor.audit(
- AuditElements.EventCategoryType.REST,
- AuditElements.AUTHENTICATION_CATEGORY,
- null,
- AuditElements.LOGIN_EVENT,
- Result.SUCCESS,
- null,
- isAuthenticated,
- authentication,
- "Successfully authenticated, with entitlements: " + token.getAuthorities());
- return token;
- }
- });
-
- LOG.debug("User {} successfully authenticated, with entitlements {}",
- authentication.getPrincipal(), token.getAuthorities());
- } else {
- AuthContextUtils.execWithAuthContext(domainKey, new Executable<Void>() {
-
- @Override
- public Void exec() {
- dataAccessor.audit(
- AuditElements.EventCategoryType.REST,
- AuditElements.AUTHENTICATION_CATEGORY,
- null,
- AuditElements.LOGIN_EVENT,
- Result.FAILURE,
- null,
- isAuthenticated,
- authentication,
- "User " + authentication.getPrincipal() + " not authenticated");
- return null;
- }
- });
-
- LOG.debug("User {} not authenticated", authentication.getPrincipal());
-
- throw new BadCredentialsException("User " + authentication.getPrincipal() + " not authenticated");
- }
-
- return token;
- }
-
- @Override
- public boolean supports(final Class<? extends Object> type) {
- return type.equals(UsernamePasswordAuthenticationToken.class);
- }
-}
http://git-wip-us.apache.org/repos/asf/syncope/blob/28569df5/core/misc/src/main/java/org/apache/syncope/core/misc/security/SyncopeGrantedAuthority.java
----------------------------------------------------------------------
diff --git a/core/misc/src/main/java/org/apache/syncope/core/misc/security/SyncopeGrantedAuthority.java b/core/misc/src/main/java/org/apache/syncope/core/misc/security/SyncopeGrantedAuthority.java
deleted file mode 100644
index 706bf15..0000000
--- a/core/misc/src/main/java/org/apache/syncope/core/misc/security/SyncopeGrantedAuthority.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.syncope.core.misc.security;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
-import org.apache.commons.collections4.Closure;
-import org.apache.commons.collections4.IterableUtils;
-import org.apache.commons.collections4.SetUtils;
-import org.apache.commons.lang3.builder.EqualsBuilder;
-import org.apache.commons.lang3.builder.HashCodeBuilder;
-import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
-import org.apache.commons.lang3.builder.ToStringStyle;
-import org.apache.syncope.core.misc.utils.RealmUtils;
-import org.springframework.security.core.GrantedAuthority;
-
-public class SyncopeGrantedAuthority implements GrantedAuthority {
-
- private static final long serialVersionUID = -5647624636011919735L;
-
- private final String entitlement;
-
- private final Set<String> realms = SetUtils.orderedSet(new HashSet<String>());
-
- public SyncopeGrantedAuthority(final String entitlement) {
- this.entitlement = entitlement;
- }
-
- public SyncopeGrantedAuthority(final String entitlement, final String realm) {
- this.entitlement = entitlement;
- this.realms.add(realm);
- }
-
- public boolean addRealm(final String newRealm) {
- return RealmUtils.normalizingAddTo(realms, newRealm);
- }
-
- public void addRealms(final Collection<String> newRealms) {
- IterableUtils.forEach(newRealms, new Closure<String>() {
-
- @Override
- public void execute(final String newRealm) {
- addRealm(newRealm);
- }
- });
- }
-
- public Set<String> getRealms() {
- return Collections.unmodifiableSet(realms);
- }
-
- @Override
- public String getAuthority() {
- return entitlement;
- }
-
- @Override
- public boolean equals(final Object obj) {
- return EqualsBuilder.reflectionEquals(this, obj);
- }
-
- @Override
- public int hashCode() {
- return HashCodeBuilder.reflectionHashCode(this);
- }
-
- @Override
- public String toString() {
- return ReflectionToStringBuilder.toString(this, ToStringStyle.MULTI_LINE_STYLE);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/syncope/blob/28569df5/core/misc/src/main/java/org/apache/syncope/core/misc/security/SyncopeUserDetailsService.java
----------------------------------------------------------------------
diff --git a/core/misc/src/main/java/org/apache/syncope/core/misc/security/SyncopeUserDetailsService.java b/core/misc/src/main/java/org/apache/syncope/core/misc/security/SyncopeUserDetailsService.java
deleted file mode 100644
index 70ec6ac..0000000
--- a/core/misc/src/main/java/org/apache/syncope/core/misc/security/SyncopeUserDetailsService.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.syncope.core.misc.security;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Configurable;
-import org.springframework.security.core.userdetails.User;
-import org.springframework.security.core.userdetails.UserDetails;
-import org.springframework.security.core.userdetails.UserDetailsService;
-
-@Configurable
-public class SyncopeUserDetailsService implements UserDetailsService {
-
- @Autowired
- protected AuthDataAccessor dataAccessor;
-
- @Override
- public UserDetails loadUserByUsername(final String username) {
- return new User(username, "<PASSWORD_PLACEHOLDER>", dataAccessor.load(username));
- }
-}
http://git-wip-us.apache.org/repos/asf/syncope/blob/28569df5/core/misc/src/main/java/org/apache/syncope/core/misc/serialization/AttributeDeserializer.java
----------------------------------------------------------------------
diff --git a/core/misc/src/main/java/org/apache/syncope/core/misc/serialization/AttributeDeserializer.java b/core/misc/src/main/java/org/apache/syncope/core/misc/serialization/AttributeDeserializer.java
deleted file mode 100644
index 5c2ab51..0000000
--- a/core/misc/src/main/java/org/apache/syncope/core/misc/serialization/AttributeDeserializer.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.syncope.core.misc.serialization;
-
-import com.fasterxml.jackson.core.JsonParser;
-import com.fasterxml.jackson.databind.DeserializationContext;
-import com.fasterxml.jackson.databind.JsonDeserializer;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.node.ObjectNode;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import org.apache.commons.lang3.StringUtils;
-import org.identityconnectors.common.Base64;
-import org.identityconnectors.common.security.GuardedString;
-import org.identityconnectors.framework.common.objects.Attribute;
-import org.identityconnectors.framework.common.objects.AttributeBuilder;
-import org.identityconnectors.framework.common.objects.Name;
-import org.identityconnectors.framework.common.objects.Uid;
-
-class AttributeDeserializer extends JsonDeserializer<Attribute> {
-
- @Override
- public Attribute deserialize(final JsonParser jp, final DeserializationContext ctx)
- throws IOException {
-
- ObjectNode tree = jp.readValueAsTree();
-
- String name = tree.get("name").asText();
-
- List<Object> values = new ArrayList<Object>();
- for (Iterator<JsonNode> itor = tree.get("value").iterator(); itor.hasNext();) {
- JsonNode node = itor.next();
- if (node.isNull()) {
- values.add(null);
- } else if (node.isObject()) {
- values.add(((ObjectNode) node).traverse(jp.getCodec()).readValueAs(GuardedString.class));
- } else if (node.isBoolean()) {
- values.add(node.asBoolean());
- } else if (node.isDouble()) {
- values.add(node.asDouble());
- } else if (node.isLong()) {
- values.add(node.asLong());
- } else if (node.isInt()) {
- values.add(node.asInt());
- } else {
- String text = node.asText();
- if (text.startsWith(AttributeSerializer.BYTE_ARRAY_PREFIX)
- && text.endsWith(AttributeSerializer.BYTE_ARRAY_SUFFIX)) {
-
- values.add(Base64.decode(StringUtils.substringBetween(
- text, AttributeSerializer.BYTE_ARRAY_PREFIX, AttributeSerializer.BYTE_ARRAY_SUFFIX)));
- } else {
- values.add(text);
- }
- }
- }
-
- return Uid.NAME.equals(name)
- ? new Uid(values.isEmpty() || values.get(0) == null ? null : values.get(0).toString())
- : Name.NAME.equals(name)
- ? new Name(values.isEmpty() || values.get(0) == null ? null : values.get(0).toString())
- : AttributeBuilder.build(name, values);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/syncope/blob/28569df5/core/misc/src/main/java/org/apache/syncope/core/misc/serialization/AttributeSerializer.java
----------------------------------------------------------------------
diff --git a/core/misc/src/main/java/org/apache/syncope/core/misc/serialization/AttributeSerializer.java b/core/misc/src/main/java/org/apache/syncope/core/misc/serialization/AttributeSerializer.java
deleted file mode 100644
index 3c79c28..0000000
--- a/core/misc/src/main/java/org/apache/syncope/core/misc/serialization/AttributeSerializer.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.syncope.core.misc.serialization;
-
-import com.fasterxml.jackson.core.JsonGenerator;
-import com.fasterxml.jackson.databind.JsonSerializer;
-import com.fasterxml.jackson.databind.SerializerProvider;
-import java.io.IOException;
-import org.identityconnectors.common.Base64;
-import org.identityconnectors.common.security.GuardedString;
-import org.identityconnectors.framework.common.objects.Attribute;
-
-class AttributeSerializer extends JsonSerializer<Attribute> {
-
- public static final String BYTE_ARRAY_PREFIX = "<binary>";
-
- public static final String BYTE_ARRAY_SUFFIX = "</binary>";
-
- @Override
- public void serialize(final Attribute source, final JsonGenerator jgen, final SerializerProvider sp)
- throws IOException {
-
- jgen.writeStartObject();
-
- jgen.writeStringField("name", source.getName());
-
- jgen.writeFieldName("value");
- if (source.getValue() == null) {
- jgen.writeNull();
- } else {
- jgen.writeStartArray();
- for (Object value : source.getValue()) {
- if (value == null) {
- jgen.writeNull();
- } else if (value instanceof GuardedString) {
- jgen.writeObject(value);
- } else if (value instanceof Integer) {
- jgen.writeNumber((Integer) value);
- } else if (value instanceof Long) {
- jgen.writeNumber((Long) value);
- } else if (value instanceof Double) {
- jgen.writeNumber((Double) value);
- } else if (value instanceof Boolean) {
- jgen.writeBoolean((Boolean) value);
- } else if (value instanceof byte[]) {
- jgen.writeString(BYTE_ARRAY_PREFIX + Base64.encode((byte[]) value) + BYTE_ARRAY_SUFFIX);
- } else {
- jgen.writeString(value.toString());
- }
- }
- jgen.writeEndArray();
- }
-
- jgen.writeEndObject();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/syncope/blob/28569df5/core/misc/src/main/java/org/apache/syncope/core/misc/serialization/GuardedStringDeserializer.java
----------------------------------------------------------------------
diff --git a/core/misc/src/main/java/org/apache/syncope/core/misc/serialization/GuardedStringDeserializer.java b/core/misc/src/main/java/org/apache/syncope/core/misc/serialization/GuardedStringDeserializer.java
deleted file mode 100644
index 1cd0ec0..0000000
--- a/core/misc/src/main/java/org/apache/syncope/core/misc/serialization/GuardedStringDeserializer.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.syncope.core.misc.serialization;
-
-import com.fasterxml.jackson.core.JsonParser;
-import com.fasterxml.jackson.databind.DeserializationContext;
-import com.fasterxml.jackson.databind.JsonDeserializer;
-import com.fasterxml.jackson.databind.node.ObjectNode;
-import java.io.IOException;
-import java.lang.reflect.Field;
-import org.identityconnectors.common.Base64;
-import org.identityconnectors.common.security.EncryptorFactory;
-import org.identityconnectors.common.security.GuardedString;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-class GuardedStringDeserializer extends JsonDeserializer<GuardedString> {
-
- private static final Logger LOG = LoggerFactory.getLogger(GuardedStringDeserializer.class);
-
- @Override
- public GuardedString deserialize(final JsonParser jp, final DeserializationContext ctx)
- throws IOException {
-
- ObjectNode tree = jp.readValueAsTree();
-
- boolean readOnly = false;
- if (tree.has("readOnly")) {
- readOnly = tree.get("readOnly").asBoolean();
- }
- boolean disposed = false;
- if (tree.has("disposed")) {
- disposed = tree.get("disposed").asBoolean();
- }
- byte[] encryptedBytes = null;
- if (tree.has("encryptedBytes")) {
- encryptedBytes = Base64.decode(tree.get("encryptedBytes").asText());
- }
- String base64SHA1Hash = null;
- if (tree.has("base64SHA1Hash")) {
- base64SHA1Hash = tree.get("base64SHA1Hash").asText();
- }
-
- final byte[] clearBytes = EncryptorFactory.getInstance().getDefaultEncryptor().decrypt(encryptedBytes);
-
- GuardedString dest = new GuardedString(new String(clearBytes).toCharArray());
-
- try {
- Field field = GuardedString.class.getDeclaredField("readOnly");
- field.setAccessible(true);
- field.setBoolean(dest, readOnly);
- } catch (Exception e) {
- LOG.error("Could not set field value to {}", readOnly, e);
- }
-
- try {
- Field field = GuardedString.class.getDeclaredField("disposed");
- field.setAccessible(true);
- field.setBoolean(dest, disposed);
- } catch (Exception e) {
- LOG.error("Could not set field value to {}", disposed, e);
- }
-
- if (base64SHA1Hash != null) {
- try {
- Field field = GuardedString.class.getDeclaredField("base64SHA1Hash");
- field.setAccessible(true);
- field.set(dest, base64SHA1Hash);
- } catch (Exception e) {
- LOG.error("Could not set field value to {}", base64SHA1Hash, e);
- }
- }
-
- return dest;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/syncope/blob/28569df5/core/misc/src/main/java/org/apache/syncope/core/misc/serialization/GuardedStringSerializer.java
----------------------------------------------------------------------
diff --git a/core/misc/src/main/java/org/apache/syncope/core/misc/serialization/GuardedStringSerializer.java b/core/misc/src/main/java/org/apache/syncope/core/misc/serialization/GuardedStringSerializer.java
deleted file mode 100644
index 5c780f0..0000000
--- a/core/misc/src/main/java/org/apache/syncope/core/misc/serialization/GuardedStringSerializer.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.syncope.core.misc.serialization;
-
-import com.fasterxml.jackson.core.JsonGenerator;
-import com.fasterxml.jackson.databind.JsonSerializer;
-import com.fasterxml.jackson.databind.SerializerProvider;
-import java.io.IOException;
-import java.lang.reflect.Field;
-import org.identityconnectors.common.Base64;
-import org.identityconnectors.common.security.EncryptorFactory;
-import org.identityconnectors.common.security.GuardedString;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-class GuardedStringSerializer extends JsonSerializer<GuardedString> {
-
- private static final Logger LOG = LoggerFactory.getLogger(GuardedStringSerializer.class);
-
- @Override
- public void serialize(final GuardedString source, final JsonGenerator jgen, final SerializerProvider sp)
- throws IOException {
-
- jgen.writeStartObject();
-
- boolean readOnly = false;
- try {
- Field field = GuardedString.class.getDeclaredField("readOnly");
- field.setAccessible(true);
- readOnly = field.getBoolean(source);
- } catch (Exception e) {
- LOG.error("Could not get field value", e);
- }
- jgen.writeBooleanField("readOnly", readOnly);
-
- boolean disposed = false;
- try {
- Field field = GuardedString.class.getDeclaredField("disposed");
- field.setAccessible(true);
- disposed = field.getBoolean(source);
- } catch (Exception e) {
- LOG.error("Could not get field value", e);
- }
- jgen.writeBooleanField("disposed", disposed);
-
- final StringBuilder cleartext = new StringBuilder();
- source.access(new GuardedString.Accessor() {
-
- @Override
- public void access(final char[] clearChars) {
- cleartext.append(clearChars);
- }
- });
- byte[] encryptedBytes =
- EncryptorFactory.getInstance().getDefaultEncryptor().encrypt(cleartext.toString().getBytes());
- jgen.writeStringField("encryptedBytes", Base64.encode(encryptedBytes));
-
- String base64SHA1Hash = null;
- try {
- Field field = GuardedString.class.getDeclaredField("base64SHA1Hash");
- field.setAccessible(true);
- base64SHA1Hash = field.get(source).toString();
- } catch (Exception e) {
- LOG.error("Could not get field value", e);
- }
- if (base64SHA1Hash != null) {
- jgen.writeStringField("base64SHA1Hash", base64SHA1Hash);
- }
-
- jgen.writeEndObject();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/syncope/blob/28569df5/core/misc/src/main/java/org/apache/syncope/core/misc/serialization/POJOHelper.java
----------------------------------------------------------------------
diff --git a/core/misc/src/main/java/org/apache/syncope/core/misc/serialization/POJOHelper.java b/core/misc/src/main/java/org/apache/syncope/core/misc/serialization/POJOHelper.java
deleted file mode 100644
index dd42568..0000000
--- a/core/misc/src/main/java/org/apache/syncope/core/misc/serialization/POJOHelper.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.syncope.core.misc.serialization;
-
-import com.fasterxml.jackson.core.Version;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.module.SimpleModule;
-import com.fasterxml.jackson.module.afterburner.AfterburnerModule;
-import org.identityconnectors.common.security.GuardedString;
-import org.identityconnectors.framework.common.objects.Attribute;
-import org.identityconnectors.framework.common.objects.SyncToken;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Helper class for serialization and deserialization of configuration objects (POJOs) in JSON.
- */
-public final class POJOHelper {
-
- private static final Logger LOG = LoggerFactory.getLogger(POJOHelper.class);
-
- private static final ObjectMapper MAPPER;
-
- static {
- SimpleModule pojoModule = new SimpleModule("POJOModule", new Version(1, 0, 0, null, null, null));
- pojoModule.addSerializer(GuardedString.class, new GuardedStringSerializer());
- pojoModule.addSerializer(Attribute.class, new AttributeSerializer());
- pojoModule.addSerializer(SyncToken.class, new SyncTokenSerializer());
- pojoModule.addDeserializer(GuardedString.class, new GuardedStringDeserializer());
- pojoModule.addDeserializer(Attribute.class, new AttributeDeserializer());
- pojoModule.addDeserializer(SyncToken.class, new SyncTokenDeserializer());
-
- MAPPER = new ObjectMapper();
- MAPPER.registerModule(pojoModule);
- MAPPER.registerModule(new AfterburnerModule());
- }
-
- public static String serialize(final Object object) {
- String result = null;
-
- try {
- result = MAPPER.writeValueAsString(object);
- } catch (Exception e) {
- LOG.error("During serialization", e);
- }
-
- return result;
- }
-
- public static <T extends Object> T deserialize(final String serialized, final Class<T> reference) {
- T result = null;
-
- try {
- result = MAPPER.readValue(serialized, reference);
- } catch (Exception e) {
- LOG.error("During deserialization", e);
- }
-
- return result;
- }
-
- private POJOHelper() {
- }
-}
http://git-wip-us.apache.org/repos/asf/syncope/blob/28569df5/core/misc/src/main/java/org/apache/syncope/core/misc/serialization/SyncTokenDeserializer.java
----------------------------------------------------------------------
diff --git a/core/misc/src/main/java/org/apache/syncope/core/misc/serialization/SyncTokenDeserializer.java b/core/misc/src/main/java/org/apache/syncope/core/misc/serialization/SyncTokenDeserializer.java
deleted file mode 100644
index cc25ef3..0000000
--- a/core/misc/src/main/java/org/apache/syncope/core/misc/serialization/SyncTokenDeserializer.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.syncope.core.misc.serialization;
-
-import com.fasterxml.jackson.core.JsonParser;
-import com.fasterxml.jackson.databind.DeserializationContext;
-import com.fasterxml.jackson.databind.JsonDeserializer;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.node.ObjectNode;
-import java.io.IOException;
-import org.apache.commons.codec.binary.Base64;
-import org.identityconnectors.framework.common.objects.SyncToken;
-
-class SyncTokenDeserializer extends JsonDeserializer<SyncToken> {
-
- @Override
- public SyncToken deserialize(final JsonParser jp, final DeserializationContext ctx)
- throws IOException {
-
- ObjectNode tree = jp.readValueAsTree();
-
- Object value = null;
- if (tree.has("value")) {
- JsonNode node = tree.get("value");
- value = node.isNull()
- ? null
- : node.isBoolean()
- ? node.asBoolean()
- : node.isDouble()
- ? node.asDouble()
- : node.isLong()
- ? node.asLong()
- : node.isInt()
- ? node.asInt()
- : node.asText();
-
- if (value instanceof String) {
- String base64 = (String) value;
- if (Base64.isBase64(base64)) {
- value = Base64.decodeBase64(base64);
- }
- }
- }
-
- return new SyncToken(value);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/syncope/blob/28569df5/core/misc/src/main/java/org/apache/syncope/core/misc/serialization/SyncTokenSerializer.java
----------------------------------------------------------------------
diff --git a/core/misc/src/main/java/org/apache/syncope/core/misc/serialization/SyncTokenSerializer.java b/core/misc/src/main/java/org/apache/syncope/core/misc/serialization/SyncTokenSerializer.java
deleted file mode 100644
index eb75eb2..0000000
--- a/core/misc/src/main/java/org/apache/syncope/core/misc/serialization/SyncTokenSerializer.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.syncope.core.misc.serialization;
-
-import com.fasterxml.jackson.core.JsonGenerator;
-import com.fasterxml.jackson.databind.JsonSerializer;
-import com.fasterxml.jackson.databind.SerializerProvider;
-import java.io.IOException;
-import org.apache.commons.codec.binary.Base64;
-import org.identityconnectors.framework.common.objects.SyncToken;
-
-class SyncTokenSerializer extends JsonSerializer<SyncToken> {
-
- @Override
- public void serialize(final SyncToken source, final JsonGenerator jgen, final SerializerProvider sp)
- throws IOException {
-
- jgen.writeStartObject();
-
- jgen.writeFieldName("value");
-
- if (source.getValue() == null) {
- jgen.writeNull();
- } else if (source.getValue() instanceof Boolean) {
- jgen.writeBoolean((Boolean) source.getValue());
- } else if (source.getValue() instanceof Double) {
- jgen.writeNumber((Double) source.getValue());
- } else if (source.getValue() instanceof Long) {
- jgen.writeNumber((Long) source.getValue());
- } else if (source.getValue() instanceof Integer) {
- jgen.writeNumber((Integer) source.getValue());
- } else if (source.getValue() instanceof byte[]) {
- jgen.writeString(Base64.encodeBase64String((byte[]) source.getValue()));
- } else {
- jgen.writeString(source.getValue().toString());
- }
-
- jgen.writeEndObject();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/syncope/blob/28569df5/core/misc/src/main/java/org/apache/syncope/core/misc/spring/ApplicationContextProvider.java
----------------------------------------------------------------------
diff --git a/core/misc/src/main/java/org/apache/syncope/core/misc/spring/ApplicationContextProvider.java b/core/misc/src/main/java/org/apache/syncope/core/misc/spring/ApplicationContextProvider.java
deleted file mode 100644
index e67dcd6..0000000
--- a/core/misc/src/main/java/org/apache/syncope/core/misc/spring/ApplicationContextProvider.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.syncope.core.misc.spring;
-
-import org.springframework.beans.factory.support.DefaultListableBeanFactory;
-import org.springframework.context.ApplicationContext;
-import org.springframework.context.ApplicationContextAware;
-import org.springframework.context.ConfigurableApplicationContext;
-
-public class ApplicationContextProvider implements ApplicationContextAware {
-
- private static ConfigurableApplicationContext CTX;
-
- private static DefaultListableBeanFactory BEAN_FACTORY;
-
- public static ConfigurableApplicationContext getApplicationContext() {
- return CTX;
- }
-
- public static DefaultListableBeanFactory getBeanFactory() {
- return BEAN_FACTORY == null
- ? CTX == null
- ? null
- : (DefaultListableBeanFactory) CTX.getBeanFactory()
- : BEAN_FACTORY;
- }
-
- public static void setBeanFactory(final DefaultListableBeanFactory beanFactory) {
- BEAN_FACTORY = beanFactory;
- }
-
- /**
- * Wiring the ApplicationContext into a static method.
- *
- * @param ctx Spring application context
- */
- @Override
- public void setApplicationContext(final ApplicationContext ctx) {
- CTX = (ConfigurableApplicationContext) ctx;
- }
-}
http://git-wip-us.apache.org/repos/asf/syncope/blob/28569df5/core/misc/src/main/java/org/apache/syncope/core/misc/spring/BeanUtils.java
----------------------------------------------------------------------
diff --git a/core/misc/src/main/java/org/apache/syncope/core/misc/spring/BeanUtils.java b/core/misc/src/main/java/org/apache/syncope/core/misc/spring/BeanUtils.java
deleted file mode 100644
index 5f9fd4d..0000000
--- a/core/misc/src/main/java/org/apache/syncope/core/misc/spring/BeanUtils.java
+++ /dev/null
@@ -1,193 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.syncope.core.misc.spring;
-
-import static org.springframework.beans.BeanUtils.getPropertyDescriptor;
-import static org.springframework.beans.BeanUtils.getPropertyDescriptors;
-
-import java.beans.PropertyDescriptor;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import org.springframework.beans.FatalBeanException;
-import org.springframework.util.Assert;
-import org.springframework.util.ClassUtils;
-
-/**
- * Overrides Spring's BeanUtils not using collection setters but instead getters + addAll() / putAll(),
- * in a JAXB friendly way.
- *
- * Refer to <a href="https://issues.apache.org/jira/browse/SYNCOPE-246">SYNCOPE-246</a> for more information.
- *
- * @see org.springframework.beans.BeanUtils
- */
-public final class BeanUtils {
-
- private BeanUtils() {
- // Empty private constructor for static utility classes
- }
-
- /**
- * Copy the property values of the given source bean into the target bean.
- * <p>
- * Note: The source and target classes do not have to match or even be derived
- * from each other, as long as the properties match. Any bean properties that the
- * source bean exposes but the target bean does not will silently be ignored.
- * </p><p>
- * This is just a convenience method. For more complex transfer needs,
- * consider using a full BeanWrapper.
- * </p>
- *
- * @param source the source bean
- * @param target the target bean
- * @see org.springframework.beans.BeanWrapper
- */
- public static void copyProperties(final Object source, final Object target) {
- copyProperties(source, target, null, (String[]) null);
- }
-
- /**
- * Copy the property values of the given source bean into the given target bean,
- * only setting properties defined in the given "editable" class (or interface).
- * <p>
- * Note: The source and target classes do not have to match or even be derived
- * from each other, as long as the properties match. Any bean properties that the
- * source bean exposes but the target bean does not will silently be ignored.
- * </p><p>
- * This is just a convenience method. For more complex transfer needs,
- * consider using a full BeanWrapper.
- * </p>
- *
- * @param source the source bean
- * @param target the target bean
- * @param editable the class (or interface) to restrict property setting to
- * @see org.springframework.beans.BeanWrapper
- */
- public static void copyProperties(final Object source, final Object target, final Class<?> editable) {
- copyProperties(source, target, editable, (String[]) null);
- }
-
- /**
- * Copy the property values of the given source bean into the given target bean,
- * ignoring the given "ignoreProperties".
- * <p>
- * Note: The source and target classes do not have to match or even be derived
- * from each other, as long as the properties match. Any bean properties that the
- * source bean exposes but the target bean does not will silently be ignored.
- * </p><p>
- * This is just a convenience method. For more complex transfer needs,
- * consider using a full BeanWrapper.
- * </p>
- *
- * @param source the source bean
- * @param target the target bean
- * @param ignoreProperties array of property names to ignore
- * @see org.springframework.beans.BeanWrapper
- */
- public static void copyProperties(final Object source, final Object target, final String... ignoreProperties) {
- copyProperties(source, target, null, ignoreProperties);
- }
-
- /**
- * Copy the property values of the given source bean into the given target bean.
- * <p>
- * Note: The source and target classes do not have to match or even be derived
- * from each other, as long as the properties match. Any bean properties that the
- * source bean exposes but the target bean does not will silently be ignored.
- * </p>
- *
- * @param source the source bean
- * @param target the target bean
- * @param editable the class (or interface) to restrict property setting to
- * @param ignoreProperties array of property names to ignore
- * @see org.springframework.beans.BeanWrapper
- */
- @SuppressWarnings("unchecked")
- private static void copyProperties(
- final Object source, final Object target, final Class<?> editable, final String... ignoreProperties) {
-
- Assert.notNull(source, "Source must not be null");
- Assert.notNull(target, "Target must not be null");
-
- Class<?> actualEditable = target.getClass();
- if (editable != null) {
- if (!editable.isInstance(target)) {
- throw new IllegalArgumentException("Target class [" + target.getClass().getName()
- + "] not assignable to Editable class [" + editable.getName() + "]");
- }
- actualEditable = editable;
- }
- PropertyDescriptor[] targetPds = getPropertyDescriptors(actualEditable);
- List<String> ignoreList = (ignoreProperties == null)
- ? Collections.<String>emptyList() : Arrays.asList(ignoreProperties);
-
- for (PropertyDescriptor targetPd : targetPds) {
- if (ignoreProperties == null || (!ignoreList.contains(targetPd.getName()))) {
- PropertyDescriptor sourcePd = getPropertyDescriptor(source.getClass(), targetPd.getName());
- if (sourcePd != null) {
- Method readMethod = sourcePd.getReadMethod();
- if (readMethod != null) {
- Method writeMethod = targetPd.getWriteMethod();
-
- try {
- // Diverts from Spring's BeanUtils: if no write method is found and property is collection,
- // try to use addAll() / putAll().
- if (writeMethod == null) {
- Object value = readMethod.invoke(source);
- Method targetReadMethod = targetPd.getReadMethod();
- if (targetReadMethod != null) {
- if (!Modifier.isPublic(targetReadMethod.getDeclaringClass().getModifiers())) {
- targetReadMethod.setAccessible(true);
- }
- Object destValue = targetReadMethod.invoke(target);
-
- if (value instanceof Collection && destValue instanceof Collection) {
- ((Collection) destValue).clear();
- ((Collection) destValue).addAll((Collection) value);
- } else if (value instanceof Map && destValue instanceof Map) {
- ((Map) destValue).clear();
- ((Map) destValue).putAll((Map) value);
- }
- }
- } else if (ClassUtils.isAssignable(
- writeMethod.getParameterTypes()[0], readMethod.getReturnType())) {
-
- if (!Modifier.isPublic(readMethod.getDeclaringClass().getModifiers())) {
- readMethod.setAccessible(true);
- }
- Object value = readMethod.invoke(source);
- if (!Modifier.isPublic(writeMethod.getDeclaringClass().getModifiers())) {
- writeMethod.setAccessible(true);
- }
- writeMethod.invoke(target, value);
- }
- } catch (Throwable ex) {
- throw new FatalBeanException(
- "Could not copy property '" + targetPd.getName() + "' from source to target", ex);
- }
- }
- }
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/syncope/blob/28569df5/core/misc/src/main/java/org/apache/syncope/core/misc/spring/DefaultRolesPrefixPostProcessor.java
----------------------------------------------------------------------
diff --git a/core/misc/src/main/java/org/apache/syncope/core/misc/spring/DefaultRolesPrefixPostProcessor.java b/core/misc/src/main/java/org/apache/syncope/core/misc/spring/DefaultRolesPrefixPostProcessor.java
deleted file mode 100644
index d91a60f..0000000
--- a/core/misc/src/main/java/org/apache/syncope/core/misc/spring/DefaultRolesPrefixPostProcessor.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.syncope.core.misc.spring;
-
-import javax.servlet.ServletException;
-import org.apache.commons.lang3.StringUtils;
-import org.springframework.beans.FatalBeanException;
-import org.springframework.beans.factory.config.BeanPostProcessor;
-import org.springframework.core.PriorityOrdered;
-import org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler;
-import org.springframework.security.web.access.expression.DefaultWebSecurityExpressionHandler;
-import org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter;
-
-/**
- * Removes the limitation of having Spring security roles to be prefixed with 'ROLE_'.
- */
-public class DefaultRolesPrefixPostProcessor implements BeanPostProcessor, PriorityOrdered {
-
- @Override
- public Object postProcessAfterInitialization(final Object bean, final String beanName) {
- if (bean instanceof DefaultMethodSecurityExpressionHandler) {
- ((DefaultMethodSecurityExpressionHandler) bean).setDefaultRolePrefix(null);
- }
- if (bean instanceof DefaultWebSecurityExpressionHandler) {
- ((DefaultWebSecurityExpressionHandler) bean).setDefaultRolePrefix(null);
- }
- if (bean instanceof SecurityContextHolderAwareRequestFilter) {
- SecurityContextHolderAwareRequestFilter filter = (SecurityContextHolderAwareRequestFilter) bean;
- filter.setRolePrefix(StringUtils.EMPTY);
- try {
- filter.afterPropertiesSet();
- } catch (ServletException e) {
- throw new FatalBeanException(e.getMessage(), e);
- }
- }
-
- return bean;
- }
-
- @Override
- public Object postProcessBeforeInitialization(final Object bean, final String beanName) {
- return bean;
- }
-
- @Override
- public int getOrder() {
- return PriorityOrdered.HIGHEST_PRECEDENCE;
- }
-}
http://git-wip-us.apache.org/repos/asf/syncope/blob/28569df5/core/misc/src/main/java/org/apache/syncope/core/misc/spring/DomainTransactionInterceptor.java
----------------------------------------------------------------------
diff --git a/core/misc/src/main/java/org/apache/syncope/core/misc/spring/DomainTransactionInterceptor.java b/core/misc/src/main/java/org/apache/syncope/core/misc/spring/DomainTransactionInterceptor.java
deleted file mode 100644
index e239002..0000000
--- a/core/misc/src/main/java/org/apache/syncope/core/misc/spring/DomainTransactionInterceptor.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.syncope.core.misc.spring;
-
-import java.lang.reflect.Method;
-import org.aopalliance.intercept.MethodInvocation;
-import org.apache.syncope.core.misc.security.AuthContextUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.transaction.interceptor.DefaultTransactionAttribute;
-import org.springframework.transaction.interceptor.TransactionAttribute;
-import org.springframework.transaction.interceptor.TransactionAttributeSource;
-import org.springframework.transaction.interceptor.TransactionInterceptor;
-
-/**
- * Extends the standard {@link TransactionInterceptor} by dynamically setting the appropriate
- * {@link TransactionAttribute} qualifier according to the authentication domain of the caller - retrieved via
- * {@link AuthContextUtils#getDomain()}.
- */
-public class DomainTransactionInterceptor extends TransactionInterceptor {
-
- private static final long serialVersionUID = 5113728988680448551L;
-
- private static final Logger LOG = LoggerFactory.getLogger(DomainTransactionInterceptor.class);
-
- @Override
- public TransactionAttributeSource getTransactionAttributeSource() {
- final TransactionAttributeSource origTxAttrSource = super.getTransactionAttributeSource();
-
- return new TransactionAttributeSource() {
-
- @Override
- public TransactionAttribute getTransactionAttribute(final Method method, final Class<?> targetClass) {
- TransactionAttribute txAttr = origTxAttrSource.getTransactionAttribute(method, targetClass);
-
- if (txAttr instanceof DefaultTransactionAttribute) {
- ((DefaultTransactionAttribute) txAttr).setQualifier(AuthContextUtils.getDomain());
- }
-
- return txAttr;
- }
- };
- }
-
- @Override
- public Object invoke(final MethodInvocation invocation) throws Throwable {
- try {
- return super.invoke(invocation);
- } catch (Throwable e) {
- LOG.debug("Error during {} invocation", invocation.getMethod(), e);
- throw e;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/syncope/blob/28569df5/core/misc/src/main/java/org/apache/syncope/core/misc/spring/DomainTransactionInterceptorInjector.java
----------------------------------------------------------------------
diff --git a/core/misc/src/main/java/org/apache/syncope/core/misc/spring/DomainTransactionInterceptorInjector.java b/core/misc/src/main/java/org/apache/syncope/core/misc/spring/DomainTransactionInterceptorInjector.java
deleted file mode 100644
index d9d772b..0000000
--- a/core/misc/src/main/java/org/apache/syncope/core/misc/spring/DomainTransactionInterceptorInjector.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.syncope.core.misc.spring;
-
-import org.springframework.beans.BeansException;
-import org.springframework.beans.factory.config.BeanDefinition;
-import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
-import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
-import org.springframework.transaction.interceptor.TransactionInterceptor;
-
-/**
- * Replaces Spring's {@link TransactionInterceptor} with {@link DomainTransactionInterceptor}.
- */
-public class DomainTransactionInterceptorInjector implements BeanFactoryPostProcessor {
-
- @Override
- public void postProcessBeanFactory(final ConfigurableListableBeanFactory beanFactory) throws BeansException {
- BeanDefinition bd = beanFactory.getBeanDefinition(TransactionInterceptor.class.getName() + "#0");
- bd.setBeanClassName(DomainTransactionInterceptor.class.getName());
- }
-
-}
http://git-wip-us.apache.org/repos/asf/syncope/blob/28569df5/core/misc/src/main/java/org/apache/syncope/core/misc/spring/ResourceWithFallbackLoader.java
----------------------------------------------------------------------
diff --git a/core/misc/src/main/java/org/apache/syncope/core/misc/spring/ResourceWithFallbackLoader.java b/core/misc/src/main/java/org/apache/syncope/core/misc/spring/ResourceWithFallbackLoader.java
deleted file mode 100644
index 0fdc116..0000000
--- a/core/misc/src/main/java/org/apache/syncope/core/misc/spring/ResourceWithFallbackLoader.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.syncope.core.misc.spring;
-
-import java.io.IOException;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.commons.lang3.ArrayUtils;
-import org.springframework.context.ResourceLoaderAware;
-import org.springframework.core.io.Resource;
-import org.springframework.core.io.ResourceLoader;
-import org.springframework.core.io.support.ResourcePatternResolver;
-
-public class ResourceWithFallbackLoader implements ResourceLoaderAware, ResourcePatternResolver {
-
- private ResourcePatternResolver resolver;
-
- private String primary;
-
- private String fallback;
-
- @Override
- public void setResourceLoader(final ResourceLoader resourceLoader) {
- this.resolver = (ResourcePatternResolver) resourceLoader;
- }
-
- public void setPrimary(final String primary) {
- this.primary = primary;
- }
-
- public void setFallback(final String fallback) {
- this.fallback = fallback;
- }
-
- @Override
- public Resource getResource(final String location) {
- Resource resource = resolver.getResource(primary + location);
- if (!resource.exists()) {
- resource = resolver.getResource(fallback + location);
- }
-
- return resource;
- }
-
- public Resource getResource() {
- return getResource(StringUtils.EMPTY);
- }
-
- @Override
- public Resource[] getResources(final String locationPattern) throws IOException {
- Resource[] resources = resolver.getResources(primary + locationPattern);
- if (ArrayUtils.isEmpty(resources)) {
- resources = resolver.getResources(fallback + locationPattern);
- }
-
- return resources;
- }
-
- public Resource[] getResources() throws IOException {
- return getResources(StringUtils.EMPTY);
- }
-
- @Override
- public ClassLoader getClassLoader() {
- return resolver.getClassLoader();
- }
-}
http://git-wip-us.apache.org/repos/asf/syncope/blob/28569df5/core/misc/src/main/java/org/apache/syncope/core/misc/utils/ConnObjectUtils.java
----------------------------------------------------------------------
diff --git a/core/misc/src/main/java/org/apache/syncope/core/misc/utils/ConnObjectUtils.java b/core/misc/src/main/java/org/apache/syncope/core/misc/utils/ConnObjectUtils.java
deleted file mode 100644
index 667a28e..0000000
--- a/core/misc/src/main/java/org/apache/syncope/core/misc/utils/ConnObjectUtils.java
+++ /dev/null
@@ -1,267 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.syncope.core.misc.utils;
-
-import org.apache.syncope.core.misc.policy.InvalidPasswordRuleConf;
-import org.apache.syncope.core.misc.security.SecureRandomUtils;
-import java.util.ArrayList;
-import java.util.List;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.syncope.common.lib.AnyOperations;
-import org.apache.syncope.common.lib.patch.AnyPatch;
-import org.apache.syncope.common.lib.policy.PasswordRuleConf;
-import org.apache.syncope.common.lib.to.AnyObjectTO;
-import org.apache.syncope.common.lib.to.AnyTO;
-import org.apache.syncope.common.lib.to.AttrTO;
-import org.apache.syncope.common.lib.to.ConnObjectTO;
-import org.apache.syncope.common.lib.to.GroupTO;
-import org.apache.syncope.common.lib.to.UserTO;
-import org.apache.syncope.core.persistence.api.dao.ExternalResourceDAO;
-import org.apache.syncope.core.persistence.api.dao.UserDAO;
-import org.apache.syncope.core.persistence.api.entity.AnyUtils;
-import org.apache.syncope.core.persistence.api.entity.resource.ExternalResource;
-import org.apache.syncope.core.persistence.api.entity.resource.MappingItem;
-import org.apache.syncope.core.persistence.api.entity.task.SyncTask;
-import org.apache.syncope.core.persistence.api.entity.user.User;
-import org.apache.syncope.core.misc.security.Encryptor;
-import org.apache.syncope.core.misc.security.PasswordGenerator;
-import org.apache.syncope.core.persistence.api.dao.RealmDAO;
-import org.apache.syncope.core.persistence.api.entity.Realm;
-import org.apache.syncope.core.persistence.api.entity.resource.Provision;
-import org.identityconnectors.common.Base64;
-import org.identityconnectors.common.security.GuardedByteArray;
-import org.identityconnectors.common.security.GuardedString;
-import org.identityconnectors.framework.common.objects.Attribute;
-import org.identityconnectors.framework.common.objects.ConnectorObject;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
-import org.springframework.transaction.annotation.Transactional;
-
-@Component
-public class ConnObjectUtils {
-
- private static final Logger LOG = LoggerFactory.getLogger(ConnObjectUtils.class);
-
- private static final Encryptor ENCRYPTOR = Encryptor.getInstance();
-
- @Autowired
- private TemplateUtils templateUtils;
-
- @Autowired
- private RealmDAO realmDAO;
-
- @Autowired
- private UserDAO userDAO;
-
- @Autowired
- private ExternalResourceDAO resourceDAO;
-
- @Autowired
- private PasswordGenerator passwordGenerator;
-
- @Autowired
- private MappingUtils mappingUtils;
-
- /**
- * Extract password value from passed value (if instance of GuardedString or GuardedByteArray).
- *
- * @param pwd received from the underlying connector
- * @return password value
- */
- public static String getPassword(final Object pwd) {
- final StringBuilder result = new StringBuilder();
-
- if (pwd instanceof GuardedString) {
- ((GuardedString) pwd).access(new GuardedString.Accessor() {
-
- @Override
- public void access(final char[] clearChars) {
- result.append(clearChars);
- }
- });
- } else if (pwd instanceof GuardedByteArray) {
- ((GuardedByteArray) pwd).access(new GuardedByteArray.Accessor() {
-
- @Override
- public void access(final byte[] clearBytes) {
- result.append(new String(clearBytes));
- }
- });
- } else if (pwd instanceof String) {
- result.append((String) pwd);
- } else {
- result.append(pwd.toString());
- }
-
- return result.toString();
- }
-
- /**
- * Build a UserTO / GroupTO / AnyObjectTO out of connector object attributes and schema mapping.
- *
- * @param obj connector object
- * @param syncTask synchronization task
- * @param provision provision information
- * @param anyUtils utils
- * @param <T> any object
- * @return UserTO for the user to be created
- */
- @Transactional(readOnly = true)
- public <T extends AnyTO> T getAnyTO(
- final ConnectorObject obj, final SyncTask syncTask, final Provision provision, final AnyUtils anyUtils) {
-
- T anyTO = getAnyTOFromConnObject(obj, syncTask, provision, anyUtils);
-
- // (for users) if password was not set above, generate
- if (anyTO instanceof UserTO && StringUtils.isBlank(((UserTO) anyTO).getPassword())) {
- final UserTO userTO = (UserTO) anyTO;
-
- List<PasswordRuleConf> ruleConfs = new ArrayList<>();
-
- Realm realm = realmDAO.find(userTO.getRealm());
- if (realm != null) {
- for (Realm ancestor : realmDAO.findAncestors(realm)) {
- if (ancestor.getPasswordPolicy() != null) {
- ruleConfs.addAll(ancestor.getPasswordPolicy().getRuleConfs());
- }
- }
- }
-
- for (String resName : userTO.getResources()) {
- ExternalResource resource = resourceDAO.find(resName);
- if (resource != null && resource.getPasswordPolicy() != null) {
- ruleConfs.addAll(resource.getPasswordPolicy().getRuleConfs());
- }
- }
-
- String password;
- try {
- password = passwordGenerator.generate(ruleConfs);
- } catch (InvalidPasswordRuleConf e) {
- LOG.error("Could not generate policy-compliant random password for {}", userTO, e);
-
- password = SecureRandomUtils.generateRandomPassword(16);
- }
- userTO.setPassword(password);
- }
-
- return anyTO;
- }
-
- /**
- * Build {@link AnyPatch} out of connector object attributes and schema mapping.
- *
- * @param key any object to be updated
- * @param obj connector object
- * @param original any object to get diff from
- * @param syncTask synchronization task
- * @param provision provision information
- * @param anyUtils utils
- * @param <T> any object
- * @return modifications for the any object to be updated
- */
- @SuppressWarnings("unchecked")
- @Transactional(readOnly = true)
- public <T extends AnyPatch> T getAnyPatch(final Long key, final ConnectorObject obj,
- final AnyTO original, final SyncTask syncTask, final Provision provision, final AnyUtils anyUtils) {
-
- AnyTO updated = getAnyTOFromConnObject(obj, syncTask, provision, anyUtils);
- updated.setKey(key);
-
- if (null != anyUtils.getAnyTypeKind()) {
- switch (anyUtils.getAnyTypeKind()) {
- case USER:
- // update password if and only if password is really changed
- User user = userDAO.authFind(key);
- if (StringUtils.isBlank(((UserTO) updated).getPassword())
- || ENCRYPTOR.verify(((UserTO) updated).getPassword(),
- user.getCipherAlgorithm(), user.getPassword())) {
-
- ((UserTO) updated).setPassword(null);
- }
- return (T) AnyOperations.diff(((UserTO) updated), ((UserTO) original), true);
-
- case GROUP:
- return (T) AnyOperations.diff(((GroupTO) updated), ((GroupTO) original), true);
-
- case ANY_OBJECT:
- return (T) AnyOperations.diff(((AnyObjectTO) updated), ((AnyObjectTO) original), true);
-
- default:
- }
- }
-
- return null;
- }
-
- private <T extends AnyTO> T getAnyTOFromConnObject(final ConnectorObject obj,
- final SyncTask syncTask, final Provision provision, final AnyUtils anyUtils) {
-
- T anyTO = anyUtils.newAnyTO();
- anyTO.setType(provision.getAnyType().getKey());
-
- // 1. fill with data from connector object
- anyTO.setRealm(syncTask.getDestinatioRealm().getFullPath());
- for (MappingItem item : MappingUtils.getSyncMappingItems(provision)) {
- mappingUtils.setIntValues(item, obj.getAttributeByName(item.getExtAttrName()), anyTO, anyUtils);
- }
-
- // 2. add data from defined template (if any)
- templateUtils.apply(anyTO, syncTask.getTemplate(provision.getAnyType()));
-
- return anyTO;
- }
-
- /**
- * Get connector object TO from a connector object.
- *
- * @param connObject connector object.
- * @return connector object TO.
- */
- public ConnObjectTO getConnObjectTO(final ConnectorObject connObject) {
- final ConnObjectTO connObjectTO = new ConnObjectTO();
-
- if (connObject != null) {
- for (Attribute attr : connObject.getAttributes()) {
- AttrTO attrTO = new AttrTO();
- attrTO.setSchema(attr.getName());
-
- if (attr.getValue() != null) {
- for (Object value : attr.getValue()) {
- if (value != null) {
- if (value instanceof GuardedString || value instanceof GuardedByteArray) {
- attrTO.getValues().add(getPassword(value));
- } else if (value instanceof byte[]) {
- attrTO.getValues().add(Base64.encode((byte[]) value));
- } else {
- attrTO.getValues().add(value.toString());
- }
- }
- }
- }
-
- connObjectTO.getPlainAttrs().add(attrTO);
- }
- }
-
- return connObjectTO;
- }
-}